binary mapping continuous ones or not

조회 수: 2 (최근 30일)
Harish Maradana
Harish Maradana 2014년 12월 27일
댓글: dpb 2014년 12월 28일
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에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by