I want to count the number of metric elements in if statement using 'sum', but it shown all the content of elements, not the number. I'm new.. pls help..
3 views (last 30 days)
Show older comments
setiawandika
on 15 Nov 2013
Commented: setiawandika
on 15 Nov 2013
here the code
stats = regionprops(L,'Area','Centroid', 'BoundingBox');
threshold = 0.88;
for k = 1:length(B)
boundary = B{k};
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
area = stats(k).Area;
metric = 4*pi*area/perimeter^2;
metric_string = sprintf('%2.2f',metric);
if metric >= threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
as = sum(metric);
end
end
0 Comments
Accepted Answer
Image Analyst
on 15 Nov 2013
Way too clumsy. Try something like this (untested):
stats = regionprops(L,'Area','Centroid', 'Perimeter');
allAreas = [stats.Area];
allPerimeters = [stats.Perimeter];
circularities = (4*pi*allAreas) ./ allPerimeters.^2; % Inverted compared to how I use it.
threshold = 0.88;
roundObjects = circularities > threshold;
as = sum(circularities(roundObjects));
More Answers (0)
See Also
Categories
Find more on Frequency Transformations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!