Removing unwanted object using regionprops
6 次查看(过去 30 天)
显示 更早的评论
I have used function below, how can I change the pixel inside the boundary which the value less than threshold(0.8) to be 0(black)? Means that, I want to remove all objects which value less than 0.80. In my picture there are 7 objects, only two objects that I want it to maintain which has value of 0.96 and 0.84. I have tried add several line of command but failed. here the image that I means: http://www.flickr.com/photos/64698236@N03/6006901788/in/photostream
here the command that i used for regionprops:
[B,L] = bwboundaries(image7,'noholes');
% Display the label matrix and draw each boundary imshow(label2rgb(L, @jet, [.5 .5 .5])) hold on for k = 1:length(B) boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2) end
stats = regionprops(L,'Area','Centroid');
threshold = 0.80;
% loop over the boundaries for k = 1:length(B)
% obtain (X,Y) boundary coordinates corresponding to label 'k' boundary = B{k};
% compute a simple estimate of the object's perimeter delta_sq = diff(boundary).^2; perimeter = sum(sqrt(sum(delta_sq,2)));
% obtain the area calculation corresponding to label 'k' area = stats(k).Area;
% compute the roundness metric metric = 4*pi*area/perimeter^2;
% display the results metric_string = sprintf('%2.2f',metric);
% mark objects above the threshold with a black circle if metric > threshold centroid = stats(k).Centroid; plot(centroid(1),centroid(2),'ko'); end
if metric < threshold L(i,j)=0; end
text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',... 'FontSize',14,'FontWeight','bold');
end
Thank you in advance.
0 个评论
回答(2 个)
Image Analyst
2011-8-12
You don't even need bwboundaries or regionprops to get rid of pixels with a value of 0.8 or less. Just try something like (untested):
mask = image7 > 0.8
mask = cast(mask, class(image7));
outputImage = mask .* image7;
Image Analyst
2011-8-19
There is nothing in the image that I can see that relates to the arbitrary text labels stuck next to your colored blobs. Not area, not intensity, not location, nothing. If you labeled and pseudocolored your blobs, then you can't do that - you'll have to work with the original grayscale image if the 0.8 is some kind of intensity value. Otherwise if you're dealing with this colored image you'll have to do something real ad hoc, such as getting rid of blobs based on their exact color rather than using the value 0.8 at all. Same thing if you use the labeled image - you'll just have to use the known label numbers of those blobs you want to remove rather than any sort of automatic removal process based on the value 0.8.
3 个评论
Harini Ramasamy
2018-2-16
how to calculate the number of similar metric value within some range for example if i had a many range of roundness value then how to calculte the number of similar range of roundness like from .2 to .8
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!