"Image Processing" method for segmentation of human eye regions by Bimodal thresholding

Source: Internet
Author: User

extraction of human eyes by Shuangfeng threshold segmentation

Human eye Area Segmentation (1) through the gray projection curve of the face, we get the rule that the face matrix changes from the line angle: The trough must contain the part of the human eye, and the largest part of the step of the crest to the trough is usually the part of the eye to the tip of the nose. Ideas:

Through the gray-level change law of human face to extract the ROI image containing the human eye part, when the eyes as the foreground, and the skin as a background, can be found through the Shuangfeng threshold to divide the ROI picture, then to maximize the retention of the human eye part. steps: 1. Extract ROI image

The image below is the gray projection curve of the human eye (filtered), the red is the crest, and the black is the trough. At the same time, it can show the regularity of gray-scale change of human face obviously. Then select the first occurrence of the crest m, the peak is selected with the Valley step of the largest crest is the second point N, the two points corresponding to the horizontal axis of the human eye matrix will be extracted line coordinates.

Through the above processing can get the ROI picture as follows, this method tests a certain number of image interception effect is better, the premise is to correct the curve filtering, so filter the small fluctuations, affecting the determination of the crest trough. The filter used here is Gaussian filtering.

This is the filter template I chose
sigma=5;
Window=double (Uint8 (3*sigma) *2+1);% window size half is 3*sigma
H=fspecial (' Gaussian ', window,sigma); 2. Determine the threshold value for Shuangfeng segmentation

Here want to use Shuangfeng to determine the threshold value of the segmentation, Shuangfeng determine the threshold of the basic principle is: gray image foreground and background difference is obvious, it will be in the gray histogram of the obvious Shuangfeng, and according to the trough in Shuangfeng can determine the segmentation foreground and background threshold, but in fact, in the process found that there will be many factors such as glasses, And the interference of the hair may not be accurate to say that the ROI picture is a clear picture of the obvious foreground and background, but here try to write this method of determining the threshold value. 2.1 Seeking gray histogram

Grayscale histogram is a function of gray level, describes the number of pixels in the image (or the frequency of the gray level pixels): The horizontal axis is the gray level, the ordinate represents the number of gray level in the image (frequency). 2.2 The peak of two peaks in the curve after filtering is Shuangfeng, and the threshold of Shuangfeng is obtained by mathematical method.

The processed results are drawn to the following image, where red is the gray function of the curve, Blue is the Gaussian filter curve, the yellow crest value, blue for the found trough value

3. Two value

Based on the obtained threshold value, the threshold value is set to 255 for the area of interest, the foreground pixel, and the background is set to 0.

Summary:

The above method can be used in the case of less interference, such as not many hair occlusion and glasses, but this method relies heavily on the effect of curve filtering. Code:

To calculate the crest and trough of a curve using the functions in MATLAB

The gray histogram of ROI graph is calculated, and the information of fixed threshold is obtained from gray histogram, so the threshold is clear.
Close all;
% filestring= ' zlroi\ ';
% Filestr=dir ([filestring, ' *.png ']);
% objstring= ' zlbw\ ';
% for Numofimg=1:length (filestr)% imgname=[filestring,filestr (numofimg). Name];
    % Roi=imread (imgname);
    Roi=imread (' roi\2.jpg ');
    MEDROI=MEDFILT2 (roi,[9,9]);
    [Row,col]=size (Medroi);
    Figure
    Imshow (Medroi);
Title (' ROI ');
        % appears multi-peak, then obviously the selected threshold value is inaccurate for k=0:255% subscript index must be a positive integer type or logical type Y (k+1) = 0;
                For I=1:row for J=1:col if (Medroi (i,j) ==k) y (k+1) =y (k+1) +1;

    End end End end x=0:1:255;
    The trough effect between peaks is not good sigma=4;
    Window=double (Uint8 (3*sigma) *2+1);% window size half is 3*sigma h=fspecial (' Gaussian ', window,sigma);
    G=imfilter (y,h, ' replicate ');% Gaussian filter [Pks,locs] = Findpeaks (G);
    Temp=pks;
    [Maxpeak,maxloc]=max (temp);
    Temp (Maxloc) = 0;
    [Maxsec,maxsecloc]=max (temp);
    New=zeros (1,255);
    A=locs (Maxloc); B=locs (maxsecLOC);
    if (a>b) new (B:A) =g (B:A);
    else New (A:B) =g (A:B);
    End [Min,minloc]=findpeaks (-new);
    [Minpeak,minpeakloc]=max (min);


    Choice=minloc (Minpeakloc);
    Figure
    Title (' Gray Histogram ');
    Plot (x, Y, ' r ');% draw unfiltered histogram hold on;
    Plot (x,g, ' B ');% draw the filtered histogram hold on; Plot (Locs,pks, ' yellow* ');% uses D to mark the filtered peak plot (1:255,new, ' black ')% to draw a curve plot between the two peaks intercepted (Choice,y (choice), ' blue* ');
            Draw the trough of the intercept curve to the threshold value processing for I=1:row for J=1:col if (Medroi (i,j) >choice) medroi (i,j) = 0;
            else Medroi (i,j) = 255;

    End End End%imwrite (Medroi,[objstring,num2str (numofimg), '. png ');
    Figure
    Title (' binary image ');
Imshow (Medroi);
%end% also to carry out corrosion expansion% morgh=bwmorph (medroi, ' dilate ', 2);
% Figure;
% imshow (Morgh);
% title (' corrosion Expansion ');
% Figure;
% Contour=bwperim (Morgh);
% imshow (contour);

%% title (' contour ');
% median filter does not have the parameter too large effect straight line% x=0:1:255;
% Y=MEDFILT2 (y,[4,4]);
% plot (x, Y, ' R ');
% linear fitting of gray function graph, the curve fitting order can not be too high, but the higher the error, and the order can not exceed 255% x=1:1:256;
% Figure;
% plot (x, Y, ' R ');
% title (' Gray function graph ');
% for i=2:2:256% fit (I/2) =y (i) +y (i-1);
% end% [P,s]=polyfit (x,y,23);
% Sum=polyval (p,x,1);
% Figure;
% plot (x,sum, ' Blue ');
% title (' Gray function graph ');
%% Sum=0;
% for i=1:46% sum=sum+p (i) *y (i);

 %% End
Conclusion:

The Shuangfeng filter method is more suitable for two peaks, and there is a distinct flat trough between the Shuangfeng.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.