[Image segmentation] Maximum between-class variance (otsu) image segmentation [Matlab 121] [Image processing 38]

The maximum between-class variance method proposed by Otsu in 1978 is a threshold selection method that has attracted more attention. It is derived on the basis of decision analysis or the principle of least squares.

references:

[1] Otsu N. A threshold selection method from gray-level histogram. IEEE Trans,1979;SMC-9;62-66 下载地址

Algorithm idea:

Suppose an image has L gray levels [1,2,...,L]. The number of pixels with gray level i is ni, then the total number of pixels should be N=n1+n2+...+nL. For the convenience of discussion, we use the normalized gray-level histogram and regard it as the probability distribution of this image:
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

 
clear
close all
clc
 
I=imread('rice.png');    
[m,n]=size(I);   
N=m*n;   
L=256;   
 
for i=1:L  
    count(i)=length(find(I==(i-1)));  
    f(i)=count(i)/(N);  %每个灰度对应的概率,i=1,对应灰度值为0(i-1)
end  
 
for i=1:L   
    if count(i)~=0   
        st=i-1;   %开始的灰度值
        break;   
    end   
end   
for i=L:-1:1   
    if count(i)~=0   
        nd=i-1;   %结束的灰度值
        break;   
    end   
end   
 
p=st;   q=nd-st+1;   
u=0;   
for i=1:q   
    u=u+f(p+i)*(p+i-1);  %u是像素的平均值    
    ua(i)=u;           %ua(i)是前i+p个像素的平均灰度值  (前p个无取值) 
end;   
 
for i=1:q   
    w(i)=sum(f(1+p:i+p));  %w(i)是前i个像素的累加概率,对应公式中P0 
end;   
 
w=w+eps;  
   %对照sigmaB的公式写出目标函数。实际是遍历所有值
d=(w./(1-w)).*(ua./w-u).^2;
[y,tp]=max(d);  %可以取出数组的最大值及取最大值的点   
th=tp+p;  
 
 
figure;imshow(im2bw(I,th/255),[]);  title('最大类间方差');
%% matlab自带函数
figure;imshow(im2bw(I,graythresh(I)),[]);  title('matlab自带');
 

Insert picture description here
Insert picture description here
Note: complete code or writing add QQ2449341593 past review
>>>>>>
[Matlab 024] [Image Processing 1] Image Compression of Matlab Image Processing Tutorial Series
[Matlab 025] [Image Processing 2] Matlab Image Processing Tutorial Series of image segmentation (1)
[Matlab 026] [Image processing 3] Matlab image processing tutorial series of image segmentation (2)
[Matlab 029] [Image processing 4] Matlab fingerprint recognition
[Matlab 030] [Image processing 5 】Bank card number recognition matlab source code
[Matlab 074 issue] [Image processing 6] [Image clustering] Based on FCM and improved FCM brain CT image clustering processing
[Matlab 075] [Image processing 7] [Image evaluation] Based on CCF Algorithmic image quality evaluation
[Matlab 076] [Image processing 8] [Image enhancement] CLAHE algorithm based on local contrast enhancement-histogram enhancement
[Matlab 077] [Image processing 9] [Image fusion] Image based on Frequency Partition Fusion
[Matlab Issue 078] [Image Processing 10] [Image Evaluation] Image quality evaluation based on svm without reference
[Image edge detection] Matlab source code for ellipse edge detection based on least squares method [Matlab Issue 079] [Image Processing 11]
[Image Encryption] Image encryption and decryption based on chaos system matlab source code with GUI [Matlab 080] [Image processing 12]
[Image processing] Based on DWT+DCT+PBFO to improve image watermark hiding and extraction matlab source code with GUI [Matlab 081] [Image processing 13】
[Image registration] Image registration matlab source code based on sift algorithm [Matlab 082] [Image processing 14]
[Image fusion] Image fusion matlab source code based on CBF algorithm [Matlab 083] [Image processing 15]
[Image segmentation] Image segmentation matlab source code based on random walk algorithm [Matlab 084] [Image processing 16]
[Image filtering] Image two-dimensional bilateral Gaussian filtering [Matlab 085] [Image processing 17]
[Image denoising] Based on adaptive morphology Image denoising [Matlab 086 period] [Image processing 18]
[Image enhancement] DEHAZENET and HWD based underwater scattering image enhancement [Matlab 087] [Image processing 19]
[Image enhancement] PSO optimization ACE image enhancement matlab Source code [Matlab 088] [Image processing 20]
[Image enhancement] Gray-scale image enhancement based on region similarity transformation function and dragonfly algorithm [Matlab 089] [Image processing 21]
[Image reconstruction] ASTRA algorithm for image reconstruction [Matlab 090 [Image processing 22]
[Image segmentation] Image segmentation based on quadtree matlab source code [Matlab 091] [Image processing 23]
[Image segmentation] Heart centerline extraction [Matlab 092] [Image processing 24]
[Image recognition ] Based on svm plant leaf disease detection and classification [Matlab 093] [Image processing 25]
[Image recognition] Based on template matching handwritten number recognition system GUI interface [Matlab 094] [Image processing 26]
[Image recognition] based on unchanged Moment’s digital verification code recognition with GUI interface [Matlab 095] [Image processing 27]
[Image recognition] Barcode recognition system [Matlab 096] [Image processing 28]
[Image recognition] RMB recognition system based on RGB and BP neural network with GUI interface [Matlab 097] [Image processing 29]
[Image recognition] Matlab source code recognition based on cnn convolutional neural network [Matlab 098] [Image Processing 30]
[Image classification] Classification of remote sensing images based on extreme learning classifier [Matlab 099] [Image processing 31]
[Image straight line fitting] Image straight line fitting based on least squares method and bisect angle bisector [Matlab 100 [Image processing 32]
[Image defogging] Image defogging based on dark channel [Matlab 101 issue] [Image processing 33]
[Image transformation] DIBR-3D image transformation (3D Image Warping) [Matlab 117 issue] [Image processing 34 ]
[image] segmentation image segmentation and morphological reconstruction filtering improved FCM algorithm (FRFCM) Matlab 118 based on the [period] [35] the image processing
[image] image segmentation based on fuzzy clustering algorithm FCM segmentation [period] [Matlab 119 Image processing 36]
[Image segmentation] Intuitionistic fuzzy C-means clustering image segmentation IFCM [Matlab 120] [Image processing 37]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/112907935