来自「选择其中图像中的矩形及正方形等感兴趣区域ROI」· 代码 · 共 748 行 · 第 1/3 页

TXT
748
字号
for i=1:2:length(PNameValArray)
    if strcmpi(PNameValArray{i},PName)
        if length(PNameValArray)>i
            res = PNameValArray{i+1};
            break;
        else
            error('%s: Parameter "%s" present, but its value absent',mfilename, PName);
        end
    end
end
return;

%==========================================================================
% Validate selection
%==========================================================================
function res = ValidateSelection
GP = guidata(gcf);
res = true;
if ~isfield(GP,'SP1')
    res = false; return;
end
if ~isfield(GP,'SP2')
    res = false; return;
end
res = res & ( GP.SP1(1) >= GP.XLim(1) );
res = res & ( GP.SP1(1) <= GP.XLim(2) );
res = res & ( GP.SP1(2) >= GP.YLim(1) );
res = res & ( GP.SP1(2) <= GP.YLim(2) );
res = res & ( GP.SP2(1) >= GP.XLim(1) );
res = res & ( GP.SP2(1) <= GP.XLim(2) );
res = res & ( GP.SP2(2) >= GP.YLim(1) );
res = res & ( GP.SP2(2) <= GP.YLim(2) );
return;

%==========================================================================
% Recalculate control points
%==========================================================================
function [r1,r2] = RecalculateControlPoints(p1,p2)
% fprintf( 'p1=[ %06g %06g ] p2=[ %06g %06g ]\n',p1,p2 );
r1  = [ min([ p1(1) p2(1) ]) min([ p1(2) p2(2) ]) ];
r2  = [ max([ p1(1) p2(1) ]) max([ p1(2) p2(2) ]) ];
% fprintf( 'r1=[ %06g %06g ] r2=[ %06g %06g ]\n',r1,r2 );
return;

%==========================================================================
% Recalculate selection rectangle
%==========================================================================
function [sp1,sp2] = RecalculateSelection(p1,p2, SelShape, SelMode)
XLen    = abs( p2(1) - p1(1) );
YLen    = abs( p2(2) - p1(2) );
MinLen  = min( [ XLen YLen ] );
Xsgn    = sign( p2(1) - p1(1) );
Ysgn    = sign( p2(2) - p1(2) );
if strcmpi(SelMode,'Centered')
    if strcmpi(SelShape,'Square')
        sp  = p1 - [Xsgn Ysgn]*MinLen;
        ep  = p1 + [Xsgn Ysgn]*MinLen;
    else
        sp  = p1 + ( p1 - p2 );
        ep  = p2;
    end
else
    if strcmpi(SelShape,'Square')
        sp  = p1;
        ep  = p1 + [Xsgn Ysgn]*MinLen;
    else
        sp  = p1;
        ep  = p2;
    end
end
[sp1,sp2] = RecalculateControlPoints(sp,ep);
return;

%==========================================================================
% Drawing cross in current axes
%==========================================================================
function h = caDrawCross(x,y,L, EraseMode, LWidth,LColor,LStyle, TColor,TSize,FontWeight, TLLabel,TRLabel,BLLabel,BRLabel)
%==========================================================================
%   This functions draws cross with four labels in current axes
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% h = caDrawCross(x,y,L, EraseMode, LWidth,LColor,LStyle,...
%                       TColor,TSize,FontWeight, TLLabel,TRLabel,BLLabel,BRLabel)
% 
%       x,y             Coordinates of center of cross
%       L               Cross size
%                           If L=0 this function draws cross trough full
%                           range of the coordinate system (like ginput)
%       EraseMode       EraseMode property of lines ad all text labels
%       LWidth          Line width
%       LColor          Line color
%       LStyle          Line style
%       TColor          Text color
%       TSize           Text size
%       FontWeight      Font weight
%       TLLabel         Top-left label string
%       TRLabel         Top-right label string
%       BLLabel         Bottom-left label string
%       BRLabel         Bottom-right label string
% 
%       h               array of handles of all created elements
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%   Type
%           help line
%   or
%           help text
%   for more information about line and text parameters
%==========================================================================
c   = 1;
if L>0
    h(c)    = line( [x-0 x+0],[y-L y+L+1], 'LineWidth',LWidth, 'LineStyle',LStyle, 'Color',LColor, 'EraseMode',EraseMode );
    c = c + 1;
    h(c)    = line( [x-L x+L+1],[y-0 y+0], 'LineWidth',LWidth, 'LineStyle',LStyle, 'Color',LColor, 'EraseMode',EraseMode );
    c = c + 1;
else
    h(c)    = line( [x-0 x+0],ylim, 'LineWidth',LWidth, 'LineStyle',LStyle, 'Color',LColor, 'EraseMode',EraseMode );
    c = c + 1;
    h(c)    = line( xlim,[y-0 y+0], 'LineWidth',LWidth, 'LineStyle',LStyle, 'Color',LColor, 'EraseMode',EraseMode );
    c = c + 1;
end
if ~strcmp(TLLabel,'')
    h(c) = text(x,y,[TLLabel ' '],...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','right',...
        'VerticalAlignment','bottom',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(TRLabel,'')
    h(c) = text(x,y,[' ' TRLabel],...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','left',...
        'VerticalAlignment','bottom',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(BLLabel,'')
    h(c) = text(x,y+1,[BLLabel ' '],...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','right',...
        'VerticalAlignment','top',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(BRLabel,'')
    h(c) = text(x,y+1,[' ' BRLabel],...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','left',...
        'VerticalAlignment','top',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    %c   = c + 1;
end
return;

%==========================================================================
% Drawing rectangle in current axes
%==========================================================================
function h = caDrawRectangle(X1,Y1,X2,Y2, EraseMode, LWidth,LColor,LStyle, FaceColor, TColor,TSize,FontWeight, TopLabel,BottomLabel,RightLabel,LeftLabel)
%==========================================================================
%   This functions draws rectangle with four labels in current axes
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% h = caDrawRectangle(X1,Y1,X2,Y2, EraseMode, LWidth,LColor,LStyle, FaceColor,...
%                       TColor,TSize,FontWeight, TopLabel,BottomLabel,RightLabel,LeftLabel)
% 
%       X1,X2,Y1,Y2     Coordinates of the rectangle
%       EraseMode       EraseMode property of rectangle ad all text labels
%       LWidth          Line width
%       LColor          Line color
%       LStyle          Line style
%       FaceColor       Face color
%       TColor          Text color
%       TSize           Text size
%       FontWeight      Font weight
%       TopLabel        Top label string
%       BottomLabel     Bottom label string
%       RightLabel      Right label string
%       LeftLabel       Left label string
% 
%       h               array of handles of all created elements
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%   Type
%           help rectangle
%   or
%           help text
%   for more information about rectangle and text parameters
%==========================================================================
c   = 1;
if (round(X1)~=round(X2))&&(round(Y1)~=round(Y2))
    h(c) = rectangle('Position',[X1,Y1,X2-X1,Y2-Y1],...
        'FaceColor',FaceColor,...
        'EraseMode',EraseMode,...
        'EdgeColor',LColor,...
        'LineWidth',LWidth,...
        'LineStyle',LStyle);
    c   = c + 1;
end
if ~strcmp(TopLabel,'')
    h(c) = text(X1,Y1,TopLabel,...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','Left',...
        'VerticalAlignment','bottom',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(BottomLabel,'')
    h(c) = text(X2,Y2+1,BottomLabel,...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','Right',...
        'VerticalAlignment','top',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(RightLabel,'')
    h(c) = text(X2,Y1,RightLabel,...
        'Rotation',-90.0,...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','Left',...
        'VerticalAlignment','bottom',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    c   = c + 1;
end
if ~strcmp(LeftLabel,'')
    h(c) = text(X1,Y2,LeftLabel,...
        'Rotation',+90.0,...
        'EraseMode',EraseMode,...
        'HorizontalAlignment','Left',...
        'VerticalAlignment','bottom',...
        'Color',TColor,...
        'FontSize',TSize,...
        'FontWeight',FontWeight);
    %c   = c + 1;
end
return;

⌨️ 快捷键说明

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