Skip to content

Commit b53b017

Browse files
authored
Merge pull request #3 from Meta-VCI-Map/feature/write-float-copy-geometry
Merge feature/write-float-copy-geometry
2 parents 1d7fe3a + b5e8af9 commit b53b017

29 files changed

+139
-59
lines changed

RegLSM/Parameter/Euler.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
(WriteTransformParametersEachIteration "false")
3232
(WriteResultImage "true")
3333
(CompressResultImage "true")
34-
(WriteResultImageAfterEachResolution "false")
35-
(ResultImageFormat "nii")
34+
(WriteResultImageAfterEachResolution "false")
35+
(ResultImageFormat "nii.gz")
36+
(ResultImagePixelType "float")
3637
(ShowExactMetricValue "false")
3738

3839
//Maximum number of iterations in each resolution level:

RegLSM/Parameter/SC_to_MNI.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
(Resampler "DefaultResampler")
2828
(DefaultPixelValue 0.000000)
2929
(ResultImageFormat "mhd")
30-
(ResultImagePixelType "short")
30+
(ResultImagePixelType "float")
3131
(CompressResultImage "true")

RegLSM/Parameter/SC_to_MNI.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// Resampler specific
3333
(Resampler "DefaultResampler")
3434
(DefaultPixelValue 0.000000)
35-
(ResultImageFormat "nii")
36-
(ResultImagePixelType "short")
35+
(ResultImageFormat "nii.gz")
36+
(ResultImagePixelType "float")
3737
(CompressResultImage "true")

RegLSM/Parameter/affine.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
(WriteTransformParametersEachIteration "false")
3232
(WriteResultImage "true")
3333
(CompressResultImage "true")
34-
(ResultImageFormat "nii")
34+
(ResultImageFormat "nii.gz")
35+
(ResultImagePixelType "float")
3536
(WriteResultImageAfterEachResolution "false")
3637
(ShowExactMetricValue "false")
3738

RegLSM/Parameter/bspline.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
(WriteTransformParametersEachIteration "false")
3030
(WriteResultImage "true")
3131
(CompressResultImage "true")
32-
(WriteResultImageAfterEachResolution "false")
33-
(ResultImageFormat "nii")
32+
(WriteResultImageAfterEachResolution "false")
33+
(ResultImageFormat "nii.gz")
34+
(ResultImagePixelType "float")
3435
(ShowExactMetricValue "false")
3536

3637
// Option supported in elastix 4.1:

RegLSM/Parameter/bspline2.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
(WriteTransformParametersEachIteration "false")
3030
(WriteResultImage "true")
3131
(CompressResultImage "true")
32-
(ResultImageFormat "nii")
32+
(ResultImageFormat "nii.gz")
33+
(ResultImagePixelType "float")
3334
(WriteResultImageAfterEachResolution "false")
3435
(ShowExactMetricValue "false")
3536

RegLSM/Parameter/bspline_CR.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
(WriteTransformParametersEachIteration "false")
3030
(WriteResultImage "true")
3131
(CompressResultImage "true")
32-
(ResultImageFormat "nii")
32+
(ResultImageFormat "nii.gz")
33+
(ResultImagePixelType "float")
3334
(WriteResultImageAfterEachResolution "false")
3435
(ShowExactMetricValue "false")
3536

RegLSM/Parameter/bspline_CT.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
(WriteTransformParametersEachIteration "false")
3030
(WriteResultImage "true")
3131
(CompressResultImage "true")
32-
(ResultImageFormat "nii")
32+
(ResultImageFormat "nii.gz")
33+
(ResultImagePixelType "float")
3334
(WriteResultImageAfterEachResolution "false")
3435
(ShowExactMetricValue "false")
3536

RegLSM/Parameter/to_MNI.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
// Resampler specific
2525
(Resampler "DefaultResampler")
2626
(DefaultPixelValue 0.000000)
27-
(ResultImageFormat "nii")
28-
(ResultImagePixelType "short")
27+
(ResultImageFormat "nii.gz")
28+
(ResultImagePixelType "float")
2929
(CompressResultImage "true")

RegLSM/Parameter/to_MNI_lesion.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
// Resampler specific
2525
(Resampler "DefaultResampler")
2626
(DefaultPixelValue 0.000000)
27-
(ResultImageFormat "nii")
27+
(ResultImageFormat "nii.gz")
2828
(ResultImagePixelType "short")
2929
(CompressResultImage "true")

RegLSM/RegLSM_batch.fig

4.47 KB
Binary file not shown.

RegLSM/RegLSM_batch.m

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
% Edit the above text to modify the response to help RegLSM_batch
2424

25-
% Last Modified by GUIDE v2.5 28-Mar-2017 11:36:27
25+
% Last Modified by GUIDE v2.5 25-Sep-2023 16:26:36
2626

2727
% Begin initialization code - DO NOT EDIT
2828
gui_Singleton = 1;
@@ -142,8 +142,9 @@ function StartReg_Callback(~, ~, handles)
142142
scheme=handles.scheme;
143143
else scheme=[];
144144
end
145+
copyLesionGeometry = handles.copyLesionGeometry.Value;
145146
% Start registration
146-
Registration_elastix_batch(Dir,scheme);
147+
Registration_elastix_batch(Dir, scheme, copyLesionGeometry);
147148

148149

149150
% --- Executes on selection change in Dir.
@@ -154,3 +155,12 @@ function Dir_Callback(hObject, eventdata, handles)
154155

155156
% Hints: contents = cellstr(get(hObject,'String')) returns Dir contents as cell array
156157
% contents{get(hObject,'Value')} returns selected item from Dir
158+
159+
160+
% --- Executes on button press in copyLesionGeometry.
161+
function copyLesionGeometry_Callback(hObject, eventdata, handles)
162+
% hObject handle to copyLesionGeometry (see GCBO)
163+
% eventdata reserved - to be defined in a future version of MATLAB
164+
% handles structure with handles and user data (see GUIDATA)
165+
166+
% Hint: get(hObject,'Value') returns toggle state of copyLesionGeometry

RegLSM/RegLSM_test.fig

4.41 KB
Binary file not shown.

RegLSM/RegLSM_test.m

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
% Edit the above text to modify the response to help RegLSM_test
2424

25-
% Last Modified by GUIDE v2.5 28-Mar-2017 11:35:54
25+
% Last Modified by GUIDE v2.5 25-Sep-2023 16:24:25
2626

2727
% Begin initialization code - DO NOT EDIT
2828
gui_Singleton = 1;
@@ -136,7 +136,8 @@ function StartReg_Callback(~, ~, handles)
136136
scheme=handles.scheme;
137137
else scheme=[];
138138
end
139-
Registration_elastix_test(Dir_img,scheme);
139+
copyLesionGeometry = handles.copyLesionGeometry.Value;
140+
Registration_elastix_test(Dir_img, scheme, copyLesionGeometry);
140141

141142

142143

@@ -213,3 +214,12 @@ function Reg2Check_CreateFcn(hObject, eventdata, handles)
213214
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
214215
set(hObject,'BackgroundColor','white');
215216
end
217+
218+
219+
% --- Executes on button press in copyLesionGeometry.
220+
function copyLesionGeometry_Callback(hObject, eventdata, handles)
221+
% hObject handle to copyLesionGeometry (see GCBO)
222+
% eventdata reserved - to be defined in a future version of MATLAB
223+
% handles structure with handles and user data (see GUIDATA)
224+
225+
% Hint: get(hObject,'Value') returns toggle state of copyLesionGeometry

RegLSM/Registration_elastix_batch.m

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Dir_subject=Registration_elastix_batch(Dir,scheme)
1+
function Dir_subject=Registration_elastix_batch(Dir, scheme, copyLesionGeometry)
22
Dir_code = fileparts(which('RegLSM.m'));
33
%% Initialization for specific registration scheme
44
if isempty(Dir)
@@ -32,19 +32,19 @@
3232

3333
subject_record=[];
3434
if ~isempty(strfind(scheme,'DWI_with_T1'))
35-
subject_record=batch_DWI_T1(Dir_code,Dir,subfolders);
35+
subject_record=batch_DWI_T1(Dir_code,Dir,subfolders,copyLesionGeometry);
3636
elseif ~isempty(strfind(scheme,'DWI_without_T1'))
37-
subject_record=batch_DWI_no_T1(Dir_code,Dir,subfolders);
37+
subject_record=batch_DWI_no_T1(Dir_code,Dir,subfolders,copyLesionGeometry);
3838
elseif ~isempty(strfind(scheme,'FLAIR_with_T1'))&&isempty(strfind(scheme,'+'))
39-
subject_record=batch_FLAIR_T1(Dir_code,Dir,subfolders);
39+
subject_record=batch_FLAIR_T1(Dir_code,Dir,subfolders,copyLesionGeometry);
4040
elseif ~isempty(strfind(scheme,'FLAIR_with_T1+'))
41-
subject_record=batch_FLAIR_T1_plus(Dir_code,Dir,subfolders);
41+
subject_record=batch_FLAIR_T1_plus(Dir_code,Dir,subfolders,copyLesionGeometry);
4242
elseif ~isempty(strfind(scheme,'FLAIR_without_T1'))&&isempty(strfind(scheme,'+'))
43-
subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,[]);
43+
subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,[],copyLesionGeometry);
4444
elseif ~isempty(strfind(scheme,'FLAIR_without_T1+'))
45-
subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,'+');
45+
subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,'+',copyLesionGeometry);
4646
elseif ~isempty(strfind(scheme,'CT'))
47-
subject_record=batch_CT(Dir_code,Dir,subfolders);
47+
subject_record=batch_CT(Dir_code,Dir,subfolders,copyLesionGeometry);
4848
else
4949
errordlg('The registration scheme has not been specified!');
5050
return;

RegLSM/Registration_elastix_test.m

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Registration_elastix_test(Dir_img,scheme)
1+
function Registration_elastix_test(Dir_img, scheme, copyLesionGeometry)
22
Dir_code = pwd;
33
%% Initialization for specific registration scheme
44
if isempty(Dir_img)
@@ -11,19 +11,19 @@ function Registration_elastix_test(Dir_img,scheme)
1111
end
1212
% sub_record=[];
1313
if ~isempty(strfind(scheme,'DWI_with_T1'))
14-
test_DWI_T1(Dir_code,Dir_img,[]);
14+
test_DWI_T1(Dir_code,Dir_img,[],copyLesionGeometry);
1515
elseif ~isempty(strfind(scheme,'DWI_without_T1'))
16-
test_DWI_no_T1(Dir_code,Dir_img,[]);
16+
test_DWI_no_T1(Dir_code,Dir_img,[],copyLesionGeometry);
1717
elseif ~isempty(strfind(scheme,'FLAIR_with_T1'))&&isempty(strfind(scheme,'+'))
18-
test_FLAIR_T1(Dir_code,Dir_img,[]);
18+
test_FLAIR_T1(Dir_code,Dir_img,[],copyLesionGeometry);
1919
elseif ~isempty(strfind(scheme,'FLAIR_with_T1+'))
20-
test_FLAIR_T1_plus(Dir_code,Dir_img,[]);
20+
test_FLAIR_T1_plus(Dir_code,Dir_img,[],copyLesionGeometry);
2121
elseif ~isempty(strfind(scheme,'FLAIR_without_T1'))&&isempty(strfind(scheme,'+'))
22-
test_FLAIR_no_T1(Dir_code,Dir_img,[],[]);
22+
test_FLAIR_no_T1(Dir_code,Dir_img,[],[],copyLesionGeometry);
2323
elseif ~isempty(strfind(scheme,'FLAIR_without_T1+'))
24-
test_FLAIR_no_T1(Dir_code,Dir_img,'+',[]);
24+
test_FLAIR_no_T1(Dir_code,Dir_img,'+',[],copyLesionGeometry);
2525
elseif ~isempty(strfind(scheme,'CT'))
26-
test_CT(Dir_code,Dir_img,[]);
26+
test_CT(Dir_code,Dir_img,[],copyLesionGeometry);
2727
else
2828
errordlg('The registration scheme has not been specified!');
2929
return;

RegLSM/batch_CT.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_CT(Dir_code,Dir,subfolders)
1+
function subject_record=batch_CT(Dir_code,Dir,subfolders,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,3);
@@ -27,7 +27,7 @@
2727

2828
try
2929
% Call test mode for image registration of a single subject
30-
sub_record=test_CT(Dir_code,Dir_img,'record');
30+
sub_record=test_CT(Dir_code,Dir_img,'record',copyLesionGeometry);
3131
subject_record(i+1,2:3)=sub_record;
3232
catch
3333
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/batch_DWI_T1.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_DWI_T1(Dir_code,Dir,subfolders)
1+
function subject_record=batch_DWI_T1(Dir_code,Dir,subfolders,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,4);
@@ -27,7 +27,7 @@
2727

2828
try
2929
% Call test mode for image registration of a single subject
30-
sub_record=test_DWI_T1(Dir_code,Dir_img,'record');
30+
sub_record=test_DWI_T1(Dir_code,Dir_img,'record',copyLesionGeometry);
3131
subject_record(i+1,2:4)=sub_record;
3232
catch
3333
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/batch_DWI_no_T1.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_DWI_no_T1(Dir_code,Dir,subfolders)
1+
function subject_record=batch_DWI_no_T1(Dir_code,Dir,subfolders,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,3);
@@ -28,7 +28,7 @@
2828

2929
try
3030
% Call test mode for image registration of a single subject
31-
sub_record=test_DWI_no_T1(Dir_code,Dir_img,'record');
31+
sub_record=test_DWI_no_T1(Dir_code,Dir_img,'record',copyLesionGeometry);
3232
subject_record(i+1,2:3)=sub_record;
3333
catch
3434
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/batch_FLAIR_T1.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_FLAIR_T1(Dir_code,Dir,subfolders)
1+
function subject_record=batch_FLAIR_T1(Dir_code,Dir,subfolders,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,4);
@@ -26,7 +26,7 @@
2626

2727
try
2828
% Call test mode for image registration of a single subject
29-
sub_record=test_FLAIR_T1(Dir_code,Dir_img,'record');
29+
sub_record=test_FLAIR_T1(Dir_code,Dir_img,'record',copyLesionGeometry);
3030
subject_record(i+1,2:4)=sub_record;
3131
catch
3232
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/batch_FLAIR_T1_plus.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_FLAIR_T1_plus(Dir_code,Dir,subfolders)
1+
function subject_record=batch_FLAIR_T1_plus(Dir_code,Dir,subfolders,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,4);
@@ -27,7 +27,7 @@
2727

2828
try
2929
% Call test mode for image registration of a single subject
30-
sub_record=test_FLAIR_T1_plus(Dir_code,Dir_img,'record');
30+
sub_record=test_FLAIR_T1_plus(Dir_code,Dir_img,'record',copyLesionGeometry);
3131
subject_record(i+1,2:4)=sub_record;
3232
catch
3333
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/batch_FLAIR_no_T1.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,mode)
1+
function subject_record=batch_FLAIR_no_T1(Dir_code,Dir,subfolders,mode,copyLesionGeometry)
22
%% Initialization
33
% Identify the subfolders with sufficient images for specified registration
44
subject_record=cell(length(subfolders)+1,3);
@@ -27,7 +27,7 @@
2727

2828
try
2929
% Call test mode for image registration of a single subject
30-
sub_record=test_FLAIR_no_T1(Dir_code,Dir_img,mode,'record');
30+
sub_record=test_FLAIR_no_T1(Dir_code,Dir_img,mode,'record',copyLesionGeometry);
3131
subject_record(i+1,2:3)=sub_record;
3232
catch
3333
fileID = fopen(strcat(Dir,'\',subfolders{i},'\','FAILED.TXT'), 'w');

RegLSM/copy_lesion_geometry.m

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function copy_lesion_geometry(source, lesion)
2+
source_nii = load_untouch_nii(source);
3+
lesion_nii = load_untouch_nii(lesion);
4+
5+
% Check dimensions.
6+
if any(lesion_nii.hdr.dime.dim ~= source_nii.hdr.dime.dim)
7+
error('Lesion and source images have different dimensions');
8+
end
9+
10+
% Copy voxel dimensions.
11+
lesion_nii.hdr.dime.pixdim = source_nii.hdr.dime.pixdim;
12+
13+
% Copy orientation.
14+
for attr = {'qform_code', 'sform_code', 'quatern_b', 'quatern_c', 'quatern_d', 'qoffset_x', 'qoffset_y', 'qoffset_z', 'srow_x', 'srow_y', 'srow_z'}
15+
lesion_nii.hdr.hist.(attr{1}) = source_nii.hdr.hist.(attr{1});
16+
end
17+
18+
% Back-up the original lesion file.
19+
copyfile(lesion, [lesion '.bak']);
20+
21+
% Save the new lesion file.
22+
save_untouch_nii(lesion_nii, lesion)

RegLSM/test_CT.m

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function sub_record=test_CT(Dir_code,Dir_img,record)
1+
function sub_record=test_CT(Dir_code,Dir_img,record,copyLesionGeometry)
22
%% Initialization
33
sub_record=cell(1,2);
44

@@ -45,8 +45,12 @@
4545
sub_record{2}='0';
4646
return;
4747
end
48-
% Specify parameter files for registration
4948

49+
if copyLesionGeometry
50+
copy_lesion_geometry(CT, LESION);
51+
end
52+
53+
% Specify parameter files for registration
5054
reg_CT_Rorden=['-p ',blanks(1),'"',Dir_code,'\Parameter\affine.txt','"',' -p ',blanks(1),'"',Dir_code,'\Parameter\bspline_CT.txt','"'];
5155

5256
% Specify the location of intermediate Rorden template

RegLSM/test_DWI_T1.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function sub_record=test_DWI_T1(Dir_code,Dir_img,record)
1+
function sub_record=test_DWI_T1(Dir_code,Dir_img,record,copyLesionGeometry)
22
%% Initialization
33
sub_record=cell(1,3);
44
% Check if the input images is sufficient to perform the specified
@@ -95,6 +95,10 @@
9595
sub_record{2}='0';
9696
return;
9797
end
98+
99+
if copyLesionGeometry
100+
copy_lesion_geometry(DWI, LESION);
101+
end
98102

99103
% Specify parameter files for registration
100104
reg_T1_Rorden=['-p ',blanks(1),'"',Dir_code,'\Parameter\affine.txt','"',' -p ',blanks(1),'"',Dir_code,'\Parameter\bspline_CR.txt','"'];

RegLSM/test_DWI_no_T1.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function sub_record=test_DWI_no_T1(Dir_code,Dir_img,record)
1+
function sub_record=test_DWI_no_T1(Dir_code,Dir_img,record,copyLesionGeometry)
22
%% Initialization
33
sub_record=cell(1,2);
44

@@ -70,6 +70,11 @@
7070
sub_record{2}='0';
7171
return;
7272
end
73+
74+
if copyLesionGeometry
75+
copy_lesion_geometry(DWI, LESION);
76+
end
77+
7378
% Specify parameter files for registration
7479
reg_DWI_Rorden=['-p ',blanks(1),'"',Dir_code,'\Parameter\affine.txt','"',' -p ',blanks(1),'"',Dir_code,'\Parameter\bspline.txt','"'];
7580

0 commit comments

Comments
 (0)