How to detect first 50 white pixels from right side of a binary image?
2 views (last 30 days)
Show older comments
i have a binary image and for extracting the REGIIN OF INTEREST we need to detect the first 50 white pixels from right side of the image. can anyone suggest me how to do it?
0 Comments
Accepted Answer
Rik
on 24 Feb 2019
Edited: Rik
on 24 Feb 2019
You can use find to get the indices from the left, so the only thing you need to do is flipping the image and convert the col indices:
A=[1 0 0;0 1 0;1 1 1];
N_pixels=3;
A=fliplr(A);%flip since find looks from the upper left corner
[r,c]=find(A,N_pixels);
c=size(A,2)-c+1;%flip indices back
%prove this is indeed correct:
B=accumarray([r,c],ones(size(r)),size(A))
%this may be faster depending on the size of your matrix and number of points:
%B=zeros(size(A));ind=sub2ind(size(B),r,c);B(ind)=1
4 Comments
Image Analyst
on 24 Feb 2019
The code Rik gave you won't work to extract that red region.
This is a classic case of someone saying "How do I do X" and then someone tells them how to do X. Then they say "That doesn't work". Then you ask what they REALLY want to do (the larger picture) and they say "What I really want to do is Y". Then the answerer says "Well if you really want to do Y then you don't want to do X at all, you want to do Z."
So now we need to know exactly what pixels should be in the red region. It appears to be a circle fitted to the right edge of a blob that is required to touch the left edge (or maybe not touch - I don't know). But the question is where is the left edge of the red circle? If you fit a circle to the pixels on the right of the blob, or a convex hull of it, then where the right part of the red circle will be depends on how far to the left you take pixels to do the circule fit.
Perhaps if you saw your gray scale, pre-segmentation image, it might give us another clue. Otherwise give us some idea of how we can determine what boundary pixels to fit to a circle.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!