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 views (last 30 days)
Show older comments
BUGATHA VARALAKSHMI
on 24 Dec 2016
Commented: BUGATHA VARALAKSHMI
on 23 Mar 2017
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);
Accepted Answer
Image Analyst
on 24 Dec 2016
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 Comments
Image Analyst
on 25 Dec 2016
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.
More Answers (0)
See Also
Categories
Find more on Point Cloud Processing 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!