필터 지우기
필터 지우기

i have seen the code of vegetation percentage and it works well..............and i had a doubt is that how we have to calculate the vegetation pixel count

조회 수: 2 (최근 30일)
a=0; b= 0; c=0; p=0; p1=0;
%pic=sprintf('E:\PPTFILES\img-thing.png') fnam=imread('E:\PPTFILES\images.png'); for mm = 1:size(fnam,1)
for nn = 1:size(fnam,2)
if (fnam(mm,nn,2) -10) > fnam(mm,nn,1) & (fnam(mm,nn,2)-10) > fnam(mm,nn,3)
fnam(mm,nn,1) = fnam(mm,nn,1);
fnam(mm,nn,2) = fnam(mm,nn,2);
fnam(mm,nn,3) = fnam(mm,nn,3);
a=a+1;
else
fnam(mm,nn,1) = 250;
fnam(mm,nn,2) = 250;
fnam(mm,nn,3) = 250;
b=b+1;
end
end
end
p = a / (a + b);
p1 = p * 100;
imshow(fnam); a = sprintf('Vegetation Pixel Count= %3d',a); b = sprintf('Non Vegetation Pixel count= %3d',b); c = sprintf('Percentage of area of veg is %3f %',p1); msgbox(a); msgbox(b); msgbox(c);

채택된 답변

Image Analyst
Image Analyst 2016년 12월 24일
You say you have the percentage already and want to know how to get the count. So simply multiply the percentage times the total number of pixels.
[rows, columns, numberOfColorChannels] = size(fnam);
count = vegPercentage * rows * columns;
Actually it looks like your (badly-named) "a" is already the count. You just probably didn't realize it because of the horribly non-descriptive name you chose for it.
  댓글 수: 3
Image Analyst
Image Analyst 2016년 12월 25일
Not sure you read my Answer or followed any of the links because you didn't format your code, you didn't attach your image, and you're still asking how to get the percentage. Look at your code. You're calling "a" the vegetation pixels and "b" the non vegetation pixels. So
p = a / (a + b);
is the vegetation area fraction, a number between 0 and 1. Then you multiply it by 100:
p1 = p * 100;
so now p1 is the vegetation percentage and has units of percent and is in the range 0 to 100.
For color segmentation tutorials, see My File Exchange.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by