A list,

A projection, we learned in solid geometry, is a projection of a line in space in some direction, and that’s the same idea in image processing.

The simplest projection: horizontal projection, the image array column sum; Vertical projection, the image array for line summation; The projection method is often used to segment the foreground and background of binary images or gray-scale images with obvious features.

Ii. Source code

function y1=OTSU(image,th_set)
clc
%X=input('Enter the picture name'.'s');
im=imread('dianbiao2.jpg');
%a2=imread('color1.bmp'); gray=rgb2gray(im); % Gray image im1= medFilt2 (gray,[3.3]); % denoising, two-dimensional median filtering, with3*3Low_high = Stretchlim (IM1); Gray =imadjust(gray,low_high,[]); gray=imadjust(gray,low_high,[]); % enhanced image contrast %subplot(224); imshow(gray); title('after adjust'); count=imhist(im1); [r,t]=size(im1); % the number of rows in the array is returned to the first output variable and the number of columns in the array is returned to the second output variable n=r*t; l=256; count=count/n; % probability of gray appearing at all levelsfor i=2:l
        if count(i)~=0
            st=i- 1;
            breakEnd end % above the loop statement to find the probability of occurrence is not0Is the minimum gray value offor i=l:- 1:1
        if count(i)~=0;
            nd=i- 1;
            breakEnd end % to find the probability of occurrence is not0F =count(st+)1:nd+1); p=st; q=nd-st; %p and are the starting and ending values u= of gray scale respectively0;
for i=1:q;
        u=u+f(i)*(p+i- 1); ua(i)=u; End % calculates the average gray value of the imagefor i=1:q;
        w(i)=sum(f(1:i)); End % calculates the probability of A region d=(u*w-ua).^2./(w.*(1-w)); % Calculate the variance between classes with different k values [y, TP]= Max (d); % the gray level corresponding to the maximum variance th= TP + P; y1=zeros(r,t);for i=1:r
        for j=1:t
            x1(i,j)=double(im1(i,j));
        end
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a