Problem by counting pixels in regions found by mh.label (regions)

18 views
Skip to first unread message

Eduardo Munizaga

unread,
Apr 8, 2016, 4:24:58 PM4/8/16
to pythonvision
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?


Luis Pedro Coelho

unread,
Apr 10, 2016, 4:37:12 AM4/10/16
to python...@googlegroups.com
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
> <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
> email to pythonvision...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Eduardo Munizaga

unread,
Apr 10, 2016, 11:12:31 AM4/10/16
to python...@googlegroups.com
Hi Luis!
Surely there is some proportion related treaty between the point and the bottom of the image. Any idea to solve it?
Reply all
Reply to author
Forward
0 new messages