need to extract rgb value of image in the format [r g b]
2 views (last 30 days)
Show older comments
i need to extract rgb value of any image in the format of [R G B]. I am using getimage() but I am getting error
??? Error using ==> getimage>parseInputs at 217 GETIMAGE: Invalid handle H.
Error in ==> getimage at 86 him = parseInputs(varargin{:});
please suggest.
0 Comments
Accepted Answer
Matt Fig
on 4 May 2011
Somehow you don't have the image handle. So try this:
IH = findall(0,'type','image');
IM = getimage(IH);
6 Comments
Matt Fig
on 5 May 2011
Ahh, but that is the problem!
It sounds like you are passing a filename to GETIMAGE, which is not correct. GETIMAGE takes a handle to an image object, not an image filename. Here I will make an example which shows what each function returns.
Image_data = imread('myimage.jpg'); % For example
Image_handle = image(Image_data); % Or IMSHOW
Image_info = getimage(Image_handle);
More Answers (1)
Teja Muppirala
on 5 May 2011
If you have a RGB image that is [m x n x 3], you can use the RESHAPE command to give you the columns as [r g b]:
I = imread('peppers.png'); % Read in a sample image
size(I)
I2 = reshape(I,[],3);
size(I2)
Now I2 is of the form [R G B] and has size [(m x n) 3]
1 Comment
Teja Muppirala
on 5 May 2011
By the way, when you were using GETIMAGE, where you perhaps trying to do something like this?
getimage('somefile.jpg')
This is not correct. The GETIMAGE command is not for reading in files, and so you will get an error if you try this. As you stated, IMREAD is the correct command.
See Also
Categories
Find more on Convert Image Type 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!