필터 지우기
필터 지우기

How to detect first 50 white pixels from right side of a binary image?

조회 수: 1 (최근 30일)
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?

채택된 답변

Rik
Rik 2019년 2월 24일
편집: Rik 2019년 2월 24일
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
anshumala rakesh
anshumala rakesh 2019년 2월 24일
편집: Image Analyst 2019년 2월 24일
Actually I have this binary image as my input and I wanted to extract only the region marked in red as output.
untitled.bmp
So I thought of detecting the first few white pixels from right side which fits that region. here 50 is just a random guess . l just wanted to know about the function.
Image Analyst
Image Analyst 2019년 2월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by