How to find minimum number of largest square of 1 in an 2D bool matrix

3 visualizaciones (últimos 30 días)
I have a 2D bool image (dimension 81x65) with several irregular regions black(mainly in the middle) and other pixes white(mainly in the outer part).
Is there a way to split the white region into square pieces as large as possible, and get the position and size for each square?
Thanks.
无标题.png
  4 comentarios
Walter Roberson
Walter Roberson el 20 de Oct. de 2019
What would be the desired output in the above case? And should all of the square be the same size?
raym
raym el 20 de Oct. de 2019
Editada: raym el 20 de Oct. de 2019

The square can be any size and with different sizes. The key is to split white pixels into less squares, so some of the square should have large area.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Oct. de 2019
D = bwdistgeodesic(logical(YourImage), ~YourImage);
Now iterate. if there are no finite values in D, break the loop. Find the largest value in D. It is at the corner of a square of white pixels of that dimension, but you will need to do a little work to figure out which corner it is. When you have figured out which corner it is, record that square location and then set all the D locations inside that square to be inf or nan. Now return back to the beginning of the loop (looking for the largest remaining value)
This is a "greedy" algorithm. It makes no attempt at all to be consistent in block sizes. If there were a situation in which two squares of equal size plus one small square would cover a section, then the algorithm would instead take the larger square leaving the rest to be broken up into a number of smaller squares.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by