【问题标题】:MATLAB: find connected component by pixel location in binary imageMATLAB:通过二进制图像中的像素位置查找连通分量
【发布时间】:2016-06-05 16:50:59
【问题描述】:

我有一个二进制图像,我使用 bwconncomp 和 regionprops 来划分感兴趣的区域。我有一行像素,我想将其放置在二进制图像上......并找到哪个感兴趣区域/连接的组件中包含最多的行像素。因此,在附加图像中,我在 bwimage 上使用 bwconncomp,得到组件 1、2、3。然后我有一个对应于蓝线的像素列表。我想找出哪个连接的组件中蓝线最多(#1)。

我想它类似于......

line=(some pixel values);
cc=bwconncomps(bwimage);
tempvar=[];

for i=1:length(bwconncomps)
     tempvar=find(cc.PixelIdxList{i}==line);
end

[~ answer]=max(tempvar);

【问题讨论】:

    标签: matlab binary components line


    【解决方案1】:

    您可以使用ismember 来确定@​​987654322@ 中有多少项目出现在沿线的像素列表中。然后你可以使用max 来识别拥有最多的组件。

    % Indices of pixels that are along the line of interest
    linePixels = [1, 2, 3, 4, ...]  
    
    % Determine the number of pixels within each component that are on this line
    nPerComponent = cellfun(@(inds)sum(ismember(inds, linePixels)), {cc.PixelIdxList});
    
    % Find the component with the most points on this line
    [~, answer] = max(nPerComponent);
    

    【讨论】:

    • 我无法正常工作:“索引超出矩阵维度”。青色只是为了说明我的问题——实际上我只有二进制图像,然后是行的值索引——它们的格式与 bwconncomps PixelIdxList 相同(即在 200x200 像素图像中,第二列中的第一个像素将是“201”而不是“1,2”)
    • 我仍然收到错误“输入 #2 应该是元胞数组,而是双精度”...抱歉可能是简单的解决方案,但我错过了它
    • 如果我执行 num2cell(cc(i).PixelIdxList) 这似乎可以在逐个组件的基础上工作 - 在 for 循环中工作正常,无法让它在完整的 CC 上工作.PixelIdxList 虽然...
    • @user3470496 你用的是什么版本?我已经更新了一个现在应该可以使用的版本。
    猜你喜欢
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2011-11-19
    相关资源
    最近更新 更多