procesamiento de imagen con python

tengo esta entradaimage1 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

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() http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.measurements.label.html#scipy.ndimage.measurements.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

PASOS:

  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.