Message Boards Message Boards

1
|
5437 Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

How do ComponentMeasurements[ ] "Area" & "Length" prop. relate to "Count"?

How do the ComponentMeasurements function computed " Area" and "Length" properties relate to the "Count" property in terms of pixels ?

POSTED BY: Amin C
4 Replies

Thank you so much for your knowledgeable and exhaustive explanation. I am very appreciative. I checked my image with ImageLevels gave me a binary results so I think my image is black and white indeed. Honestly,I was totally unaware of this important distinction .In general, does that mean that I need always to mask my image when I am working with ComponentMeasurements properties ? is there some rationale or rule of thumb I need to consider ?

Please kindly advise. Thank you very much.

Amin.

POSTED BY: Amin C
ImageType[img]
ImageChannels[img]
ImageColorSpace[img]

ImageType gives Bit for a black/white image. ImageChannels gives 1. ImageColorSpace gives Automatic I think...

POSTED BY: Sander Huisman

Thank you so much.

POSTED BY: Amin C

Hi Amin,

Area and Count are very much related. I presume you have a black/white image (not grayscale). Then Count means the number of white pixels. Area is more tricky, it will look at the neighbours of the pixels in order to determine what the 'value' is for each pixels. To be more precise it will look at a 2*2 neighbourhood then assign the following values depending on the neighbourhood:

  • 0 white pixels => 0
  • 1 white pixel => 1/4
  • 2 white adjacent pixels => 1/2
  • 2 white pixels diagonally => 3/4
  • 3 white pixels (an L shape) => 7/8
  • 4 white pixels => 1

to exemplify:

w1 = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
     0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 
    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 
    0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 
    1, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

Image[w1]
tmp = Values[
   ComponentMeasurements[Image[w1], {"Image", "Area", "Count"}, 
    "ComponentAssociation"]];
tmp[[All, 1]] = ImagePad[#, 2, Black] & /@ tmp[[All, 1]];
tmp // Grid

enter image description here

this will show you the parts of the image, the area and the count. As you can see, area and count are not always the same.

I break the parts of the images down into 2*2 sections:

func[img_Image] := Grid[Map[Magnify[ImagePad[#, 2, Black], 4] &, (ImagePartition[img, {2, 2}, {1, 1}]), {2}]]
Column[func /@ tmp[[All, 1]], Frame -> All, Spacings -> {3, 3}]

enter image description here

So in the top grid of images, we see 4 times a single pixel. Each having a 'value' of 1/4, resulting in a total of 1. In the second, we have 6 times a single pixel. Each having a value of 1/4, totalling 3/2 and a single diagonal of 2 pixels with a value of 3/4, giving a total of 9/4 (2.25).

et cetera for the other configurations. Because Area depends on the configuration of the neighborhood one can not directly relate Count and Area. They are very much related as they both give an indication of a surface-area.

"Length" is found by fitting the shape with an ellipse, and returning the long-axis of the ellipse. This can not be directly related count.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract