binary mapping continuous ones or not

8 次查看(过去 30 天)
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 个评论
dpb
dpb 2014-12-27
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2014-12-27
编辑:Image Analyst 2014-12-27
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 个评论
dpb
dpb 2014-12-28
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...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by