【问题标题】:How to find all the blue pixels and the location of the two boundaries in blue pixels?如何找到所有蓝色像素以及蓝色像素中两个边界的位置?
【发布时间】:2015-01-27 11:16:42
【问题描述】:

我想在每列中找到第一个和最后一个蓝色像素,然后他们在之前实现的这些行内找到另一个边界(第一个和最后一个蓝色像素行)。

我根据之前的答案进行了更改,但现在在尝试查找 bif_first 和 last 时出现此错误:下标分配维度不匹配。 bif_first2(2,z)=find(dx(:,z)==1,2,'first');

怎么了?请参阅下面的代码:

 rgbImage_blue=zeros(size(movingRegistered));

  lumen_first=zeros(1,size(movingRegistered,2)); lumen_last=zeros(1,size(movingRegistered,2)); bif_first=zeros(1,size(movingRegistered,2)); bif_last=zeros(1,size(movingRegistered,2)); bif_last2=zeros(2,size(movingRegistered,2)); bif_first2=zeros(2,size(movingRegistered,2));

    blue=cat(3,0,0,255); 
ix=all(bsxfun(@eq,movingRegistered,blue),3);% find all the blue pixels, and put them at 1 % logical array of where blue pixels are dx=[zeros(1,size(movingRegistered,2));diff(ix)]; % zeros to make the same number of columns and rows % the difference by row for all columns
 nTops=sum(dx==1); % the transitions to blue
 nBots=sum(dx==-1); % and from blue... % see if are consistent; if not, something's not right in image
 if(nTops~=nBots), error('Mismatch in Top/Bottom'),end

 for z=1:1:size(movingRegistered,2);
    if  nTops(1,z)==2; bifurcation=false;lumen=true; %only existis two boundaries no bifurcation
    lumen_first(1,z)=find(ix(:,z)==1,1,'first');
    lumen_last(1,z)=find(ix(:,z)==1,1,'last');
    end
    if nTops(1,z)>2;
    bifurcation=true;
    lumen_first(1,z)=find(ix(:,z)==1,1,'first');
    lumen_last(1,z)=find(ix(:,z)==1,1,'last');
    bif_first2(2,z)=find(dx(:,z)==1,2,'first');
    bif_first(1,z)=bif_first2(2,z);
    bif_last2(2,z)=find(dx(:,z)==1,2,'last');
    bif_last(1,z)=bif_last2(2,z);
    end
 end

【问题讨论】:

  • 试试ix=(movingRegistered(:,:,1)==blue(1))&(movingRegistered(:,:,2)==blue(2))&(movingRegistered(:,:,3)==blue(3))
  • blue 未定义为 [0 0 255].' 的任何原因?
  • 是的 255 是我的错!!
  • 请不要使用@Daniel 提供的答案来编辑您的问题,因为这是一个完全不同的问题!如果答案解决了您的问题,请将其标记为已接受,如果有其他问题,请提出另一个问题。

标签: matlab indexing find


【解决方案1】:

您的问题是您将 n*m*3 图像与 3*1 向量进行比较。此操作未定义。

使用此代码:

blue=cat(3,0,0,250)
ix=all(bsxfun(@eq,movingRegistered,blue),3)

Matlab 中的图像使用第三维作为颜色,这就是我创建 blue 为 1*1*3 向量的原因。现在将此向量与图像进行比较,使用 bsxfun 扩展向量以匹配图像大小。此操作单独比较每个颜色通道,因此all 用于收集所有三个通道的数据。

【讨论】:

  • 你少了一个括号,是不是......?
猜你喜欢
  • 2019-02-07
  • 2023-03-08
  • 1970-01-01
  • 2022-12-19
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多