Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

Walter Roberson
Walter Roberson il 16 Apr 2012
row = find( any(~YourImage, 2), 1);
col = find(~YourImage(row,:), 1);
  3 Commenti
Image Analyst
Image Analyst il 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.

Accedi per commentare.


Geoff
Geoff il 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 Commenti
Walter Roberson
Walter Roberson il 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
Geoff il 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);

Accedi per commentare.

Categorie

Scopri di più su Read, Write, and Modify Image in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by