JPG to RGB image?

I'm using a method that requires an rgb image as input. I tried
[cdata,map] = imread('face.jpg' )
cdata = ind2rgb( cdata, map );
to get that rgb image in cdata. However, map is always empty, no matter what image I try (jpg, tif, or bmp), resulting in the error "Index exceeds matrix dimensions." cdata is an mxnx3 matrix, I expected it to be just an mxn matrix?
I have no idea how to get my rgb image. Any help would be greatly appreciated!

Answers (2)

David Young
David Young on 5 Dec 2011

0 votes

JPEG images are read directly as rgb - so there's no map. So you don't need the call to ind2rgb (or the second result from imread). The reason the third dimension of cdata is 3 is that it is already rgb.
Tessa
Tessa on 5 Dec 2011
I was afraid so. That probably means the method I'm trying to use is corrupt. It includes this line:
if (not (ismatrix(im)) || not (ndims (im) == 3))
error ('Argument 1 (im) must be a RGB image')
end
Now, how I understand it, ismatrix(im) includes
if (not(ndims (im) == 2))
ret = 0;
end
This means that my original error check will return an error in all cases right? Because ismatrix will return false on all rgb images?

1 Comment

David Young
David Young on 5 Dec 2011
The expression
(not (ismatrix(im)) || not (ndims (im) == 3))
is true for all values of im. It doesn't matter what im is, the function will always throw an error.
I guess you should probably just omit the first part of the test, so you have
if not(ndims(im) == 3)

Sign in to comment.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Asked:

on 5 Dec 2011

Community Treasure Hunt

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

Start Hunting!