JPG to RGB image?
Show older comments
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
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
on 5 Dec 2011
1 Comment
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)
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!