1 | function fig=vgg_gui_F(i1,i2,F)
|
---|
2 | %
|
---|
3 | % fig=vgg_gui_F(i1,i2,F)
|
---|
4 | %
|
---|
5 | %
|
---|
6 | % Visualizes the fundamental matrix of two views
|
---|
7 | %
|
---|
8 | %IN:
|
---|
9 | % i1 - Matlab image
|
---|
10 | % i2 - Matlab image
|
---|
11 | % F - Fundamental matrix (p1'*F*p2=0). Assumes that image coordiantes
|
---|
12 | % are 1..width where pixel centers are at integer locations.
|
---|
13 | %
|
---|
14 | %OUT:
|
---|
15 | % fig - handle to the figure
|
---|
16 |
|
---|
17 | % $Id: vgg_gui_F.m,v 1.8 2002/05/20 21:35:42 wexler Exp $
|
---|
18 | % Yoni, Tue Mar 27 19:31:16 2001
|
---|
19 |
|
---|
20 |
|
---|
21 | if nargin==3
|
---|
22 | action='start';
|
---|
23 | else
|
---|
24 | action=i1;
|
---|
25 | ud = get(gcf, 'UserData');
|
---|
26 | end
|
---|
27 |
|
---|
28 | if strcmp(action,'start'),
|
---|
29 | if nargin ~= 3
|
---|
30 | error('Must give 3 arguments... read the docs.\n');
|
---|
31 | end
|
---|
32 |
|
---|
33 | h0 = figure('Color',[0.8 0.8 0.8], ...
|
---|
34 | 'NumberTitle','off', ...
|
---|
35 | 'Name','Play With Fundamental Matrix', ...
|
---|
36 | 'ButtonDownFcn', 'disp(''Click on images'')',...
|
---|
37 | 'WindowButtonUpFcn', 'vgg_gui_F(''none'');',...
|
---|
38 | 'WindowButtonMotionFcn', 'vgg_gui_F(''move'')', ...
|
---|
39 | 'Pointer', 'crosshair', ...
|
---|
40 | 'DoubleBuffer', 'on',...
|
---|
41 | 'Units','normalized');
|
---|
42 | [pointerShape, pointerHotSpot] = CreatePointer;
|
---|
43 | set(h0, 'Pointer', 'custom', ...
|
---|
44 | 'PointerShapeCData', pointerShape, ...
|
---|
45 | 'PointerShapeHotSpot', pointerHotSpot);
|
---|
46 |
|
---|
47 | m0=uimenu('Label', '&Color');
|
---|
48 | uimenu(m0, 'Label', 'blac&K', 'ForegroundColor', [0 0 0], ...
|
---|
49 | 'Accelerator', 'k', 'Callback', 'vgg_gui_F(''ck'');');
|
---|
50 | uimenu(m0, 'Label', '&Red', 'ForegroundColor', [1 0 0], ...
|
---|
51 | 'Accelerator', 'r', 'Callback', 'vgg_gui_F(''cr'');');
|
---|
52 | uimenu(m0, 'Label', '&Green', 'ForegroundColor', [0 1 0], ...
|
---|
53 | 'Accelerator', 'g', 'Callback', 'vgg_gui_F(''cg'');');
|
---|
54 | uimenu(m0, 'Label', '&Blue', 'ForegroundColor', [0 0 1], ...
|
---|
55 | 'Accelerator', 'b', 'Callback', 'vgg_gui_F(''cb'');');
|
---|
56 | m1=uimenu('Label', '&Size');
|
---|
57 | uimenu(m1, 'Label', '&Increase', 'Callback', 'vgg_gui_F(''s+'');', 'Accelerator', '+');
|
---|
58 | uimenu(m1, 'Label', '&Decrease', 'Callback', 'vgg_gui_F(''s-'');', 'Accelerator', '-');
|
---|
59 | uimenu(m1, 'Label', '&1', 'Callback', 'vgg_gui_F(''s1'');', 'Accelerator', '1');
|
---|
60 | uimenu(m1, 'Label', '&2', 'Callback', 'vgg_gui_F(''s2'');', 'Accelerator', '2');
|
---|
61 | uimenu(m1, 'Label', '&3', 'Callback', 'vgg_gui_F(''s3'');', 'Accelerator', '3');
|
---|
62 | uimenu(m1, 'Label', '&4', 'Callback', 'vgg_gui_F(''s4'');', 'Accelerator', '4');
|
---|
63 | uimenu(m1, 'Label', '&5', 'Callback', 'vgg_gui_F(''s5'');', 'Accelerator', '5');
|
---|
64 | uimenu(m1, 'Label', '&6', 'Callback', 'vgg_gui_F(''s6'');', 'Accelerator', '6');
|
---|
65 | uimenu(m1, 'Label', '&7', 'Callback', 'vgg_gui_F(''s7'');', 'Accelerator', '7');
|
---|
66 | uimenu(m1, 'Label', '&8', 'Callback', 'vgg_gui_F(''s8'');', 'Accelerator', '8');
|
---|
67 | uimenu(m1, 'Label', '&9', 'Callback', 'vgg_gui_F(''s9'');', 'Accelerator', '9');
|
---|
68 |
|
---|
69 | ah1 = axes('Parent', h0, ...
|
---|
70 | 'Position',[0 0 .5 1]);
|
---|
71 | % h1=imshow(i1);
|
---|
72 | h1 = imagesc(i1) ; colormap gray ; axis image ; axis off ;% min midified
|
---|
73 | hold on; title('Image 1');
|
---|
74 | set(h1, 'ButtonDownFcn','vgg_gui_F(''b1'');');
|
---|
75 |
|
---|
76 | ah2 = axes('Parent',h0, ...
|
---|
77 | 'Position',[.5 0 .5 1], ...
|
---|
78 | 'Tag','Axes2');
|
---|
79 | % h2=imshow(i2);
|
---|
80 | h2 = imagesc(i2) ; colormap gray ; axis image ; axis off ;% min midified
|
---|
81 | hold on; title('Image 2');
|
---|
82 | set(h2, 'ButtonDownFcn','vgg_gui_F(''b2'');');
|
---|
83 |
|
---|
84 | point=plot(-1000, -1000,'EraseMode','xor');
|
---|
85 | l=plot([-1000, -1001], [-1000 -1000], 'r-','EraseMode','xor');
|
---|
86 |
|
---|
87 | s1=size(i1); s2=size(i2);
|
---|
88 | t(:,:,1)=F'; t(:,:,2)=F; F=t;
|
---|
89 |
|
---|
90 | ud=struct('h0', h0, 'h',[h1 h2], 'ah', [ah1, ah2], ...
|
---|
91 | 'sizes', [s1(1:2); s2(1:2)], ...
|
---|
92 | 'current', -1, 'color', 'k', 'size', 1, ...
|
---|
93 | 'p', point, 'F', F, 'l', l );
|
---|
94 |
|
---|
95 | set(h0,'UserData',ud);
|
---|
96 |
|
---|
97 | if nargout > 0, fig = h0; end
|
---|
98 | elseif strcmp(action, 'move')
|
---|
99 | if ud.current<0 return; end;
|
---|
100 | pt=get(ud.ah(ud.current),'CurrentPoint');
|
---|
101 | pts=get_line_points(ud.F(:,:,ud.current)*pt(1,:)', ...
|
---|
102 | ud.sizes(ud.current,:));
|
---|
103 |
|
---|
104 | set(ud.l, 'XData', pts(1,:), 'YData', pts(2,:))
|
---|
105 | set(ud.p, 'XData', pt(1,1), 'YData', pt(1,2))
|
---|
106 |
|
---|
107 | elseif action(1)=='b'
|
---|
108 | if action(2)=='1' ud.current=1;
|
---|
109 | elseif action(2)=='2' ud.current=2;
|
---|
110 | else return;
|
---|
111 | end
|
---|
112 | pt=get(ud.ah(ud.current),'CurrentPoint');
|
---|
113 |
|
---|
114 | pts=get_line_points(ud.F(:,:,ud.current)*pt(1,:)', ud.sizes(1,:));
|
---|
115 | delete(ud.p);
|
---|
116 | delete(ud.l);
|
---|
117 | axes(ud.ah(ud.current));
|
---|
118 | ud.p=plot(pt(1,1), pt(1,2), [ud.color '+'], ...
|
---|
119 | 'MarkerSize', 8+2*ud.size, 'LineWidth', ud.size,...
|
---|
120 | 'EraseMode','xor');
|
---|
121 | axes(ud.ah(3-ud.current));
|
---|
122 | ud.l=plot(pts(1,:), pts(2,:), [ud.color '-'], ...
|
---|
123 | 'LineWidth', ud.size, 'EraseMode','xor');
|
---|
124 | elseif action(1)=='c'
|
---|
125 | ud.color=action(2);
|
---|
126 | %get(ud.l)
|
---|
127 | set(ud.l, 'Color', ud.color);
|
---|
128 | set(ud.p, 'Color', ud.color);
|
---|
129 | elseif action(1)=='s'
|
---|
130 | if action(2)=='+' ud.size=ud.size+1;
|
---|
131 | elseif action(2)=='-' ud.size=max(1, ud.size-1);
|
---|
132 | else
|
---|
133 | ud.size = str2num(action(2));
|
---|
134 | end
|
---|
135 | set(ud.p, 'LineWidth', ud.size, 'MarkerSize', 8+2*ud.size);
|
---|
136 | set(ud.l, 'LineWidth', ud.size, 'MarkerSize', 8+2*ud.size);
|
---|
137 | elseif strcmp(action, 'none')
|
---|
138 | ud.current = -1;
|
---|
139 | else
|
---|
140 | error(['Unknown command: ' action]);
|
---|
141 | end
|
---|
142 |
|
---|
143 | set(ud.h0, 'UserData',ud);
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 | function pts=get_line_points(l,sz)
|
---|
148 | a=l(1); b=l(2);c=l(3);
|
---|
149 | h=sz(1); w=sz(2);
|
---|
150 |
|
---|
151 | % This might cause 'divide by zero' warning:
|
---|
152 | ys=c/-b ;
|
---|
153 | yf=-(a*w+c)/b;
|
---|
154 | xs=c/-a;
|
---|
155 | xf=-(b*h+c)/a;
|
---|
156 |
|
---|
157 | m1 = [[xs;1] [xf;h] [1;ys] [w;yf]];
|
---|
158 | w2 = [(xs<=w & xs>=1) (xf<=w & xf>=1) (ys<=h & ys>=1) (yf<=h & yf>=1)];
|
---|
159 | v = w2>0;
|
---|
160 | pts = [m1(:,v)];
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | % Taken from pixval.m:
|
---|
165 | function [pointerShape, pointerHotSpot] = CreatePointer
|
---|
166 |
|
---|
167 | pointerHotSpot = [8 8];
|
---|
168 | pointerShape = [ ...
|
---|
169 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
170 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
171 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
172 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
173 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
174 | 1 1 1 1 1 1 2 NaN 2 1 1 1 1 1 1 1
|
---|
175 | 2 2 2 2 2 2 NaN NaN NaN 2 2 2 2 2 2 2
|
---|
176 | NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
|
---|
177 | 2 2 2 2 2 2 NaN NaN NaN 2 2 2 2 2 2 2
|
---|
178 | 1 1 1 1 1 1 2 NaN 2 1 1 1 1 1 1 1
|
---|
179 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
180 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
181 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
182 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
183 | NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
|
---|
184 | NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN];
|
---|