need to extract rgb value of image in the format [r g b]

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.

 Accepted Answer

Somehow you don't have the image handle. So try this:
IH = findall(0,'type','image');
IM = getimage(IH);

6 Comments

still not working. could you please give me alternative code for this
Wow, that is one fast mouse click. What does the call to FINDALL return? If it returns [], then I am afraid you don't have an image to pass to GETIMAGE. Are you trying to pass an array to GETIMAGE? Because an array is not an image object. An image object is returned from, for example:
IH = image(A);% Where A is an array.
same image name is iving me results with imread() but fails with getimage..!!!!.can we use imread() to give results like [r g b] value in a simple vector matrix. because it is showing results in te format of m x n x 3.
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);
thank you it really helped.

Sign in to comment.

More Answers (1)

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

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.

Sign in to comment.

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!