tengo esta entrada
image1 which is 20x20 size and looks like this
00000000000000000000 00111000000000000000 01101100000001111000 11000110000001111110 11100000001100011110
and I need a function that will generate an output, say
image2 of 20x20 size, that will look like this
00000000000000000000 00111000000000000000 11011000000022220000 11000110000002222220 11000110000002222220 11100000003300022220
The difference is that the first appears to be a grey-scale image (only 0 and 1) while the desired output, based on the similar areas of the input image, will now contain 2,3 and so on.
So far I am looking for some of
pillow's build in functions that might suit me but I am not even sure if I am looking in the right direction. Could you please suggest a way to approach this?
preguntado el 28 de mayo de 14 a las 12:05
Did you checked this previous post on stackoverflow (Reconocimiento de objetos simples)?
In sum you can use SciPy's ndimage.label() http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.label
Well I would suggest to write a simple function
- make a copy of the image filled with zeros and use it as the visited array
- perform dfs. You just have to find islands on the image it is a simple graph problem. google for finding islands in a graph.
Hope it helps and you always dont need a named algo to do simple things