⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11processregion.m

📁 这是关于人脸检测的matlab代码
💻 M
字号:
%                                 processregion.m
%
%                     By: Henry Chang and Ulises Robles

% ---------------------------------------------------------------------
% Given a image with only one region on it, determine if this region
% 给予的一图像与唯一的一区域在它上,决定是否这一个区域
% suggests a face or not. If so, we return a rectangle coordinate that
% 不管建议一个脸与否。 如果如此, 我们回返长方形同等的人物哪一

% will be drawn to indicate a detected face.  % 意志憔悴指出一发现脸。
% Arguments: 
%    imsourcegray: the original image in grayscale. 
imsourcegray: 在 grayscale 中的最初图像。
%    bwsegment: the black and white image with the desired region on it
%    bwsegment: 黑白的图像与那在它上需要了区域

%    numholes: the number of black areas inside the region
%    numholes: 在区域内的黑色区域的数字

%    frontalmodel: the grayscale image of our frontal face model
%    frontalmodel: 我们的 grayscale 图像前的脸模型

%
% ----------------------------------------------------------------------


function [RectCoord, imsourcegray] = processregion(imsourcegray, bwsegment, numholes, ...
				     frontalmodel)

  RectCoord = -1;
  % Get the size of the image  % 得到图像的大小
  [m n] = size(bwsegment);
   
  % Get the center of mass (energy) of the image   % 得到中心块 (能源) 那图像
  [cx,cy]=center(bwsegment);
  
  % Fill the holes in the binary image    % 填充洞在那二进位的图像
  bwnohole=bwfill(bwsegment,'holes');
  
  % To get just the probable face from the image  % 变得很正直有希望的候选人脸从那图像
  justface = uint8(double(bwnohole) .* double(imsourcegray));
  
  % Get the angle of rotation   % 拿旋转的角度
  angle = orient(bwsegment,cx,cy);
  
  % This is to compute the width and height of the region
  % 这将计算宽度和区域的高度
  bw = imrotate(bwsegment, angle, 'bilinear');
  bw = bwfill(bw,'holes');
  [l,r,u,d] = recsize(bw);
  wx = (r - l +1);  % width
  ly = (d - u + 1); % height
  
  % Get the ration between the height (ly) and width(wx) of the region
  % 拿高度 (ly) 和区域的宽度 (wx) 之间的定额
  wratio = ly/wx   
 
  % To be used if we find regions that are very tall
   % 被用如果我们找非常高的区域
  % Adjust the ratio by reducing the height of the region
  % 藉由减少区域的高度调整比
    if (wratio > 1.6) 

      ly = floor(1.5 * wx);    % approx. computation of the new height
      % 大概。 新高度的计算
      % This is to eliminate the parts of the image that are cut 
      % 这将除去图像的部份哪一是削减
      % after computing the new height of the region
      % 在计算机之后区域的新的高度
      [l,r,u,d] = recsize(bwnohole);
      start = floor((u+ly)*cos(-angle*pi/180));
      for i=start:m,
         for j=1:n,  
           bwsegment(i,j) = 0;
         end
      end
      
      % Compute the coordinates of the center of the new region
      % 计算新区域的中心的坐标
      [cx,cy]=center(bwsegment);
      
      % Get the new ratio  % 拿新的比
      wratio = ly/wx;   
    end;
   
  
 % We will determine the cross-correlation value between the image region
  % 我们意志决定跨相互关系价值在图像区域之间
 % that might indicate a face and the face model if the number of holes
 % 那可能指出一个脸和脸模型如果那数字洞
 % is greater than one. The ratio > 0.8 condition avoids the problem of
 % 是大超过一。 比 >0.8种情况避免问题
 % dealing with regions that are too wide.
   % 用太宽的区域的行为。
  if (numholes >=1  &  wratio >= 0.8) 
    [ccorr,mfit, RectCoord] = faceInfo(justface,frontalmodel,ly,wx, cx,cy, angle);
   else ccorr = 0;
  end;
   
  
 % ****************************************************************** 
 % Do the following only if we claim that we have found a face.
  % 做那下列各项只有当如果我们要求「我们有」发现一脸。
 % *****************************************************************

 % If we have holes, and the result of the cross-correlation above 1.6,
 % 如果我们有洞, 和那结果跨相互关系上方 1.6,
 % this is a face region.  % 这是一个脸区域。
 
 if (ccorr > 0.6 & numholes >= 1)  
   
   % Get an image with a black whole in the region where the face model
    % 拿一图像与一黑色的全部在区域中哪里脸模型
   % is. (Get the quantized version of the face model)
   % 是。 (拿那量化了脸模型的版本)
   mfitbw = (mfit >=1);
  
   % Flip the values of the image, so we can have white areas. This
    % 突然转动那价值那图像, 因此我们能有白色的区域。
   % areas will be multiplied by the original image. The remainding 
   % 区域将会是以最初人相乘描绘。 remainding
   % black "hole" is to be added by the face model.
   % 黑色的 " 洞 " 是附加的在~手边脸模型。
   invbw = xor(mfitbw,ones(size(mfitbw)));
   
   % Multiply the above image by the original one
   % 乘那上方最初的的图像
   source_with_hole = uint8(double(invbw) .* double(imsourcegray));
    
   % Add the rotated model face.
   % 增加那替换模型脸。
   % This image contains the original image part that is not the face
   % 这图像包含那最初的图像部份哪一是不那脸
   % and the model face added.
    % 而且那模型脸附加的。
   final_image = uint8(double(source_with_hole) + double(mfit));
   
   figure;
   imshow(final_image);
  
   imsourcegray = final_image;
 end;
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -