Using RegionProps for User-Defined ROI

I would like to use the "regionprops" function on a user-defined ROI from an image (The image is the output from my code which detects circular objects from the entire image using "regionprops" and "viscircles" documentation ) in order to plot a histogram that plots the frequencies of the diameters of the circular objects ONLY within the user-defined ROI. I was experimenting with some cropping documentation but was having a bit of trouble. Would someone be able to provide me with any recommendations for documentation to experiment with to allow the "regionprops" function to use the user-defined ROI? I have attached a sample output image that I would like the user to define their own ROI from and generate the histogram.

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 12 月 23 日

0 投票

The first parameter to regionprops() needs to be a BW (binary) or CC (connected component) or L (label matrix), but the second parameter can be the image data.
You would apply the user ROI to the BW or CC or L first.
If you binarized the image, then convert the user ROI to a mask (such as with roi2mask) and "and" it with the binary image.

5 件のコメント

Michael DiStefano
Michael DiStefano 2020 年 12 月 23 日
Thank you for your response and I will certainly incorporate your recommendations. As a follow up, prior to posting my original post, I had gotten to the point where my code allows the user to draw their ROI from the image I had provided and then marked the centroids of the circular objects within the user-defined ROI (See attached "ImageROI" image file). Is there any possible way I would be able to use any functions to outline the ROI circular objects in a different color and then measure the diameters of the circles only within the yellow "ROI" region that have their centroids marked with the yellow crosses? Or is using regionprops method you outlined in your post the ideal path to follow? Thank you.
Walter Roberson
Walter Roberson 2020 年 12 月 23 日
Is the user marking the center of each of those circles, or are you locating them in your code and you are just plotting them here to point out which of the circles you want to be affected?
Michael DiStefano
Michael DiStefano 2020 年 12 月 23 日
編集済み: Michael DiStefano 2020 年 12 月 23 日
Thank you for your response. The code is plotting the centroids based upon the polygon ROI the user had drawn using the inpolygon function. Just to note, the viscircles function below is detecting all of the circles in the image. I've added the specific portion of code that executes this step below:
ROI = drawpolygon('Color','y');
pospoly = get(ROI,'Position');
P1 = pospoly(:,1);
P2 = pospoly(:,2);
rows = size(imread(file),1);
columns = size(imread(file),2);
C1 = centroids(:,1);
C2 = centroids(:,2);
imshow(imread(file))
hold on
plot(C1,C2,'b*')
viscircles(centroids, diameters/2);
[insideROI edgeROI] = inpolygon(C1, C2 , P1, P2);
axis equal
hold on
C1_in = C1(insideROI);
C2_in = C2(insideROI);
plot(C1_in, C2_in,'y+')
Walter Roberson
Walter Roberson 2020 年 12 月 23 日
viscircles does not detect anything: it only draws circles.
Where is centroids and diameters coming from? Whatever is creating those is what is detecting the circles.
Michael DiStefano
Michael DiStefano 2020 年 12 月 23 日
I apologzie, I meant to say draw. The centroids and diameters are coming from a regionprops that I use for the entire image in a previous portion of the code. I want to be able to allow the user to outline an ROI based on the region of circular objects within the image that are outlined with greatest precision (which is determined from the regionprops/viscircles-generated image in my original post that has all of the circles outlined).

サインインしてコメントする。

質問済み:

2020 年 12 月 22 日

コメント済み:

2020 年 12 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by