forked from sidney001/image_pairs_deblur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcenter_kernel_separate.m
30 lines (22 loc) · 996 Bytes
/
center_kernel_separate.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
function [x, y, k] = center_kernel_separate(x, y, k)
%
% Center the kernel by translation so that boundary issues are mitigated£¨»º½â£©. Additionally,
% if one shifts the kernel the the image must also be shifted in the
% opposite direction.
% get centre of mass
mu_y = sum([1:size(k, 1)] .* sum(k, 2)');
mu_x = sum([1:size(k, 2)] .* sum(k, 1));
% get mean offset
offset_x = round( floor(size(k, 2) / 2) + 1 - mu_x );
offset_y = round( floor(size(k, 1) / 2) + 1 - mu_y );
fprintf('CenterKernel: weightedMean[%f %f] offset[%d %d]\n', mu_x-1, mu_y-1, offset_x, offset_y);
% make kernel to do translation
shift_kernel = zeros(abs(offset_y * 2) + 1, abs(offset_x * 2) + 1);
shift_kernel(abs(offset_y) + 1 + offset_y, abs(offset_x) + 1 + offset_x) = 1;
% shift both image and blur kernel
kshift = conv2(k, shift_kernel, 'same');
k = kshift;
xshift = conv2(x, flipud(fliplr(shift_kernel)), 'same');
x = xshift;
yshift = conv2(y, flipud(fliplr(shift_kernel)), 'same');
y = yshift;