Home > Matching_SYM_LSM > demo_LSM_medium.m

demo_LSM_medium

PURPOSE ^

% Sym-LSM medium demo

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Sym-LSM medium demo

 The demo routine demo_LSM_medium.m shows how the noise variance 
 estimation is integrated into the matching process. Again the required 
 input data are loaded from file. Here these are the two complete images 
 together with two corresponding Lowe-keypoints (coordinates, scale, 
 direction). These are used to define the window size and the approximate 
 values. The noise variance functions vg and vh are determined 
 automatically from the area around the keypoints. First, the input images 
 with the keypoints are shown. When zooming into the keypoints the centre 
 and the direction vector fixing the scale and the direction can be seen. 
 Further figures show the selected windows, the noise standard deviations 
 and the change of the estimated image windows.

 wf 7/2020

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Sym-LSM medium demo
0002 %
0003 % The demo routine demo_LSM_medium.m shows how the noise variance
0004 % estimation is integrated into the matching process. Again the required
0005 % input data are loaded from file. Here these are the two complete images
0006 % together with two corresponding Lowe-keypoints (coordinates, scale,
0007 % direction). These are used to define the window size and the approximate
0008 % values. The noise variance functions vg and vh are determined
0009 % automatically from the area around the keypoints. First, the input images
0010 % with the keypoints are shown. When zooming into the keypoints the centre
0011 % and the direction vector fixing the scale and the direction can be seen.
0012 % Further figures show the selected windows, the noise standard deviations
0013 % and the change of the estimated image windows.
0014 %
0015 % wf 7/2020
0016 
0017 close all
0018 clearvars
0019 %clc
0020 
0021 addpath(genpath('src/')) 
0022 
0023 disp(' --------------------------------------------------------------------- ')
0024 disp(' ---- Symmetric LSM with 6 geometric and 2 radiometric parameters ---- ')
0025 disp(' -------------- two images with corresponding keypoints -------------- ')
0026 disp(' --------------------------------------------------------------------- ')
0027 
0028 
0029 
0030 %% set control parameters
0031 plot_type       = 1;        % medium output
0032 max_iter        = 9;        % maximum number of iterations
0033 sigma_smooth    = 0;        % smoothing of estimated reference image
0034 
0035 %% provide input data
0036 % --- load data ---------------------------------------------------------
0037 load('example_data/Sym_LSM_medium_demo');
0038 % Image_l, Image_r       images
0039 % X                      2x4 matrix of corresponding keypoints
0040 %                        [x,y,scale,direction]
0041 
0042 figure('name','left and right images')
0043 subplot(1,2,1)
0044 imshow(Image_l)
0045     hold on
0046     plot_circle_direction_with_background(X(1,2),X(1,1),3*X(1,3),X(1,4),8,4)
0047 title('left')
0048 subplot(1,2,2)
0049 imshow(Image_r)
0050     hold on
0051     plot_circle_direction_with_background(X(2,2),X(2,1),3*X(2,3),X(2,4),8,4)
0052 title('right')
0053 
0054 
0055 %% select windows ======================================================
0056 % half size of window in left image: 4 * Lowe-scale
0057 Nig = round(4*X(1,3));
0058 Nih = round(4*X(2,3));
0059 
0060 % windows
0061 g = round(mean(Image_l(X(1,1)-Nig:X(1,1)+Nig,X(1,2)-Nig:X(1,2)+Nig,:),3));
0062 h = round(mean(Image_r(X(2,1)-Nih:X(2,1)+Nih,X(2,2)-Nih:X(2,2)+Nih,:),3));
0063 
0064 figure('name','left and right image window')
0065 subplot(1,2,1)
0066 imshow(g/255)
0067 title('left')
0068 subplot(1,2,2)
0069 imshow(h/255)
0070 title('right')
0071 
0072 
0073 %% determine noise standard deviations of surrounding area
0074 DD = 100; % 10000 pixels should be sufficient
0075 
0076 % --- estimate noise standard deviations of Image_l ---------------------
0077 % determine bounding box within Image_l
0078 [M,N] = size(Image_l);
0079 x_min = max([1,X(1,1)-DD]); y_min = max([1,X(1,2)-DD]);
0080 x_max = min([M,X(1,1)+DD]); y_max = min([N,X(1,2)+DD]);
0081 % estimate noise standard deviations
0082 [s_g,m_g,~] = noise_standard_deviation_estimation(Image_l(x_min:x_max,y_min:y_max,:));
0083 
0084 % --- estimate noise standard deviations of Image_l ---------------------
0085 % determine bounding box within Image_r
0086 [M,N] = size(Image_r);
0087 x_min = max([1,X(2,1)-DD]); y_min = max([1,X(2,2)-DD]);
0088 x_max = min([M,X(2,1)+DD]); y_max = min([N,X(2,2)+DD]);
0089 % estimate noise standard deviations
0090 [s_h,m_h,~] = noise_standard_deviation_estimation(Image_r(x_min:x_max,y_min:y_max,:));
0091 
0092 % variances in pixels^2
0093 vg      = (mean(s_g,1)'*256).^2;
0094 vh      = (mean(s_h,1)'*256).^2;
0095 % --- show noise standard deviations vg and vh (256x1) -----------------
0096 figure('name','noise standard deviations');
0097 hold on
0098 plot(mean(s_g,1)*255,'-b','LineWidth',2);
0099 plot(mean(s_h,1)*255,'-r','LineWidth',2);
0100 title('Noise standard deviations: left (blue), right(red)')
0101 xlim([min([m_g(:);m_h(:)]),max([m_g(:);m_h(:)])]*255)
0102 ylim([0,1.1*max([mean(s_g,1)'*255;mean(s_h,1)'*255])])
0103    
0104 %% === approximate values ==============================================
0105 % --- approximate affinity referring to centre of window ---------------
0106 D       = [X(2,3)/X(1,3)*eye(2),[0;0];0 0 1]; % relative scaling
0107 alpha   = X(2,4)-X(1,4);                      % rotation
0108 R       = [cos(alpha) -sin(alpha) 0;sin(alpha) cos(alpha) 0;0 0 1];
0109 A_a     = D*R;                                % similarity
0110 % --- approximate radiometric transformation --------------------------
0111 R_a     = [1,0];
0112 % minimum size of overlap
0113 Nf_MIN = 4;
0114 
0115 % Approximate geometric affinity z = B y
0116 disp([ 'approximate scale difference                                 : ',num2str(X(2,3)/X(1,3))])
0117 disp([ 'approximate rotation difference                              : ',num2str(alpha*180/pi), '°'])
0118 disp( 'approximate geometric affinity       z = A y                 : ')
0119 disp(A_a);
0120 
0121 disp(['approximate intensity transformation h = b7*y + b8 [gr] : [',...
0122     num2str(R_a(1)),',',num2str(R_a(2)*255),']'])
0123 x_approx = [reshape(A_a(1:2,:),6,1);R_a'];
0124 
0125 % ---  maximum number of iterations N_iter ------------------------------
0126 disp(['Maximum number of iterations                             : ', num2str(max_iter)])
0127 
0128 % ---  minimum size of overlap  ------------------------------
0129 disp(['Minimum size of overlap                                  : ', num2str(Nf_MIN),'x', num2str(Nf_MIN)])
0130 
0131 % ---  smoothing kernel sigma_smooth ------------------------------------
0132 disp(['Smoothing kernel [pixels]                                : 0'])
0133 
0134  
0135 %% === main routine Sym-LSM =============================================
0136 
0137 disp('=== Iteration sequence =======================================')
0138 
0139 [est_x,est_sigma_0,NN,Nf,Red,N_iter] = LSM_62_sym_warp_main...
0140     (g,h,vg,vh,A_a,R_a,sigma_smooth,max_iter,Nf_MIN,1);
0141 
0142 %% === show results =====================================================
0143 A_est   = [reshape(est_x.x(1:6),2,3);0 0 1];
0144     Rm_est  = [ est_x.x(7:8)';0 1];
0145     Ai_est  = A_est;
0146     
0147 image_pair_analyse(...
0148     A_a,  ...
0149     R_a, ...
0150     Ai_est, ...
0151     Red, ...
0152     est_sigma_0, ...
0153     est_x, ...
0154     1,0);
0155 
0156 disp(' --------------------------------- ')
0157 disp(' ----  end demo symmetric LSM ---- ')
0158 disp(' --------------------------------- ')
0159 
0160

Generated on Sun 19-Jul-2020 23:00:25 by m2html © 2005