亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fit_ellipse.m

?? 目標輪廓的橢圓擬合
?? M
字號:
function ellipse_t = fit_ellipse( x,y,axis_handle )
%
% fit_ellipse - finds the best fit to an ellipse for the given set of points.
%
% Format:   ellipse_t = fit_ellipse( x,y,axis_handle )
%
% Input:    x,y         - a set of points in 2 column vectors. AT LEAST 5 points are needed !
%           axis_handle - optional. a handle to an axis, at which the estimated ellipse 
%                         will be drawn along with it's axes
%
% Output:   ellipse_t - structure that defines the best fit to an ellipse
%                       a           - sub axis (radius) of the X axis of the non-tilt ellipse
%                       b           - sub axis (radius) of the Y axis of the non-tilt ellipse
%                       phi         - orientation in radians of the ellipse (tilt)
%                       X0          - center at the X axis of the non-tilt ellipse
%                       Y0          - center at the Y axis of the non-tilt ellipse
%                       X0_in       - center at the X axis of the tilted ellipse
%                       Y0_in       - center at the Y axis of the tilted ellipse
%                       long_axis   - size of the long axis of the ellipse
%                       short_axis  - size of the short axis of the ellipse
%                       status      - status of detection of an ellipse
%
% Note:     if an ellipse was not detected (but a parabola or hyperbola), then
%           an empty structure is returned

% =====================================================================================
%                  Ellipse Fit using Least Squares criterion
% =====================================================================================
% We will try to fit the best ellipse to the given measurements. the mathematical
% representation of use will be the CONIC Equation of the Ellipse which is:
% 
%    Ellipse = a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0
%   
% The fit-estimation method of use is the Least Squares method (without any weights)
% The estimator is extracted from the following equations:
%
%    g(x,y;A) := a*x^2 + b*x*y + c*y^2 + d*x + e*y = f
%
%    where:
%       A   - is the vector of parameters to be estimated (a,b,c,d,e)
%       x,y - is a single measurement
%
% We will define the cost function to be:
%
%   Cost(A) := (g_c(x_c,y_c;A)-f_c)'*(g_c(x_c,y_c;A)-f_c)
%            = (X*A+f_c)'*(X*A+f_c) 
%            = A'*X'*X*A + 2*f_c'*X*A + N*f^2
%
%   where:
%       g_c(x_c,y_c;A) - vector function of ALL the measurements
%                        each element of g_c() is g(x,y;A)
%       X              - a matrix of the form: [x_c.^2, x_c.*y_c, y_c.^2, x_c, y_c ]
%       f_c            - is actually defined as ones(length(f),1)*f
%
% Derivation of the Cost function with respect to the vector of parameters "A" yields:
%
%   A'*X'*X = -f_c'*X = -f*ones(1,length(f_c))*X = -f*sum(X)
%
% Which yields the estimator:
%
%       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%       |  A_least_squares = -f*sum(X)/(X'*X) ->(normalize by -f) = sum(X)/(X'*X)  |
%       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%
% (We will normalize the variables by (-f) since "f" is unknown and can be accounted for later on)
%  
% NOW, all that is left to do is to extract the parameters from the Conic Equation.
% We will deal the vector A into the variables: (A,B,C,D,E) and assume F = -1;
%
%    Recall the conic representation of an ellipse:
% 
%       A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0
% 
% We will check if the ellipse has a tilt (=orientation). The orientation is present
% if the coefficient of the term "x*y" is not zero. If so, we first need to remove the
% tilt of the ellipse.
%
% If the parameter "B" is not equal to zero, then we have an orientation (tilt) to the ellipse.
% we will remove the tilt of the ellipse so as to remain with a conic representation of an 
% ellipse without a tilt, for which the math is more simple:
%
% Non tilt conic rep.:  A`*x^2 + C`*y^2 + D`*x + E`*y + F` = 0
%
% We will remove the orientation using the following substitution:
%   
%   Replace x with cx+sy and y with -sx+cy such that the conic representation is:
%   
%   A(cx+sy)^2 + B(cx+sy)(-sx+cy) + C(-sx+cy)^2 + D(cx+sy) + E(-sx+cy) + F = 0
%
%   where:      c = cos(phi)    ,   s = sin(phi)
%
%   and simplify...
%
%       x^2(A*c^2 - Bcs + Cs^2) + xy(2A*cs +(c^2-s^2)B -2Ccs) + ...
%           y^2(As^2 + Bcs + Cc^2) + x(Dc-Es) + y(Ds+Ec) + F = 0
%
%   The orientation is easily found by the condition of (B_new=0) which results in:
% 
%   2A*cs +(c^2-s^2)B -2Ccs = 0  ==> phi = 1/2 * atan( b/(c-a) )
%   
%   Now the constants   c=cos(phi)  and  s=sin(phi)  can be found, and from them
%   all the other constants A`,C`,D`,E` can be found.
%
%   A` = A*c^2 - B*c*s + C*s^2                  D` = D*c-E*s
%   B` = 2*A*c*s +(c^2-s^2)*B -2*C*c*s = 0      E` = D*s+E*c 
%   C` = A*s^2 + B*c*s + C*c^2
%
% Next, we want the representation of the non-tilted ellipse to be as:
%
%       Ellipse = ( (X-X0)/a )^2 + ( (Y-Y0)/b )^2 = 1
%
%       where:  (X0,Y0) is the center of the ellipse
%               a,b     are the ellipse "radiuses" (or sub-axis)
%
% Using a square completion method we will define:
%       
%       F`` = -F` + (D`^2)/(4*A`) + (E`^2)/(4*C`)
%
%       Such that:    a`*(X-X0)^2 = A`(X^2 + X*D`/A` + (D`/(2*A`))^2 )
%                     c`*(Y-Y0)^2 = C`(Y^2 + Y*E`/C` + (E`/(2*C`))^2 )
%
%       which yields the transformations:
%       
%           X0  =   -D`/(2*A`)
%           Y0  =   -E`/(2*C`)
%           a   =   sqrt( abs( F``/A` ) )
%           b   =   sqrt( abs( F``/C` ) )
%
% And finally we can define the remaining parameters:
%
%   long_axis   = 2 * max( a,b )
%   short_axis  = 2 * min( a,b )
%   Orientation = phi
%
%

% initialize
orientation_tolerance = 1e-3;

% empty warning stack
warning( '' );

% prepare vectors, must be column vectors
x = x(:);
y = y(:);

% remove bias of the ellipse - to make matrix inversion more accurate. (will be added later on).
mean_x = mean(x);
mean_y = mean(y);
x = x-mean_x;
y = y-mean_y;

% the estimation for the conic equation of the ellipse
X = [x.^2, x.*y, y.^2, x, y ];
a = sum(X)/(X'*X);

% check for warnings
if ~isempty( lastwarn )
    disp( 'stopped because of a warning regarding matrix inversion' );
    ellipse_t = [];
    return
end

% extract parameters from the conic equation
[a,b,c,d,e] = deal( a(1),a(2),a(3),a(4),a(5) );

% remove the orientation from the ellipse
if ( min(abs(b/a),abs(b/c)) > orientation_tolerance )
    
    orientation_rad = 1/2 * atan( b/(c-a) );
    cos_phi = cos( orientation_rad );
    sin_phi = sin( orientation_rad );
    [a,b,c,d,e] = deal(...
        a*cos_phi^2 - b*cos_phi*sin_phi + c*sin_phi^2,...
        0,...
        a*sin_phi^2 + b*cos_phi*sin_phi + c*cos_phi^2,...
        d*cos_phi - e*sin_phi,...
        d*sin_phi + e*cos_phi );
    [mean_x,mean_y] = deal( ...
        cos_phi*mean_x - sin_phi*mean_y,...
        sin_phi*mean_x + cos_phi*mean_y );
else
    orientation_rad = 0;
    cos_phi = cos( orientation_rad );
    sin_phi = sin( orientation_rad );
end

% check if conic equation represents an ellipse
test = a*c;
switch (1)
case (test>0),  status = '';
case (test==0), status = 'Parabola found';  warning( 'fit_ellipse: Did not locate an ellipse' );
case (test<0),  status = 'Hyperbola found'; warning( 'fit_ellipse: Did not locate an ellipse' );
end

% if we found an ellipse return it's data
if (test>0)
    
    % make sure coefficients are positive as required
    if (a<0), [a,c,d,e] = deal( -a,-c,-d,-e ); end
    
    % final ellipse parameters
    X0          = mean_x - d/2/a;
    Y0          = mean_y - e/2/c;
    F           = 1 + (d^2)/(4*a) + (e^2)/(4*c);
    [a,b]       = deal( sqrt( F/a ),sqrt( F/c ) );    
    long_axis   = 2*max(a,b);
    short_axis  = 2*min(a,b);

    % rotate the axes backwards to find the center point of the original TILTED ellipse
    R           = [ cos_phi sin_phi; -sin_phi cos_phi ];
    P_in        = R * [X0;Y0];
    X0_in       = P_in(1);
    Y0_in       = P_in(2);
    
    % pack ellipse into a structure
    ellipse_t = struct( ...
        'a',a,...
        'b',b,...
        'phi',orientation_rad,...
        'X0',X0,...
        'Y0',Y0,...
        'X0_in',X0_in,...
        'Y0_in',Y0_in,...
        'long_axis',long_axis,...
        'short_axis',short_axis,...
        'status','' );
else
    % report an empty structure
    ellipse_t = struct( ...
        'a',[],...
        'b',[],...
        'phi',[],...
        'X0',[],...
        'Y0',[],...
        'X0_in',[],...
        'Y0_in',[],...
        'long_axis',[],...
        'short_axis',[],...
        'status',status );
end

% check if we need to plot an ellipse with it's axes.
if (nargin>2) & ~isempty( axis_handle ) & (test>0)
    
    % rotation matrix to rotate the axes with respect to an angle phi
    R = [ cos_phi sin_phi; -sin_phi cos_phi ];
    
    % the axes
    ver_line        = [ [X0 X0]; Y0+b*[-1 1] ];
    horz_line       = [ X0+a*[-1 1]; [Y0 Y0] ];
    new_ver_line    = R*ver_line;
    new_horz_line   = R*horz_line;
    
    % the ellipse
    theta_r         = linspace(0,2*pi);
    ellipse_x_r     = X0 + a*cos( theta_r );
    ellipse_y_r     = Y0 + b*sin( theta_r );
    rotated_ellipse = R * [ellipse_x_r;ellipse_y_r];
    
    % draw
    hold_state = get( axis_handle,'NextPlot' );
    set( axis_handle,'NextPlot','add' );
    plot( new_ver_line(1,:),new_ver_line(2,:),'r' );
    plot( new_horz_line(1,:),new_horz_line(2,:),'r' );
    plot( rotated_ellipse(1,:),rotated_ellipse(2,:),'r' );
    set( axis_handle,'NextPlot',hold_state );
end

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av在线一区二区| 午夜视频在线观看一区二区| 欧美v日韩v国产v| 91久久久免费一区二区| 色综合天天综合在线视频| 成人av手机在线观看| 不卡免费追剧大全电视剧网站| 国产高清不卡二三区| 成人午夜av在线| 欧美三电影在线| 欧美日韩精品一区二区三区蜜桃 | 亚洲一区二区欧美日韩 | 亚洲国产日韩精品| 亚洲第一主播视频| 热久久久久久久| 激情偷乱视频一区二区三区| 成人性生交大合| 色视频欧美一区二区三区| 欧美午夜精品一区二区三区| 日韩一级二级三级| 欧美经典三级视频一区二区三区| 国产欧美精品一区二区三区四区| 《视频一区视频二区| 亚洲一区二区在线视频| 欧美aⅴ一区二区三区视频| 国产一区二区看久久| av不卡一区二区三区| 欧美日韩另类一区| 日本一区二区免费在线观看视频| 亚洲欧美自拍偷拍| 麻豆视频观看网址久久| 不卡av免费在线观看| 在线播放一区二区三区| 国产精品国产三级国产aⅴ原创| 中文字幕一区二区三区在线播放| 亚洲成年人网站在线观看| 国产成人综合在线观看| 欧美性猛交xxxx乱大交退制版| 欧美成人三级在线| 亚洲天堂免费在线观看视频| 蜜桃久久精品一区二区| 91浏览器入口在线观看| 精品欧美一区二区久久| 一片黄亚洲嫩模| 国产成人精品影院| 91精品国产综合久久蜜臀| 中文字幕第一区二区| 美女诱惑一区二区| 欧美最猛性xxxxx直播| 精品国产一区二区国模嫣然| 亚洲美女免费视频| 不卡一卡二卡三乱码免费网站 | 视频在线观看国产精品| 不卡av电影在线播放| 欧美成人一区二区| 五月天视频一区| 色综合一区二区三区| 欧美国产一区二区在线观看 | 国产校园另类小说区| 日韩不卡在线观看日韩不卡视频| 91亚洲资源网| 国产精品的网站| 狠狠色2019综合网| 欧美一区二区三区影视| 亚洲最快最全在线视频| 99re这里只有精品6| 国产精品毛片久久久久久久| 国产高清视频一区| 久久久国产精品不卡| 精品综合久久久久久8888| 日韩一级免费一区| 青青草原综合久久大伊人精品 | 久久精品视频在线看| 麻豆精品国产传媒mv男同| 88在线观看91蜜桃国自产| 亚洲精品成人a在线观看| 91丨九色porny丨蝌蚪| 亚洲欧美偷拍另类a∨色屁股| 成人免费va视频| 国产精品传媒入口麻豆| 成人av资源在线| 国产精品成人免费| 日本高清不卡一区| 视频一区在线播放| 精品乱人伦小说| 成人性视频免费网站| 国产精品久久久久一区二区三区 | 88在线观看91蜜桃国自产| 日韩avvvv在线播放| 4438成人网| 久久99精品久久久久久| 亚洲国产精品99久久久久久久久| 欧美日韩小视频| 免费看欧美美女黄的网站| xvideos.蜜桃一区二区| av在线综合网| 午夜精品久久久久久久蜜桃app| 欧美一级久久久| 国产一区二区看久久| 一区二区三区在线视频免费观看| 欧美日韩综合在线| 久久99国产精品久久99果冻传媒| 国产精品午夜电影| 欧美日韩成人激情| 国产一级精品在线| 一区二区免费视频| 精品av综合导航| 在线看日本不卡| 国产一区二区三区久久久| 一区在线观看视频| 欧美成人aa大片| 在线亚洲人成电影网站色www| 亚洲成av人影院| 欧美精品一二三区| 国产高清不卡一区二区| 亚洲国产乱码最新视频| 国产亚洲一区二区三区| 欧美三区在线观看| 丁香婷婷深情五月亚洲| 日韩电影一区二区三区| 国产精品久久一级| 欧美岛国在线观看| 欧美日韩精品福利| 91一区二区三区在线观看| 国产一区在线观看麻豆| 一区二区三区在线影院| 国产精品丝袜在线| 精品国产乱码久久久久久久久| 色综合久久88色综合天天免费| 国产一区二区在线影院| 香蕉影视欧美成人| 亚洲免费毛片网站| 最新欧美精品一区二区三区| 精品88久久久久88久久久| 91精品福利在线一区二区三区| 色哟哟精品一区| aaa欧美日韩| 丁香桃色午夜亚洲一区二区三区| 蜜臀av亚洲一区中文字幕| 亚洲第一福利一区| 亚洲国产精品尤物yw在线观看| 国产精品国产a| 欧美国产97人人爽人人喊| 精品国产乱码久久久久久浪潮 | 狠狠色狠狠色综合| 免费成人在线观看视频| 午夜成人在线视频| 亚洲成人中文在线| 午夜成人免费视频| 免费成人小视频| 日韩高清电影一区| 琪琪久久久久日韩精品| 日韩精品久久理论片| 丝袜脚交一区二区| 日韩av成人高清| 国产在线精品免费av| 国产在线视频一区二区三区| 国模娜娜一区二区三区| 国产精品一区二区无线| 处破女av一区二区| 99热国产精品| 久久综合久久久久88| 久久久久久免费网| 国产精品毛片高清在线完整版| 亚洲少妇30p| 亚洲国产欧美在线| 日本特黄久久久高潮| 久久国产夜色精品鲁鲁99| 蜜臀精品一区二区三区在线观看| 极品少妇xxxx偷拍精品少妇| 国产伦精品一区二区三区免费迷| 国产99久久久久| 欧美在线观看一二区| 日韩欧美成人激情| 国产精品短视频| 性感美女极品91精品| 狠狠色综合播放一区二区| 波多野结衣亚洲| 欧美日本在线播放| 久久亚洲二区三区| 中文字幕视频一区二区三区久| 亚洲在线一区二区三区| 麻豆精品视频在线观看免费| 成人综合激情网| 69av一区二区三区| 中文子幕无线码一区tr| 亚洲1区2区3区视频| 国产精品一区二区三区99| 色婷婷一区二区三区四区| 欧美大片在线观看一区| 亚洲美女区一区| 国产一区二区三区高清播放| 色综合天天性综合| 精品国产免费人成在线观看| 综合欧美亚洲日本| 国产成人在线网站| 欧美精品乱码久久久久久| 中文字幕不卡的av| 久久精品国产99| 欧美日韩五月天|