What happens when an image is first edited in Paint and then processed in Matlab?

When I open an existing image (TIF) with Paint and do some corrections and save it, and open it with MATLAB, it gives me the error of exceeding dimension! Why? What happens in Paint? I checked it and see it turns a 2D image into 3D! why and how? How can I correct it? If I need to do some modifications in Paint before going to Matlab, what should I do to keep the dimensions?
Thanks so much. Steven

 Accepted Answer

If the corrections were done in color, it would need to change it to RGB, which involves a 3D array.
If the corrections are in grayscale, it is possible that Paint is choosing to write the file in RGB anyhow. It has been a long long time since I used Paint, so I do not know if there is some option you could use for grayscale output.
If Paint is changing it to an RGB image, then you can apply rgb2gray() to it to change it back to grayscale.

3 Comments

Thanks Walter!
I tried that but I get this error:
RGB must be a m x n x 3 array.
>> size(image)
ans =
930 768 4
what does that mean? Has Paint saved it as 4D?! I checked the size and it is here. what do you think? Thanks.
If it shows up as N x M x 4 then it is saved as CMYK. In some of the other file formats one might guess it would be RGBA, but TIFF RGBA need special reading procedures and the x 4 is specifically documented for CMYK for TIFF files.
To do the conversion to RGB see the following (and just don't do the grayscale conversion): http://www.mathworks.com/matlabcentral/answers/96767-how-can-i-convert-my-4-channel-cmyk-image-data-to-gray-scale-for-image-processing

Sign in to comment.

More Answers (1)

If im is your image, write
im=im(:,:,1)

1 Comment

If the file stored CMYK and the image is grayscale, you could try extracting im(:,:,4) . I am seeing discussions indicating that there may be some shifts if that is done.

Sign in to comment.

Asked:

on 14 Dec 2013

Commented:

on 14 Dec 2013

Community Treasure Hunt

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

Start Hunting!