我在试着从图像中提取边缘。我使用了以下algorithm.Input图像(E11),也给出了512 * 512灰度图像。
下面给出了我编写的matlab代码
e11 = imread("lena.jpg");
e11= double(e11);
gradientim = imdilate(e11,se) - imerode(e11,se);
negativeim = imcomplement(gradientim);
bottomhatim = imclose(negativeim,se) - e11 ;
AVG = mean2(e11);
%-------Computing binary image--------
for i=1:(height)
for j=1:(width)
if(AVG > bottomhatim(i,j,:))
bottomhatim(i,j,:) = 1;
else
bottomhatim(i,j,:) = 0;
end
end
end
CC = bwconncomp(bottomhatim);
edge = bottomhatim - CC;

在执行步骤7时,由于连接组件(CC)的类型为“struct”,因此将得到如下错误
“未定义函数‘减号’用于输入‘struct’类型的参数”。
是否可以使用"bwconncomp“函数来查找最大的连接区域?是否有其他函数可供选择?请帮助我提前更正此code.Thanks。
发布于 2015-03-14 06:06:56
假设CC是一个数组,但它实际上是一个结构。具体来说,这就是文档对bwconncomp的看法。
bwconncomp Find connected components in binary image.
CC = bwconncomp(BW) returns the connected components CC found in BW.
BW is a binary image that can have any dimension. CC is a structure
with four fields:
Connectivity Connectivity of the connected components (objects).
ImageSize Size of BW.
NumObjects Number of connected components (objects) in BW.
PixelIdxList 1-by-NumObjects cell array where the kth element
in the cell array is a vector containing the linear
indices of the pixels in the kth object.通过算法描述,您希望找到最大的连接组件,并将其从图像中减去,以获得存储在edge中的最终图像。我建议您使用bwlabel,它返回一个标签映射,它用唯一的ID标记每个不同的对象。bwlabel的第二个输出返回检测到的对象数量。
我会使用bwlabel,结合histc来计算每个区域的像素数。我们将利用它来确定面积最大的地区。然后,您将制作一个由该对象组成的掩码,然后使用该掩码并将其与图像相减以获得最终的输出edge。
具体来说,在代码的末尾执行以下操作:
%// Do bwlabel on image
[L, num] = bwlabel(bottomhatim);
%// Count how many values belong to each object, ignoring background
counts = histc(L(:), 1:num);
%// Find which object gives us the largest area
[~,max_id] = max(counts);
%// Make a mask and then subtract
CC = L == max_id;
edge = imsubtract(bottomhatim, CC);https://stackoverflow.com/questions/29045952
复制相似问题