how to scan the first black pixel of top left on image

조회 수: 1 (최근 30일)
mohd
mohd 2012년 4월 15일
hello there, i want to scan the first black pixel of top left on image and store the coordinate of that pixel. how can i do.. here i attach example of image.

답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 16일
row = find( any(~YourImage, 2), 1);
col = find(~YourImage(row,:), 1);
  댓글 수: 3
Image Analyst
Image Analyst 2012년 4월 16일
True, but I think that mohd wants to shift the image so that the left most part of the black frame is in column 1, and the top most part of the black frame gets shifted to row 1 (he mentioned that in hist prior post). Walter's code finds the bounding box of the black frame, even if it's tilted, and so I think that is exactly what mohd needs. I don't think he really needs the upper left corner despite the fact that he asked for that. (If he really did want the upper left corner you might have to use regionprops of find and examine all coordinates and find how which had the shortest distance to row 1, column1.) But like I said, I don't think that is really what he requires if he just wants to shift the image to the upper left, as he mentioned in his prior post where I recommended circshift(). Now he's wanting to know how much shift to pass into circshift, and Walter's code will give that.
Geoff
Geoff 2012년 4월 16일
Ahh, sweet as =)

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


Geoff
Geoff 2012년 4월 16일
If your image data is grayscale or indexed (1 value per pixel), you can do this:
[y,x] = find( img == 0, 1 );
If it's RGB, you can do the zero-test in each channel:
[y,x] = find( all(img==0, 3), 1 );
This assumes pure-black.
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 4월 16일
Geoff, that find() line will go down the columns first. If the picture is tilted towards the right, that would find the bottom left corner instead of the top left. The code I gave in my answer finds the top row first and then the first column in the top. Mind you, that has the opposite problem, finding the upper right corner if the picture is tilted towards the left.
Geoff
Geoff 2012년 4월 16일
Hmm, true. You might want to change your code to find the zero pixels ;-) I suppose a solution then would be to find all the [x,y] coords for black pixels and then do:
cornerDist = hypot(x,y)
iCorner = find( cornerDist == min(cornerDist), 1 );
x = x(iCorner);
y = y(iCorner);

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

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by