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(imagen,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 square point of 200x200 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 = mahotas.imread('100x100.png')
#imagen = mahotas.imread('200x200.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:
- Image 100x100.png print sizes = 1012 pixels
- Image 200x 200.png print sizes = 1292 pixels
- Image 76x66.png print sizes = 848 pixels
But, everyone should be equal or similar
Since the regions have different sizes, the background (the space left unoccupied) will also be different in the 3 situations as shown in your answer. The values your code outputs - 1012, 1292 and 848 - are the backround sizes for the three situations respectively. But you also mentioned that "...the intention is to measure the amount of pixels of the regions identified by the code..." This you get by:
print sizes[1].Obviusly not equal for the three situations- you should get 8988,38708 and 4168 - in the order of your results above. This is as per the reference link you provided.Code after edit follows: