How to find all the blue pixels and the location of the two boundaries in blue pixels?

I want to find per column the first and last blue pixels and them find the other boundary ( first and last blue pixel rows) inside this rows achieved before.

I made the alterations based on the previous answeers, but now I have this error when it tries to find the bif_first and last: Subscripted assignment dimension mismatch. bif_first2(2,z)=find(dx(:,z)==1,2,'first');

What is wrong? Please see my code below:

 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

enter image description here

Upvotes: 0

Views: 144

Answers (1)

Daniel
Daniel

Reputation: 36710

Your problem is you are comparing a n*m*3 image with a 3*1 vector. This operation is not defined.

Use this code:

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

Images in Matlab use the third dimension for color, that's why I created blue to be a 1*1*3 vector. Now this vector is compared to the image, using bsxfun to expand the vector to match the image size. This operation compares each color channel individually, so all is used to collect the data for all three channels.

Upvotes: 1

Related Questions