Get pixels in a region

15 visualizaciones (últimos 30 días)
Niamh Shiel
Niamh Shiel el 7 de Mzo. de 2016
Comentada: Image Analyst el 8 de Mzo. de 2016
Hi,
I'm looking to get the locations of the first white pixel (top left) of each region and the last white pixel in each region (bottom right) of the image supplied. I do not need every white pixel in the region either, just the beginning and end points. I need this to determine the "entry and exit points" of the regions in the image so it can later be compared against a similar image.
If anyone has any suggestions of how this would be done, I'd really appreciate it. I've tried using find() but I only ever manage to get the very first white pixel and the very last in the image.
Thanks.
  2 comentarios
Walter Roberson
Walter Roberson el 7 de Mzo. de 2016
Your question is ambiguous. Do you need the leftmost white pixel of the top row that has at least one white pixel, or do you need the topmost white pixel of the first column that has at least one white pixel? Likewise, do you need the rightmost white pixel of the bottom row that has at least one white pixel, or do you need the bottommost white pixel of the last column that has at least one white pixel?
Your image has slanted lines so it does make a difference.
Niamh Shiel
Niamh Shiel el 8 de Mzo. de 2016
Thanks for trying to help Walter, it's columns I need I believe. I think I found a way to achieve what I wanted - I added a Bounding Box to all the regions and, from that, got the coordinates of the top left and top right corners of the bounding box. I'm only interested in the horizontal locations, and not the vertical, so this seems to work.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 8 de Mzo. de 2016
From your clarification, it sounds like you could do
[rows, columns] = find(binaryImage);
leftColumn = min(columns);
rightColumn = max(columns);
  4 comentarios
Niamh Shiel
Niamh Shiel el 8 de Mzo. de 2016
I see what you mean. I noticed the outputs were all decimals and I thought it was a little strange, so thank you for clearing that up for me! I don't think the half a pixel either side would matter too much for what I need it for. However, as a work around, I could just apply round and floor to correct the results again, couldn't I?
Image Analyst
Image Analyst el 8 de Mzo. de 2016
Sure, do whatever you need to to get the right answer.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by