.dat file image generation and analysis

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.

 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.
M.

8 Comments

Thanks for your answer. I am not aware of the underlying file type - I am hoping to be able to convert the contents of the .dat file to an image.
What the .dat contains is 16-bit greyscale values for each pixel in an X-Ray image. I am wanting to convert this from a collection of numeric values into an image which can be viewed. I have attached one of the .dat files.
I don't see the file David, where did you upload it?
M.
Apologies, please see previous comment with hyperlink now shown.
Hi David, I think you have uploaded that to your university (OneDrive?) directory, which I don't have access to. You will have to either make it accessible to people outside your campus and university network or upload it somewhere else, like Google drive.
Or just click 'attachments' when you are writing a comment and upload it directly on this site.
M.
The above link shoud work as the access preferences have been amended. It wont allow me up attach a .dat file for some reason!
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
figure
subplot(2,2,1)
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')
subplot(2,2,2)
imagesc(img)
daspect([1 1 1])
colormap(gca,jet)
title('imagesc, jet') % same thing as above with the more fondly used jet colormap
caxis([intmin('uint16') intmax('uint16')])
subplot(2,2,3)
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,
M.
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.
M.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!