From: Mathew Thomas on
Hello All,

Can someone please explain how the "bwarea" command works ? It says that the value given is a rough estimate of the number of ON pixels. So if I have a binary image, and the number of ON or white pixels obtained using bwarea is 1800, how can I convert this into metric value if I know 1 pixel = 0.05 mm ?

Thanks in advance for any help.

Mathew
From: Jeff on
"Mathew Thomas" <mathew99(a)gmail.com> wrote in message <i1idkh$3om$1(a)fred.mathworks.com>...
> Hello All,
>
> Can someone please explain how the "bwarea" command works ? It says that the value given is a rough estimate of the number of ON pixels. So if I have a binary image, and the number of ON or white pixels obtained using bwarea is 1800, how can I convert this into metric value if I know 1 pixel = 0.05 mm ?
>
> Thanks in advance for any help.
>
> Mathew

If 1 pixel = 0.05 mm on a side, then square it to get the area of a pixel = .0025 mm^2. Multiply that value by the number of pixels to get the area = 1.5 mm^2.

bwarea_count = bwarea(image);
real_area = bw_area_count * .0025;

----Jeff----
From: Jeff on
"Jeff " <jea(a)gene.dot.com> wrote in message <i1ie23$2b5$1(a)fred.mathworks.com>...
> "Mathew Thomas" <mathew99(a)gmail.com> wrote in message <i1idkh$3om$1(a)fred.mathworks.com>...
> > Hello All,
> >
> > Can someone please explain how the "bwarea" command works ? It says that the value given is a rough estimate of the number of ON pixels. So if I have a binary image, and the number of ON or white pixels obtained using bwarea is 1800, how can I convert this into metric value if I know 1 pixel = 0.05 mm ?
> >
> > Thanks in advance for any help.
> >
> > Mathew
>
> If 1 pixel = 0.05 mm on a side, then square it to get the area of a pixel = .0025 mm^2. Multiply that value by the number of pixels to get the area = 1.5 mm^2.
>
> bwarea_count = bwarea(image);
> real_area = bw_area_count * .0025;
>
> ----Jeff----

Curse these fat fingers... total area = 4.5 mm^2
From: Mathew Thomas on
lol..Tnx Jeff
From: Cris Luengo on
"Mathew Thomas" <mathew99(a)gmail.com> wrote in message <i1idkh$3om$1(a)fred.mathworks.com>...
> Hello All,
>
> Can someone please explain how the "bwarea" command works ? It says that the value given is a rough estimate of the number of ON pixels. So if I have a binary image, and the number of ON or white pixels obtained using bwarea is 1800, how can I convert this into metric value if I know 1 pixel = 0.05 mm ?
>
> Thanks in advance for any help.
>
> Mathew

I'm not replying to your question, you've already gotten a good answer. This is to warn you about the BWAREA. I don't know what it is optimized for, but just using SUM to count pixels is a better way to estimate the area of a binarized object. It is a well-known result that the "sum of ON pixels" is an unbiased estimate of area. The following script illustrates this:


figure,hold on
for jj=1:10
xx = (-128:127)+rand;
yy = (-128:127)+rand;
[xx,yy]=meshgrid(xx,yy);
rr = sqrt(xx.^2+yy.^2);
a = [];
for ii=1:25
r = ii*5;
m = rr<=r;
a(ii,1) = pi*r^2;
a(ii,2) = sum(m(:));
a(ii,3) = bwarea(m);
end
plot(a(:,1),a(:,2)-a(:,1))
plot(a(:,1),a(:,3)-a(:,1),'r')
end
plot(a([1,end],1),[0,0],'k:')
legend('sum=unbiased estimate','bwarea=biased estimate','Location','NorthWest')


Cheers,
Cris.