Creating RGB images from .Mat arrays with imaginary entries

I have a series of .mat files which contain raw image data that is unscaled and contains imaginary entries. I can display these images by loading the .mat and then using imagesc(abs(file(:,:,#))); where # indicates a single positive integer. This properly displays the scaled image, but I cannot do any operations on the image. Creating a handle such as img1 = imagesc(...) and then using imwrite to create an RGB image does not work and imread tells me that I need to imput a string as the target but then I cannot get the modulus with abs or reference a single 2-d array, which results in a matrix dimensions error. What is the best way to read from a .mat slice and convert it to a scaled rgb image?

Answers (2)

You could extract just the real components using:
doc real
or just the imaginary ones using
doc imag
E.g.
Irgbreal = real(Irgb);

6 Comments

I tried this:
Irgbreal = real(file(:,:,5)) (where file is the .mat file
then I looked at the image using both image and imagesc and both displayed the image with very distorted colors so something is being lost.
That's a good reason to avoid both of those!
Do you have the Image Processing Toolbox?
If so:
imtool(Irgbreal);
%You can adjust the contrasts and the values are the pixel intensities, not pseudocoloring.
What does the imaginary component look like? Do you need to do some operation on the two components?
And pulling just file(:,:,5) will be gray scale 2-dimensional.
In order to have it be RGB, you need an R&G&B component: e.g. file(:,:,1:3);%1->R,2->G,3->B
btw I can get the values using
Irgbreal = abs(file(:,:,5));
and then imagesc displays the image correctly. I guess what I'm trying to do is scale the values in this matrix so that I can write it to a usable image file. If I use
imwrite(Irgbreal, 'RGBimg.jpg')
I have get a very very color-distorted image that has only a few dots (I assume this is because most of the values exceed 255)
for my .mat file, (:,:,5) is an rgb image, not a gray scale
No it is not. If you are pulling just one slice of it, it has no G/B components. You may be visualizing it as an RGB image with some pseudocolor, but it does not have enough information to be RGB.

Sign in to comment.

I just figured out that the matrix file(:,:,#) is actually an intensity map that is just being colormapped (red corresponding to highest values, blue to lowest) by imagesc, but I am still stuck on converting this to a usable image file. I suppose the easiest thing would be to use the intensity map to give a grayscale image. How should I go about that. Sorry I'm not very familiar with Matlab as is probably obvious.

2 Comments

I would leave it as grayscale unless you need to impress some lawyers or politicians ;)
The intensity map is the information you have so you might as well view it as such in grayscale.
well I need to eventually be able to segment the image, so I guess I'll just drag along the intensity map after using abs to get rid of the imaginary values, then use imfilter, etc. for gradient mapping.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 19 May 2011

Community Treasure Hunt

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

Start Hunting!