-
Notifications
You must be signed in to change notification settings - Fork 3
/
verticalRegistrationTool.m
121 lines (105 loc) · 4.52 KB
/
verticalRegistrationTool.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
classdef verticalRegistrationTool < handle
properties
FigureImages
AxisImage
HandleImage
HandleOverlay
Image
Overlay
Dialog
Slider
Tform
DoneButtonPushed
end
methods
function tool = verticalRegistrationTool(Moving,Fixed,varargin)
tool.Image{1} = Moving;
tool.Image{2} = Fixed;
tool.Tform = affine2d(eye(3,3));
tool.DoneButtonPushed = false;
p = inputParser;
p.addParameter('MaxShift',50);
p.addParameter('NHLines',7);
p.addParameter('NVLines',5);
p.parse(varargin{:});
p = p.Results;
maxShift = p.MaxShift;
nHLines = p.NHLines;
nVLines = p.NVLines;
ss = get(0,'ScreenSize'); % [left botton width height]
tool.FigureImages = figure('Position',[ss(3)/4 ss(4)/4 ss(3)/2 ss(4)/2],...
'NumberTitle','off', 'Name','Vertical Registration Tool', 'CloseRequestFcn',@tool.closeFigure, 'Resize','on');
vPositions = linspace(1,size(tool.Image{1},2),nVLines+2);
vPositions = vPositions(2:end-1);
hPositions = linspace(1,size(tool.Image{1},1),nHLines+2);
hPositions = hPositions(2:end-1);
tool.AxisImage{1} = subplot(1,3,1);
tool.HandleImage{1} = imshow(tool.Image{1});
hold on
for i = 1:length(vPositions)
plot([vPositions(i) vPositions(i)], [1 size(tool.Image{1},1)],'y')
end
for i = 1:length(hPositions)
plot([1 size(tool.Image{1},2)], [hPositions(i) hPositions(i)],'y')
end
hold off
tool.AxisImage{2} = subplot(1,3,2);
tool.HandleImage{2} = imshow(tool.Image{2});
hold on
for i = 1:length(vPositions)
plot([vPositions(i) vPositions(i)], [1 size(tool.Image{1},1)],'y')
end
for i = 1:length(hPositions)
plot([1 size(tool.Image{1},2)], [hPositions(i) hPositions(i)],'y')
end
hold off
tool.AxisImage{3} = subplot(1,3,3);
I2Red = zeros(size(tool.Image{2},1),size(tool.Image{2},2),3);
I2Red(:,:,1) = tool.Image{2};
tool.HandleImage{3} = imshow(I2Red);
hold on
tool.Overlay = zeros(size(tool.Image{1},1),size(tool.Image{1},2),3);
tool.Overlay(:,:,2) = tool.Image{1}; % green
tool.HandleOverlay = imshow(tool.Overlay);
tool.HandleOverlay.AlphaData = 0.5*ones(size(tool.Image{1}));
hold off
dwidth = 500;
dborder = 10;
cwidth = dwidth-2*dborder;
cheight = 20;
tool.Dialog = dialog('WindowStyle', 'normal',...
'Name', 'VRT',...
'CloseRequestFcn', @tool.closeDialog,...
'Position',[100 100 dwidth 3*dborder+3*cheight]);
% slider
Slider = uicontrol('Parent',tool.Dialog,'Style','slider','Min',-maxShift,'Max',maxShift,'Value',0,'Position',[dborder 2*dborder+2*cheight cwidth cheight]);
addlistener(Slider,'Value','PostSet',@tool.continuousSliderManage);
% quit
uicontrol('Parent',tool.Dialog,'Style','pushbutton','String','Done','Position',[dborder dborder cwidth 2*cheight],'Callback',@tool.buttonDonePushed);
uiwait(tool.Dialog)
end
function continuousSliderManage(tool,~,callbackdata)
value = callbackdata.AffectedObject.Value;
T = eye(3,3);
T(3,2) = value;
tool.Tform = affine2d(T);
I = imwarp(tool.Image{1},tool.Tform,'OutputView',imref2d(size(tool.Image{1})));
tool.HandleImage{1}.CData = I;
tool.Overlay(:,:,2) = I;
tool.HandleOverlay.CData = tool.Overlay;
end
function buttonDonePushed(tool,~,~)
delete(tool.FigureImages);
delete(tool.Dialog);
tool.DoneButtonPushed = true;
end
function closeDialog(tool,~,~)
delete(tool.FigureImages);
delete(tool.Dialog);
end
function closeFigure(tool,~,~)
delete(tool.FigureImages);
delete(tool.Dialog);
end
end
end