find the coordinates 5 first white pixels in an image

2 次查看(过去 30 天)
I am trying to find the coordinates of the first 5 white pixels of a black and white image. With the find function I am able to find the first and the last one, but I need more, could someone help me? Thanks
%Find coordinates of the last and first white pixel
%First image
pix_amarelor = imread('pac14_e.png')
[row1first,colum1first] = find(pix_amarelor,1,'first');
imshow(pix_amarelor);
hold on;
plot(colum1first,row1first,'r+','LineWidth',2,'MarkerSize',30);
[row1last,colum1last] = find(pix_amarelor,1,'last');
% imshow(pix_amarillor);
hold on;
plot(colum1last,row1last,'r+','LineWidth',2,'MarkerSize',30)
  2 个评论
Image Analyst
Image Analyst 2023-8-30
Depends on how you define "first". Attach 'pac14.png' and tell us what pixels you consider to be the "first". And format your code as code with the code icon/button.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Rocío García Mojón
编辑:Rocío García Mojón 2023-8-31
Thank you very much.
I have an image like the first one and I would like to find the coordinates of the second photo, but with 4 additional points that are in the same column.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2023-8-31
Try this:
% Find coordinates of the last and first white pixel
% First image
pix_amarelor = imread('pac14_e.png');
[row1first,colum1first] = find(pix_amarelor,1,'first');
imshow(pix_amarelor);
hold on;
plot(colum1first,row1first,'r+','LineWidth',2,'MarkerSize',30);
[row1last,colum1last] = find(pix_amarelor,1,'last');
% imshow(pix_amarillor);
hold on;
plot(colum1last,row1last,'r+','LineWidth',2,'MarkerSize',30)
% Find all other pixels in the first column.
col1 = pix_amarelor(:, colum1first);
rowsInCol1 = find(col1)
rowsInCol1 = 6×1
292 293 294 295 296 297
% Find all other pixels in the last column.
col2 = pix_amarelor(:, colum1last);
rowsInCol2 = find(col2)
rowsInCol2 = 6×1
714 715 716 717 718 719
  3 个评论
Dyuman Joshi
Dyuman Joshi 2023-9-1
Hello @Rocío García Mojón, if this answer solved your problem, please consider accepting the answer.
Accepting the answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.
You can accept only 1 answer for a question, but you can vote for as many answers as you want. Voting an answer also provides reputation points.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by