binary mapping continuous ones or not

1 visualización (últimos 30 días)
Harish Maradana
Harish Maradana el 27 de Dic. de 2014
Comentada: dpb el 28 de Dic. de 2014
we have divided a 256*256 matrix into 4*4 matrix and we have got 4096 combination.now we want to map these 4*4 matrix to binay 1's and 0's in such a way that if there are minimum four continuous 1's in any direction or in any manner we want to map it to binary '1' else map it to binary '0'
ex: (1)
[0 0 1 1;...
0 0 1 0;...
0 1 0 0;...
1 0 0 0] it must be mapped to binary '1'
(2) [0 0 0 0;...
0 0 1 1;...
0 1 0 0;...
1 0 0 0] it must be mapped to binary '1'
(3) [0 0 0 1;...
0 1 0 0;...
0 0 0 0;...
1 0 0 1] it must be mapped to binary '0'
  1 comentario
dpb
dpb el 27 de Dic. de 2014
The cases (1) and similar are pretty easy...it's
any(all(x).' | all(x,2) | all(diag(x)) | all(fliplr(diag(x))))
which simply checks all rows and columns plus the diagonals. The above has no attempt at simplification; just the logic. Of course, it's applied with arrayfun or similar construct over the full set of arrays, x, however they're stored.
The other cases are tougher; don't have time at the moment but look at
doc nearestNeighbor
for thoughts to get started, maybe. On thought is that you can reduce the dimensionality by reducing any arrays with zero columns/rows such as (2) to a 3x2 and (3) to two; one a row vector and the other 2x3 in these particular examples. Maybe the resulting strength reduction in search those reduced arrays outweighs the extra ones to keep track of, I don't know.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 27 de Dic. de 2014
Editada: Image Analyst el 27 de Dic. de 2014
If you have the Image Processing Toolbox, it's trivial. Just label and get the largest area.
% Label the 4-by-4 matrix.
labeledImage = bwlabel(matrix4x4, 8);
% Measure areas
measurements = regionprops(labeledImage, 'Area');
% Get the areas of all the blobs in the image
allAreas = [measurement.Area];
% Find the largest area
maxArea = max(allAreas);
% See what it needs to be "mapped" to.
if maxArea >= 4
% It must be mapped to binary '1'
else
% It must be mapped to binary '0'
end
  1 comentario
dpb
dpb el 28 de Dic. de 2014
Good catch, IA...I've never had the Image Processing Toolbox; not sure even if had would've thought of the single line as an area altho suppose that with "time-in-grade" doing image processing it's a natural...

Iniciar sesión para comentar.

Categorías

Más información sobre Image Segmentation and Analysis 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