Borrar filtros
Borrar filtros

How do I find the white pixel in the row/column

5 visualizaciones (últimos 30 días)
Kantachai Chamnarnkit
Kantachai Chamnarnkit el 9 de Feb. de 2023
Editada: Vilém Frynta el 9 de Feb. de 2023
I can find the centroid of an white pixel image. I want to find the first/last white pixel in the row/column to calculate the distance of x and y.

Respuestas (1)

Vilém Frynta
Vilém Frynta el 9 de Feb. de 2023
Editada: Vilém Frynta el 9 de Feb. de 2023
Hope this answers your question.
img = imread("pic1.jpg"); % loading your picture
img = rgb2gray(img); % convert to black-and-white pic
row = 450; % choosing random row
idx = find(img(row,:)==0); % position of all white pixels in row 450
diff = idx(1) - idx(end) % difference of first and last pixel in row 450
diff = -598
This should work fine. I noticed your white == 0 and black == 255.
Also, this is for chosen row. If you change this a bit, you can get it for any column.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by