www.pudn.com > zhishiyingyuzhihua.rar > adaptive_threshold.m


%-------------------------------------------------------------------------- 
%  heuristic Global Thresholding 
% 
%-------------------------------------------------------------------------- 
clear all;      clc; 
 
imoriginal = double(imread('block.bmp')); 
[imh,imw] = size(imoriginal); 
 
figure,subplot(2,2,1),imshow(uint8(imoriginal)); 
title('原始图像','fontweight','bold','fontsize',20); 
 
[imresult,itrenum,Thre] = heuristic_global_thre(imoriginal); 
subplot(2,2,2),imshow(imresult); 
title(['阈值为:' num2str(Thre) ',迭代次数为:' num2str(itrenum)],... 
    'fontweight','bold','fontsize',20); 
 
% 将图像分为4块,进行自适应阈值化 
num = 1; 
for i = 1:1:2 
    for j = 1:1:2 
        imtemp = imcrop(imoriginal,[round((j-1)*imw/2)+1,round((i-1)*imh/2)+1 imw/2-1 imh/2-1]); 
        [imtemp1(:,:,num),itrenum,Thre] = heuristic_global_thre(imtemp); 
        num = num+1; 
    end 
end 
imresult = [imtemp1(:,:,1) imtemp1(:,:,2) 
    imtemp1(:,:,3) imtemp1(:,:,4)]; 
subplot(2,2,3),imshow(imresult); 
title('自适应阈值化','fontweight','bold','fontsize',20);