How can i count the sum of the gray level value in a segmented region
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I was segmented an image with level set method now i should calculte the sum of all the gray level values in this region which is represented in blue in the picture below
</matlabcentral/answers/uploaded_files/115557/30.bmp> thank you in advance
0 commentaires
Réponses (1)
Rik
le 10 Juin 2018
The code below should work
IM=double(imread('corn.tif',3))/255;
polygon_x=[109;142;166;178;155;131;112;124;125;116;102;82;67;74;90;109];
polygon_y=[159;147;163;191;220;239;227;206;189;180;185;199;191;166;158;159];
[X,Y]=meshgrid(1:size(IM,2),1:size(IM,1));
in=inpolygon(X(:),Y(:),polygon_x,polygon_y);
IM_part=IM;IM_part(~in)=0;
sum_of_masked_area=sum(IM_part(:));
figure(1),clf(1)
subplot(1,2,1)
imshow(IM)
hold on
plot(polygon_x,polygon_y)
title('original gray scale image')
subplot(1,2,2)
imshow(IM_part)
title(sprintf('sum of values: %.1f',sum_of_masked_area))
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!