how to scan the first black pixel of top left on image
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Walter Roberson
2012 年 4 月 16 日
row = find( any(~YourImage, 2), 1);
col = find(~YourImage(row,:), 1);
3 件のコメント
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
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
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
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 Center および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!