MATLAB Answers

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

4 views (last 30 days)
Steven on 14 Dec 2013
Commented: Steven on 14 Dec 2013
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


Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Dec 2013
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.


Steven on 14 Dec 2013
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.
Walter Roberson
Walter Roberson on 14 Dec 2013
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):

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 14 Dec 2013
If im is your image, write

  1 Comment

Walter Roberson
Walter Roberson on 14 Dec 2013
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.

Community Treasure Hunt

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

Start Hunting!