diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/affine')
21 files changed, 775 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/README b/SD-VBS/common/toolbox/toolbox_basic/affine/README new file mode 100755 index 0000000..e578a74 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/affine/README | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | Top level program is "compute_AD.m". Use "compute_AD_disp.m" if one | ||
| 2 | wants to display results as program runs. | ||
| 3 | |||
| 4 | The testing programs are called "simulation.m" for synthetic images, | ||
| 5 | and "test_affine.m" for real images. | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/carve_it.m b/SD-VBS/common/toolbox/toolbox_basic/affine/carve_it.m new file mode 100755 index 0000000..1a44f89 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/affine/carve_it.m | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | function img = carve_it(I,center,window_size_h) | ||
| 2 | |||
| 3 | [size_y,size_x]= size(I); | ||
| 4 | min_x = round(center(1)-window_size_h(1)); | ||
| 5 | max_x = round(center(1)+window_size_h(1)); | ||
| 6 | min_y = round(center(2)-window_size_h(2)); | ||
| 7 | max_y = round(center(2)+window_size_h(2)); | ||
| 8 | window_size = window_size_h*2 +1; | ||
| 9 | |||
| 10 | if (min_x <1)|(max_x > size_x)|(min_y<1)|(max_y>size_y), | ||
| 11 | disp('window too big'); | ||
| 12 | center | ||
| 13 | window_size_h | ||
| 14 | img = zeros(window_size(2),window_size(1)); | ||
| 15 | n_min_x = max(1,round(min_x)); | ||
| 16 | n_min_y = max(1,round(min_y)); | ||
| 17 | n_max_x = min(size_x,round(max_x)); | ||
| 18 | n_max_y = min(size_y,round(max_y)); | ||
| 19 | img(1+(n_min_y-min_y):window_size(2)-(max_y-n_max_y),1+(n_min_x-min_x):window_size(1)-(max_x-n_max_x))=I(n_min_y:n_max_y,n_min_x:n_max_x); | ||
| 20 | else | ||
| 21 | img = I(center(2)-window_size_h(2):center(2)+window_size_h(2),... | ||
| 22 | center(1)-window_size_h(1):center(1)+window_size_h(1)); | ||
| 23 | end | ||
| 24 | |||
| 25 | |||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m new file mode 100755 index 0000000..a39acd6 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | function [A,D,mask] =... | ||
| 2 | compute_AD(img_i,img_j,center_i,center_j,window_size_h,num_iter,w,num_trans,Dest,mask) | ||
| 3 | % | ||
| 4 | % function [A,D,mask] = ... | ||
| 5 | % compute_AD(img_i,img_j,center_i,center_j,window_size_h,num_iter,w, | ||
| 6 | % mask,num_trans) | ||
| 7 | % | ||
| 8 | % A: Affine motion; | ||
| 9 | % D: Displacement; | ||
| 10 | % | ||
| 11 | % img_i, img_j: the two image(in full size); | ||
| 12 | % center_i, center_j: the centers of the feature in two images; | ||
| 13 | % window_size_h: half size of the feature window; | ||
| 14 | % num_iter: number of iterations; | ||
| 15 | % w: parameter used in "grad.m" for computing gaussians used for | ||
| 16 | % gradient estimation; | ||
| 17 | % | ||
| 18 | % num_trans: OPTIONAL, number of translation iteration; default = 3; | ||
| 19 | % mask: OPTIONAL, if some area of the square shaped feature window should | ||
| 20 | % be weighted less; | ||
| 21 | % | ||
| 22 | |||
| 23 | % | ||
| 24 | % Jianbo Shi | ||
| 25 | % | ||
| 26 | |||
| 27 | if ~exist('Dest'), | ||
| 28 | Dest = [0,0]; | ||
| 29 | end | ||
| 30 | |||
| 31 | if ~exist('mask'), | ||
| 32 | mask = ones(2*window_size_h+1)'; | ||
| 33 | end | ||
| 34 | |||
| 35 | % set the default num_trans | ||
| 36 | if ~exist('num_trans'), | ||
| 37 | num_trans= 3; | ||
| 38 | end | ||
| 39 | |||
| 40 | % normalize image intensity to the range of 0.0-1.0 | ||
| 41 | img_i = norm_inten(img_i); | ||
| 42 | img_j = norm_inten(img_j); | ||
| 43 | |||
| 44 | window_size = 2*window_size_h + 1; | ||
| 45 | I = carve_it(img_i,center_i,window_size_h); | ||
| 46 | J = carve_it(img_j,center_j,window_size_h); | ||
| 47 | |||
| 48 | % init. step | ||
| 49 | J_computed = I; | ||
| 50 | D_computed = Dest; | ||
| 51 | A_computed = eye(2); | ||
| 52 | J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h); | ||
| 53 | |||
| 54 | %% level of noise | ||
| 55 | sig = 0.1; | ||
| 56 | |||
| 57 | records = zeros(num_iter,6); | ||
| 58 | errs = zeros(1,num_iter); | ||
| 59 | |||
| 60 | k = 1; | ||
| 61 | % iteration | ||
| 62 | while k <= num_iter, | ||
| 63 | [A,D] = iter_AD(J_computed,J,mask,w,k,num_trans); | ||
| 64 | |||
| 65 | A_computed = A*A_computed; | ||
| 66 | D_computed = (A*D_computed')' + D; | ||
| 67 | |||
| 68 | % compute the warped image | ||
| 69 | J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h); | ||
| 70 | |||
| 71 | % compute the SSD error | ||
| 72 | errs(k) = sqrt(sum(sum((mask.*(J_computed-J)).^2)))/prod(size(J)); | ||
| 73 | |||
| 74 | % update the mask, discounting possible occlusion region | ||
| 75 | if (k>num_trans), | ||
| 76 | mask = exp(-abs(J_computed-J)/sig); | ||
| 77 | end | ||
| 78 | |||
| 79 | % record the A and D | ||
| 80 | records(k,:) = [reshape(A_computed,1,4),reshape(D_computed,1,2)]; | ||
| 81 | |||
| 82 | k = k+1; | ||
| 83 | end | ||
| 84 | |||
| 85 | [tmp,id] = min(errs); | ||
| 86 | A = reshape(records(id,1:4),2,2); | ||
| 87 | D = reshape(records(id,5:6),1,2); | ||
| 88 | |||
| 89 | J_computed = compute_J(A,D,img_i,center_i,window_size_h); | ||
| 90 | mask = exp(-abs(J_computed-J)/sig); | ||
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD_disp.m b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD_disp.m new file mode 100755 index 0000000..f2e6c62 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD_disp.m | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | function [A,D,mask] =... | ||
| 2 | compute_AD_disp(img_i,img_j,center_i,center_j,window_size_h,num_iter,w,fig_disp,num_trans,Dest,mask) | ||
| 3 | % | ||
| 4 | % function [A,D,mask] = ... | ||
| 5 | % compute_AD_disp(img_i,img_j,center_i,center_j,window_size_h,num_iter,w, | ||
| 6 | % fig_disp,mask,num_trans) | ||
| 7 | % | ||
| 8 | % Computing affine transform for matching to image patches. Display results | ||
| 9 | % as program runs. | ||
| 10 | % | ||
| 11 | % A: Affine motion; | ||
| 12 | % D: Displacement; | ||
| 13 | % | ||
| 14 | % | ||
| 15 | % img_i, img_j: the two image(in full size); | ||
| 16 | % center_i, center_j: the centers of the feature in two images; | ||
| 17 | % window_size_h: half size of the feature window; | ||
| 18 | % num_iter: number of iterations; | ||
| 19 | % w: parameter used in "grad.m" for computing gaussians used for | ||
| 20 | % gradient estimation; | ||
| 21 | % fig_disp: figure for display; | ||
| 22 | % | ||
| 23 | % num_trans: OPTIONAL, number of translation iteration; | ||
| 24 | % mask: OPTIONAL, if some area of the square shaped feature window should | ||
| 25 | % be weighted less; | ||
| 26 | % | ||
| 27 | |||
| 28 | |||
| 29 | % | ||
| 30 | % Jianbo Shi | ||
| 31 | % | ||
