Find out the first while pixel from right side ?

조회 수: 5 (최근 30일)
Sobit Singh
Sobit Singh 2018년 6월 11일
편집: Sobit Singh 2018년 6월 11일
I have done few process on my image and got stuck here. So far,this is the result that i got For now, all i need is to find the first white pixel in that image at every column from right side and display only that pixel rest all pixel in same row to be black .

채택된 답변

Matt J
Matt J 2018년 6월 11일
[m,n]=size(yourImage);
[~,idx]=max(fliplr(yourImage),[],2);
newImage= ( (n+1-idx)==(1:n) );
  댓글 수: 1
Sobit Singh
Sobit Singh 2018년 6월 11일
편집: Sobit Singh 2018년 6월 11일
Sir can you help me a little further i have to now find the distance between these two lines my approach is to add the two images and no of black pixel between white pixel from same row would be my distance . But i am not able to code my idea..

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

추가 답변 (1개)

Guillaume
Guillaume 2018년 6월 11일
The index of the maximum of each row of a binary image is also the index of the first white pixel of each row, thus:
newimage = false(size(yourimage)); %create blank binary image.
[~, col] = max(yourimage, [], 2); %find coordinate of 1st pixel of each row
newimage(ind2sub(size(newimage), (1:size(newimage, 1))', col)) = true;

Community Treasure Hunt

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

Start Hunting!

Translated by