procesamiento de imagen con python

tengo esta entradaimage1 which is 20x20 size and looks like this


and I need a function that will generate an output, say image2 of 20x20 size, that will look like this


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

You should have a look to Flood-Fill-Algorithms they are easy and fast to implement. -

@PeterNL I had no clue.. Alright thanks -

2 Respuestas

Did you checked this previous post on stackoverflow (Reconocimiento de objetos simples)?

In sum you can use SciPy's ndimage.label()

Buena suerte.

contestado el 23 de mayo de 17 a las 12:05

ndimage.label() is the way to go. It essentially performs flood fill. Good answer. - Rayryeng

Well I would suggest to write a simple function


  1. make a copy of the image filled with zeros and use it as the visited array
  2. 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

contestado el 29 de mayo de 15 a las 06:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.