how to scan the first black pixel of top left on image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (2)
Walter Roberson
am 16 Apr. 2012
row = find( any(~YourImage, 2), 1);
col = find(~YourImage(row,:), 1);
3 Kommentare
Image Analyst
am 16 Apr. 2012
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
am 16 Apr. 2012
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 Kommentare
Walter Roberson
am 16 Apr. 2012
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
am 16 Apr. 2012
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);
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!