图像分块数目

ClydeZhang 2007-12-13 02:42:16
一个nxm二值画图像,如果把相邻(8 临点)的颜色相同的地方看成一块区域,请问这个图像的最大区域数目是什么?数学理论证明?

例如:下面的4x4图像的块数被认为是3而不是4.
1 0 1 0
0 1 0 0
0 0 0 0
1 1 1 1
那么对任意的nxm二值画图像,这个块数的精确上限的表达是是什么?
...全文
515 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
ClydeZhang 2008-03-10
  • 打赏
  • 举报
回复
Thanks for Iorikingdom.I have implemented a function like bwlabel in C in N, and now it works fine.
iorikingdom 2008-02-13
  • 打赏
  • 举报
回复
不需要膨胀收缩的,
估计类似于Matlab的
bwlabel
可以满足你的要求

function [L,numComponents] = bwlabel(BW,mode)
%BWLABEL Label connected components in 2-D binary image.
% L = BWLABEL(BW,N) returns a matrix L, of the same size as BW, containing
% labels for the connected components in BW. N can have a value of either
% 4 or 8, where 4 specifies 4-connected objects and 8 specifies
% 8-connected objects; if the argument is omitted, it defaults to 8.
%
% The elements of L are integer values greater than or equal to 0. The
% pixels labeled 0 are the background. The pixels labeled 1 make up one
% object, the pixels labeled 2 make up a second object, and so on.
%
% [L,NUM] = BWLABEL(BW,N) returns in NUM the number of connected objects
% found in BW.
%
% Note: Comparing BWLABEL and BWLABELN
% ------------------------------------
% BWLABEL supports 2-D inputs only, whereas BWLABELN support any
% input dimension. In some cases you might prefer to use BWLABELN even
% for 2-D problems because it can be faster. If you have a 2-D input
% whose objects are relatively "thick" in the vertical direction,
% BWLABEL will probably be faster; otherwise BWLABELN will probably be
% faster.
%
% Class Support
% -------------
% BW can be logical or numeric, and it must be real, 2-D, and
% nonsparse. L is double.
%
% Example
% -------
% BW = logical([1 1 1 0 0 0 0 0
% 1 1 1 0 1 1 0 0
% 1 1 1 0 1 1 0 0
% 1 1 1 0 0 0 1 0
% 1 1 1 0 0 0 1 0
% 1 1 1 0 0 0 1 0
% 1 1 1 0 0 1 1 0
% 1 1 1 0 0 0 0 0]);
% L = bwlabel(BW,4);
% [r,c] = find(L == 2);
%
% See also BWAREAOPEN, BWEULER, BWLABELN, BWSELECT, LABEL2RGB.

% Copyright 1993-2005 The MathWorks, Inc.
% $Revision: 1.29.4.5 $ $Date: 2006/06/15 20:08:28 $

iptchecknargin(1,2,nargin,mfilename);
iptcheckinput(BW, {'logical' 'numeric'}, {'real', '2d', 'nonsparse'}, ...
mfilename, 'BW', 1);

if (nargin < 2)
mode = 8;
else
iptcheckinput(mode, {'double'}, {'scalar'}, mfilename, 'N', 2);
end

if ~islogical(BW)
BW = BW ~= 0;
end


[M,N] = size(BW);

% Compute run-length encoding and assign initial labels.
[sr,er,sc,labels,i,j] = bwlabel1(BW,mode);
if (isempty(labels))
numLabels = 0;
else
numLabels = max(labels);
end

% Create a sparse matrix representing the equivalence graph.
tmp = (1:numLabels)';
A = sparse([i;j;tmp], [j;i;tmp], 1, numLabels, numLabels);

% Determine the connected components of the equivalence graph
% and compute a new label vector.

% Find the strongly connected components of the adjacency graph
% of A. dmperm finds row and column permutations that transform
% A into upper block triangular form. Each block corresponds to
% a connected component; the original source rows in each block
% correspond to the members of the corresponding connected
% component. The first two output% arguments (row and column
% permutations, respectively) are the same in this case because A
% is symmetric. The vector r contains the locations of the
% blocks; the k-th block as indices r(k):r(k+1)-1.
[p,p,r] = dmperm(A);

% Compute vector containing the number of elements in each
% component.
sizes = diff(r);
numComponents = length(sizes); % Number of components.

blocks = zeros(1,numLabels);
blocks(r(1:numComponents)) = 1;
blocks = cumsum(blocks);
blocks(p) = blocks;
labels = blocks(labels);

% Given label information, create output matrix.
L = bwlabel2(sr, er, sc, labels, M, N);


上面的代码凑合点参考下,详细可以看看matlab里面的
legendwin 2008-02-04
  • 打赏
  • 举报
回复
直觉:你可以用腐蚀,膨胀算法处理,然后去计算大体的块状,这样就能求一个近似的值了。我想依照这条路也是可以去证明的。
ClydeZhang 2008-01-05
  • 打赏
  • 举报
回复
我的问题不是如何编程找到符合要求的图像分块,而是估计这个块数的上限的数学证明。
ClydeZhang 2008-01-03
  • 打赏
  • 举报
回复
感谢大家对这个问题感兴趣,
1 0 1 0
0 1 0 0
0 0 0 0
1 1 1 1
这个图中,三个块 分别是,*是无关内容,数字是属于同一个块区域的像素。凡是跟一个点A能通过8临点联通的点B都与A属于同一个块;
1 * 1 *
* 1 * *
* * * *
//////////////////////////////////
* 0 * 0
0 * 0 0
0 0 0 0
* * * *
///////////////////////////////
* * * *
* * * *
1 1 1 1

ClydeZhang 2008-01-03
  • 打赏
  • 举报
回复
感谢大家对这个问题感兴趣,
1 0 1 0
0 1 0 0
0 0 0 0
1 1 1 1
这个图中,三个块 分别是,*是无关内容,数字是属于同一个块区域的像素。凡是跟一个点A能通过8临点联通的点B都与A属于同一个块;
1 * 1 *
* 1 * *
* * * *
//////////////////////////////////
* 0 * 0
0 * 0 0
0 0 0 0
* * * *
///////////////////////////////
* * * *
* * * *
1 1 1 1

ClydeZhang 2008-01-03
  • 打赏
  • 举报
回复
感谢大家对这个问题感兴趣,
1 0 1 0
0 1 0 0
0 0 0 0
1 1 1 1
这个图中,三个块 分别是,*是无关内容,数字是属于同一个块区域的像素。凡是跟一个点A能通过8临点联通的点B都与A属于同一个块;
1 * 1 *
* 1 * *
* * * *
//////////////////////////////////
* 0 * 0
0 * 0 0
0 0 0 0
* * * *
///////////////////////////////
* * * *
* * * *
1 1 1 1

jhs1982419 2008-01-03
  • 打赏
  • 举报
回复
你的意思就是说用你所说的矩阵模板对你的图像进行匹配,如全部相同则划分为同一分块,关键问题是如何找到符合要求的图像分块 。
chehw 2008-01-03
  • 打赏
  • 举报
回复
0. 定义一个flag矩阵, 用于表示各点的visit状态;
1. 从第一个点出发, 找一个unvisit的点, 若均visit, 则退出.
2. 用类似maze的算法递归查找下一个可联通且unvisit的点, 若找到则置该点visit状态为true;
3. 返回1
skytiger_z 2007-12-26
  • 打赏
  • 举报
回复

更详细清楚的描述一下哈。
jmulxg 2007-12-25
  • 打赏
  • 举报
回复
更加详细的描述
buggycode 2007-12-24
  • 打赏
  • 举报
回复
可能看懂,

任意一个图形计算几个块容易。
最大块数也应该不会太难,但是证明就麻烦了。

放弃
wuchuncai 2007-12-24
  • 打赏
  • 举报
回复
描述不清
lucian2007 2007-12-24
  • 打赏
  • 举报
回复
好像真的不太理解楼主的意思!
能说得更详细点么?
好像问题挺有意思的!
coffeaddice 2007-12-24
  • 打赏
  • 举报
回复
怎么感觉和图象里面的标签算法有关

你说的8连接最大上限 理论上应该可以算出模型

不过不是短时间可以搞顶的
np1234 2007-12-23
  • 打赏
  • 举报
回复
没有理解,不知道是我们笨,还是您的表达不清,希望再说清点,最好对那个例子,因没我没有看出来是3或是4,按您的表述我看一个也没有.
ClydeZhang 2007-12-14
  • 打赏
  • 举报
回复
看来这个问题把大家都难到了。

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧