MATLAB: How to pick all RGB values inside a region of interest

Image Processing Toolboximage segmentationmaskmaskingrgb

I define the region of interest by h = imfreehand. After that I need to pick all the RGB values inside the specified region.

Best Answer

From your description my understanding is you would like to select a region of your interest and then to get the pixel value of all the points bounded by the region. You can create a binary mask for the bounded region of interest and then get all the coordinates. Finally we can get all the pixel of that region using the function 'impixel'.
The following code illustrates how to achieve this:
>> i=imshow('sampleimg.png')
>> h=imfreehand(gca)
>> roi=createMask(h);
>> [row,col]=find(roi);
>> i1=imread('sampleimg.png');
>> RGBpixels=impixel(i1,col,row)
For more details the functions 'createMask' and 'impixel', refer to the following links: