 %%%%下面检测二值图的轮廓:如果与四邻域的差中有一个为1,则为内点,否则为外点.
 function output=contour_bw(input)
 %input=imread('bw_image.bmp');
 %%输入图像矩阵:input
 %%输出图像矩阵:在边界处为255,内部为0
%  input=Lnew_out;
 
 [r,c]=size(input);
 output=255*zeros(r,c);
 %改动过
%  global num;
 global r_avg;
 r_avg=0;
 global g_avg;
 g_avg=0;
 global b_avg;
 b_avg=0;
%  global rect_rgb_01;%最初切割原图像
 Reb_dot=0;


 for i=2:r-1
     for j=2:c-1
         if (input(i,j)-input(i,j+1)==1 ||  input(i,j)-input(i,j-1)==1  ||  input(i,j)-input(i+1,j)==1 ||  input(i,j)-input(i-1,j)==1)
                 output(i,j)=255;
%                 r_avg=r_avg+double(rect_rgb_01(i,j,1));
%                 g_avg=g_avg+double(rect_rgb_01(i,j,2));
%                 b_avg=b_avg+double(rect_rgb_01(i,j,3));
%                 num=num+1;
                 Reb_dot=Reb_dot+1;
         else
                 output(i,j)=0;
         end
     end
     Reb_dot
 end


 

 
%   r_avg=uint8(r_avg/num);
%   g_avg=uint8(g_avg/num);
%   b_avg=uint8(b_avg/num);


 
 