필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Tweety
Tweety 2015년 12월 8일
댓글: Image Analyst 2018년 9월 23일
I define the region of interest by h = imfreehand. After that I need to pick all the RGB values inside the specified region.

채택된 답변

Arnab Sen
Arnab Sen 2015년 12월 28일
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:
  댓글 수: 4
Zahara
Zahara 2016년 2월 15일
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!
Z
Image Analyst
Image Analyst 2018년 9월 23일
Get the values from your image with a mask:
[rows, columns] = size(grayImage);
mask = poly2mask(x, y, rows, columns);
imageValues = grayImage(mask);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nuttawut Yeenang
Nuttawut Yeenang 2018년 9월 23일
Thank you

Community Treasure Hunt

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

Start Hunting!

Translated by