Sir, how to find area & coordinates of white pixels in binary image?

1 view (last 30 days)
How to find area & coordinates of white pixels in binary image?
  2 Comments
hemanth kumar.v
hemanth kumar.v on 6 Nov 2018
I wanted to crop those white pixels & i did with the help of find function.. thanks sir

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Dec 2024
Edited: Image Analyst on 26 Dec 2024
To get all the rows and columns of the white pixels, you can do
[rows, columns] = find(binaryImage);
You'll get two vectors and a given index will give you the same pixel. For example to get the row and column of the 37th pixel, you can do
r = rows(37)
c = columns(37)
If you want to use x,y terminology, you can do
[y, x] = find(binaryImage);
because rows are y and columns are x.
To crop you can do
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
binaryImage = binaryImage(row1:row2, col1:col2);

Community Treasure Hunt

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

Start Hunting!