close allI = imread('E:\txm
jpg');J= rgb2gray(I);figure(1)imshow(J);title('灰度化图像 ’);[e1,e2]=size(J);Im=imcrop(J,[e2/2—200,e1/2-200,400,400]);figure(2)subplot(1,2,1),imshow(Im)title('中心区域 ');subplot(1,2,2),imhist(Im)title('中心区域直方图');[xa,ya]=size(Im); b=double(Im); zd=double(max(Im)) ; zx=double(min(Im)) ; T=double((zd+zx))/2; count=double(0); while 1 count=count+1; S0=0
0; n0=0
0; S1=0
0; n1=0
0; for i=1:xafor j=1:yaif double(Im(i,j))〉=TS1=S1+double(Im(i,j)); n1=n1+1; else S0=S0+double(Im(i,j)); n0=n0+1; end end end T0=S0/n0; T1=S1/n1; if abs(T-((T0+T1)/2))=T);J(K)=255;figure(3)imshow(J)title(' 图像二值化 ');B=medfilt2(J,[5,1]);figure(4)imshow(B)title('中值滤波后图像’);[y0,x0]=size(B);BW = edge(B,'log’); figure(5);imshow(BW);title('边缘检测图像'