sorry the code copied wrongly. here is my code again.
global im
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprintf('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im); %converts to double
axes(handles.axes1);
imshow(im);
imgray=(im(:,:,1)+im(:,:,2)+im(:,:,2))/3;
axes(handles.axes1);
imshow(imgray);
hy=fspecial('sobel');
hx=hy;
Iy=imfilter(double(imgray),hy,'replicate');
Ix=imfilter(double(imgray),hx,'replicate');
imgradmag=sqrt(Ix.^2+Iy.^2);
axes(handles.axes1);
imshow(imgradmag);
se=strel('disk',20);
Ie=imerode(imgray,se);
Iobr=imreconstruct(Ie,imgray);
axes(handles.axes1);
imshow(Iobr);
edgeim=edge(Iobr,'canny',[0.15 0.2]);
axes(handles.axes1);
imshow(edgeim);
d=imdistline;
[centers,radii]=imfindcircles(edgeim,[5 10],'sensitivity',0.92,'Edge',0.03);
viscircles(centers,radii,'EdgeColor','b');
axes(handles.axes1);
figure,imshow(edgeim);
h=length(centers);
Total=ones(240,320);
figure,imshow(Total);
hold on
HDText=insertText(Total,[205 55],h,'AnchorPoint','LeftCenter');
imshow(HDText);
text(25,55,'TOTAL : ','FontSize',12,'FontWeight','bold','Color','m');
hold off
rgbImage=imread(im);
imshow(rgbImage,'Parent',handles.axes1);
imshow(imgray,'Parent',handles.axes2);
imshow(imgradmag,'Parent',handles.axes3);
imshow(Iobr,'Parent',handles.axes4);
imshow(Total,'Parent',handles.axes5);