【发布时间】:2014-04-07 18:08:26
【问题描述】:
考虑分割算法的输出是一个与输入图像大小相同的矩阵。对于检测到的每个段,矩阵的特定部分都使用特定的数字/索引进行索引,如下所示。
我想检索特定段的邻居。 Here 有描述取每个像素不同大小的邻居。例如,在 3x3、5x5、7x7 等中。我们可以使用上面链接中的时间高效方式对不同大小(大约)的邻域中的特定段执行类似的过程吗?
最好的问候,
透特
PS:非常感谢任何问题。
【问题讨论】:
考虑分割算法的输出是一个与输入图像大小相同的矩阵。对于检测到的每个段,矩阵的特定部分都使用特定的数字/索引进行索引,如下所示。
我想检索特定段的邻居。 Here 有描述取每个像素不同大小的邻居。例如,在 3x3、5x5、7x7 等中。我们可以使用上面链接中的时间高效方式对不同大小(大约)的邻域中的特定段执行类似的过程吗?
最好的问候,
透特
PS:非常感谢任何问题。
【问题讨论】:
如果要查找特定区域的邻居的索引,可以执行以下操作:
%# input: lblImg - image where pix(x,y) is the index of the segment
targetSegment = 4;
%# grow the segment by 2 pixels, since I assume the boundary in between is 1 pixel wide
msk = imdilate(lblImg == targetSegment,strel('disk',2));
msk(lblImg == targetSegment | lblImg == 0) = false; %# remove original cell, and boundary
%# retrieve the list of neighbors
listOfNeighbors = unique(lblImg(msk));
当然,您可以对所有段并行执行此操作,并创建一个邻接矩阵。 Dilation 是一个局部极大值操作,所以它会使不同索引的标签重叠。
dilImg = imdilate(lblImg, strel('disk',2));
msk = dilImg ~= lblImg & lblImg > 0; %# assume indices are all positive
%# msk contains the indices of pixels where dilation
%# has created an overlap between segments.
rowColIdx = unique( [dilImg(msk), lblImg(msk)], 'rows');
%# create adjacency matrix. Due to the nature of imdilate, this will fill in
%# only the values below the diagonal.
%# adjacencyMatrix = adjacencyMatrix + adjacencyMatrix.' would fix that.
nLabels = max(lblImg(:));
adjacencyMatrix = sparse(rowColIdx(:,1),rowColIdx(:,2),ones(size(rowColIdx,1),1),...
nLabels, nLabels);
【讨论】: