find out the percentage of pixels having value 1
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a binary image (with values 0 & 1) of the dimensions 497*597. I want to calculate the fraction (%) of pixels with value 1 in each array of 3*3 pixels out of the full image. can anybody help me in this regard?
Any help is highly appriciated.
Thanks in advance
Bhavini
回答(3 个)
Andrei Bobrov
2013-6-17
编辑:Andrei Bobrov
2013-6-17
a = randi([0 1],497,597);
ones_frac = conv2(a,ones(3),'valid')/9*100;
or if you have Image Processing Toolbox
ones_frac = blockproc(a,[3 3],@(x)sum(x.data(:))/9*100);
0 个评论
Bhomik Luthra
2013-6-17
Lets take a random matrix of size 497*597. I have found the number of 1's in each 3*3 matrix in first horizontal row, u can do it for 497/3 rows by putting a for loop.
a = randint(497,597);
for i = 1:597/3
p(i)= length(find (a(1:3,3*i-2:3*i)==1))
end
p(i) returns the number of 1's in each 3*3 matrix.
Bhomik Luthra
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!