Clear Filters
Clear Filters

find the coordinates 5 first white pixels in an image

2 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 30 Aug 2023
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 on 31 Aug 2023
Edited: Rocío García Mojón on 31 Aug 2023
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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 31 Aug 2023
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 Comments
Dyuman Joshi
Dyuman Joshi on 1 Sep 2023
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!