How to detect certain pixel value in a stick.

1 visualización (últimos 30 días)
Chathurika Sandamali
Chathurika Sandamali el 19 de Feb. de 2021
Comentada: Chathurika Sandamali el 22 de Feb. de 2021
I want to measure the diameter of cinnamon sticks. I already did edge detection. I want to get one pixel value from upper line and second pixel value from lower line and then substract and get the diameter.
I am troubling when get upper and lower lines pixel values.It should be auto detecting when upload an image.
Thank you.

Respuesta aceptada

Rik
Rik el 19 de Feb. de 2021
Something like this will do it:
A=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/524729/image.png');
%convert image back to logical mask
L=im2double(im2gray(A))>0.5;
width=zeros(size(L,2),1);
for n=1:size(L,2)
tmp=L(:,n);
tmp=diff([find(tmp,1,'first') find(tmp,1,'last')]);
tmp=sort([0 tmp]);tmp=tmp(end);%catch empty case
width(n)=tmp;
end
width=median(width);
disp(width)
15
  3 comentarios
Rik
Rik el 22 de Feb. de 2021
If it works, please consider marking my answer as accepted answer.
The easiest way to repeat a process in Matlab is to use a loop. You can easily put my code in a function:
function width=WidthOfContour(L)
width=zeros(size(L,2),1);
for n=1:size(L,2)
tmp=L(:,n);
tmp=diff([find(tmp,1,'first') find(tmp,1,'last')]);
tmp=sort([0 tmp]);tmp=tmp(end);%catch empty case
width(n)=tmp;
end
width=median(width);
end
Chathurika Sandamali
Chathurika Sandamali el 22 de Feb. de 2021
Ok Thank you @Rik.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by