How to use the find function discover the row and column [pixel coordinates] of all the blue pixels per column?

3 views (last 30 days)
I’m having problems using the find function to discover the row and column [pixel coordinates] of the blue pixels.
What I want to do is find the first and last blue pixels these will correspond to the boundaries of the lumen where I want to paint the range between these first and last boundaries in blue, per column. But in some column values I have the bifurcation of the vessel, and here again I want to find the first and last blue pixel of the bifurcation (between the first and last blue pixels found for lumen) and paint the range between these values in black.
I was able to find the first and last blue pixels using the code below (but without using the row value jj), only with movingRegistered(:,zz,3)==).
  1. First I don’t understand why it only works with (: )
  2. But using the same logic to find the first and last bifurcation values between the values found, appears the error:Subscripted assignment dimension mismatch
I tried to make :
(movingRegistered- 499x631x3 uint8
Bif_firt(1x631)
Bif_last(1x631)
bif_first(1,zz)=find((movingRegistered(jj,zz,1)==0 & ...
movingRegistered(jj,zz,2)==0 & ...
movingRegistered(jj,zz,3)==255),1,'first'); % the first blue row for that column
bif_last(1,zz)=find((movingRegistered(jj,zz,1)==0 & ...
movingRegistered(jj,zz,2)==0 & ...
movingRegistered(jj,zz,3)==255),1,'last'); %the last blue row for that column
But it only appears 1 in every column.
3-Does anybody have any suggestion?
4- I tried to paint the image with blue and the rest with black but my figure (13) appears the same as before, what I’m doing wrong? Please see my code below:
%%Find the countour indexes and paint the lumen in blue %%%%%%
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));
lumen=false;
for zz=1:1:size(movingRegistered,2);%columns
for jj=1:size(movingRegistered,1);%rows
if(movingRegistered(jj,zz,1)==0 && ...
movingRegistered(jj,zz,2)==0 && ...
movingRegistered(jj,zz,3)==255)
lumen=true;
lumen_first(1,zz)=find((movingRegistered(:,zz,1)==0 & ...
movingRegistered(:,zz,2)==0 & ...
movingRegistered(:,zz,3)==255),1,'first'); % the first blue row for that column
lumen_last(1,zz)=find((movingRegistered(:,zz,1)==0 & ...
movingRegistered(:,zz,2)==0 & ...
movingRegistered(:,zz,3)==255),1,'last'); %the last blue row for that column
end
end
end
for zz=1:1:size(movingRegistered,2);%columns
for jj=lumen_first(1,zz)+4:lumen_last(1,zz)-1;%rows
bifurcacao=false;
if (movingRegistered(jj,zz,1)==0 && ...
movingRegistered(jj,zz,2)==0 && ...
movingRegistered(jj,zz,3)==255)
bifurcacao=true; %existis bifurcation
bif_first(1,zz)=find((movingRegistered(jj,zz,1)==0 & ...
movingRegistered(jj,zz,2)==0 & ...
movingRegistered(jj,zz,3)==255),1,'first'); % the first blue row for that column
bif_last(1,zz)=find((movingRegistered(jj,zz,1)==0 & ...
movingRegistered(jj,zz,2)==0 & ...
movingRegistered(jj,zz,3)==255),1,'last'); %the last blue row for that column
end
end
end
rgbImage_blue=movingRegistered;
%%Paint in blue the lumen region
%Verify if where vector lumen_first has 0 values
zmin_lumen=find(lumen_first(:),1,'first');%column value
zmax_lumen=find(lumen_last(:),1,'last');%column value
lumen_green=zeros(size(movingRegistered));
for z=zmin_lumen:zmax_lumen
for j1=lumen_first(1,z):lumen_last(1,z);
lumen_green(j1,z)=1;
end
end
for zz=1:size(rgbImage_blue,2);
for jj=size(rgbImage_blue,1);
if lumen_green(jj,zz) ==1;
rgbImage_blue(jj,zz,1)=0;
rgbImage_blue(jj,zz,2)=0;
rgbImage_blue(jj,zz,3)=255;
else
rgbImage_blue(jj,zz,1)=0;
rgbImage_blue(jj,zz,2)=0;
rgbImage_blue(jj,zz,3)=0;
end
end
% if bifurcacao,
% for j2=bif_first(1,zz):bif_last(1,zz)
% rgbImage_blue(j2,zz,1)=0;
% rgbImage_blue(j2,zz,2)=0;
% rgbImage_blue(j2,zz,3)=0;
% end
end
figure(13),imshow(rgbImage_blue);
<</matlabcentral/answers/uploaded_files/24482/movingRegistered.png>>
  8 Comments
Helena Henrques
Helena Henrques on 27 Jan 2015
Edited: Helena Henrques on 27 Jan 2015
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
dpb
dpb on 27 Jan 2015
Oh, yeah, I don't do 3D that much, so the 2D indexing doesn't work. I'll try to find the time later on to look at this a little more and work out the syntax problems in my approach. I know it'll work; I just have to work thru the syntax.
Is the outline really "true blue" of [0 0 255]? I pasted the image from the screen shot bitmap and saved it to a jpg for 'spearminting but there the colors aren't pure.
I'm wondering that if they really are, maybe you get the same result if simply look at the blue plane alone? Would there be any pixels of full 255 blue saturation also of anything but blue? If that were true would reduce the problem size by 2/3rds...plus only be a 2D instead of 3D problem.

Sign in to comment.

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!