How can i count the sum of the gray level value in a segmented region

7 vues (au cours des 30 derniers jours)
maria harrabi
maria harrabi le 1 Mai 2018
Réponse apportée : Rik le 10 Juin 2018
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

Réponses (1)

Rik
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))

Community Treasure Hunt

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

Start Hunting!

Translated by