MATLAB Answers


.dat file image generation and analysis

Asked by David Comiskey on 9 Sep 2019
Latest activity Commented on by Neuropragmatist on 9 Sep 2019
I have a current need to undertake image analysis and have the following query. I have .dat file containing an industrial X-Ray image with 16 bit greyscale range values. The .dat file contains values for each pixel in the 250 x 439 image size. My question, as a non-user and novice in this area, is if Matlab can be used to create a visual image from the .dat file and be used for analysis? Any links or suggested learning documentation in this area would be most welcome.


Sign in to comment.


1 Answer

Answer by Neuropragmatist on 9 Sep 2019
 Accepted Answer

Matlab has countless ways to visualise images loaded into the workspace.
The problem with your file is that .dat sounds like a generic file type and Matlab won't know how to load it. Do you know if the file has an underlying file type like .tiff? Or can you convert your .dat file to an image or text file? What program do you normally use to view your .dat files?
If you upload one of your files we might be able to take a closer look.


OK, I was expecting to have to go digging around but the first thing I tried actually worked. I just passed the file to Matlab's inbuilt 'importdata' function and it does fine to load your file. From there plotting it is really easy:
img = importdata('Ulster Univ Cladding _Insul Samples_20_summed.dat');
% img is a matrix that seems to just be your image
% some plotting routines
imagesc(img) % imagesc is the easiest and one of the most commonly used
daspect([1 1 1])
colormap(gca,gray) % using a gray colormap for grayscale makes sense
caxis([intmin('uint16') intmax('uint16')]) % I scale the colormap for what should be
% the min and max value of your image (min possible uint16 value to max possible uint16 value)
title('imagesc, gray')
daspect([1 1 1])
title('imagesc, jet') % same thing as above with the more fondly used jet colormap
caxis([intmin('uint16') intmax('uint16')])
imshow(img,[intmin('uint16') intmax('uint16')]) % imshow is a similar function
daspect([1 1 1])
title('imshow for uint16')
I've included just a couple of different ways to plot the data here, I'll let you explore around for what suits you best.
Hope this helps,
Edit: also I just remembered that you mentioned image analysis. In the code above 'img' is a matrix that contains your x-ray image. In the above code I have just plotted it graphically, but you can also apply image analysis techniques to this matrix if you like:
Thanks so much, that is perfect. It gives me confidence that this is the way to go. Time to get trained up in Matlab!
Cool, glad to help.

Sign in to comment.