Skip to content

Commit f10b48c

Browse files
authored
Add files via upload
1 parent d0cd6ab commit f10b48c

File tree

1 file changed

+99
-96
lines changed

1 file changed

+99
-96
lines changed

shared/get_NDJH_registration.m

Lines changed: 99 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,99 @@
1-
%% get_NDJH_registration
2-
% Joshua Doyle, 07/2018
3-
% Edited: Benjamin Green 12/2022
4-
%% Description
5-
% calculate the optimal mututal information registration between two
6-
% images.
7-
% size(im) - size(im2) should be positive and determines the search space.
8-
%% Input
9-
% image_a: the stationary, reference image
10-
% image_b: is the floating image
11-
% mi_vars: a data structure with the following values
12-
% - step_size: is the step size as [stepx stepy]
13-
% - scale (logical): whether or not to scale the images
14-
% - subsampling: the amount of the image to subsample for the
15-
% registration
16-
%
17-
%% Output
18-
% an array of the maximum mutual information and position (x, y)
19-
%% ---------------------------------------
20-
function [MMI_all, MMI_coords, MMI2] = get_NDJH_registration(...
21-
image_a, image_b, mi_vars)
22-
%
23-
[mi_vars, image_a] = prepare_mi_vars(image_a, image_b, mi_vars);
24-
%
25-
% sort the mutual information locations
26-
%
27-
if any(mi_vars.search_space <= 0)
28-
MMI2 = cast(0, 'single');
29-
MMIx = MMI2;
30-
MMIy = MMI2;
31-
mi_vars.global_search_grids = [];
32-
else
33-
search_space_x = 1:mi_vars.step_size(1):mi_vars.search_space(1);
34-
search_space_y = 1:mi_vars.step_size(2):mi_vars.search_space(2);
35-
[MMIx, MMIy] = meshgrid(search_space_x, search_space_y);
36-
X2 = reshape(MMIx, [], 1);
37-
Y2 = reshape(MMIy, [], 1);
38-
mi_vars.global_search_grids = [X2, Y2];
39-
MMI2 = zeros(size(Y2), 'single');
40-
mi_vars.global_search_grids(:,3) = ...
41-
(mi_vars.global_search_grids(:,1) + mi_vars.width_b - 1);
42-
mi_vars.global_search_grids(:,4) = ...
43-
(mi_vars.global_search_grids(:,2) + mi_vars.height_b - 1);
44-
end
45-
%
46-
if isfield(mi_vars,'parallel')
47-
%
48-
MMI2 = num2cell(MMI2);
49-
%
50-
parfor correction = 1:length(mi_vars.global_search_grids)
51-
%
52-
sliced_image_a = image_a(...
53-
mi_vars.global_search_grids(correction, 2):...
54-
mi_vars.global_search_grids(correction, 4), ...
55-
mi_vars.global_search_grids(correction, 1):...
56-
mi_vars.global_search_grids(correction, 3), ...
57-
:);
58-
%
59-
reshaped_image_a = reshape(sliced_image_a, [], mi_vars.levels_a) + 1;
60-
reshaped_image_a = reshaped_image_a(mi_vars.p, :);
61-
%
62-
MMI2{correction} = estimate_mi(reshaped_image_a, mi_vars);
63-
%
64-
end
65-
%
66-
MMI2 = cell2mat(MMI2);
67-
%
68-
else
69-
%
70-
for correction = 1:length(mi_vars.global_search_grids)
71-
%
72-
sliced_image_a = image_a(...
73-
mi_vars.global_search_grids(correction, 2):...
74-
mi_vars.global_search_grids(correction, 4), ...
75-
mi_vars.global_search_grids(correction, 1):...
76-
mi_vars.global_search_grids(correction, 3), ...
77-
:);
78-
%
79-
reshaped_image_a = reshape(sliced_image_a, [], mi_vars.levels_a) + 1;
80-
reshaped_image_a = reshaped_image_a(mi_vars.p, :);
81-
%
82-
MMI2(correction) = estimate_mi(reshaped_image_a, mi_vars);
83-
%
84-
end
85-
%
86-
end
87-
%
88-
MMI2 = reshape(MMI2, size(MMIy));
89-
%
90-
[MMI_all, ind] = max(MMI2, [], 'all', 'linear');
91-
MMIx_all = MMIx(ind);
92-
MMIy_all = MMIy(ind);
93-
%
94-
MMI_coords = [MMIx_all, MMIy_all];
95-
%
96-
end
1+
%% get_NDJH_registration
2+
% Joshua Doyle, 07/2018
3+
% Edited: Benjamin Green 12/2022
4+
%% Description
5+
% calculate the optimal mututal information registration between two
6+
% images.
7+
% size(im) - size(im2) should be positive and determines the search space.
8+
%% Input
9+
% image_a: the stationary, reference image
10+
% image_b: is the floating image
11+
% mi_vars: a data structure with the following values
12+
% - step_size: is the step size as [stepx stepy]
13+
% - scale (logical): whether or not to scale the images
14+
% - subsampling: the amount of the image to subsample for the
15+
% registration
16+
%
17+
%% Output
18+
% an array of the maximum mutual information and position (x, y)
19+
%% ---------------------------------------
20+
function [MMI_all, MMI_coords, MMI2] = get_NDJH_registration(...
21+
image_a, image_b, mi_vars)
22+
%
23+
[mi_vars, image_a] = prepare_mi_vars(image_a, image_b, mi_vars);
24+
%
25+
% sort the mutual information locations
26+
%
27+
if any(mi_vars.search_space <= 0)
28+
MMI2 = cast(0, 'single');
29+
MMIx = MMI2;
30+
MMIy = MMI2;
31+
mi_vars.global_search_grids = [];
32+
else
33+
search_space_x = 1:mi_vars.step_size(1):mi_vars.search_space(1);
34+
search_space_y = 1:mi_vars.step_size(2):mi_vars.search_space(2);
35+
[MMIx, MMIy] = meshgrid(search_space_x, search_space_y);
36+
X2 = reshape(MMIx, [], 1);
37+
Y2 = reshape(MMIy, [], 1);
38+
mi_vars.global_search_grids = [X2, Y2];
39+
MMI2 = zeros(size(Y2), 'single');
40+
mi_vars.global_search_grids(:,3) = ...
41+
(mi_vars.global_search_grids(:,1) + mi_vars.width_b - 1);
42+
mi_vars.global_search_grids(:,4) = ...
43+
(mi_vars.global_search_grids(:,2) + mi_vars.height_b - 1);
44+
end
45+
%
46+
if isfield(mi_vars,'parallel')
47+
%
48+
MMI2 = num2cell(MMI2);
49+
s = size(mi_vars.global_search_grids);
50+
%
51+
parfor correction = 1:s(1)
52+
%
53+
sliced_image_a = image_a(...
54+
mi_vars.global_search_grids(correction, 2):...
55+
mi_vars.global_search_grids(correction, 4), ...
56+
mi_vars.global_search_grids(correction, 1):...
57+
mi_vars.global_search_grids(correction, 3), ...
58+
:);
59+
%
60+
reshaped_image_a = reshape(sliced_image_a, [], mi_vars.levels_a) + 1;
61+
reshaped_image_a = reshaped_image_a(mi_vars.p, :);
62+
%
63+
MMI2{correction} = estimate_mi(reshaped_image_a, mi_vars);
64+
%
65+
end
66+
%
67+
MMI2 = cell2mat(MMI2);
68+
%
69+
else
70+
%
71+
s = size(mi_vars.global_search_grids);
72+
%
73+
for correction = 1:s(1)
74+
%
75+
sliced_image_a = image_a(...
76+
mi_vars.global_search_grids(correction, 2):...
77+
mi_vars.global_search_grids(correction, 4), ...
78+
mi_vars.global_search_grids(correction, 1):...
79+
mi_vars.global_search_grids(correction, 3), ...
80+
:);
81+
%
82+
reshaped_image_a = reshape(sliced_image_a, [], mi_vars.levels_a) + 1;
83+
reshaped_image_a = reshaped_image_a(mi_vars.p, :);
84+
%
85+
MMI2(correction) = estimate_mi(reshaped_image_a, mi_vars);
86+
%
87+
end
88+
%
89+
end
90+
%
91+
MMI2 = reshape(MMI2, size(MMIy));
92+
%
93+
[MMI_all, ind] = max(MMI2, [], 'all', 'linear');
94+
MMIx_all = MMIx(ind);
95+
MMIy_all = MMIy(ind);
96+
%
97+
MMI_coords = [MMIx_all, MMIy_all];
98+
%
99+
end

0 commit comments

Comments
 (0)