Clear Filters
Clear Filters

How can I pick all RGB values inside a region of interest?

5 views (last 30 days)
I define the region of interest by h = imfreehand. After that I need to pick all the RGB values inside the specified region.

Accepted Answer

Arnab Sen
Arnab Sen on 28 Dec 2015
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:
Zahara on 15 Feb 2016
Hi there,
I have a similar problem. I have been trying to sort this out for a few days... I need help :). I have an image, I created a region of interest based on xp=[x1 x2 x3 x4] and yp=[y1 y2 y3 y4]. The region of interest is kind of curvy, as it follows a pattern.
I'd like to get the information from inside this region of interest. For the sake of automation, I wouldn't like to use imfreehand. I have to do this for many regions on interest. Instead, I calculated the line which join the points as a squarish region of interest. Fed the point, which belong to each line as col and row values for impixel.When I compare what I would get using imfreehand and my method...No luck!
I've tried imcrop also but because the region of interest is angled and a bit curvy, it would do the trick.
Any advice to point me on the right direction would be appreciate it.
Thanks a lot!
Image Analyst
Image Analyst on 23 Sep 2018
Get the values from your image with a mask:
[rows, columns] = size(grayImage);
mask = poly2mask(x, y, rows, columns);
imageValues = grayImage(mask);

Sign in to comment.

More Answers (1)

Nuttawut Yeenang
Nuttawut Yeenang on 23 Sep 2018
Thank you

Community Treasure Hunt

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

Start Hunting!