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
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 ?
采纳的回答
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
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!