How to detect the shape in specifiv region in image?

3 次查看(过去 30 天)
Excuse me, I have a question.
I have an image with various object but I want to detect some objects in some specific regions.
In the attached image, I want specify the red box region and detect the object in the green circle inside the red box.
I want to detect the region because the program detect many of undesired object outside the red box.
Could anyone help me with that? It would be greatful if you can give some source code of demo code.
Thank you in advance.
  2 个评论
Walter Roberson
Walter Roberson 2022-10-21
Will the red box be already part of the image? And the location of the red box needs to be found in the image, and then object detection is to take place only inside the region?
Or will the image have no markings on it and you will be using ginput to ask the user to point to corners of the region?
Or will the image have no markings on it and you will be using drawrectangle to create a rectangular ROI ?
Chanoknunt Sangsobhon
Both the red boxes and green circle are not parts of the image. The image have no marking. The location of the red boxes needs to be found, and the object detection will take place inside them.
I want this to run automatically because there are about hundreds of similar images to be process.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2022-10-21
You can specify a region of interest with drawrectangle. See attached example. Now that you have a rectangular region of interest identified in the image, extraction of the information or objects inside that region depends on what you want to measure. For example, you could just take the mean gray level. Or you could threshold the image and count the number of bright blobs and find their areas and brightnesses with regionprops. Or whatever, but it's totally dependent on how you define the things you're interested in.
Why don't you start with my Image Segmentation Tutorial in my File Exchange
  3 个评论
Image Analyst
Image Analyst 2022-10-25
STATS is an array of structures. Each structure has fields which are the measurements you asked regionprops to make. For example to get the area of blob #3 you can do
area3 = STATS(3).Area;
To get the areas of all the blobs you can do
allAreas = [props.Area]
BoundingBox is a 4 element vector with the values [xLeft, yTop, width, height]. To get them all into a matrix, you can (optionally) do this
bb = vertcat(props.BoundingBox);
xLefts = bb(:, 1);
ytops = bb(:, 2);
allWidths = bb(:, 3);
allHeights = bb(:, 4);
The centroid field is (xCentroid, yCentroid). If you want them all with x in column1 and y in column 2 you can do
xyCentroid = vertcat(STATS.Centroid);
or you can ask regionprops to return the values in a table instead of a structure array.
Chanoknunt Sangsobhon
Thank you so much. I understood now. Your explanation is very helpful.
Sorry to bother you again but I have 1 more question. I have seen more of your demo for image masking and followed them. I tried to masking the image outside the ROI but the masking area outside the region is not black.
The code I used was
blackMaskedImage = originalImage;
blackMaskedImage(~cumulativeBinaryImage) = 0;
imshow(blackMaskedImage);
Thank you in advanced

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by