Discussion:
Problem by counting pixels in regions found by mh.label (regions)
Eduardo Munizaga
2016-04-08 20:24:58 UTC
Permalink
I am using the algorithm attached and the intention is to measure the
amount of pixels of the regions identified by the code "mahotas.label
(image)".

The problem is that the greater the area of the background, the greater the
number of pixels that detects, considering that all points have the same
number of pixels in different images. This is due to the following line:
"mh.gaussian_filter (image 4)"

However this should not happen because what I need is that the regions are
exactly independent measurements of the area that has the background.

Attached the script and images of different sizes but with the same picture
of 200 x 200 pixels as examples.

*****************************************************
import mahotas as mh
import mahotas.demos
import numpy as np
from pylab import imshow, show

imagen = mahotas.imread('76x66.png')
imagen = imagen[:,:,0]
imagen = mh.gaussian_filter(imagen, 4)
imagen = (imagen> imagen.mean())


etiquetas, unidades = mahotas.label(imagen)
sizes = mahotas.labeled.labeled_size(etiquetas)

print sizes[0]

imshow(imagen)
show()

**********************************
Result:
100x100.png print sizes = 1012 pixeles
200x 200.png print sizes = 1292 pixeles
76x66.png print sizes = 848 pixeles


How I can do that, regardless of the background area, the result will not
have change?

<Loading Image...>
<Loading Image...>
<Loading Image...>
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2016-04-10 08:37:07 UTC
Permalink
Hi Eduardo,

The issue is that when you are using the mean as the threshold. However,
when you increase the size of the background, you also increase change
the value of the mean. Thus, your thresholds are different. Because you
have smoothed the image, different thresholds result in different areas.

HTH
Luis

Luis Pedro Coelho | EMBL | http://luispedro.org
My blog: http://metarabbit.wordpress.com
Post by Eduardo Munizaga
I am using the algorithm attached and the intention is to measure the
amount of pixels of the regions identified by the code "mahotas.label
(image)".
The problem is that the greater the area of the background, the greater the
number of pixels that detects, considering that all points have the same
"mh.gaussian_filter (image 4)"
However this should not happen because what I need is that the regions are
exactly independent measurements of the area that has the background.
Attached the script and images of different sizes but with the same picture
of 200 x 200 pixels as examples.
*****************************************************
import mahotas as mh
import mahotas.demos
import numpy as np
from pylab import imshow, show
imagen = mahotas.imread('76x66.png')
imagen = imagen[:,:,0]
imagen = mh.gaussian_filter(imagen, 4)
imagen = (imagen> imagen.mean())
etiquetas, unidades = mahotas.label(imagen)
sizes = mahotas.labeled.labeled_size(etiquetas)
print sizes[0]
imshow(imagen)
show()
**********************************
100x100.png print sizes = 1012 pixeles
200x 200.png print sizes = 1292 pixeles
76x66.png print sizes = 848 pixeles
How I can do that, regardless of the background area, the result will not
have change?
<https://lh3.googleusercontent.com/-CQ4a0O20Dn8/VwgS5IPEArI/AAAAAAAAAo4/uBQVHSHD_vc-ZziCTZixEIdUOBccfYAzQ/s1600/76x66.png>
<https://lh3.googleusercontent.com/-7aRKDQ3ZFvo/VwgS7OaIIhI/AAAAAAAAAo8/L1090xDxzd8MfAnCBPF-iuuwuPoPBD43A/s1600/100x100.png>
<https://lh3.googleusercontent.com/-PTY1-ueKoy4/VwgS9IBvlEI/AAAAAAAAApA/tJo3pC484k8DKlKZYlqoRVtq29o2Icjtg/s1600/200x200.png>
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eduardo Munizaga
2016-04-10 15:12:30 UTC
Permalink
Hi Luis!
Surely there is some proportion related treaty between the point and the
bottom of the image. Any idea to solve it?
Post by Luis Pedro Coelho
Hi Eduardo,
The issue is that when you are using the mean as the threshold. However,
when you increase the size of the background, you also increase change
the value of the mean. Thus, your thresholds are different. Because you
have smoothed the image, different thresholds result in different areas.
HTH
Luis
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...