How to do a Algoritm of globals' thresholding segmentation?
1 view (last 30 days)
Show older comments
Hi:
I must do a practice of a globals' thresholding segmentation for one leason at university, and I'm a little bit lost.
This is the code if have done, but it has a bug...Could some one help me?
im=imread('C:\Users\Fran\Desktop\Universidad\Ing. Industrial\5º AÑO\1º Cuatrimestres\Vision por computador\Imagenes\texto.jpg');
U=graythresh(im);
US=im2double(im);
UI=im2bw(US);
U0=0.5;
[nfilas, ncolumnas]=size(UI);
tic
while U<U0
G1M=0;G1=0;
G2M=0;G2=0;
for i=1:nfilas
for j=1:ncolumnas
U1=im(i,j);
if U1>=U
G1=G1+U1;
G1M=G1M+1;
im(i,j)=1;
end
if U1<U
%G2A=G2;
G2=G2+U1;
G2M=G2M+1;
im(i,j)=0;
end
end
M1=G1/G1M;
M2=G2/G2M;
U=0.5*(M1+M2);
end
figure, imshow(im);
end
toc;
Thanks a lot
1 Comment
Answers (2)
Image Analyst
on 3 Nov 2013
You don't need that for loop. Simply do
binaryImage = im>U; % Binarize.
G1M = sum(im(binaryImage)); % Sum gray levels above threshold (for some reason???)
G2M = sum(im(~binaryImage)); % Sum gray levels below threshold (for some reason???)
Not sure what G1M and G2M were computed for.
1 Comment
Image Analyst
on 3 Nov 2013
Francisco. Nice try but not very efficient. See my code attached below.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!