[37] | 1 | function h=plotframe(frames,varargin) |
---|
| 2 | % PLOTFRAME Plot feature frame |
---|
| 3 | % PLOTFRAME(FRAME) plots the frames FRAME. Frames are attributed |
---|
| 4 | % image regions (as, for example, extracted by a feature detector). A |
---|
| 5 | % frame is a vector of D=2,3,..,6 real numbers, depending on its |
---|
| 6 | % class. PLOTFRAME() supports the following classes: |
---|
| 7 | % |
---|
| 8 | % * POINTS |
---|
| 9 | % + FRAME(1:2) coordinates |
---|
| 10 | % |
---|
| 11 | % * CIRCLES |
---|
| 12 | % + FRAME(1:2) center |
---|
| 13 | % + FRAME(3) radius |
---|
| 14 | % |
---|
| 15 | % * ORIENTED CIRCLES |
---|
| 16 | % + FRAME(1:2) center |
---|
| 17 | % + FRAME(3) radius |
---|
| 18 | % + FRAME(4) orientation |
---|
| 19 | % |
---|
| 20 | % * ELLIPSES |
---|
| 21 | % + FRAME(1:2) center |
---|
| 22 | % + FRAME(3:5) S11, S12, S22 of x' inv(S) x = 1. |
---|
| 23 | % |
---|
| 24 | % * ORIENTED ELLIPSES |
---|
| 25 | % + FRAME(1:2) center |
---|
| 26 | % + FRAME(3:6) A(:) of ELLIPSE = A UNIT_CIRCLE |
---|
| 27 | % |
---|
| 28 | % H=PLOTFRAME(...) returns the handle of the graphical object |
---|
| 29 | % representing the frames. |
---|
| 30 | % |
---|
| 31 | % PLOTFRAME(FRAMES) where FRAMES is a matrix whose column are FRAME |
---|
| 32 | % vectors plots all frames simultaneously. Using this call is much |
---|
| 33 | % faster than calling PLOTFRAME() for each frame. |
---|
| 34 | % |
---|
| 35 | % PLOTFRAME(FRAMES,...) passes any extra argument to the underlying |
---|
| 36 | % plot function. |
---|
| 37 | |
---|
| 38 | % AUTORIGHTS |
---|
| 39 | % Copyright (C) 2006 Andrea Vedaldi |
---|
| 40 | % |
---|
| 41 | % This file is part of VLUtil. |
---|
| 42 | % |
---|
| 43 | % VLUtil is free software; you can redistribute it and/or modify |
---|
| 44 | % it under the terms of the GNU General Public License as published by |
---|
| 45 | % the Free Software Foundation; either version 2, or (at your option) |
---|
| 46 | % any later version. |
---|
| 47 | % |
---|
| 48 | % This program is distributed in the hope that it will be useful, |
---|
| 49 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 50 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 51 | % GNU General Public License for more details. |
---|
| 52 | % |
---|
| 53 | % You should have received a copy of the GNU General Public License |
---|
| 54 | % along with this program; if not, write to the Free Software Foundation, |
---|
| 55 | % Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 56 | |
---|
| 57 | % number of vertices drawn for each frame |
---|
| 58 | np = 40 ; |
---|
| 59 | |
---|
| 60 | % -------------------------------------------------------------------- |
---|
| 61 | % Handle various frame classes |
---|
| 62 | % -------------------------------------------------------------------- |
---|
| 63 | |
---|
| 64 | % if just a vector, make sure it is column |
---|
| 65 | if(min(size(frames))==1) |
---|
| 66 | frames = frames(:) ; |
---|
| 67 | end |
---|
| 68 | |
---|
| 69 | [D,K] = size(frames) ; |
---|
| 70 | zero_dimensional = D==2 ; |
---|
| 71 | |
---|
| 72 | % just points? |
---|
| 73 | if zero_dimensional |
---|
| 74 | h = plot(frames(1,:),frames(2,:),'g.',varargin{:}) ; |
---|
| 75 | return ; |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | % reduce all other cases to ellipses/oriented ellipses |
---|
| 79 | frames = frame2oell(frames) ; |
---|
| 80 | do_arrows = (D==4 || D==6) ; |
---|
| 81 | |
---|
| 82 | % -------------------------------------------------------------------- |
---|
| 83 | % Draw |
---|
| 84 | % -------------------------------------------------------------------- |
---|
| 85 | |
---|
| 86 | K = size(frames,2) ; |
---|
| 87 | thr = linspace(0,2*pi,np) ; |
---|
| 88 | |
---|
| 89 | % allx and ally are nan separated lists of the vertices describing the |
---|
| 90 | % boundary of the frames |
---|
| 91 | allx = nan*ones(1, np*K+(K-1)) ; |
---|
| 92 | ally = nan*ones(1, np*K+(K-1)) ; |
---|
| 93 | |
---|
| 94 | if do_arrows |
---|
| 95 | % allxf and allyf are nan separated lists of the vertices of the |
---|
| 96 | allxf = nan*ones(1, 3*K) ; |
---|
| 97 | allyf = nan*ones(1, 3*K) ; |
---|
| 98 | end |
---|
| 99 | |
---|
| 100 | % vertices around a unit circle |
---|
| 101 | Xp = [cos(thr) ; sin(thr) ;] ; |
---|
| 102 | |
---|
| 103 | for k=1:K |
---|
| 104 | |
---|
| 105 | % frame center |
---|
| 106 | xc = frames(1,k) ; |
---|
| 107 | yc = frames(2,k) ; |
---|
| 108 | |
---|
| 109 | % frame matrix |
---|
| 110 | A = reshape(frames(3:6,k),2,2) ; |
---|
| 111 | |
---|
| 112 | % vertices along the boundary |
---|
| 113 | X = A * Xp ; |
---|
| 114 | X(1,:) = X(1,:) + xc ; |
---|
| 115 | X(2,:) = X(2,:) + yc ; |
---|
| 116 | |
---|
| 117 | % store |
---|
| 118 | allx((k-1)*(np+1) + (1:np)) = X(1,:) ; |
---|
| 119 | ally((k-1)*(np+1) + (1:np)) = X(2,:) ; |
---|
| 120 | |
---|
| 121 | if do_arrows |
---|
| 122 | allxf((k-1)*3 + (1:2)) = xc + [0 A(1,1)] ; |
---|
| 123 | allyf((k-1)*3 + (1:2)) = yc + [0 A(2,1)] ; |
---|
| 124 | end |
---|
| 125 | |
---|
| 126 | end |
---|
| 127 | |
---|
| 128 | if do_arrows |
---|
| 129 | h = line([allx nan allxf], ... |
---|
| 130 | [ally nan allyf], ... |
---|
| 131 | 'Color','g','LineWidth',3, ... |
---|
| 132 | varargin{:}) ; |
---|
| 133 | else |
---|
| 134 | h = line(allx, ally, ... |
---|
| 135 | 'Color','g','LineWidth',3, ... |
---|
| 136 | varargin{:}) ; |
---|
| 137 | end |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | % -------------------------------------------------------------------- |
---|
| 141 | function eframes = frame2oell(frames) |
---|
| 142 | % FRAMES2OELL Convert generic frame to oriented ellipse |
---|
| 143 | % EFRAMES = FRAME2OELL(FRAMES) converts the frames FRAMES to |
---|
| 144 | % oriented ellipses EFRAMES. This is useful because many tasks are |
---|
| 145 | % almost equivalent for all kind of regions and are immediately |
---|
| 146 | % reduced to the most general case. |
---|
| 147 | |
---|
| 148 | % |
---|
| 149 | % Determine the kind of frames |
---|
| 150 | % |
---|
| 151 | [D,K] = size(frames) ; |
---|
| 152 | |
---|
| 153 | switch D |
---|
| 154 | case 2 |
---|
| 155 | kind = 'point' ; |
---|
| 156 | |
---|
| 157 | case 3 |
---|
| 158 | kind = 'disk' ; |
---|
| 159 | |
---|
| 160 | case 4 |
---|
| 161 | kind = 'odisk' ; |
---|
| 162 | |
---|
| 163 | case 5 |
---|
| 164 | kind = 'ellipse' ; |
---|
| 165 | |
---|
| 166 | case 6 |
---|
| 167 | kind = 'oellipse' ; |
---|
| 168 | |
---|
| 169 | otherwise |
---|
| 170 | error(['FRAMES format is unknown']) ; |
---|
| 171 | end |
---|
| 172 | |
---|
| 173 | eframes = zeros(6,K) ; |
---|
| 174 | |
---|
| 175 | % |
---|
| 176 | % Do converison |
---|
| 177 | % |
---|
| 178 | switch kind |
---|
| 179 | case 'point' |
---|
| 180 | eframes(1:2,:) = frames(1:2,:) ; |
---|
| 181 | |
---|
| 182 | case 'disk' |
---|
| 183 | eframes(1:2,:) = frames(1:2,:) ; |
---|
| 184 | eframes(3,:) = frames(3,:) ; |
---|
| 185 | eframes(6,:) = frames(3,:) ; |
---|
| 186 | |
---|
| 187 | case 'odisk' |
---|
| 188 | r = frames(3,:) ; |
---|
| 189 | c = r.*cos(frames(4,:)) ; |
---|
| 190 | s = r.*sin(frames(4,:)) ; |
---|
| 191 | |
---|
| 192 | eframes(1:2,:) = frames(1:2,:) ; |
---|
| 193 | eframes(3:6,:) = [c ; s ; -s ; c] ; |
---|
| 194 | |
---|
| 195 | case 'ellipse' |
---|
| 196 | eframes(1:2,:) = frames(1:2,:) ; |
---|
| 197 | |
---|
| 198 | eframes(3,:) = sqrt(frames(3,:)) ; |
---|
| 199 | eframes(4,:) = frames(4,:) ./ eframes(3,:) ; |
---|
| 200 | eframes(5,:) = zeros(1,K) ; |
---|
| 201 | eframes(6,:) = sqrt(frames(5,:) - ... |
---|
| 202 | frames(4,:).*frames(4,:)./frames(3,:)) ; |
---|
| 203 | case 'oellipse' |
---|
| 204 | eframes = frames ; |
---|
| 205 | end |
---|