-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPTRegister.m
88 lines (77 loc) · 3.69 KB
/
IPTRegister.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
% La lista de estudios disponibles es:
% 000: Training 000
% 001: Patient 001
% 002: Patient 002
% 005: Patient 005
% 006: Patient 006
% 007: Patient 007
%% Close all windows and delete all variables and matrices
close all
clear
%% Functions
addpath(genpath('functions/'))
%% Getting DICOM images
patient=002;
[moving,fixed]=dicomOpen(patient);
% Graphics
figure('Name',['Patient ' num2str(patient) ': Unregistered images']);
imshowpair(moving,fixed, 'montage');
figure('Name',['Patient ' num2str(patient) ': Unregistered images']);
imshowpair(moving,fixed);
%% Registration
%[moving, fixed, optimizer, metric] = imgRegister(moving, fixed, growthfactor, epsilon, initialradius, iterations, samples, histogrambins, pixels, type)
[movingRegDefault, optimizer, metric] = imgRegister(moving, fixed, -1, -1, -1, -1, -1, -1, -1, 'affine');
figure('Name',['Patient ' num2str(patient) ': Default registration on affine transformation model']);
imshowpair(movingRegDefault, fixed);
disp('1: Default registration on affine transformation model')
disp(optimizer)
disp(metric)
[movingRegRadius, optimizer, metric] = imgRegister(moving, fixed, -1, -1, optimizer.InitialRadius/10, -1, -1, -1, -1, 'affine');
figure('Name',['Patient ' num2str(patient) ': Registration with 1/10 default InitialRadius']);
imshowpair(movingRegRadius, fixed);
disp(' ')
disp('2: Registration with 1/10 default InitialRadius')
disp(optimizer)
disp(metric)
[movingRegIter, optimizer, metric] = imgRegister(moving, fixed, -1, -1, -1, 10, -1, -1, -1, 'affine');
figure('Name',['Patient ' num2str(patient) ': Registration with 10 iterations']);
imshowpair(movingRegIter, fixed);
disp(' ')
disp('3: Registration with 10 iterations')
disp(optimizer)
disp(metric)
[movingRegBins, optimizer, metric] = imgRegister(moving, fixed, -1, -1, -1, -1, -1, 10, -1, 'affine');
figure('Name',['Patient ' num2str(patient) ': Registration with 10 bins']);
imshowpair(movingRegBins, fixed);
disp(' ')
disp('4: Registration with 10 bins')
disp(optimizer)
disp(metric)
[movingRegSimil, optimizer, metric] = imgRegister(moving, fixed, -1, -1, -1, -1, -1, -1, -1, 'similarity');
figure('Name',['Patient ' num2str(patient) ': Registration based on similarity transformation model']);
imshowpair(movingRegSimil, fixed);
disp(' ')
disp('5: Registration based on similarity transformation model')
disp(optimizer)
disp(metric)
tformSimilarity = imregtform(moving,fixed,'similarity',optimizer,metric); % get an initial transformation estimate based on a 'similarity' model (translation,rotation, and scale)
Rfixed = imref2d(size(fixed));
movingRegRigid = imwarp(moving,tformSimilarity,'OutputView',Rfixed); % apply the geometric transformation output from imregtform to the moving image to align it with the fixed image
figure('Name',['Patient ' num2str(patient) ': Registration based on similarity transformation model']);
imshowpair(movingRegRigid, fixed);
disp(' ')
disp('6: Registration based on similarity transformation model')
disp(optimizer)
disp(metric)
%The "T" property of the output geometric transformation defines the
%transformation matrix that maps points in moving to corresponding points in fixed.
movingRegAffineWithIC = imregister(moving,fixed,'affine',optimizer,metric,'InitialTransformation',tformSimilarity);
%Using the 'InitialTransformation' to refine the 'similarity' result of imregtform with a
%full affine model has also yielded a nice registration result.
figure('Name',['Patient ' num2str(patient) ': Registration based on affine transformation model with initial conditions']);
imshowpair(movingRegSimil, fixed);
disp(' ')
disp('7: Registration based on affine transformation model with initial conditions')
disp(optimizer)
disp(metric)
tformSimilarity.T