0% found this document useful (0 votes)
38 views

Function He

This document contains Matlab code to analyze an image of a cookie. It converts the image to grayscale and performs binary thresholding. Morphological opening and closing operations are performed to clean up the image. The centroids of objects in the binary image are then found and plotted on the original image. Centroid coordinates and counts are displayed on the plotted image.

Uploaded by

Melanie Inglish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Function He

This document contains Matlab code to analyze an image of a cookie. It converts the image to grayscale and performs binary thresholding. Morphological opening and closing operations are performed to clean up the image. The centroids of objects in the binary image are then found and plotted on the original image. Centroid coordinates and counts are displayed on the plotted image.

Uploaded by

Melanie Inglish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

%function he = objetos(f)

f=im2double(imread('C:\galleta1.jpg'));
figure, imshow(f), title('imagen original')
I = rgb2gray(f);
figure,imshow(I), title('imagen gray')
%Binariza la imagen fuente
fbw=im2bw(I, 0.9);
figure, imshow(fbw), title('imagen binaria')
fbw = not(fbw);%imagen negativa
se = strel ('square',8);%elemento estructural
fbw = imopen(fbw, se);
figure, imshow(fbw);title('imagen open');
se= strel('square',25);%elemento estructural
fbw = imclose(fbw, se);
figure, imshow(fbw);title('imagen open');
%encuentra los centroides.
[L, n] = bwlabel(fbw);
[r, c] = find(L == 3); % las filas y las %colum. de todos los pixeles del
obj. #3.
rbar = mean(r);
cbar = mean(c);
imshow(fbw)
hold on
for k=1:n
[r,c] = find (L == k);
rbar = mean(r);
cbar = mean (c);

plot(cbar,rbar,'marker','O','MarkerEdgeColor','k','MarkerFaceColor','k','
MarkerSize',10)
plot(cbar, rbar, 'marker','*','MarkerEdgeColor','w')

col = sprintf('%2.2f', cbar);


row = sprintf('%2.2f', rbar);
text (cbar+5,rbar+5,col,'color','r',...
'FontSize',10,'FontWeight','bold');
text ( cbar+5,rbar+35,col,'color','r',...
'FontSize',10,'FontWeight','bold');

end

You might also like