summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic
diff options
context:
space:
mode:
authorLeo Chan <leochanj@live.unc.edu>2020-10-22 01:53:21 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-22 01:56:35 -0400
commitd17b33131c14864bd1eae275f49a3f148e21cf29 (patch)
tree0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/toolbox_basic
parent601ed25a4c5b66cb75315832c15613a727db2c26 (diff)
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to: - Use libextra to loop as realtime jobs - Preallocate memory before starting their main computation - Accept input via stdin instead of via argc Does not include the SD-VBS matlab code. Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Distor2Calib.m391
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Rectangle2Square.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m54
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/add_suppress.m98
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/analyse_error.m141
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/apply_distortion.m137
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/calib_gui.m117
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_active_images.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_convergence.m48
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_directory.m97
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_extracted_images.m37
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clear_windows.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clearwin.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_calib.m193
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib.m230
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib3D.m482
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion2.m71
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion_oulu.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_error_calib.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_collineation.m66
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic.m123
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_init.m151
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_refine.m113
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_homography.m163
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/cornerfinder.m215
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/count_squares.m74
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/data_calib.m92
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/error_analysis.m182
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/export_calib_data.m99
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ext_calib.m152
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_grid.m234
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters3D.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extrinsic_computation.m185
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixallvariables.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixvariable.m18
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ginput3.m216
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim.m139
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim_iter.m394
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ima_read_calib.m158
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/init_intrinsic_param.m158
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/is3D.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loading_calib.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadinr.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadpgm.m89
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadppm.m109
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mean_std_robust.m7
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mosaic.m92
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/normalize.m43
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/pgmread.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project2_oulu.m53
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points.m276
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points2.m312
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projectedGrid.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projector_calib.m258
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/readras.m87
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/recomp_corner_calib.m119
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rect.m127
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/reproject_calib.m121
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rigid_motion.m66
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rodrigues.m217
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rotation.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/run_error_analysis.m65
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveinr.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/savepgm.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveppm.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saving_calib.m95
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/script_fit_distortion.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/startup.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/undistort_image.m193
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_convert.m89
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_read.m59
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/writeras.m105
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/README5
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/carve_it.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m90
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/compute_AD_disp.m103
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/compute_J.m31
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/find_AD.m82
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/find_D.m65
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/find_center.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/gen_feature_s.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/grad.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/hemisphere_s.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/im.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/iter_AD.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m49
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/norm_inten.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/pan.0.pgm53
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/pan.1.pgm59
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/readpgm.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/simulation.m42
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/sports1_11_28.jpegbin0 -> 23655 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/test_affine.m33
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affinityic.c186
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib/TOOLBOX_calib.tarbin0 -> 98304 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Distor2Calib.m391
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Multi_Calib_oulu.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Rectangle2Square.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/UnWarpPlane.m54
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/add_suppress.m91
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/analyse_error.m104
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib.m74
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib3D_gui.m115
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib_gui.m81
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_active_images.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_convergence.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_planarity.m41
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib.m99
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib3D.m79
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib.m218
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib3D.m482
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion2.m71
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion_oulu.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_error_calib.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_collineation.m66
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic.m123
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_init.m149
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_refine.m110
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_homography.m163
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/convert_oulu.m35
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/cornerfinder.m215
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/count_squares.m74
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/data_calib.m89
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/error_analysis.m182
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ext_calib.m130
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_grid.m227
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters3D.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extrinsic_computation.m173
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ginput3.m216
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim.m60
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim3D.m264
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_cont.m142
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_iter.m332
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib3D.m153
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ima_read_calib.m107
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_calib_param.m210
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_intrinsic_param.m153
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/is3D.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loading_calib.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadinr.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadpgm.m89
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadppm.m101
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/mean_std_robust.m7
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/multi_error_oulu.m49
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/normalize.m32
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/pgmread.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project2_oulu.m53
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project_points.m276
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/projectedGrid.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/readras.m87
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/recomp_corner_calib.m96
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rect.m93
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/reproject_calib.m92
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rigid_motion.m66
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rodrigues.m217
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rotation.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/run_error_analysis.m65
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveinr.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/savepgm.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveppm.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saving_calib.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/script_fit_distortion.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center3D.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center3D.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/startup.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/test_3d.m80
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/undistort_image.m88
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/writeras.m105
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/calib_bouguetj2/TOOLBOX_calib.tarbin0 -> 253952 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m.m42
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m2.m51
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/affinityic.c186
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexa64bin0 -> 10209 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexglxbin0 -> 8828 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/anisodiff.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/bin.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.c189
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexa64bin0 -> 9679 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexglxbin0 -> 8486 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/density.m133
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/find_edge.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/grad.m28
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_even2.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_odd2.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/max_supress2.m59
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/mgrad.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/mpgread.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/mpgread.mexlxbin0 -> 84735 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.mexlxbin0 -> 105791 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut.m108
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_b.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_bb.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_e.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_neg.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_sparse.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncut_tmp.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/ncutd.m108
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/nonmaxsup.m81
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/pair_dist.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/quadedgep.m106
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/readpcm.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/readpdm.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/readpfm.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/renormalize.m32
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/show_edge.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.c141
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexa64bin0 -> 9427 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexglxbin0 -> 8198 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/tmp.tex16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/vmquant.m112
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexhp7bin0 -> 24603 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexlxbin0 -> 16987 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexsolbin0 -> 27012 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/writepdm.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/common/writepfm.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/disp_image.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/draw_box.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/draw_box2.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/im.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/ims.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/montage2.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/showmask.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/disp/showmaskb.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/construct_w.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/construct_w2.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/factor.m50
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/factor_test.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/factor_test2.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/factorizaion.tarbin0 -> 81920 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/findG.m48
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/findg1.m49
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/findg2.m56
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/hotel.matbin0 -> 56320 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/show_3dpoints.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/show_S.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/show_t.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/show_t3.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/zt.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/91048.jpgbin0 -> 2553 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/bar2d.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/barrot.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/bars.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/clip_image.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_J_simple.m50
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_angle.m18
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_filter_fft.m84
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_g2.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_h2.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/compute_ofilter_fft.m88
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/dgauss.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/dog1.m28
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/dog2.m31
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/doog1.m32
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/doog2.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/fft_filt.m82
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/fft_filt_2.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/filter_bank_jshi.tarbin0 -> 71680 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/gauss.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/gaussian.m31
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/get_diff2.m43
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/get_diff_free.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/grad1.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/grad2.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/m_interp4.m49
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank.m63
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_23.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_even.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_odd.m41
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mdoog2.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mimrotate.m119
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mk_odd_filter.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mkdog1.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mkdog2.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mkdoog2.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mkdoogs.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/mkg.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/quadpair.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/smooth.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/softkmean.m56
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/softmeans.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter/softmeans2.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filterQuad.zipbin0 -> 4531 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/1d_cut.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/Bfilter.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/BfilterS.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/Ncut.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/apply_image.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/back_proj.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank.m33
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank2.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/binize.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/binize_old.m34
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/binomialfield.m75
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_hist.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_s.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_sf.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histneighb.m37
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_joint_hist.m41
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_test.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compact.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_J.m31
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_Lf.m35
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_corr.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch.m34
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch2.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter.m84
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter_fft.m84
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/conv_trim.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/corr_hist.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/crop_im_fil.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/cutoff.m13
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/cutout.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_Imask.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_diff.m37
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult.m435
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult2.m215
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresulthome.m237
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_groups.m13
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_hist2d.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair.m28
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair_chank.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/doog2.m43
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp_v5.m13
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_proj.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/eigs_decomp.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/euclid_dist.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_all_files.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_output.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/find_bst_cut.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/find_center.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/find_cutpoint.m13
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/gen_filters.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist_inten.m7
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist_inten.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win5.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/grad.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/half_sigmoid.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist2d.m13
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_I_f.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_diff.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_f.m28
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_in_chank.m33
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_inner.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/histbin_fv_chank.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/hsv2clrs.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/id_cut.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/im.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/im3.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/im5.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/im_vect.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/imrotate.m119
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/ims.m3
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/imvs.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/is_step.m33
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/ks_2d.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/load_result.m39
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/m_interp4.m49
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/make_masks.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/makefilter.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t1.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t2.m21
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_test.m43
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkg.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkgaussian.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkmulfilter.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mkpoog2.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn2.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm2.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis_image.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/myinterp.m18
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/ncut_b.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/new_compute_J.m32
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist2.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text.m70
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text2.m58
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text3.m84
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text4.m81
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/patch_cat.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/pgmread.m15
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/poisson.m44
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/poissonfield.m53
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back_id.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/quant.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpdm.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_id.m21
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_idf.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpgm.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readpnm.m21
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/readppm.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/record.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/recursive_cut_tc.m140
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/reduce_all.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/rotate_J.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/session.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/show_cumhist.m28
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/show_hist.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm_v5.m34
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/sigmoid.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/signif.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/signif_N.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/smooth.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/startup.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/swarp.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/swarpback.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test.m110
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test1.m175
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test2.m220
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test3.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_best_cut.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex.m361
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex2.m136
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex3.m169
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex4.m353
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex5.m446
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion.m117
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion2.m127
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_period.m58
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/test_text.m434
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp.m68
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp1.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp2.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp3.m126
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/true_loc.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/vmquant.m112
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm2.m66
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm3.m71
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/write_command.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/write_test.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/writeout_feature.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/writepfm.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/writepgm.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/writepmm.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filter_hist/writepnm5.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog1.m32
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog2.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_even2.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_odd2.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/filtersQuad/quadedgep2.m188
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/convert422.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/im_vd.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/imread2.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m19
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/pgmread.m24
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m25
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read422.m45
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read422f.m50
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m40
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m29
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_scan.m42
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readlines.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m16
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfm.m10
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m11
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpgm.m30
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m35
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readpmm.m22
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/readppm.m23
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/writepgm.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/io/writeppm.m14
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m54
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/hungarian.m464
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/test.m87
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/091399fbn-jets.3.jpgbin0 -> 25886 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/expand.m8
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/gauss_lowpass.m9
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/gen_w.m12
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/reduce.m7
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/session.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/pyramid/startup.m5
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/remap_angle.m4
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/spmtimesd.c141
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m73
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m65
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m67
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m47
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m6
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m94
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m20
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m136
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m52
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/showim.m36
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/showncut.m92
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/startup.m18
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/tars/TOOLBOX_calib.tarbin0 -> 253952 bytes
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/textons/dist2.m27
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m46
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/textons/find_textons1.m37
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/textons/kmeans2.m127
525 files changed, 31550 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Distor2Calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Distor2Calib.m
new file mode 100755
index 0000000..a82f583
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Distor2Calib.m
@@ -0,0 +1,391 @@
1function [fc_2,Rc_2,Tc_2,H_2,distance,V_vert,V_hori,x_all_c,V_hori_pix,V_vert_pix,V_diag1_pix,V_diag2_pix]=Distor2Calib(k_dist,grid_pts_centered,n_sq_x,n_sq_y,Np,W,L,Xgrid_2,f_ini,N_iter,two_focal);
2
3% Computes the calibration parameters knowing the
4% distortion factor k_dist
5
6% grid_pts_centered are the grid point coordinates after substraction of
7% the optical center.
8
9% can give an optional guess for the focal length f_ini (can set to [])
10% can provide the number of iterations for the Iterative Vanishing Point Algorithm
11
12% if the focal length is known perfectly, then, there is no need to iterate,
13% and therefore, one can fix: N_iter = 0;
14
15% California Institute of Technology
16% (c) Jean-Yves Bouguet - October 7th, 1997
17
18
19
20%keyboard;
21
22if exist('two_focal'),
23 if isempty(two_focal),
24 two_focal=0;
25 end;
26else
27 two_focal = 0;
28end;
29
30
31if exist('N_iter'),
32 if ~isempty(N_iter),
33 disp('Use number of iterations provided');
34 else
35 N_iter = 10;
36 end;
37else
38 N_iter = 10;
39end;
40
41if exist('f_ini'),
42 if ~isempty(f_ini),
43 disp('Use focal provided');
44 if length(f_ini)<2, f_ini=[f_ini;f_ini]; end;
45 fc_2 = f_ini;
46 x_all_c = [grid_pts_centered(1,:)/fc_2(1);grid_pts_centered(2,:)/fc_2(2)];
47 x_all_c = comp_distortion(x_all_c,k_dist); % we can this time!!!
48 else
49 fc_2 = [1;1];
50 x_all_c = grid_pts_centered;
51 end;
52else
53 fc_2 = [1;1];
54 x_all_c = grid_pts_centered;
55end;
56
57
58dX = W/n_sq_x;
59dY = L/n_sq_y;
60
61
62N_x = n_sq_x+1;
63N_y = n_sq_y+1;
64
65
66x_grid = zeros(N_x,N_y);
67y_grid = zeros(N_x,N_y);
68
69
70
71
72
73%%% Computation of the four vanishing points in pixels
74
75
76 x_grid(:) = grid_pts_centered(1,:);
77 y_grid(:) = grid_pts_centered(2,:);
78
79 for k=1:n_sq_x+1,
80 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
81 vert(:,k) = U(:,3);
82 end;
83
84 for k=1:n_sq_y+1,
85 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
86 hori(:,k) = U(:,3);
87 end;
88
89 % 2 principle Vanishing points:
90 [U,S,V] = svd(vert);
91 V_vert = U(:,3);
92 [U,S,V] = svd(hori);
93 V_hori = U(:,3);
94
95
96
97 % Square warping:
98
99
100 vert_first = vert(:,1) - dot(V_vert,vert(:,1))/dot(V_vert,V_vert) * V_vert;
101 vert_last = vert(:,n_sq_x+1) - dot(V_vert,vert(:,n_sq_x+1))/dot(V_vert,V_vert) * V_vert;
102
103 hori_first = hori(:,1) - dot(V_hori,hori(:,1))/dot(V_hori,V_hori) * V_hori;
104 hori_last = hori(:,n_sq_y+1) - dot(V_hori,hori(:,n_sq_y+1))/dot(V_hori,V_hori) * V_hori;
105
106
107 x1 = cross(hori_first,vert_first);
108 x2 = cross(hori_first,vert_last);
109 x3 = cross(hori_last,vert_last);
110 x4 = cross(hori_last,vert_first);
111
112 x1 = x1/x1(3);
113 x2 = x2/x2(3);
114 x3 = x3/x3(3);
115 x4 = x4/x4(3);
116
117
118
119 [square] = Rectangle2Square([x1 x2 x3 x4],W,L);
120
121 y1 = square(:,1);
122 y2 = square(:,2);
123 y3 = square(:,3);
124 y4 = square(:,4);
125
126 H2 = cross(V_vert,V_hori);
127
128 V_diag1 = cross(cross(y1,y3),H2);
129 V_diag2 = cross(cross(y2,y4),H2);
130
131 V_diag1 = V_diag1 / norm(V_diag1);
132 V_diag2 = V_diag2 / norm(V_diag2);
133
134 V_hori_pix = V_hori;
135 V_vert_pix = V_vert;
136 V_diag1_pix = V_diag1;
137 V_diag2_pix = V_diag2;
138
139
140% end of computation of the vanishing points in pixels.
141
142
143
144
145
146
147
148
149if two_focal, % only if we attempt to estimate two focals...
150 % Use diagonal lines also to add two extra vanishing points (?)
151 N_min = min(N_x,N_y);
152
153 if N_min < 2,
154 use_diag = 0;
155 two_focal = 0;
156 disp('Cannot estimate two focals (no existing diagonals)');
157 else
158 use_diag = 1;
159 Delta_N = abs(N_x-N_y);
160 N_extra = round((N_min - Delta_N - 1)/2);
161 diag_list = -N_extra:Delta_N+N_extra;
162 N_diag = length(diag_list);
163 diag_1 = zeros(3,N_diag);
164 diag_2 = zeros(3,N_diag);
165 end;
166else
167 % Give up the use of the diagonals (so far)
168 % it seems that the error is increased
169 use_diag = 0;
170end;
171
172
173
174% The vertical lines: vert, Horizontal lines: hori
175vert = zeros(3,n_sq_x+1);
176hori = zeros(3,n_sq_y+1);
177
178for counter_k = 1:N_iter, % the Iterative Vanishing Points Algorithm to
179 % estimate the focal length accurately
180
181 x_grid(:) = x_all_c(1,:);
182 y_grid(:) = x_all_c(2,:);
183
184 for k=1:n_sq_x+1,
185 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
186 vert(:,k) = U(:,3);
187 end;
188
189 for k=1:n_sq_y+1,
190 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
191 hori(:,k) = U(:,3);
192 end;
193
194 % 2 principle Vanishing points:
195 [U,S,V] = svd(vert);
196 V_vert = U(:,3);
197 [U,S,V] = svd(hori);
198 V_hori = U(:,3);
199
200
201
202 % Square warping:
203
204
205 vert_first = vert(:,1) - dot(V_vert,vert(:,1))/dot(V_vert,V_vert) * V_vert;
206 vert_last = vert(:,n_sq_x+1) - dot(V_vert,vert(:,n_sq_x+1))/dot(V_vert,V_vert) * V_vert;
207
208 hori_first = hori(:,1) - dot(V_hori,hori(:,1))/dot(V_hori,V_hori) * V_hori;
209 hori_last = hori(:,n_sq_y+1) - dot(V_hori,hori(:,n_sq_y+1))/dot(V_hori,V_hori) * V_hori;
210
211
212 x1 = cross(hori_first,vert_first);
213 x2 = cross(hori_first,vert_last);
214 x3 = cross(hori_last,vert_last);
215 x4 = cross(hori_last,vert_first);
216
217 x1 = x1/x1(3);
218 x2 = x2/x2(3);
219 x3 = x3/x3(3);
220 x4 = x4/x4(3);
221
222
223
224 [square] = Rectangle2Square([x1 x2 x3 x4],W,L);
225
226 y1 = square(:,1);
227 y2 = square(:,2);
228 y3 = square(:,3);
229 y4 = square(:,4);
230
231 H2 = cross(V_vert,V_hori);
232
233 V_diag1 = cross(cross(y1,y3),H2);
234 V_diag2 = cross(cross(y2,y4),H2);
235
236 V_diag1 = V_diag1 / norm(V_diag1);
237 V_diag2 = V_diag2 / norm(V_diag2);
238
239
240
241
242 % Estimation of the focal length, and normalization:
243
244 % Compute the ellipsis of (1/f^2) positions:
245 % a * (1/fx)^2 + b * (1/fx)^2 = -c
246
247
248 a1 = V_hori(1);
249 b1 = V_hori(2);
250 c1 = V_hori(3);
251
252 a2 = V_vert(1);
253 b2 = V_vert(2);
254 c2 = V_vert(3);
255
256 a3 = V_diag1(1);
257 b3 = V_diag1(2);
258 c3 = V_diag1(3);
259
260 a4 = V_diag2(1);
261 b4 = V_diag2(2);
262 c4 = V_diag2(3);
263
264
265 if two_focal,
266
267
268 A = [a1*a2 b1*b2;a3*a4 b3*b4];
269 b = -[c1*c2;c3*c4];
270
271 f = sqrt(abs(1./(inv(A)*b)));
272
273 else
274
275 f = sqrt(abs(-(c1*c2*(a1*a2 + b1*b2) + c3*c4*(a3*a4 + b3*b4))/(c1^2*c2^2 + c3^2*c4^2)));
276
277 f = [f;f];
278
279 end;
280
281
282
283 % REMARK:
284 % if both a and b are small, the calibration is impossible.
285 % if one of them is small, only the other focal length is observable
286 % if none is small, both focals are observable
287
288
289 fc_2 = fc_2 .* f;
290
291
292 % DEBUG PART: fix focal to 500...
293 %fc_2= [500;500]; disp('Line 293 to be earased in Distor2Calib.m');
294
295
296 % end of focal compensation
297
298 % normalize by the current focal:
299
300 x_all = [grid_pts_centered(1,:)/fc_2(1);grid_pts_centered(2,:)/fc_2(2)];
301
302 % Compensate by the distortion factor:
303
304 x_all_c = comp_distortion(x_all,k_dist);
305
306end;
307
308% At that point, we hope that the distortion is gone...
309
310x_grid(:) = x_all_c(1,:);
311y_grid(:) = x_all_c(2,:);
312
313for k=1:n_sq_x+1,
314 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
315 vert(:,k) = U(:,3);
316end;
317
318for k=1:n_sq_y+1,
319 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
320 hori(:,k) = U(:,3);
321end;
322
323% Vanishing points:
324[U,S,V] = svd(vert);
325V_vert = U(:,3);
326[U,S,V] = svd(hori);
327V_hori = U(:,3);
328
329% Horizon:
330
331H_2 = cross(V_vert,V_hori);
332
333% H_2 = cross(V_vert,V_hori);
334
335% pick a plane in front of the camera (positive depth)
336if H_2(3) < 0, H_2 = -H_2; end;
337
338
339% Rotation matrix:
340
341if V_hori(1) < 0, V_hori = -V_hori; end;
342
343V_hori = V_hori/norm(V_hori);
344H_2 = H_2/norm(H_2);
345
346V_hori = V_hori - dot(V_hori,H_2)*H_2;
347
348Rc_2 = [V_hori cross(H_2,V_hori) H_2];
349
350Rc_2 = Rc_2 / det(Rc_2);
351
352%omc_2 = rodrigues(Rc_2);
353
354%Rc_2 = rodrigues(omc_2);
355
356% Find the distance of the plane for translation vector:
357
358xc_2 = [x_all_c;ones(1,Np)];
359
360Zc_2 = 1./sum(xc_2 .* (Rc_2(:,3)*ones(1,Np)));
361
362Xo_2 = [sum(xc_2 .* (Rc_2(:,1)*ones(1,Np))).*Zc_2 ; sum(xc_2 .* (Rc_2(:,2)*ones(1,Np))).*Zc_2];
363
364XXo_2 = Xo_2 - mean(Xo_2')'*ones(1,Np);
365
366distance_x = norm(Xgrid_2(1,:))/norm(XXo_2(1,:));
367distance_y = norm(Xgrid_2(2,:))/norm(XXo_2(2,:));
368
369
370distance = sum(sum(XXo_2(1:2,:).*Xgrid_2(1:2,:)))/sum(sum(XXo_2(1:2,:).^2));
371
372alpha = abs(distance_x - distance_y)/distance;
373
374if (alpha>0.1)&~two_focal,
375 disp('Should use two focals in x and y...');
376end;
377
378% Deduce the translation vector:
379
380Tc_2 = distance * H_2;
381
382
383
384
385
386return;
387
388 V_hori_pix/V_hori_pix(3)
389 V_vert_pix/V_vert_pix(3)
390 V_diag1_pix/V_diag1_pix(3)
391 V_diag2_pix/V_diag2_pix(3)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Rectangle2Square.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Rectangle2Square.m
new file mode 100755
index 0000000..a6bbbe5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/Rectangle2Square.m
@@ -0,0 +1,19 @@
1function [square] = Rectangle2Square(rectangle,L,W);
2
3% Generate the square from a rectangle of known segment lengths
4% from pt1 to pt2 : L
5% from pt2 to pt3 : W
6
7[u_hori,u_vert] = UnWarpPlane(rectangle);
8
9coeff_x = sqrt(W/L);
10coeff_y = 1/coeff_x;
11
12x_coord = [ 0 coeff_x coeff_x 0];
13y_coord = [ 0 0 coeff_y coeff_y];
14
15
16square = rectangle(:,1) * ones(1,4) + u_hori*x_coord + u_vert*y_coord;
17square = square ./ (ones(3,1)*square(3,:));
18
19
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m
new file mode 100755
index 0000000..8addf52
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m
@@ -0,0 +1,54 @@
1function [u_hori,u_vert] = UnWarpPlane(x1,x2,x3,x4);
2
3% Recovers the two 3D directions of the rectangular patch x1x2x3x4
4% x1 is the origin point, ie any point of planar coordinate (x,y) on the
5% rectangular patch will be projected on the image plane at:
6% x1 + x * u_hori + y * u_vert
7%
8% Note: u_hori and u_vert are also the two vanishing points.
9
10
11if nargin < 4,
12
13 x4 = x1(:,4);
14 x3 = x1(:,3);
15 x2 = x1(:,2);
16 x1 = x1(:,1);
17
18end;
19
20
21% Image Projection:
22L1 = cross(x1,x2);
23L2 = cross(x4,x3);
24L3 = cross(x2,x3);
25L4 = cross(x1,x4);
26
27% Vanishing point:
28V1 = cross(L1,L2);
29V2 = cross(L3,L4);
30
31% Horizon line:
32H = cross(V1,V2);
33
34if H(3) < 0, H = -H; end;
35
36
37H = H / norm(H);
38
39
40X1 = x1 / dot(H,x1);
41X2 = x2 / dot(H,x2);
42X3 = x3 / dot(H,x3);
43X4 = x4 / dot(H,x4);
44
45scale = X1(3);
46
47X1 = X1/scale;
48X2 = X2/scale;
49X3 = X3/scale;
50X4 = X4/scale;
51
52
53u_hori = X2 - X1;
54u_vert = X4 - X1;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/add_suppress.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/add_suppress.m
new file mode 100755
index 0000000..a8a32c0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/add_suppress.m
@@ -0,0 +1,98 @@
1
2if ~exist('n_ima'),
3 fprintf(1,'No data to process.\n');
4 return;
5end;
6
7
8check_active_images;
9
10
11fprintf(1,'\nThis function is useful to select a subset of images to calibrate\n');
12
13 fprintf(1,'\nThere are currently %d active images selected for calibration (out of %d):\n',length(ind_active),n_ima);
14
15 if ~isempty(ind_active),
16
17 for ii = 1:length(ind_active)-2,
18
19 fprintf(1,'%d, ',ind_active(ii));
20
21 end;
22
23 fprintf(1,'%d and %d.',ind_active(end-1),ind_active(end));
24
25 end;
26
27 fprintf(1,'\n');
28
29
30fprintf(1,'\nDo you want to suppress or add images from that list?\n');
31
32choice = 2;
33
34while (choice~=0)&(choice~=1),
35 choice = input('For suppressing images enter 0, for adding images enter 1 ([]=no change): ');
36 if isempty(choice),
37 fprintf(1,'No change applied to the list of active images.\n');
38 return;
39 end;
40 if (choice~=0)&(choice~=1),
41 disp('Bad entry. Try again.');
42 end;
43end;
44
45
46if choice,
47
48 ima_numbers = input('Number(s) of image(s) to add ([] = all images) = ');
49
50if isempty(ima_numbers),
51 fprintf(1,'All %d images are now active\n',n_ima);
52 ima_proc = 1:n_ima;
53 else
54 ima_proc = ima_numbers;
55 end;
56
57else
58
59
60 ima_numbers = input('Number(s) of image(s) to suppress ([] = no image) = ');
61
62 if isempty(ima_numbers),
63 fprintf(1,'No image has been suppressed. No modication of the list of active images.\n',n_ima);
64 ima_proc = [];
65 else
66 ima_proc = ima_numbers;
67 end;
68
69end;
70
71if ~isempty(ima_proc),
72
73 active_images(ima_proc) = choice * ones(1,length(ima_proc));
74
75end;
76
77
78 check_active_images;
79
80
81 fprintf(1,'\nThere is now a total of %d active images for calibration:\n',length(ind_active));
82
83 if ~isempty(ind_active),
84
85 for ii = 1:length(ind_active)-2,
86
87 fprintf(1,'%d, ',ind_active(ii));
88
89 end;
90
91 fprintf(1,'%d and %d.',ind_active(end-1),ind_active(end));
92
93 end;
94
95 fprintf(1,'\n\nYou may now run ''Calibration'' to recalibrate based on this new set of images.\n');
96
97
98 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/analyse_error.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/analyse_error.m
new file mode 100755
index 0000000..7a9cf0f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/analyse_error.m
@@ -0,0 +1,141 @@
1% Color code for each image:
2
3if ~exist('n_ima')|~exist('fc'),
4 fprintf(1,'No calibration data available.\n');
5 return;
6end;
7
8check_active_images;
9
10if ~exist(['ex_' num2str(ind_active(1)) ]),
11 fprintf(1,'Need to calibrate before analysing reprojection error. Maybe need to load Calib_Results.mat file.\n');
12 return;
13end;
14
15
16%if ~exist('no_grid'),
17 no_grid = 0;
18%end;
19
20colors = 'brgkcm';
21
22
23figure(5);
24
25for kk = 1:n_ima,
26 if exist(['y_' num2str(kk)]),
27 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
28
29 if ~no_grid,
30 eval(['XX_kk = X_' num2str(kk) ';']);
31 N_kk = size(XX_kk,2);
32
33 if ~exist(['n_sq_x_' num2str(kk)]),
34 no_grid = 1;
35 end;
36
37 if ~no_grid,
38 eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
39 eval(['n_sq_y = n_sq_y_' num2str(kk) ';']);
40 if (N_kk ~= ((n_sq_x+1)*(n_sq_y+1))),
41 no_grid = 1;
42 end;
43 end;
44 end;
45
46 eval(['plot(ex_' num2str(kk) '(1,:),ex_' num2str(kk) '(2,:),''' colors(rem(kk-1,6)+1) '+'');']);
47
48 hold on;
49 end;
50 end;
51end;
52
53hold off;
54axis('equal');
55if 1, %~no_grid,
56 title('Reprojection error (in pixel) - To exit: right button');
57else
58 title('Reprojection error (in pixel)');
59end;
60xlabel('x');
61ylabel('y');
62
63set(5,'Name','error','NumberTitle','off');
64
65
66
67err_std = std(ex')';
68
69fprintf(1,'Pixel error: err = [ %3.5f %3.5f] (all active images)\n\n',err_std);
70
71
72b = 1;
73
74while b==1,
75
76[xp,yp,b] = ginput3(1);
77
78if b==1,
79ddd = (ex(1,:)-xp).^2 + (ex(2,:)-yp).^2;
80
81[mind,indmin] = min(ddd);
82
83
84done = 0;
85kk_ima = 1;
86while (~done)&(kk_ima<=n_ima),
87 %fprintf(1,'%d...',kk_ima);
88 eval(['ex_kk = ex_' num2str(kk_ima) ';']);
89 sol_kk = find((ex_kk(1,:) == ex(1,indmin))&(ex_kk(2,:) == ex(2,indmin)));
90 if isempty(sol_kk),
91 kk_ima = kk_ima + 1;
92 else
93 done = 1;
94 end;
95end;
96
97if ~no_grid,
98
99eval(['n_sq_x = n_sq_x_' num2str(kk_ima) ';']);
100eval(['n_sq_y = n_sq_y_' num2str(kk_ima) ';']);
101
102Nx = n_sq_x+1;
103Ny = n_sq_y+1;
104
105y1 = floor((sol_kk-1)./Nx);
106x1 = sol_kk - 1 - Nx*y1; %rem(sol_kk-1,Nx);
107
108y1 = (n_sq_y+1) - y1;
109x1 = x1 + 1;
110
111fprintf(1,'\nSelected image: %d\nSelected point: (col,row)=(%d,%d)\nNcol=%d, Nrow=%d\n',[kk_ima x1 y1 Nx Ny]);
112fprintf(1,'Pixel error = (%3.5f,%3.5f)\n',[ex(1,indmin) ex(2,indmin)]);
113
114else
115
116 eval(['x_kk = x_' num2str(kk_ima) ';']);
117
118 xpt = x_kk(:,sol_kk);
119
120fprintf(1,'\nSelected image: %d\nImage coordinates (in pixel): (%3.2f,%3.2f)\n',[kk_ima xpt']);
121fprintf(1,'Pixel error = (%3.5f,%3.5f)\n',[ex(1,indmin) ex(2,indmin)]);
122
123
124end;
125
126
127if exist(['wintx_' num2str(kk_ima)]),
128
129 eval(['wintx = wintx_' num2str(kk_ima) ';']);
130 eval(['winty = winty_' num2str(kk_ima) ';']);
131
132 fprintf(1,'Window size: wintx = %d, winty = %d\n',[wintx winty]);
133end;
134
135
136end;
137
138end;
139
140disp('done');
141
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/apply_distortion.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/apply_distortion.m
new file mode 100755
index 0000000..f5c5b48
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/apply_distortion.m
@@ -0,0 +1,137 @@
1function [xd,dxddk] = apply_distortion(x,k)
2
3
4[m,n] = size(x);
5
6% Add distortion:
7
8r2 = x(1,:).^2 + x(2,:).^2;
9
10r4 = r2.^2;
11
12% Radial distortion:
13
14cdist = 1 + k(1) * r2 + k(2) * r4;
15
16if nargout > 1,
17 dcdistdk = [ r2' r4' zeros(n,2)];
18end;
19
20
21xd1 = x .* (ones(2,1)*cdist);
22
23coeff = (reshape([cdist;cdist],2*n,1)*ones(1,3));
24
25if nargout > 1,
26 dxd1dk = zeros(2*n,4);
27 dxd1dk(1:2:end,:) = (x(1,:)'*ones(1,4)) .* dcdistdk;
28 dxd1dk(2:2:end,:) = (x(2,:)'*ones(1,4)) .* dcdistdk;
29end;
30
31
32% tangential distortion:
33
34a1 = 2.*x(1,:).*x(2,:);
35a2 = r2 + 2*x(1,:).^2;
36a3 = r2 + 2*x(2,:).^2;
37
38delta_x = [k(3)*a1 + k(4)*a2 ;
39 k(3) * a3 + k(4)*a1];
40
41aa = (2*k(3)*x(2,:)+6*k(4)*x(1,:))'*ones(1,3);
42bb = (2*k(3)*x(1,:)+2*k(4)*x(2,:))'*ones(1,3);
43cc = (6*k(3)*x(2,:)+2*k(4)*x(1,:))'*ones(1,3);
44
45if nargout > 1,
46 ddelta_xdk = zeros(2*n,4);
47 ddelta_xdk(1:2:end,3) = a1';
48 ddelta_xdk(1:2:end,4) = a2';
49 ddelta_xdk(2:2:end,3) = a3';
50 ddelta_xdk(2:2:end,4) = a1';
51end;
52
53xd = xd1 + delta_x;
54
55if nargout > 1,
56 dxddk = dxd1dk + ddelta_xdk ;
57end;
58
59
60return;
61
62% Test of the Jacobians:
63
64n = 10;
65
66X = 10*randn(3,n);
67om = randn(3,1);
68T = [10*randn(2,1);40];
69f = 1000*rand(2,1);
70c = 1000*randn(2,1);
71k = 0.5*randn(4,1);
72
73
74[x,dxdom,dxdT,dxdf,dxdc,dxdk] = project_points(X,om,T,f,c,k);
75
76
77% Test on om: NOT OK
78
79dom = 0.000000001 * norm(om)*randn(3,1);
80om2 = om + dom;
81
82[x2] = project_points(X,om2,T,f,c,k);
83
84x_pred = x + reshape(dxdom * dom,2,n);
85
86
87norm(x2-x)/norm(x2 - x_pred)
88
89
90% Test on T: OK!!
91
92dT = 0.0001 * norm(T)*randn(3,1);
93T2 = T + dT;
94
95[x2] = project_points(X,om,T2,f,c,k);
96
97x_pred = x + reshape(dxdT * dT,2,n);
98
99
100norm(x2-x)/norm(x2 - x_pred)
101
102
103
104% Test on f: OK!!
105
106df = 0.001 * norm(f)*randn(2,1);
107f2 = f + df;
108
109[x2] = project_points(X,om,T,f2,c,k);
110
111x_pred = x + reshape(dxdf * df,2,n);
112
113
114norm(x2-x)/norm(x2 - x_pred)
115
116
117% Test on c: OK!!
118
119dc = 0.01 * norm(c)*randn(2,1);
120c2 = c + dc;
121
122[x2] = project_points(X,om,T,f,c2,k);
123
124x_pred = x + reshape(dxdc * dc,2,n);
125
126norm(x2-x)/norm(x2 - x_pred)
127
128% Test on k: OK!!
129
130dk = 0.001 * norm(4)*randn(4,1);
131k2 = k + dk;
132
133[x2] = project_points(X,om,T,f,c,k2);
134
135x_pred = x + reshape(dxdk * dk,2,n);
136
137norm(x2-x)/norm(x2 - x_pred)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/calib_gui.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/calib_gui.m
new file mode 100755
index 0000000..d591d03
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/calib_gui.m
@@ -0,0 +1,117 @@
1fig_number = 1;
2
3n_row = 4;
4n_col = 4;
5
6string_list = cell(n_row,n_col);
7callback_list = cell(n_row,n_col);
8
9x_size = 85;
10y_size = 14;
11gap_x = 0;
12font_name = 'clean';
13font_size = 8;
14
15title_figure = 'Camera Calibration Toolbox';
16
17string_list{1,1} = 'Image names';
18string_list{1,2} = 'Read images';
19string_list{1,3} = 'Extract grid corners';
20string_list{1,4} = 'Calibration';
21string_list{2,1} = 'Show Extrinsic';
22string_list{2,2} = 'Reproject on images';
23string_list{2,3} = 'Analyse error';
24string_list{2,4} = 'Recomp. corners';
25string_list{3,1} = 'Add/Suppress images';
26string_list{3,2} = 'Save';
27string_list{3,3} = 'Load';
28string_list{3,4} = 'Exit';
29
30string_list{4,1} = 'Comp. Extrinsic';
31string_list{4,2} = 'Undistort image';
32string_list{4,3} = 'Export calib data';
33
34
35callback_list{1,1} = 'data_calib;';
36callback_list{1,2} = 'ima_read_calib;';
37callback_list{1,3} = 'click_calib;';
38callback_list{1,4} = 'go_calib_optim;';
39callback_list{2,1} = 'ext_calib;';
40callback_list{2,2} = 'reproject_calib;';
41callback_list{2,3} = 'analyse_error;';
42callback_list{2,4} = 'recomp_corner_calib;';
43callback_list{3,1} = 'add_suppress;';
44callback_list{3,2} = 'saving_calib;';
45callback_list{3,3} = 'loading_calib;';
46callback_list{3,4} = ['disp(''Bye. To run again, type calib_gui.''); close(' num2str(fig_number) ');'];
47
48callback_list{4,1} = 'extrinsic_computation;';
49callback_list{4,2} = 'undistort_image;';
50callback_list{4,3} = 'export_calib_data;';
51
52
53%------- BEGIN PROECTED REGION -----------%
54%------- DO NOT EDIT IN THIS REGION -----------%
55
56figure(fig_number); clf;
57pos = get(fig_number,'Position');
58
59fig_size_x = x_size*n_col+(n_col+1)*gap_x;
60fig_size_y = y_size*n_row+(n_row+1)*gap_x;
61
62set(fig_number,'Units','points', ...
63 'BackingStore','off', ...
64 'Color',[0.8 0.8 0.8], ...
65 'MenuBar','none', ...
66 'Resize','off', ...
67 'Name',title_figure, ...
68'Position',[pos(1) pos(2) fig_size_x fig_size_y], ...
69'NumberTitle','off'); %,'WindowButtonMotionFcn',['figure(' num2str(fig_number) ');']);
70
71h_mat = zeros(n_row,n_col);
72
73posx = zeros(n_row,n_col);
74posy = zeros(n_row,n_col);
75
76for i=n_row:-1:1,
77 for j = n_col:-1:1,
78 posx(i,j) = gap_x+(j-1)*(x_size+gap_x);
79 posy(i,j) = fig_size_y - i*(gap_x+y_size);
80 end;
81end;
82
83for i=n_row:-1:1,
84 for j = n_col:-1:1,
85 if ~isempty(string_list{i,j}) & ~isempty(callback_list{i,j}),
86 h_mat(i,j) = uicontrol('Parent',fig_number, ...
87 'Units','points', ...
88 'Callback',callback_list{i,j}, ...
89 'ListboxTop',0, ...
90 'Position',[posx(i,j) posy(i,j) x_size y_size], ...
91 'String',string_list{i,j}, ...
92 'fontsize',font_size,...
93 'fontname',font_name,...
94 'Tag','Pushbutton1');
95 end;
96 end;
97end;
98
99%------ END PROTECTED REGION ----------------%
100
101if 0,
102%-- VERSION:
103
104uicontrol('Parent',fig_number, ...
105 'Units','points', ...
106 'ListboxTop',0, ...
107 'Position',[(fig_size_x-x_size/2)-2 -5 x_size/2 y_size], ...
108 'String','ver. 1.0', ...
109 'fontsize',8,...
110 'BackgroundColor',[0.8 0.8 0.8], ...
111 'fontname','clean',...
112 'HorizontalAlignment','right', ...
113 'Style','text');
114end;
115
116
117%clear callback_list string_list fig_number fig_size_x fig_size_y i j n_col n_row pos string_list title_figure x_size y_size font_name font_size gap_x h_mat posx posy
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_active_images.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_active_images.m
new file mode 100755
index 0000000..fc365a5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_active_images.m
@@ -0,0 +1,19 @@
1
2if ~exist('active_images'),
3 active_images = ones(1,n_ima);
4end;
5n_act = length(active_images);
6if n_act < n_ima,
7 active_images = [active_images ones(1,n_ima-n_act)];
8else
9 if n_act > n_ima,
10 active_images = active_images(1:n_ima);
11 end;
12end;
13
14ind_active = find(active_images);
15
16if prod(active_images == 0),
17 disp('Error: There is no active image');
18 break
19end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_convergence.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_convergence.m
new file mode 100755
index 0000000..c4b13fd
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_convergence.m
@@ -0,0 +1,48 @@
1%%% Replay the set of solution vectors:
2
3
4if ~exist('param_list'),
5 if ~exist('solution');
6 fprintf(1,'Error: Need to calibrate first\n');
7 return;
8 else
9 param_list = solution;
10 end;
11end;
12
13N_iter = size(param_list,2);
14
15if N_iter == 1,
16 fprintf(1,'Warning: There is a unique state in the list of parameters.\n');
17end;
18
19
20
21%M = moviein(N_iter);
22
23for nn = 1:N_iter,
24
25 solution = param_list(:,nn);
26
27 extract_parameters;
28 comp_error_calib;
29
30 ext_calib;
31
32 drawnow;
33
34% Mnn = getframe(gcf);
35
36% M(:,nn) = Mnn;
37
38end;
39
40%fig = gcf;
41
42
43%figure(fig+1);
44%close;
45%figure(fig+1);
46
47%clf;
48%movie(M,20);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_directory.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_directory.m
new file mode 100755
index 0000000..dc23149
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_directory.m
@@ -0,0 +1,97 @@
1% This small script looks in the direcory and checks if the images are there.
2%
3% This works only on Matlab 5.x (otherwise, the dir commands works differently)
4
5% (c) Jean-Yves Bouguet - Dec. 27th, 1999
6
7l = dir([calib_name '*']);
8
9Nl = size(l,1);
10Nima_valid = 0;
11ind_valid = [];
12loc_extension = [];
13length_name = size(calib_name,2);
14
15if Nl > 0,
16
17 for pp = 1:Nl,
18 filenamepp = l(pp).name;
19 iii = findstr(filenamepp,calib_name);
20
21 loc_ext = findstr(filenamepp,format_image);
22 string_num = filenamepp(length_name+1:loc_ext - 2);
23
24 if isempty(str2num(string_num)),
25 iii = [];
26 end;
27
28
29 if ~isempty(iii),
30 if (iii(1) ~= 1),
31 iii = [];
32 end;
33 end;
34
35
36
37 if ~isempty(iii) & ~isempty(loc_ext),
38
39 Nima_valid = Nima_valid + 1;
40 ind_valid = [ind_valid pp];
41 loc_extension = [loc_extension loc_ext(1)];
42
43 end;
44
45 end;
46
47 if (Nima_valid==0),
48
49 fprintf(1,'No image found. File format may be wrong.\n');
50
51 else
52
53 % Get all the string numbers:
54
55 string_length = zeros(1,Nima_valid);
56 indices = zeros(1,Nima_valid);
57
58
59 for ppp = 1:Nima_valid,
60
61 name = l(ind_valid(ppp)).name;
62 string_num = name(length_name+1:loc_extension(ppp) - 2);
63 string_length(ppp) = size(string_num,2);
64 indices(ppp) = str2num(string_num);
65
66 end;
67
68 % Number of images...
69 first_num = min(indices);
70 n_ima = max(indices) - first_num + 1;
71
72 if min(string_length) == max(string_length),
73
74 N_slots = min(string_length);
75 type_numbering = 1;
76
77 else
78
79 N_slots = 1;
80 type_numbering = 0;
81
82 end;
83
84 image_numbers = first_num:n_ima-1+first_num;
85
86 %%% By default, all the images are active for calibration:
87
88 active_images = ones(1,n_ima);
89
90 end;
91
92else
93
94 fprintf(1,'No image found. Basename may be wrong.\n');
95
96end;
97
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_extracted_images.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_extracted_images.m
new file mode 100755
index 0000000..fa7df87
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/check_extracted_images.m
@@ -0,0 +1,37 @@
1check_active_images;
2
3for kk = ind_active,
4
5 if ~exist(['x_' num2str(kk)]),
6
7 fprintf(1,'WARNING: Need to extract grid corners on image %d\n',kk);
8
9 active_images(kk) = 0;
10
11 eval(['dX_' num2str(kk) ' = NaN;']);
12 eval(['dY_' num2str(kk) ' = NaN;']);
13
14 eval(['wintx_' num2str(kk) ' = NaN;']);
15 eval(['winty_' num2str(kk) ' = NaN;']);
16
17 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
18 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
19
20 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
21 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
22
23 else
24
25 eval(['xkk = x_' num2str(kk) ';']);
26
27 if isnan(xkk(1)),
28
29 fprintf(1,'WARNING: Need to extract grid corners on image %d - This image is now set inactive\n',kk);
30
31 active_images(kk) = 0;
32
33 end;
34
35 end;
36
37end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clear_windows.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clear_windows.m
new file mode 100755
index 0000000..1eccbd3
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clear_windows.m
@@ -0,0 +1,4 @@
1for kk = 1:n_ima,
2 eval(['clear wintx_' num2str(kk)]);
3 eval(['clear winty_' num2str(kk)]);
4end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clearwin.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clearwin.m
new file mode 100755
index 0000000..a04be67
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/clearwin.m
@@ -0,0 +1,10 @@
1% Function that clears all the wintx_i and winty_i
2% In normal operation of the toolbox, this function should not be
3% useful.
4% only in cases where you want to re-extract corners using the Extract grid corners another time... not common. You might as well use the Recomp. corners.
5
6for kk = 1:n_ima,
7
8 eval(['clear wintx_' num2str(kk) ' winty_' num2str(kk)]);
9
10end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_calib.m
new file mode 100755
index 0000000..1a6d2d7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_calib.m
@@ -0,0 +1,193 @@
1%if exist('images_read');
2% active_images = active_images & images_read;
3%end;
4
5var2fix = 'dX_default';
6
7fixvariable;
8
9var2fix = 'dY_default';
10
11fixvariable;
12
13var2fix = 'map';
14
15fixvariable;
16
17
18if ~exist('n_ima'),
19 data_calib;
20end;
21
22check_active_images;
23
24if ~exist(['I_' num2str(ind_active(1))]),
25 ima_read_calib;
26 if isempty(ind_read),
27 disp('Cannot extract corners without images');
28 return;
29 end;
30end;
31
32
33%wintx = 10; % neigborhood of integration for
34%winty = 10; % the corner finder
35
36fprintf(1,'\nExtraction of the grid corners on the images\n');
37
38
39if ~exist('map'), map = gray(256); end;
40
41
42disp('WARNING!!! Do not forget to change dX_default and dY_default in click_calib.m!!!')
43
44if ~exist('dX_default');
45
46% Default size of the pattern squares;
47
48% Setup of JY (old at Caltech)
49%dX_default = 21.9250/11;
50%dY_default = 18.1250/9;
51
52% Setup of JY (new at Intel)
53%dX_default = 1.9750;
54%dY_default = 1.9865;
55
56
57% Setup of Luis and Enrico
58%dX_default = 67.7/16;
59%dY_default = 50.65/12;
60
61
62% Setup of German
63%dX_default = 10.16;
64%dY_default = 10.16;
65
66% Setup of JY (new at Intel)
67%dX_default = 1.9750*2.54;
68%dY_default = 1.9865*2.54;
69
70% Setup of JY - 3D calibration rig at Intel (new at Intel)
71%dX_default = 3;
72%dY_default = 3;
73
74% Setup of JY - 3D calibration rig at Intel (new at Intel) - use units in mm to match Zhang
75dX_default = 30;
76dY_default = 30;
77
78end;
79
80
81if ~exist('dont_ask'),
82 dont_ask = 0;
83end;
84
85
86if ~dont_ask,
87 ima_numbers = input('Number(s) of image(s) to process ([] = all images) = ');
88else
89 ima_numbers = [];
90end;
91
92if isempty(ima_numbers),
93 ima_proc = 1:n_ima;
94else
95 ima_proc = ima_numbers;
96end;
97
98
99% Useful option to add images:
100kk_first = ima_proc(1); %input('Start image number ([]=1=first): ');
101
102%if isempty(kk_first), kk_first = 1; end;
103
104
105if exist(['wintx_' num2str(kk_first)]),
106
107 eval(['wintxkk = wintx_' num2str(kk_first) ';']);
108
109 if isempty(wintxkk) | isnan(wintxkk),
110
111 disp('Window size for corner finder (wintx and winty):');
112 wintx = input('wintx ([] = 5) = ');
113 if isempty(wintx), wintx = 5; end;
114 wintx = round(wintx);
115 winty = input('winty ([] = 5) = ');
116 if isempty(winty), winty = 5; end;
117 winty = round(winty);
118
119 fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
120
121 end;
122
123else
124
125 disp('Window size for corner finder (wintx and winty):');
126 wintx = input('wintx ([] = 5) = ');
127 if isempty(wintx), wintx = 5; end;
128 wintx = round(wintx);
129 winty = input('winty ([] = 5) = ');
130 if isempty(winty), winty = 5; end;
131 winty = round(winty);
132
133 fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
134
135end;
136
137
138for kk = ima_proc,
139 if exist(['I_' num2str(kk)]),
140 click_ima_calib;
141 active_images(kk) = 1;
142 else
143 eval(['dX_' num2str(kk) ' = NaN;']);
144 eval(['dY_' num2str(kk) ' = NaN;']);
145
146 eval(['wintx_' num2str(kk) ' = NaN;']);
147 eval(['winty_' num2str(kk) ' = NaN;']);
148
149 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
150 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
151
152 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
153 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
154 end;
155end;
156
157
158check_active_images;
159
160
161% Fix potential non-existing variables:
162
163for kk = 1:n_ima,
164 if ~exist(['x_' num2str(kk)]),
165 eval(['dX_' num2str(kk) ' = NaN;']);
166 eval(['dY_' num2str(kk) ' = NaN;']);
167
168 eval(['wintx_' num2str(kk) ' = NaN;']);
169 eval(['winty_' num2str(kk) ' = NaN;']);
170
171 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
172 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
173
174 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
175 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
176 end;
177end;
178
179
180string_save = 'save calib_data active_images ind_active wintx winty n_ima type_numbering N_slots first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default dX dY';
181
182for kk = 1:n_ima,
183 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
184end;
185
186eval(string_save);
187
188disp('done');
189
190return;
191
192go_calib_optim;
193
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib.m
new file mode 100755
index 0000000..f0fd4ca
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib.m
@@ -0,0 +1,230 @@
1 % Cleaned-up version of init_calib.m
2
3 fprintf(1,'\nProcessing image %d...\n',kk);
4
5 eval(['I = I_' num2str(kk) ';']);
6
7 if exist(['wintx_' num2str(kk)]),
8
9 eval(['wintxkk = wintx_' num2str(kk) ';']);
10
11 if ~isempty(wintxkk) & ~isnan(wintxkk),
12
13 eval(['wintx = wintx_' num2str(kk) ';']);
14 eval(['winty = winty_' num2str(kk) ';']);
15
16 end;
17 end;
18
19
20 fprintf(1,'Using (wintx,winty)=(%d,%d) - Window size = %dx%d\n',wintx,winty,2*wintx+1,2*winty+1);
21
22
23 figure(2);
24 image(I);
25 colormap(map);
26
27 title(['Click on the four extreme corners of the rectangular pattern... Image ' num2str(kk)]);
28
29 disp('Click on the four extreme corners of the rectangular complete pattern...');
30
31 [x,y] = ginput3(4);
32
33 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
34
35 x = Xc(1,:)';
36 y = Xc(2,:)';
37
38 [y,indy] = sort(y);
39 x = x(indy);
40
41 if (x(2) > x(1)),
42 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
43 else
44 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
45 end;
46 if (x(3) > x(4)),
47 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
48 else
49 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
50 end;
51
52 x = [x1;x2;x3;x4];
53 y = [y1;y2;y3;y4];
54
55
56 figure(2); hold on;
57 plot([x;x(1)],[y;y(1)],'g-');
58 plot(x,y,'og');
59 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
60 set(hx,'color','g','Fontsize',14);
61 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
62 set(hy,'color','g','Fontsize',14);
63 hold off;
64
65
66 % Try to automatically count the number of squares in the grid
67
68 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
69 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
70 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
71 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
72
73
74
75 % If could not count the number of squares, enter manually
76
77 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
78
79
80 disp('Could not count the number of squares in the grid. Enter manually.');
81 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
82 if isempty(n_sq_x), n_sq_x = 10; end;
83 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
84 if isempty(n_sq_y), n_sq_y = 10; end;
85
86 else
87
88 n_sq_x = n_sq_x1;
89 n_sq_y = n_sq_y1;
90
91 end;
92
93
94 % Enter the size of each square
95
96 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'mm) = ']);
97 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'mm) = ']);
98 if isempty(dX), dX = dX_default; else dX_default = dX; end;
99 if isempty(dY), dY = dY_default; else dY_default = dY; end;
100
101 % Compute the inside points through computation of the planar homography (collineation)
102
103 a00 = [x(1);y(1);1];
104 a10 = [x(2);y(2);1];
105 a11 = [x(3);y(3);1];
106 a01 = [x(4);y(4);1];
107
108
109 % Compute the planar collineation: (return the normalization matrix as well)
110
111 [Homo,Hnorm,inv_Hnorm] = compute_homography ([a00 a10 a11 a01],[0 1 1 0;0 0 1 1;1 1 1 1]);
112
113
114 % Build the grid using the planar collineation:
115
116 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
117 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
118 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
119
120 XX = Homo*pts;
121 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
122
123
124 % Complete size of the rectangle
125
126 W = n_sq_x*dX;
127 L = n_sq_y*dY;
128
129
130
131
132 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
133 figure(2);
134 hold on;
135 plot(XX(1,:),XX(2,:),'r+');
136 title('The red crosses should be close to the image corners');
137 hold off;
138
139 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
140 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
141 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
142
143 quest_distort = ~isempty(quest_distort);
144
145 if quest_distort,
146 % Estimation of focal length:
147 c_g = [size(I,2);size(I,1)]/2 + .5;
148 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
149 f_g = mean(f_g);
150 script_fit_distortion;
151 end;
152 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
153
154
155
156
157
158 Np = (n_sq_x+1)*(n_sq_y+1);
159
160 disp('Corner extraction...');
161
162 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
163
164
165
166 %save all_corners x y grid_pts
167
168 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
169
170
171
172 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
173 ind_orig = (n_sq_x+1)*n_sq_y + 1;
174 xorig = grid_pts(1,ind_orig);
175 yorig = grid_pts(2,ind_orig);
176 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
177 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
178
179
180 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
181 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
182
183
184 figure(3);
185 image(I); colormap(map); hold on;
186 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
187 plot(x_box_kk+1,y_box_kk+1,'-b');
188 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
189 plot(xorig+1,yorig+1,'*m');
190 h = text(xorig-15,yorig-15,'O');
191 set(h,'Color','m','FontSize',14);
192 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
193 set(h2,'Color','g','FontSize',14);
194 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
195 set(h3,'Color','g','FontSize',14);
196 xlabel('Xc (in camera frame)');
197 ylabel('Yc (in camera frame)');
198 title('Extracted corners');
199 zoom on;
200 drawnow;
201 hold off;
202
203
204 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
205 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
206 Zi = zeros(1,Np);
207
208 Xgrid = [Xi;Yi;Zi];
209
210
211 % All the point coordinates (on the image, and in 3D) - for global optimization:
212
213 x = grid_pts;
214 X = Xgrid;
215
216
217 % Saves all the data into variables:
218
219 eval(['dX_' num2str(kk) ' = dX;']);
220 eval(['dY_' num2str(kk) ' = dY;']);
221
222 eval(['wintx_' num2str(kk) ' = wintx;']);
223 eval(['winty_' num2str(kk) ' = winty;']);
224
225 eval(['x_' num2str(kk) ' = x;']);
226 eval(['X_' num2str(kk) ' = X;']);
227
228 eval(['n_sq_x_' num2str(kk) ' = n_sq_x;']);
229 eval(['n_sq_y_' num2str(kk) ' = n_sq_y;']);
230 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib3D.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib3D.m
new file mode 100755
index 0000000..7718268
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/click_ima_calib3D.m
@@ -0,0 +1,482 @@
1 % Cleaned-up version of init_calib.m
2
3 eval(['I = I_' num2str(kk) ';']);
4
5 figure(2);
6 image(I);
7 colormap(map);
8
9
10
11
12
13 %%%%%%%%%%%%%%%%%%%%%%%%% LEFT PATTERN ACQUISITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15
16
17 title(['Click on the four extreme corners of the left rectangular pattern... Image ' num2str(kk)]);
18
19 disp('Click on the four extreme corners of the left rectangular pattern...');
20
21 [x,y] = ginput3(4);
22
23 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
24
25 x = Xc(1,:)';
26 y = Xc(2,:)';
27
28 [y,indy] = sort(y);
29 x = x(indy);
30
31 if (x(2) > x(1)),
32 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
33 else
34 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
35 end;
36 if (x(3) > x(4)),
37 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
38 else
39 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
40 end;
41
42 x = [x1;x2;x3;x4];
43 y = [y1;y2;y3;y4];
44
45
46 figure(2); hold on;
47 plot([x;x(1)],[y;y(1)],'g-');
48 plot(x,y,'og');
49 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
50 set(hx,'color','g','Fontsize',14);
51 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
52 set(hy,'color','g','Fontsize',14);
53 hold off;
54
55 drawnow;
56
57
58 % Try to automatically count the number of squares in the grid
59
60 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
61 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
62 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
63 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
64
65
66
67 % If could not count the number of squares, enter manually
68
69 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
70
71
72 disp('Could not count the number of squares in the grid. Enter manually.');
73 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
74 if isempty(n_sq_x), n_sq_x = 10; end;
75 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
76 if isempty(n_sq_y), n_sq_y = 10; end;
77
78 else
79
80 n_sq_x = n_sq_x1;
81 n_sq_y = n_sq_y1;
82
83 end;
84
85
86 if 1,
87 % Enter the size of each square
88
89 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'cm) = ']);
90 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'cm) = ']);
91 if isempty(dX), dX = dX_default; else dX_default = dX; end;
92 if isempty(dY), dY = dY_default; else dY_default = dY; end;
93
94 else
95
96 dX = 3;
97 dY = 3;
98
99 end;
100
101
102 % Compute the inside points through computation of the planar homography (collineation)
103
104 a00 = [x(1);y(1);1];
105 a10 = [x(2);y(2);1];
106 a11 = [x(3);y(3);1];
107 a01 = [x(4);y(4);1];
108
109
110 % Compute the planart collineation: (return the normalization matrice as well)
111
112 [Homo,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
113
114
115 % Build the grid using the planar collineation:
116
117 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
118 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
119 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
120
121 XX = Homo*pts;
122 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
123
124
125 % Complete size of the rectangle
126
127 W = n_sq_x*dX;
128 L = n_sq_y*dY;
129
130
131
132 if 1,
133 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
134 figure(2);
135 hold on;
136 plot(XX(1,:),XX(2,:),'r+');
137 title('The red crosses should be close to the image corners');
138 hold off;
139
140 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
141 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
142 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
143
144 quest_distort = ~isempty(quest_distort);
145
146 if quest_distort,
147 % Estimation of focal length:
148 c_g = [size(I,2);size(I,1)]/2 + .5;
149 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
150 f_g = mean(f_g);
151 script_fit_distortion;
152 end;
153 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
154 end;
155
156
157 Np = (n_sq_x+1)*(n_sq_y+1);
158
159 disp('Corner extraction...');
160
161 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
162
163 %save all_corners x y grid_pts
164
165 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
166
167
168 % Global Homography from plane to pixel coordinates:
169
170 H_total = [1 0 -1 ; 0 1 -1 ; 0 0 1]*Homo*[1 0 0;0 -1 1;0 0 1]*[1/W 0 0 ; 0 1/L 0; 0 0 1];
171 % WARNING!!! the first matrix (on the left side) takes care of the transformation of the pixel cooredinates by -1 (previous line)
172 % If it is not done, then this matrix should not appear (in C)
173 H_total = H_total / H_total(3,3);
174
175
176 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
177 ind_orig = (n_sq_x+1)*n_sq_y + 1;
178 xorig = grid_pts(1,ind_orig);
179 yorig = grid_pts(2,ind_orig);
180 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
181 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
182
183
184 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
185 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
186
187
188 figure(3);
189 image(I); colormap(map); hold on;
190 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
191 plot(x_box_kk+1,y_box_kk+1,'-b');
192 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
193 plot(xorig+1,yorig+1,'*m');
194 h = text(xorig-15,yorig-15,'O');
195 set(h,'Color','m','FontSize',14);
196 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
197 set(h2,'Color','g','FontSize',14);
198 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
199 set(h3,'Color','g','FontSize',14);
200 xlabel('Xc (in camera frame)');
201 ylabel('Yc (in camera frame)');
202 title('Extracted corners');
203 zoom on;
204 drawnow;
205 hold off;
206
207
208 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
209 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
210 Zi = zeros(1,Np);
211
212 Xgrid = [Xi;Yi;Zi];
213
214
215 % All the point coordinates (on the image, and in 3D) - for global optimization:
216
217 x = grid_pts;
218 X = Xgrid;
219
220
221 % The left pannel info:
222
223 xl = x;
224 Xl = X;
225 nl_sq_x = n_sq_x;
226 nl_sq_y = n_sq_y;
227 Hl = H_total;
228
229
230
231
232
233
234 %%%%%%%%%%%%%%%%%%%%%%%%% RIGHT PATTERN ACQUISITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
236
237 x1 = a10(1)/a10(3);
238 x4 = a11(1)/a11(3);
239
240 y1 = a10(2)/a10(3);
241 y4 = a11(2)/a11(3);
242
243
244 figure(2);
245 hold on;
246 plot([x1 x4],[y1 y4],'c-');
247 plot([x1 x4],[y1 y4],'co');
248 hold off;
249
250 title(['Click on the two remaining extreme corners of the right rectangular pattern... Image ' num2str(kk)]);
251
252 disp('Click on the two remaining extreme corners of the right rectangular pattern...');
253
254 [x,y] = ginput3(2);
255
256 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
257
258 x = Xc(1,:)';
259 y = Xc(2,:)';
260
261 [y,indy] = sort(y);
262 x = x(indy);
263
264 x2 = x(2);
265 x3 = x(1);
266
267 y2 = y(2);
268 y3 = y(1);
269
270
271 x = [x1;x2;x3;x4];
272 y = [y1;y2;y3;y4];
273
274 figure(2); hold on;
275 plot([x;x(1)],[y;y(1)],'c-');
276 plot(x,y,'oc');
277 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
278 set(hx,'color','c','Fontsize',14);
279 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
280 set(hy,'color','c','Fontsize',14);
281 hold off;
282 drawnow;
283
284
285 % Try to automatically count the number of squares in the grid
286
287 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
288 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
289 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
290 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
291
292
293
294 % If could not count the number of squares, enter manually
295
296 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
297
298
299 disp('Could not count the number of squares in the grid. Enter manually.');
300 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
301 if isempty(n_sq_x), n_sq_x = 10; end;
302 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
303 if isempty(n_sq_y), n_sq_y = 10; end;
304
305 else
306
307 n_sq_x = n_sq_x1;
308 n_sq_y = n_sq_y1;
309
310 end;
311
312
313 if 1,
314 % Enter the size of each square
315
316 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'cm) = ']);
317 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'cm) = ']);
318 if isempty(dX), dX = dX_default; else dX_default = dX; end;
319 if isempty(dY), dY = dY_default; else dY_default = dY; end;
320
321 else
322
323 dX = 3;
324 dY = 3;
325
326 end;
327
328
329 % Compute the inside points through computation of the planar homography (collineation)
330
331 a00 = [x(1);y(1);1];
332 a10 = [x(2);y(2);1];
333 a11 = [x(3);y(3);1];
334 a01 = [x(4);y(4);1];
335
336
337 % Compute the planart collineation: (return the normalization matrice as well)
338
339 [Homo,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
340
341
342 % Build the grid using the planar collineation:
343
344 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
345 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
346 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
347
348 XX = Homo*pts;
349 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
350
351
352 % Complete size of the rectangle
353
354 W = n_sq_x*dX;
355 L = n_sq_y*dY;
356
357
358
359 if 1,
360 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
361 figure(2);
362 hold on;
363 plot(XX(1,:),XX(2,:),'r+');
364 title('The red crosses should be close to the image corners');
365 hold off;
366
367 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
368 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
369 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
370
371 quest_distort = ~isempty(quest_distort);
372
373 if quest_distort,
374 % Estimation of focal length:
375 c_g = [size(I,2);size(I,1)]/2 + .5;
376 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
377 f_g = mean(f_g);
378 script_fit_distortion;
379 end;
380 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
381 end;
382
383
384 Np = (n_sq_x+1)*(n_sq_y+1);
385
386 disp('Corner extraction...');
387
388 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
389
390 %save all_corners x y grid_pts
391
392 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
393
394
395 % Global Homography from plane to pixel coordinates:
396
397 H_total = [1 0 -1 ; 0 1 -1 ; 0 0 1]*Homo*[1 0 0;0 -1 1;0 0 1]*[1/W 0 0 ; 0 1/L 0; 0 0 1];
398 % WARNING!!! the first matrix (on the left side) takes care of the transformation of the pixel cooredinates by -1 (previous line)
399 % If it is not done, then this matrix should not appear (in C)
400 H_total = H_total / H_total(3,3);
401
402
403 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
404 ind_orig = (n_sq_x+1)*n_sq_y + 1;
405 xorig = grid_pts(1,ind_orig);
406 yorig = grid_pts(2,ind_orig);
407 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
408 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
409
410
411 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
412 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
413
414
415 figure(3);
416 hold on;
417 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
418 plot(x_box_kk+1,y_box_kk+1,'-b');
419 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
420 plot(xorig+1,yorig+1,'*m');
421 h = text(xorig-15,yorig-15,'O');
422 set(h,'Color','m','FontSize',14);
423 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
424 set(h2,'Color','g','FontSize',14);
425 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
426 set(h3,'Color','g','FontSize',14);
427 xlabel('Xc (in camera frame)');
428 ylabel('Yc (in camera frame)');
429 title('Extracted corners');
430 zoom on;
431 drawnow;
432 hold off;
433
434
435 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
436 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
437 Zi = zeros(1,Np);
438
439 Xgrid = [Xi;Yi;Zi];
440
441
442 % All the point coordinates (on the image, and in 3D) - for global optimization:
443
444 x = grid_pts;
445 X = Xgrid;
446
447
448 % The right pannel info:
449
450 xr = x;
451 Xr = X;
452 nr_sq_x = n_sq_x;
453 nr_sq_y = n_sq_y;
454 Hr = H_total;
455
456
457
458%%%%%%%% REGROUP THE LEFT AND RIHT PATTERNS %%%%%%%%%%%%%
459
460
461Xr2 = [0 0 1;0 1 0;-1 0 0]*Xr + [dX*nl_sq_x;0;0]*ones(1,length(Xr));
462
463
464x = [xl xr];
465
466X = [Xl Xr2];
467
468
469
470 eval(['x_' num2str(kk) ' = x;']);
471 eval(['X_' num2str(kk) ' = X;']);
472
473 eval(['nl_sq_x_' num2str(kk) ' = nl_sq_x;']);
474 eval(['nl_sq_y_' num2str(kk) ' = nl_sq_y;']);
475
476 eval(['nr_sq_x_' num2str(kk) ' = nr_sq_x;']);
477 eval(['nr_sq_y_' num2str(kk) ' = nr_sq_y;']);
478
479 % Save the global planar homography:
480
481 eval(['Hl_' num2str(kk) ' = Hl;']);
482 eval(['Hr_' num2str(kk) ' = Hr;']); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion.m
new file mode 100755
index 0000000..a0f03de
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion.m
@@ -0,0 +1,38 @@
1function [x_comp] = comp_distortion(x_dist,k2);
2
3% [x_comp] = comp_distortion(x_dist,k2);
4%
5% compensates the radial distortion of the camera
6% on the image plane.
7%
8% x_dist : the image points got without considering the
9% radial distortion.
10% x : The image plane points after correction for the distortion
11%
12% x and x_dist are 2xN arrays
13%
14% NOTE : This compensation has to be done after the substraction
15% of the center of projection, and division by the focal
16% length.
17%
18% (do it up to a second order approximation)
19
20[two,N] = size(x_dist);
21
22if (two ~= 2 ),
23 error('ERROR : The dimension of the points should be 2xN');
24end;
25
26if length(k2) > 2,
27 [x_comp] = comp_distortion_oulu(x_dist,k2);
28else
29
30radius_2= x_dist(1,:).^2 + x_dist(2,:).^2;
31radial_distortion = 1 + ones(2,1)*(k2 * radius_2);
32radius_2_comp = (x_dist(1,:).^2 + x_dist(2,:).^2) ./ radial_distortion(1,:);
33radial_distortion = 1 + ones(2,1)*(k2 * radius_2_comp);
34x_comp = x_dist ./ radial_distortion;
35
36end;
37
38%% Function completely checked : It works fine !!! \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion2.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion2.m
new file mode 100755
index 0000000..532ee9a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion2.m
@@ -0,0 +1,71 @@
1function [x_comp] = comp_distortion(x_dist,k2);
2
3% [x_comp] = comp_distortion(x_dist,k2);
4%
5% compensates the radial distortion of the camera
6% on the image plane.
7%
8% x_dist : the image points got without considering the
9% radial distortion.
10% k2: Radial distortion factor
11%
12% x : The image plane points after correction for the distortion
13%
14% x and x_dist are 2xN arrays
15%
16% NOTE : This compensation has to be done after the substraction
17% of the center of projection, and division by the focal
18% length.
19%
20% Solve for cubic roots using method from Numerical Recipes in C 2nd Ed.
21% pages 184-185.
22
23
24% California Institute of Technology
25% (c) Jean-Yves Bouguet - April 27th, 1998
26
27% fully checked! JYB, april 27th, 1998 - 2am
28
29if k2 ~= 0,
30
31[two,N] = size(x_dist);
32
33if (two ~= 2 ),
34 error('ERROR : The dimension of the points should be 2xN');
35end;
36
37
38ph = atan2(x_dist(2,:),x_dist(1,:));
39
40Q = -1/(3*k2);
41R = -x_dist(1,:)./(2*k2*cos(ph));
42
43R2 = R.^2;
44Q3 = Q^3;
45
46
47if k2 < 0,
48
49 % this works in all practical situations (it starts failing for very large
50 % values of k2)
51
52 th = acos(R./sqrt(Q3));
53 r = -2*sqrt(Q)*cos((th-2*pi)/3);
54
55else
56
57 % note: this always works, even for ridiculous values of k2
58
59 A = (sqrt(R2-Q3)-R).^(1/3);
60 B = Q*(1./A);
61 r = (A+B);
62
63end;
64
65x_comp = [r.*cos(ph); r.*sin(ph)];
66
67else
68
69 x_comp = x_dist;
70
71end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion_oulu.m
new file mode 100755
index 0000000..67d02d5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_distortion_oulu.m
@@ -0,0 +1,47 @@
1function [x] = comp_distortion_oulu(xd,k);
2
3%comp_distortion_oulu.m
4%
5%[x] = comp_distortion_oulu(xd,k)
6%
7%Compensates for radial and tangential distortion. Model From Oulu university.
8%For more informatino about the distortion model, check the forward projection mapping function:
9%project_points.m
10%
11%INPUT: xd: distorted (normalized) point coordinates in the image plane (2xN matrix)
12% k: Distortion coefficients (radial and tangential) (4x1 vector)
13%
14%OUTPUT: x: undistorted (normalized) point coordinates in the image plane (2xN matrix)
15%
16%Method: Iterative method for compensation.
17%
18%NOTE: This compensation has to be done after the subtraction
19% of the principal point, and division by the focal length.
20
21
22if length(k) < 4,
23
24 [x] = comp_distortion(xd,k);
25
26else
27
28
29 k1 = k(1);
30 k2 = k(2);
31 p1 = k(3);
32 p2 = k(4);
33
34 x = xd; % initial guess
35
36 for kk=1:5;
37
38 r_2 = sum(x.^2);
39 k_radial = 1 + k1 * r_2 + k2 * r_2.^2;
40 delta_x = [2*p1*x(1,:).*x(2,:) + p2*(r_2 + 2*x(1,:).^2) ;
41 p1 * (r_2 + 2*x(2,:).^2)+2*p2*x(1,:).*x(2,:)];
42 x = (xd - delta_x)./(ones(2,1)*k_radial);
43
44 end;
45
46end;
47
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_error_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_error_calib.m
new file mode 100755
index 0000000..c7bf662
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/comp_error_calib.m
@@ -0,0 +1,46 @@
1%%%%%%%%%%%%%%%%%%%% RECOMPUTES THE REPROJECTION ERROR %%%%%%%%%%%%%%%%%%%%%%%%
2
3check_active_images;
4
5% Reproject the patterns on the images, and compute the pixel errors:
6
7ex = []; % Global error vector
8x = []; % Detected corners on the image plane
9y = []; % Reprojected points
10
11if ~exist('alpha_c'),
12 alpha_c = 0;
13end;
14
15for kk = 1:n_ima,
16
17 eval(['omckk = omc_' num2str(kk) ';']);
18 eval(['Tckk = Tc_' num2str(kk) ';']);
19
20 if active_images(kk) & (~isnan(omckk(1,1))),
21
22 %Rkk = rodrigues(omckk);
23
24 eval(['y_' num2str(kk) ' = project_points2(X_' num2str(kk) ',omckk,Tckk,fc,cc,kc,alpha_c);']);
25
26 eval(['ex_' num2str(kk) ' = x_' num2str(kk) ' -y_' num2str(kk) ';']);
27
28 eval(['x_kk = x_' num2str(kk) ';']);
29
30 eval(['ex = [ex ex_' num2str(kk) '];']);
31 eval(['x = [x x_' num2str(kk) '];']);
32 eval(['y = [y y_' num2str(kk) '];']);
33
34 else
35
36 % eval(['y_' num2str(kk) ' = NaN*ones(2,1);']);
37
38
39 % If inactivated image, the error does not make sense:
40 eval(['ex_' num2str(kk) ' = NaN*ones(2,1);']);
41
42 end;
43
44end;
45
46err_std = std(ex')';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_collineation.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_collineation.m
new file mode 100755
index 0000000..809c309
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_collineation.m
@@ -0,0 +1,66 @@
1function [H,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
2
3% new formalism using homographies
4
5a00 = a00 / a00(3);
6a10 = a10 / a10(3);
7a11 = a11 / a11(3);
8a01 = a01 / a01(3);
9
10
11% Prenormalization of point coordinates (very important):
12% (Affine normalization)
13
14ax = [a00(1);a10(1);a11(1);a01(1)];
15ay = [a00(2);a10(2);a11(2);a01(2)];
16
17mxx = mean(ax);
18myy = mean(ay);
19ax = ax - mxx;
20ay = ay - myy;
21
22scxx = mean(abs(ax));
23scyy = mean(abs(ay));
24
25
26Hnorm = [1/scxx 0 -mxx/scxx;0 1/scyy -myy/scyy;0 0 1];
27inv_Hnorm = [scxx 0 mxx ; 0 scyy myy; 0 0 1];
28
29
30a00n = Hnorm*a00;
31a10n = Hnorm*a10;
32a11n = Hnorm*a11;
33a01n = Hnorm*a01;
34
35
36% Computation of the vanishing points:
37
38V1n = cross(cross(a00n,a10n),cross(a01n,a11n));
39V2n = cross(cross(a00n,a01n),cross(a10n,a11n));
40
41V1 = inv_Hnorm*V1n;
42V2 = inv_Hnorm*V2n;
43
44
45% Normalizaion of the vanishing points:
46
47V1n = V1n/norm(V1n);
48V2n = V2n/norm(V2n);
49
50
51% Closed-form solution of the coefficients:
52
53alpha_x = (a10n(2)*a00n(1) - a10n(1)*a00n(2))/(V1n(2)*a10n(1)-V1n(1)*a10n(2));
54
55alpha_y = (a01n(2)*a00n(1) - a01n(1)*a00n(2))/(V2n(2)*a01n(1)-V2n(1)*a01n(2));
56
57
58% Remaining Homography
59
60Hrem = [alpha_x*V1n alpha_y*V2n a00n];
61
62
63% Final homography:
64
65H = inv_Hnorm*Hrem;
66
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic.m
new file mode 100755
index 0000000..5217351
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic.m
@@ -0,0 +1,123 @@
1function [omckk,Tckk,Rckk,H,x,ex,JJ] = compute_extrinsic(x_kk,X_kk,fc,cc,kc,alpha_c,MaxIter,thresh_cond),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk,H,x,ex] = compute_extrinsic(x_kk,X_kk,fc,cc,kc,alpha_c)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16% alpha_c: Skew coefficient
17%
18%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
19% Tckk: 3D translation vector attached to the grid positions in space
20% Rckk: 3D rotation matrices corresponding to the omc vectors
21% H: Homography between points on the grid and points on the image plane (in pixel)
22% This makes sense only if the planar that is used in planar.
23% x: Reprojections of the points on the image plane
24% ex: Reprojection error: ex = x_kk - x;
25%
26%Method: Computes the normalized point coordinates, then computes the 3D pose
27%
28%Important functions called within that program:
29%
30%normalize: Computes the normalize image point coordinates.
31%
32%pose3D: Computes the 3D pose of the structure given the normalized image projection.
33%
34%project_points.m: Computes the 2D image projections of a set of 3D points
35
36
37
38if nargin < 8,
39 thresh_cond = inf;
40end;
41
42
43if nargin < 7,
44 MaxIter = 20;
45end;
46
47
48if nargin < 6,
49 alpha_c = 0;
50 if nargin < 5,
51 kc = zeros(4,1);
52 if nargin < 4,
53 cc = zeros(2,1);
54 if nargin < 3,
55 fc = ones(2,1);
56 if nargin < 2,
57 error('Need 2D projections and 3D points (in compute_extrinsic.m)');
58 return;
59 end;
60 end;
61 end;
62 end;
63end;
64
65% Initialization:
66
67[omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc,alpha_c);
68
69% Refinement:
70
71[omckk,Tckk,Rckk,JJ] = compute_extrinsic_refine(omckk,Tckk,x_kk,X_kk,fc,cc,kc,alpha_c,MaxIter,thresh_cond);
72
73
74% computation of the homography (not useful in the end)
75
76H = [Rckk(:,1:2) Tckk];
77
78% Computes the reprojection error in pixels:
79
80x = project_points2(X_kk,omckk,Tckk,fc,cc,kc,alpha_c);
81
82ex = x_kk - x;
83
84
85% Converts the homography in pixel units:
86
87KK = [fc(1) alpha_c*fc(1) cc(1);0 fc(2) cc(2); 0 0 1];
88
89H = KK*H;
90
91
92
93
94return;
95
96
97% Test of compte extrinsic:
98
99Np = 4;
100sx = 10;
101sy = 10;
102sz = 5;
103
104om = randn(3,1);
105T = [0;0;100];
106
107noise = 2/1000;
108
109XX = [sx*randn(1,Np);sy*randn(1,Np);sz*randn(1,Np)];
110xx = project_points(XX,om,T);
111
112xxn = xx + noise * randn(2,Np);
113
114[omckk,Tckk] = compute_extrinsic(xxn,XX);
115
116[om omckk om-omckk]
117[T Tckk T-Tckk]
118
119figure(3);
120plot(xx(1,:),xx(2,:),'r+');
121hold on;
122plot(xxn(1,:),xxn(2,:),'g+');
123hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_init.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_init.m
new file mode 100755
index 0000000..2e6d821
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_init.m
@@ -0,0 +1,151 @@
1function [omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc,alpha_c),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc,alpha_c)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16% alpha_c: Skew coefficient
17%
18%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
19% Tckk: 3D translation vector attached to the grid positions in space
20% Rckk: 3D rotation matrices corresponding to the omc vectors
21%
22%Method: Computes the normalized point coordinates, then computes the 3D pose
23%
24%Important functions called within that program:
25%
26%normalize: Computes the normalize image point coordinates.
27%
28%pose3D: Computes the 3D pose of the structure given the normalized image projection.
29%
30%project_points.m: Computes the 2D image projections of a set of 3D points
31
32
33
34if nargin < 6,
35 alpha_c = 0;
36 if nargin < 5,
37 kc = zeros(4,1);
38 if nargin < 4,
39 cc = zeros(2,1);
40 if nargin < 3,
41 fc = ones(2,1);
42 if nargin < 2,
43 error('Need 2D projections and 3D points (in compute_extrinsic.m)');
44 return;
45 end;
46 end;
47 end;
48 end;
49end;
50
51
52% Compute the normalized coordinates:
53
54xn = normalize(x_kk,fc,cc,kc,alpha_c);
55
56
57
58Np = size(xn,2);
59
60%% Check for planarity of the structure:
61
62X_mean = mean(X_kk')';
63
64Y = X_kk - (X_mean*ones(1,Np));
65
66YY = Y*Y';
67
68[U,S,V] = svd(YY);
69
70r = S(3,3)/S(2,2);
71
72if (r < 1e-3)|(Np < 6), %1e-3, %1e-4, %norm(X_kk(3,:)) < eps, % Test of planarity
73
74 %fprintf(1,'Planar structure detected: r=%f\n',r);
75
76 % Transform the plane to bring it in the Z=0 plane:
77
78 R_transform = V';
79
80 if det(R_transform) < 0, R_transform = -R_transform; end;
81
82 T_transform = -(R_transform)*X_mean;
83
84 X_new = R_transform*X_kk + T_transform*ones(1,Np);
85
86
87 % Compute the planar homography:
88
89 H = compute_homography (xn,X_new(1:2,:));
90
91 % De-embed the motion parameters from the homography:
92
93 sc = mean([norm(H(:,1));norm(H(:,2))]);
94
95 H = H/sc;
96
97 omckk = rodrigues([H(:,1:2) cross(H(:,1),H(:,2))]);
98 Rckk = rodrigues(omckk);
99 Tckk = H(:,3);
100
101 %If Xc = Rckk * X_new + Tckk, then Xc = Rckk * R_transform * X_kk + Tckk + T_transform
102
103 Tckk = Tckk + Rckk* T_transform;
104 Rckk = Rckk * R_transform;
105
106 omckk = rodrigues(Rckk);
107 Rckk = rodrigues(omckk);
108
109
110else
111
112 %fprintf(1,'Non planar structure detected: r=%f\n',r);
113
114 % Computes an initial guess for extrinsic parameters (works for general 3d structure, not planar!!!):
115 % The DLT method is applied here!!
116
117 J = zeros(2*Np,12);
118
119 xX = (ones(3,1)*xn(1,:)).*X_kk;
120 yX = (ones(3,1)*xn(2,:)).*X_kk;
121
122 J(1:2:end,[1 4 7]) = -X_kk';
123 J(2:2:end,[2 5 8]) = X_kk';
124 J(1:2:end,[3 6 9]) = xX';
125 J(2:2:end,[3 6 9]) = -yX';
126 J(1:2:end,12) = xn(1,:)';
127 J(2:2:end,12) = -xn(2,:)';
128 J(1:2:end,10) = -ones(Np,1);
129 J(2:2:end,11) = ones(Np,1);
130
131 JJ = J'*J;
132 [U,S,V] = svd(JJ);
133
134 RR = reshape(V(1:9,12),3,3);
135
136 if det(RR) < 0,
137 V(:,12) = -V(:,12);
138 RR = -RR;
139 end;
140
141 [Ur,Sr,Vr] = svd(RR);
142
143 Rckk = Ur*Vr';
144
145 sc = norm(V(1:9,12)) / norm(Rckk(:));
146 Tckk = V(10:12,12)/sc;
147
148 omckk = rodrigues(Rckk);
149 Rckk = rodrigues(omckk);
150
151end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_refine.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_refine.m
new file mode 100755
index 0000000..a4d066c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_extrinsic_refine.m
@@ -0,0 +1,113 @@
1function [omckk,Tckk,Rckk,JJ] = compute_extrinsic_refine(omc_init,Tc_init,x_kk,X_kk,fc,cc,kc,alpha_c,MaxIter,thresh_cond),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk] = compute_extrinsic_refine(x_kk,X_kk,fc,cc,kc,alpha_c,MaxIter)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16% alpha_c: Skew coefficient
17% MaxIter: Maximum number of iterations
18%
19%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
20% Tckk: 3D translation vector attached to the grid positions in space
21% Rckk: 3D rotation matrices corresponding to the omc vectors
22
23%
24%Method: Computes the normalized point coordinates, then computes the 3D pose
25%
26%Important functions called within that program:
27%
28%normalize: Computes the normalize image point coordinates.
29%
30%pose3D: Computes the 3D pose of the structure given the normalized image projection.
31%
32%project_points.m: Computes the 2D image projections of a set of 3D points
33
34
35if nargin < 10,
36 thresh_cond = inf;
37end;
38
39
40if nargin < 9,
41 MaxIter = 20;
42end;
43
44if nargin < 8,
45 alpha_c = 0;
46 if nargin < 7,
47 kc = zeros(4,1);
48 if nargin < 6,
49 cc = zeros(2,1);
50 if nargin < 5,
51 fc = ones(2,1);
52 if nargin < 4,
53 error('Need 2D projections and 3D points (in compute_extrinsic_refine.m)');
54 return;
55 end;
56 end;
57 end;
58 end;
59end;
60
61
62% Initialization:
63
64omckk = omc_init;
65Tckk = Tc_init;
66
67
68% Final optimization (minimize the reprojection error in pixel):
69% through Gradient Descent:
70
71param = [omckk;Tckk];
72
73change = 1;
74
75iter = 0;
76
77%keyboard;
78
79%fprintf(1,'Gradient descent iterations: ');
80
81while (change > 1e-10)&(iter < MaxIter),
82
83 %fprintf(1,'%d...',iter+1);
84
85 [x,dxdom,dxdT] = project_points2(X_kk,omckk,Tckk,fc,cc,kc,alpha_c);
86
87 ex = x_kk - x;
88
89 %keyboard;
90
91 JJ = [dxdom dxdT];
92
93 if cond(JJ) > thresh_cond,
94 change = 0;
95 else
96
97 JJ2 = JJ'*JJ;
98
99 param_innov = inv(JJ2)*(JJ')*ex(:);
100 param_up = param + param_innov;
101 change = norm(param_innov)/norm(param_up);
102 param = param_up;
103 iter = iter + 1;
104
105 omckk = param(1:3);
106 Tckk = param(4:6);
107 end;
108
109end;
110
111%fprintf(1,'\n');
112
113Rckk = rodrigues(omckk);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_homography.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_homography.m
new file mode 100755
index 0000000..fcc9003
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/compute_homography.m
@@ -0,0 +1,163 @@
1function [H,Hnorm,inv_Hnorm] = compute_homography (m,M);
2
3%compute_homography
4%
5%[H,Hnorm,inv_Hnorm] = compute_homography (m,M)
6%
7%Computes the planar homography between the point coordinates on the plane (M) and the image
8%point coordinates (m).
9%
10%INPUT: m: homogeneous coordinates in the image plane (3xN matrix)
11% M: homogeneous coordinates in the plane in 3D (3xN matrix)
12%
13%OUTPUT: H: Homography matrix (3x3 homogeneous matrix)
14% Hnorm: Normlization matrix used on the points before homography computation
15% (useful for numerical stability is points in pixel coordinates)
16% inv_Hnorm: The inverse of Hnorm
17%
18%Definition: m ~ H*M where "~" means equal up to a non zero scalar factor.
19%
20%Method: First computes an initial guess for the homography through quasi-linear method.
21% Then, if the total number of points is larger than 4, optimize the solution by minimizing
22% the reprojection error (in the least squares sense).
23%
24%
25%Important functions called within that program:
26%
27%comp_distortion_oulu: Undistorts pixel coordinates.
28%
29%compute_homography.m: Computes the planar homography between points on the grid in 3D, and the image plane.
30%
31%project_points.m: Computes the 2D image projections of a set of 3D points, and also returns te Jacobian
32% matrix (derivative with respect to the intrinsic and extrinsic parameters).
33% This function is called within the minimization loop.
34
35
36
37
38Np = size(m,2);
39
40if size(m,1)<3,
41 m = [m;ones(1,Np)];
42end;
43
44if size(M,1)<3,
45 M = [M;ones(1,Np)];
46end;
47
48
49m = m ./ (ones(3,1)*m(3,:));
50M = M ./ (ones(3,1)*M(3,:));
51
52% Prenormalization of point coordinates (very important):
53% (Affine normalization)
54
55ax = m(1,:);
56ay = m(2,:);
57
58mxx = mean(ax);
59myy = mean(ay);
60ax = ax - mxx;
61ay = ay - myy;
62
63scxx = mean(abs(ax));
64scyy = mean(abs(ay));
65
66
67Hnorm = [1/scxx 0 -mxx/scxx;0 1/scyy -myy/scyy;0 0 1];
68inv_Hnorm = [scxx 0 mxx ; 0 scyy myy; 0 0 1];
69
70mn = Hnorm*m;
71
72% Compute the homography between m and mn:
73
74% Build the matrix:
75
76L = zeros(2*Np,9);
77
78L(1:2:2*Np,1:3) = M';
79L(2:2:2*Np,4:6) = M';
80L(1:2:2*Np,7:9) = -((ones(3,1)*mn(1,:)).* M)';
81L(2:2:2*Np,7:9) = -((ones(3,1)*mn(2,:)).* M)';
82
83if Np > 4,
84 L = L'*L;
85end;
86
87[U,S,V] = svd(L);
88
89hh = V(:,9);
90hh = hh/hh(9);
91
92Hrem = reshape(hh,3,3)';
93%Hrem = Hrem / Hrem(3,3);
94
95% Final homography:
96
97H = inv_Hnorm*Hrem;
98
99
100%%% Homography refinement if there are more than 4 points:
101
102if Np > 4,
103
104 % Final refinement:
105
106 hhv = reshape(H',9,1);
107 hhv = hhv(1:8);
108
109 for iter=1:10,
110
111 mrep = H * M;
112
113 J = zeros(2*Np,8);
114
115 MMM = (M ./ (ones(3,1)*mrep(3,:)));
116
117 J(1:2:2*Np,1:3) = -MMM';
118 J(2:2:2*Np,4:6) = -MMM';
119
120 mrep = mrep ./ (ones(3,1)*mrep(3,:));
121
122 m_err = m(1:2,:) - mrep(1:2,:);
123 m_err = m_err(:);
124
125 MMM2 = (ones(3,1)*mrep(1,:)) .* MMM;
126 MMM3 = (ones(3,1)*mrep(2,:)) .* MMM;
127
128 J(1:2:2*Np,7:8) = MMM2(1:2,:)';
129 J(2:2:2*Np,7:8) = MMM3(1:2,:)';
130
131 MMM = (M ./ (ones(3,1)*mrep(3,:)))';
132
133 hh_innov = inv(J'*J)*J'*m_err;
134
135 hhv_up = hhv - hh_innov;
136
137 H_up = reshape([hhv_up;1],3,3)';
138
139 %norm(m_err)
140 %norm(hh_innov)
141
142 hhv = hhv_up;
143 H = H_up;
144
145 end;
146
147end;
148
149
150
151
152
153return;
154
155%test of Jacobian
156
157mrep = H*M;
158mrep = mrep ./ (ones(3,1)*mrep(3,:));
159
160m_err = mrep(1:2,:) - m(1:2,:);
161figure(8);
162plot(m_err(1,:),m_err(2,:),'r+');
163std(m_err')
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/cornerfinder.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/cornerfinder.m
new file mode 100755
index 0000000..9bfa51f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/cornerfinder.m
@@ -0,0 +1,215 @@
1function [xc,good,bad,type] = cornerfinder(xt,I,wintx,winty,wx2,wy2);
2
3%[xc] = cornerfinder(xt,I);
4%
5%Finds the sub-pixel corners on the image I with initial guess xt
6%xt and xc are 2xN matrices. The first component is the x coordinate
7%(horizontal) and the second component is the y coordinate (vertical)
8%
9%Based on Harris corner finder method
10%
11%Finds corners to a precision below .1 pixel!
12%Oct. 14th, 1997 - UPDATED to work with vertical and horizontal edges as well!!!
13%Sept 1998 - UPDATED to handle diverged points: we keep the original points
14%good is a binary vector indicating wether a feature point has been properly
15%found.
16%
17%Add a zero zone of size wx2,wy2
18%July 15th, 1999 - Bug on the mask building... fixed + change to Gaussian mask with higher
19%resolution and larger number of iterations.
20
21
22% California Institute of Technology
23% (c) Jean-Yves Bouguet -- Oct. 14th, 1997
24
25
26
27line_feat = 1; % set to 1 to allow for extraction of line features.
28
29xt = xt';
30xt = fliplr(xt);
31
32
33if nargin < 4,
34 winty = 5;
35 if nargin < 3,
36 wintx = 5;
37 end;
38end;
39
40
41if nargin < 6,
42 wx2 = -1;
43 wy2 = -1;
44end;
45
46
47%mask = ones(2*wintx+1,2*winty+1);
48mask = exp(-((-wintx:wintx)'/(wintx)).^2) * exp(-((-winty:winty)/(winty)).^2);
49
50
51if (wx2>0) & (wy2>0),
52 if ((wintx - wx2)>=2)&((winty - wy2)>=2),
53 mask(wintx+1-wx2:wintx+1+wx2,winty+1-wy2:winty+1+wy2)= zeros(2*wx2+1,2*wy2+1);
54 end;
55end;
56
57offx = [-wintx:wintx]'*ones(1,2*winty+1);
58offy = ones(2*wintx+1,1)*[-winty:winty];
59
60resolution = 0.005;
61
62MaxIter = 10;
63
64[nx,ny] = size(I);
65N = size(xt,1);
66
67xc = xt; % first guess... they don't move !!!
68
69type = zeros(1,N);
70
71
72for i=1:N,
73
74 v_extra = resolution + 1; % just larger than resolution
75
76 compt = 0; % no iteration yet
77
78 while (norm(v_extra) > resolution) & (compt<MaxIter),
79
80 cIx = xc(i,1); %
81 cIy = xc(i,2); % Coords. of the point
82 crIx = round(cIx); % on the initial image
83 crIy = round(cIy); %
84 itIx = cIx - crIx; % Coefficients
85 itIy = cIy - crIy; % to compute
86 if itIx > 0, % the sub pixel
87 vIx = [itIx 1-itIx 0]'; % accuracy.
88 else
89 vIx = [0 1+itIx -itIx]';
90 end;
91 if itIy > 0,
92 vIy = [itIy 1-itIy 0];
93 else
94 vIy = [0 1+itIy -itIy];
95 end;
96
97
98 % What if the sub image is not in?
99
100 if (crIx-wintx-2 < 1), xmin=1; xmax = 2*wintx+5;
101 elseif (crIx+wintx+2 > nx), xmax = nx; xmin = nx-2*wintx-4;
102 else
103 xmin = crIx-wintx-2; xmax = crIx+wintx+2;
104 end;
105
106 if (crIy-winty-2 < 1), ymin=1; ymax = 2*winty+5;
107 elseif (crIy+winty+2 > ny), ymax = ny; ymin = ny-2*winty-4;
108 else
109 ymin = crIy-winty-2; ymax = crIy+winty+2;
110 end;
111
112
113 SI = I(xmin:xmax,ymin:ymax); % The necessary neighborhood
114 SI = conv2(conv2(SI,vIx,'same'),vIy,'same');
115 SI = SI(2:2*wintx+4,2:2*winty+4); % The subpixel interpolated neighborhood
116 [gy,gx] = gradient(SI); % The gradient image
117 gx = gx(2:2*wintx+2,2:2*winty+2); % extraction of the useful parts only
118 gy = gy(2:2*wintx+2,2:2*winty+2); % of the gradients
119
120 px = cIx + offx;
121 py = cIy + offy;
122
123 gxx = gx .* gx .* mask;
124 gyy = gy .* gy .* mask;
125 gxy = gx .* gy .* mask;
126
127
128 bb = [sum(sum(gxx .* px + gxy .* py)); sum(sum(gxy .* px + gyy .* py))];
129
130 a = sum(sum(gxx));
131 b = sum(sum(gxy));
132 c = sum(sum(gyy));
133
134 dt = a*c - b^2;
135
136 xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
137
138
139 %keyboard;
140
141 if line_feat,
142
143 G = [a b;b c];
144 [U,S,V] = svd(G);
145
146 %keyboard;
147
148 % If non-invertible, then project the point onto the edge orthogonal:
149
150 if (S(1,1)/S(2,2) > 50),
151 % projection operation:
152 xc2 = xc2 + sum((xc(i,:)-xc2).*(V(:,2)'))*V(:,2)';
153 type(i) = 1;
154 end;
155
156 end;
157
158
159 %keyboard;
160
161% G = [a b;b c];
162% [U,S,V] = svd(G);
163
164
165% if S(1,1)/S(2,2) > 150,
166% bb2 = U'*bb;
167% xc2 = (V*[bb2(1)/S(1,1) ;0])';
168% else
169% xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
170% end;
171
172
173 %if (abs(a)> 50*abs(c)),
174% xc2 = [(c*bb(1)-b*bb(2))/dt xc(i,2)];
175% elseif (abs(c)> 50*abs(a))
176% xc2 = [xc(i,1) (a*bb(2)-b*bb(1))/dt];
177% else
178% xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
179% end;
180
181 %keyboard;
182
183 v_extra = xc(i,:) - xc2;
184
185 xc(i,:) = xc2;
186
187% keyboard;
188
189 compt = compt + 1;
190
191 end
192end;
193
194
195% check for points that diverge:
196
197delta_x = xc(:,1) - xt(:,1);
198delta_y = xc(:,2) - xt(:,2);
199
200%keyboard;
201
202
203bad = (abs(delta_x) > wintx) | (abs(delta_y) > winty);
204good = ~bad;
205in_bad = find(bad);
206
207% For the diverged points, keep the original guesses:
208
209xc(in_bad,:) = xt(in_bad,:);
210
211xc = fliplr(xc);
212xc = xc';
213
214bad = bad';
215good = good';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/count_squares.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/count_squares.m
new file mode 100755
index 0000000..0e226c0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/count_squares.m
@@ -0,0 +1,74 @@
1function ns = count_squares(I,x1,y1,x2,y2,win);
2
3%keyboard;
4
5[ny,nx] = size(I);
6
7lambda = [y1 - y2;x2 - x1;x1*y2 - x2*y1];
8
9lambda = 1/sqrt(lambda(1)^2 + lambda(2)^2) * lambda;
10
11l1 = lambda + [0;0;win];
12l2 = lambda - [0;0;win];
13
14
15dx = x2-x1;
16dy = y2 - y1;
17
18
19if abs(dx) > abs(dy),
20
21 if x2 > x1,
22 xs = x1:x2;
23 else
24 xs = x1:-1:x2;
25 end;
26
27 ys = -(lambda(3) + lambda(1)*xs)/lambda(2);
28
29else
30
31 if y2 > y1,
32 ys = y1:y2;
33 else
34 ys = y1:-1:y2;
35 end;
36 xs = -(lambda(3) + lambda(2)*ys)/lambda(1);
37
38end;
39
40
41
42 Np = length(xs);
43
44 xs_mat = ones(2*win + 1,1)*xs;
45 ys_mat = ones(2*win + 1,1)*ys;
46
47 win_mat = (-win:win)'*ones(1,Np);
48
49
50 xs_mat2 = round(xs_mat - win_mat * lambda(1));
51 ys_mat2 = round(ys_mat - win_mat * lambda(2));
52
53 ind_mat = (xs_mat2 - 1) * ny + ys_mat2;
54
55 ima_patch = zeros(2*win + 1,Np);
56
57 ima_patch(:) = I(ind_mat(:));
58
59 %ima2 = ima_patch(:,win+1:end-win);
60
61 filtk = [ones(win,Np);zeros(1,Np);-ones(win,Np)];
62
63 out_f = sum(filtk.*ima_patch);
64
65 out_f_f = conv2(out_f,[1/4 1/2 1/4],'same');
66
67 out_f_f = out_f_f(win+1:end-win);
68
69 ns = length(find(((out_f_f(2:end)>=0)&(out_f_f(1:end-1)<0)) | ((out_f_f(2:end)<=0)&(out_f_f(1:end-1)>0))))+1;
70
71
72
73
74return;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/data_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/data_calib.m
new file mode 100755
index 0000000..422769b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/data_calib.m
@@ -0,0 +1,92 @@
1%%% This script alets the user enter the name of the images (base name, numbering scheme,...
2
3
4% Checks that there are some images in the directory:
5
6l_ras = dir('*ras');
7s_ras = size(l_ras,1);
8l_bmp = dir('*bmp');
9s_bmp = size(l_bmp,1);
10l_tif = dir('*tif');
11s_tif = size(l_tif,1);
12l_pgm = dir('*pgm');
13s_pgm = size(l_pgm,1);
14l_jpg = dir('*jpg');
15s_jpg = size(l_jpg,1);
16
17s_tot = s_ras + s_bmp + s_tif + s_pgm + s_jpg;
18
19if s_tot < 1,
20 fprintf(1,'No image in this directory in either ras, bmp, tif, pgm or jpg format. Change directory and try again.\n');
21 break;
22end;
23
24
25% IF yes, display the directory content:
26
27dir;
28
29Nima_valid = 0;
30
31while (Nima_valid==0),
32
33 fprintf(1,'\n');
34 calib_name = input('Basename camera calibration images (without number nor suffix): ','s');
35
36 format_image = '0';
37
38 while format_image == '0',
39
40 format_image = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'', ''m''=''ppm'') ','s');
41
42 if isempty(format_image),
43 format_image = 'ras';
44 end;
45
46 if lower(format_image(1)) == 'm',
47 format_image = 'ppm';
48 else
49 if lower(format_image(1)) == 'b',
50 format_image = 'bmp';
51 else
52 if lower(format_image(1)) == 't',
53 format_image = 'tif';
54 else
55 if lower(format_image(1)) == 'p',
56 format_image = 'pgm';
57 else
58 if lower(format_image(1)) == 'j',
59 format_image = 'jpg';
60 else
61 if lower(format_image(1)) == 'r',
62 format_image = 'ras';
63 else
64 disp('Invalid image format');
65 format_image = '0'; % Ask for format once again
66 end;
67 end;
68 end;
69 end;
70 end;
71 end;
72 end;
73
74
75 check_directory;
76
77end;
78
79
80
81%string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name first_num';
82
83%eval(string_save);
84
85
86
87if (Nima_valid~=0),
88 % Reading images:
89
90 ima_read_calib; % may be launched from the toolbox itself
91end;
92
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/error_analysis.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/error_analysis.m
new file mode 100755
index 0000000..85feac5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/error_analysis.m
@@ -0,0 +1,182 @@
1%%% ERROR_ANALYSIS
2%%% This simulation helps coputing the acturacies of calibration
3%%% Run it after the main calibration
4
5
6
7N_runs = 200;
8
9%N_ima_active = 4;
10
11saving = 1;
12
13if 1, %~exist('fc_list'), % initialization
14
15 % Initialization:
16
17 load Calib_Results;
18 check_active_images;
19
20 fc_list = [];
21 cc_list = [];
22 kc_list = [];
23 active_images_list = [];
24
25
26 for kk=1:n_ima,
27
28 eval(['omc_list_' num2str(kk) ' = [];']);
29 eval(['Tc_list_' num2str(kk) ' = [];']);
30
31 end;
32
33 %sx = median(abs(ex(1,:)))*1.4836;
34 %sy = median(abs(ex(2,:)))*1.4836;
35
36 sx = std(ex(1,:));
37 sy = std(ex(2,:));
38
39 % Saving the feature locations:
40
41 for kk = 1:n_ima,
42
43 eval(['x_save_' num2str(kk) ' = x_' num2str(kk) ';']);
44 eval(['y_save_' num2str(kk) ' = y_' num2str(kk) ';']);
45
46 end;
47
48 active_images_save = active_images;
49 ind_active_save = ind_active;
50
51 fc_save = fc;
52 cc_save = cc;
53 kc_save = kc;
54 KK_save = KK;
55
56
57end;
58
59
60
61
62%%% The main loop:
63
64
65for ntrial = 1:N_runs,
66
67 fprintf(1,'\nRun number: %d\n',ntrial);
68 fprintf(1, '----------\n');
69
70 for kk = 1:n_ima,
71
72 eval(['y_kk = y_save_' num2str(kk) ';'])
73
74 if active_images(kk) & ~isnan(y_kk(1,1)),
75
76 Nkk = size(y_kk,2);
77
78 x_kk_new = y_kk + [sx * randn(1,Nkk);sy*randn(1,Nkk)];
79
80 eval(['x_' num2str(kk) ' = x_kk_new;']);
81
82 end;
83
84 end;
85
86 N_active = length(ind_active_save);
87 junk = randn(1,N_active);
88 [junk,junk2] = sort(junk);
89
90 active_images = zeros(1,n_ima);
91 active_images(ind_active_save(junk2(1:N_ima_active))) = ones(1,N_ima_active);
92
93 fc = fc_save;
94 cc = cc_save;
95 kc = kc_save;
96 KK = KK_save;
97
98 go_calib_optim;
99
100 fc_list = [fc_list fc];
101 cc_list = [cc_list cc];
102 kc_list = [kc_list kc];
103 active_images_list = [active_images_list active_images'];
104
105 for kk=1:n_ima,
106
107 eval(['omc_list_' num2str(kk) ' = [ omc_list_' num2str(kk) ' omc_' num2str(kk) ' ];']);
108 eval(['Tc_list_' num2str(kk) ' = [ Tc_list_' num2str(kk) ' Tc_' num2str(kk) ' ];']);
109
110 end;
111
112end;
113
114
115
116
117if 0,
118
119% Restoring the feature locations:
120
121for kk = 1:n_ima,
122
123 eval(['x_' num2str(kk) ' = x_save_' num2str(kk) ';']);
124
125end;
126
127fprintf(1,'\nFinal run (with the real data)\n');
128fprintf(1, '------------------------------\n');
129
130active_images = active_images_save;
131ind_active = ind_active_save;
132
133go_calib_optim;
134
135fc_list = [fc_list fc];
136cc_list = [cc_list cc];
137kc_list = [kc_list kc];
138active_images_list = [active_images_list active_images'];
139
140for kk=1:n_ima,
141
142 eval(['omc_list_' num2str(kk) ' = [ omc_list_' num2str(kk) ' omc_' num2str(kk) ' ];']);
143 eval(['Tc_list_' num2str(kk) ' = [ Tc_list_' num2str(kk) ' Tc_' num2str(kk) ' ];']);
144
145end;
146
147end;
148
149
150
151
152
153if saving,
154
155disp(['Save Calibration accuracy results under Calib_Accuracies_' num2str(N_ima_active) '.mat']);
156
157string_save = ['save Calib_Accuracies_' num2str(N_ima_active) ' active_images n_ima N_ima_active N_runs active_images_list fc cc kc fc_list cc_list kc_list'];
158
159for kk = 1:n_ima,
160 string_save = [string_save ' Tc_list_' num2str(kk) ' omc_list_' num2str(kk) ' Tc_' num2str(kk) ' omc_' num2str(kk) ];
161end;
162
163eval(string_save);
164
165end;
166
167
168return;
169
170std(fc_list')
171
172std(cc_list')
173
174std(kc_list')
175
176for kk = 1:n_ima,
177
178 eval(['std(Tc_list_' num2str(kk) ''')'])
179
180end;
181
182
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/export_calib_data.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/export_calib_data.m
new file mode 100755
index 0000000..39506a8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/export_calib_data.m
@@ -0,0 +1,99 @@
1%% Export calibration data (corners + 3D coordinates) to
2%% text files (in Willson-Heikkila's format or Zhang's format)
3
4%% Thanks to Michael Goesele (from the Max-Planck-Institut) for the original suggestion
5%% of adding thsi export function to the toolbox.
6
7
8if ~exist('n_ima'),
9 fprintf(1,'ERROR: No calibration data to export\n');
10
11else
12
13 check_active_images;
14
15 check_extracted_images;
16
17 check_active_images;
18
19 fprintf(1,'Tool that exports calibration data to Willson-Heikkila or Zhang formats\n');
20
21 qformat = -1;
22
23 while (qformat ~=0)&(qformat ~=1),
24
25 fprintf(1,'Two possible formats of export: 0=Willson and Heikkila, 1=Zhang\n')
26 qformat = input('Format of export (enter 0 or 1): ');
27
28 if isempty(qformat)
29 qformat = -1;
30 end;
31
32 if (qformat ~=0)&(qformat ~=1),
33
34 fprintf(1,'Invalid entry. Try again.\n')
35
36 end;
37
38 end;
39
40 if qformat == 0,
41
42 fprintf(1,'\nExport of calibration data to text files (Willson and Heikkila''s format)\n');
43 outputfile = input('File basename: ','s');
44
45 for kk = ind_active,
46
47 eval(['X_kk = X_' num2str(kk) ';']);
48 eval(['x_kk = x_' num2str(kk) ';']);
49
50 Xx = [X_kk ; x_kk]';
51
52 file_name = [outputfile num2str(kk)];
53
54 disp(['Exporting calibration data (3D world + 2D image coordinates) of image ' num2str(kk) ' to file ' file_name '...']);
55
56 eval(['save ' file_name ' Xx -ASCII']);
57
58 end;
59
60 else
61
62 fprintf(1,'\nExport of calibration data to text files (Zhang''s format)\n');
63 modelfile = input('File basename for the 3D world coordinates: ','s');
64 datafile = input('File basename for the 2D image coordinates: ','s');
65
66 for kk = ind_active,
67
68 eval(['X_kk = X_' num2str(kk) ';']);
69 eval(['x_kk = x_' num2str(kk) ';']);
70
71 if ~exist(['n_sq_x_' num2str(kk)]),
72 n_sq_x = 1;
73 n_sq_y = size(X_kk,2);
74 else
75 eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
76 eval(['n_sq_y = n_sq_y_' num2str(kk) ';']);
77 end;
78
79 X = reshape(X_kk(1,:)',n_sq_x+1,n_sq_y+1)';
80 Y = reshape(X_kk(2,:)',n_sq_x+1,n_sq_y+1)';
81 XY = reshape([X;Y],n_sq_y+1,2*(n_sq_x+1));
82
83 x = reshape(x_kk(1,:)',n_sq_x+1,n_sq_y+1)';
84 y = reshape(x_kk(2,:)',n_sq_x+1,n_sq_y+1)';
85 xy = reshape([x;y],n_sq_y+1,2*(n_sq_x+1));
86
87 disp(['Exporting calibration data of image ' num2str(kk) ' to files ' modelfile num2str(kk) '.txt and ' datafile num2str(kk) '.txt...']);
88
89 eval(['save ' modelfile num2str(kk) '.txt XY -ASCII']);
90 eval(['save ' datafile num2str(kk) '.txt xy -ASCII']);
91
92 end;
93
94
95end;
96
97fprintf(1,'done\n');
98
99end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ext_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ext_calib.m
new file mode 100755
index 0000000..04d6319
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ext_calib.m
@@ -0,0 +1,152 @@
1
2%%%%%%%%%%%%%%%%%%%% SHOW EXTRINSIC RESULTS %%%%%%%%%%%%%%%%%%%%%%%%
3
4if ~exist('n_ima')|~exist('fc'),
5 fprintf(1,'No calibration data available.\n');
6 return;
7end;
8
9check_active_images;
10
11if ~exist(['omc_' num2str(ind_active(1))]),
12 fprintf(1,'No calibration data available.\n');
13 return;
14end;
15
16%if ~exist('no_grid'),
17 no_grid = 0;
18%end;
19
20if ~exist(['n_sq_x_' num2str(ind_active(1))]),
21 no_grid = 1;
22end;
23
24
25if 0,
26
27err_std = std(ex');
28
29fprintf(1,'\n\nCalibration results without principal point estimation:\n\n');
30fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
31fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
32fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
33fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
34
35end;
36
37
38% Color code for each image:
39
40colors = 'brgkcm';
41
42
43%%% Show the extrinsic parameters
44
45if ~exist('dX'),
46 eval(['dX = norm(Tc_' num2str(ind_active(1)) ')/10;']);
47 dY = dX;
48end;
49
50IP = 5*dX*([0 nx-1 nx-1 0 0 ; 0 0 ny-1 ny-1 0;1 1 1 1 1] - [cc;0]*ones(1,5)) ./ ([fc;1]*ones(1,5));
51BASE = 5*dX*([0 1 0 0 0 0;0 0 0 1 0 0;0 0 0 0 0 1]);
52IP = reshape([IP;BASE(:,1)*ones(1,5);IP],3,15);
53
54figure(4);
55[a,b] = view;
56
57figure(4);
58plot3(BASE(1,:),BASE(3,:),-BASE(2,:),'b-','linewidth',2');
59hold on;
60plot3(IP(1,:),IP(3,:),-IP(2,:),'r-','linewidth',2);
61text(6*dX,0,0,'X_c');
62text(-dX,5*dX,0,'Z_c');
63text(0,0,-6*dX,'Y_c');
64text(-dX,-dX,dX,'O_c');
65
66
67for kk = 1:n_ima,
68
69 if active_images(kk);
70
71 if exist(['X_' num2str(kk)]) & exist(['omc_' num2str(kk)]),
72
73 eval(['XX_kk = X_' num2str(kk) ';']);
74
75 if ~isnan(XX_kk(1,1))
76
77 eval(['omc_kk = omc_' num2str(kk) ';']);
78 eval(['Tc_kk = Tc_' num2str(kk) ';']);
79 N_kk = size(XX_kk,2);
80
81 if ~exist(['n_sq_x_' num2str(kk)]),
82 no_grid = 1;
83 else
84 eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
85 if isnan(n_sq_x(1)),
86 no_grid = 1;
87 end;
88 end;
89
90
91 if ~no_grid,
92 eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
93 eval(['n_sq_y = n_sq_y_' num2str(kk) ';']);
94 if (N_kk ~= ((n_sq_x+1)*(n_sq_y+1))),
95 no_grid = 1;
96 end;
97 end;
98
99 if ~isnan(omc_kk(1,1)),
100
101 R_kk = rodrigues(omc_kk);
102
103 YY_kk = R_kk * XX_kk + Tc_kk * ones(1,length(XX_kk));
104
105 uu = [-dX;-dY;0]/2;
106 uu = R_kk * uu + Tc_kk;
107
108 if ~no_grid,
109 YYx = zeros(n_sq_x+1,n_sq_y+1);
110 YYy = zeros(n_sq_x+1,n_sq_y+1);
111 YYz = zeros(n_sq_x+1,n_sq_y+1);
112
113 YYx(:) = YY_kk(1,:);
114 YYy(:) = YY_kk(2,:);
115 YYz(:) = YY_kk(3,:);
116
117 %keyboard;
118
119 figure(4);
120 hhh= mesh(YYx,YYz,-YYy);
121 set(hhh,'edgecolor',colors(rem(kk-1,6)+1),'linewidth',1); %,'facecolor','none');
122 %plot3(YY_kk(1,:),YY_kk(3,:),-YY_kk(2,:),['o' colors(rem(kk-1,6)+1)]);
123 text(uu(1),uu(3),-uu(2),num2str(kk),'fontsize',14,'color',colors(rem(kk-1,6)+1));
124 else
125
126 figure(4);
127 plot3(YY_kk(1,:),YY_kk(3,:),-YY_kk(2,:),['.' colors(rem(kk-1,6)+1)]);
128 text(uu(1),uu(3),-uu(2),num2str(kk),'fontsize',14,'color',colors(rem(kk-1,6)+1));
129
130 end;
131
132 end;
133
134 end;
135
136 end;
137
138 end;
139
140end;
141
142figure(4);rotate3d on;
143axis('equal');
144title('Extrinsic parameters');
145%view(60,30);
146view(a,b);
147hold off;
148
149set(4,'Name','3D','NumberTitle','off');
150
151%fprintf(1,'To generate the complete movie associated to the optimization loop, try: check_convergence;\n');
152
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_grid.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_grid.m
new file mode 100755
index 0000000..0cf9abe
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_grid.m
@@ -0,0 +1,234 @@
1function [x,X,n_sq_x,n_sq_y,ind_orig,ind_x,ind_y] = extract_grid(I,wintx,winty,fc,cc,kc,dX,dY);
2
3map = gray(256);
4
5minI = min(I(:));
6maxI = max(I(:));
7
8Id = 255*(I - minI)/(maxI - minI);
9
10 figure(2);
11 image(Id);
12 colormap(map);
13
14
15 if nargin < 2,
16
17 disp('Window size for corner finder (wintx and winty):');
18 wintx = input('wintx ([] = 5) = ');
19 if isempty(wintx), wintx = 5; end;
20 wintx = round(wintx);
21 winty = input('winty ([] = 5) = ');
22 if isempty(winty), winty = 5; end;
23 winty = round(winty);
24
25 fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
26
27 end;
28
29
30
31 title('Click on the four extreme corners of the rectangular pattern...');
32
33 disp('Click on the four extreme corners of the rectangular complete pattern...');
34
35 [x,y] = ginput3(4);
36
37 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
38
39 x = Xc(1,:)';
40 y = Xc(2,:)';
41
42 [y,indy] = sort(y);
43 x = x(indy);
44
45 if (x(2) > x(1)),
46 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
47 else
48 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
49 end;
50 if (x(3) > x(4)),
51 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
52 else
53 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
54 end;
55
56 x = [x1;x2;x3;x4];
57 y = [y1;y2;y3;y4];
58
59
60 figure(2); hold on;
61 plot([x;x(1)],[y;y(1)],'g-');
62 plot(x,y,'og');
63 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
64 set(hx,'color','g','Fontsize',14);
65 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
66 set(hy,'color','g','Fontsize',14);
67 hold off;
68
69
70 % Try to automatically count the number of squares in the grid
71
72 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
73 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
74 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
75 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
76
77
78
79 % If could not count the number of squares, enter manually
80
81 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
82
83
84 disp('Could not count the number of squares in the grid. Enter manually.');
85 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
86 if isempty(n_sq_x), n_sq_x = 10; end;
87 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
88 if isempty(n_sq_y), n_sq_y = 10; end;
89
90 else
91
92 n_sq_x = n_sq_x1;
93 n_sq_y = n_sq_y1;
94
95 end;
96
97 if ~exist('dX')|~exist('dY'),
98
99 % Enter the size of each square
100
101 dX = input(['Size dX of each square along the X direction ([]=30mm) = ']);
102 dY = input(['Size dY of each square along the Y direction ([]=30mm) = ']);
103 if isempty(dX), dX = 30; end;
104 if isempty(dY), dY = 30; end;
105
106 end;
107
108
109 % Compute the inside points through computation of the planar homography (collineation)
110
111 a00 = [x(1);y(1);1];
112 a10 = [x(2);y(2);1];
113 a11 = [x(3);y(3);1];
114 a01 = [x(4);y(4);1];
115
116
117 % Compute the planart collineation: (return the normalization matrice as well)
118
119 [Homo,Hnorm,inv_Hnorm] = compute_homography ([a00 a10 a11 a01],[0 1 1 0;0 0 1 1;1 1 1 1]);
120
121
122 % Build the grid using the planar collineation:
123
124 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
125 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
126 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
127
128 XX = Homo*pts;
129 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
130
131
132 % Complete size of the rectangle
133
134 W = n_sq_x*dX;
135 L = n_sq_y*dY;
136
137
138
139 if nargin < 6,
140
141 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
142 figure(2);
143 hold on;
144 plot(XX(1,:),XX(2,:),'r+');
145 title('The red crosses should be close to the image corners');
146 hold off;
147
148 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
149 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
150 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
151
152 quest_distort = ~isempty(quest_distort);
153
154 if quest_distort,
155 % Estimation of focal length:
156 c_g = [size(I,2);size(I,1)]/2 + .5;
157 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
158 f_g = mean(f_g);
159 script_fit_distortion;
160 end;
161 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
162
163 else
164
165 xy_corners_undist = comp_distortion_oulu([(x' - cc(1))/fc(1);(y'-cc(2))/fc(1)],kc);
166
167 xu = xy_corners_undist(1,:)';
168 yu = xy_corners_undist(2,:)';
169
170 [XXu] = projectedGrid ( [xu(1);yu(1)], [xu(2);yu(2)],[xu(3);yu(3)], [xu(4);yu(4)],n_sq_x+1,n_sq_y+1); % The full grid
171
172 r2 = sum(XXu.^2);
173 XX = (ones(2,1)*(1 + kc(1) * r2 + kc(2) * (r2.^2))) .* XXu;
174 XX(1,:) = fc(1)*XX(1,:)+cc(1);
175 XX(2,:) = fc(2)*XX(2,:)+cc(2);
176
177 end;
178
179
180 Np = (n_sq_x+1)*(n_sq_y+1);
181
182 disp('Corner extraction...');
183
184 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
185
186 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
187
188 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
189 ind_orig = (n_sq_x+1)*n_sq_y + 1;
190 xorig = grid_pts(1,ind_orig);
191 yorig = grid_pts(2,ind_orig);
192 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
193 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
194
195
196 ind_x = (n_sq_x+1)*(n_sq_y + 1);
197 ind_y = 1;
198
199 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
200 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
201
202
203 figure(3);
204 image(Id); colormap(map); hold on;
205 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
206 plot(x_box_kk+1,y_box_kk+1,'-b');
207 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
208 plot(xorig+1,yorig+1,'*m');
209 h = text(xorig-15,yorig-15,'O');
210 set(h,'Color','m','FontSize',14);
211 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
212 set(h2,'Color','g','FontSize',14);
213 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
214 set(h3,'Color','g','FontSize',14);
215 xlabel('Xc (in camera frame)');
216 ylabel('Yc (in camera frame)');
217 title('Extracted corners');
218 zoom on;
219 drawnow;
220 hold off;
221
222
223 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
224 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
225 Zi = zeros(1,Np);
226
227 Xgrid = [Xi;Yi;Zi];
228
229
230 % All the point coordinates (on the image, and in 3D) - for global optimization:
231
232 x = grid_pts;
233 X = Xgrid;
234
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters.m
new file mode 100755
index 0000000..035b97d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters.m
@@ -0,0 +1,46 @@
1
2%%% Extraction of the final intrinsic and extrinsic paramaters:
3
4check_active_images;
5
6fc = solution(1:2);%***
7cc = solution(3:4);%***
8alpha_c = solution(5);%***
9kc = solution(6:9);%***
10
11
12% Calibration matrix:
13
14KK = [fc(1) fc(1)*alpha_c cc(1);0 fc(2) cc(2); 0 0 1];
15inv_KK = inv(KK);
16
17% Extract the extrinsic paramters, and recomputer the collineations
18
19for kk = 1:n_ima,
20
21 if active_images(kk),
22
23 omckk = solution(15+6*(kk-1) + 1:15+6*(kk-1) + 3);%***
24 Tckk = solution(15+6*(kk-1) + 4:15+6*(kk-1) + 6);%***
25
26 Rckk = rodrigues(omckk);
27
28 Hkk = KK * [Rckk(:,1) Rckk(:,2) Tckk];
29
30 Hkk = Hkk / Hkk(3,3);
31
32 else
33
34 omckk = NaN*ones(3,1);
35 Tckk = NaN*ones(3,1);
36 Rckk = NaN*ones(3,3);
37 Hkk = NaN*ones(3,3);
38
39 end;
40
41 eval(['omc_' num2str(kk) ' = omckk;']);
42 eval(['Rc_' num2str(kk) ' = Rckk;']);
43 eval(['Tc_' num2str(kk) ' = Tckk;']);
44 eval(['H_' num2str(kk) '= Hkk;']);
45
46end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters3D.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters3D.m
new file mode 100755
index 0000000..841c6ab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extract_parameters3D.m
@@ -0,0 +1,36 @@
1
2%%% Extraction of the final intrinsic and extrinsic paramaters:
3
4
5fc = solution(1:2);
6kc = solution(3:6);
7cc = solution(6*n_ima + 4 +3:6*n_ima + 5 +3);
8
9% Calibration matrix:
10
11KK = [fc(1) 0 cc(1);0 fc(2) cc(2); 0 0 1];
12inv_KK = inv(KK);
13
14% Extract the extrinsic paramters, and recomputer the collineations
15
16for kk = 1:n_ima,
17
18 omckk = solution(4+6*(kk-1) + 3:6*kk + 3);
19
20 Tckk = solution(6*kk+1 + 3:6*kk+3 + 3);
21
22 Rckk = rodrigues(omckk);
23
24 Hlkk = KK * [Rckk(:,1) Rckk(:,2) Tckk];
25
26 Hlkk = Hlkk / Hlkk(3,3);
27
28 eval(['omc_' num2str(kk) ' = omckk;']);
29 eval(['Rc_' num2str(kk) ' = Rckk;']);
30 eval(['Tc_' num2str(kk) ' = Tckk;']);
31
32 eval(['Hl_' num2str(kk) '=Hlkk;']);
33
34end;
35
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extrinsic_computation.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extrinsic_computation.m
new file mode 100755
index 0000000..fbba78e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/extrinsic_computation.m
@@ -0,0 +1,185 @@
1%%% INPUT THE IMAGE FILE NAME:
2
3if ~exist('fc')|~exist('cc')|~exist('kc')|~exist('alpha_c'),
4 fprintf(1,'No intrinsic camera parameters available.\n');
5 return;
6end;
7
8dir;
9
10fprintf(1,'\n');
11disp('Computation of the extrinsic parameters from an image of a pattern');
12disp('The intrinsic camera parameters are assumed to be known (previously computed)');
13
14fprintf(1,'\n');
15image_name = input('Image name (full name without extension): ','s');
16
17format_image2 = '0';
18
19while format_image2 == '0',
20
21 format_image2 = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'', ''m''=''ppm'') ','s');
22
23 if isempty(format_image2),
24 format_image2 = 'ras';
25 end;
26
27 if lower(format_image2(1)) == 'm',
28 format_image2 = 'ppm';
29 else
30 if lower(format_image2(1)) == 'b',
31 format_image2 = 'bmp';
32 else
33 if lower(format_image2(1)) == 't',
34 format_image2 = 'tif';
35 else
36 if lower(format_image2(1)) == 'p',
37 format_image2 = 'pgm';
38 else
39 if lower(format_image2(1)) == 'j',
40 format_image2 = 'jpg';
41 else
42 if lower(format_image2(1)) == 'r',
43 format_image2 = 'ras';
44 else
45 disp('Invalid image format');
46 format_image2 = '0'; % Ask for format once again
47 end;
48 end;
49 end;
50 end;
51 end;
52 end;
53end;
54
55ima_name = [image_name '.' format_image2];
56
57
58%%% READ IN IMAGE:
59
60if format_image2(1) == 'p',
61 if format_image2(2) == 'p',
62 I = double(loadppm(ima_name));
63 else
64 I = double(loadpgm(ima_name));
65 end;
66else
67 if format_image2(1) == 'r',
68 I = readras(ima_name);
69 else
70 I = double(imread(ima_name));
71 end;
72end;
73
74if size(I,3)>1,
75 I = I(:,:,2);
76end;
77
78
79%%% EXTRACT GRID CORNERS:
80
81fprintf(1,'\nExtraction of the grid corners on the image\n');
82
83disp('Window size for corner finder (wintx and winty):');
84wintx = input('wintx ([] = 5) = ');
85if isempty(wintx), wintx = 5; end;
86wintx = round(wintx);
87winty = input('winty ([] = 5) = ');
88if isempty(winty), winty = 5; end;
89winty = round(winty);
90
91fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
92
93[x_ext,X_ext,n_sq_x,n_sq_y,ind_orig,ind_x,ind_y] = extract_grid(I,wintx,winty,fc,cc,kc);
94
95
96
97%%% Computation of the Extrinsic Parameters attached to the grid:
98
99[omc_ext,Tc_ext,Rc_ext,H_ext] = compute_extrinsic(x_ext,X_ext,fc,cc,kc,alpha_c);
100
101
102%%% Reproject the points on the image:
103
104[x_reproj] = project_points2(X_ext,omc_ext,Tc_ext,fc,cc,kc,alpha_c);
105
106err_reproj = x_ext - x_reproj;
107
108err_std2 = std(err_reproj')';
109
110
111Basis = [X_ext(:,[ind_orig ind_x ind_orig ind_y ind_orig ])];
112
113VX = Basis(:,2) - Basis(:,1);
114VY = Basis(:,4) - Basis(:,1);
115
116nX = norm(VX);
117nY = norm(VY);
118
119VZ = min(nX,nY) * cross(VX/nX,VY/nY);
120
121Basis = [Basis VZ];
122
123[x_basis] = project_points2(Basis,omc_ext,Tc_ext,fc,cc,kc,alpha_c);
124
125dxpos = (x_basis(:,2) + x_basis(:,1))/2;
126dypos = (x_basis(:,4) + x_basis(:,3))/2;
127dzpos = (x_basis(:,6) + x_basis(:,5))/2;
128
129
130
131figure(2);
132image(I);
133colormap(gray(256));
134hold on;
135plot(x_ext(1,:)+1,x_ext(2,:)+1,'r+');
136plot(x_reproj(1,:)+1,x_reproj(2,:)+1,'yo');
137h = text(x_ext(1,ind_orig)-25,x_ext(2,ind_orig)-25,'O');
138set(h,'Color','g','FontSize',14);
139h2 = text(dxpos(1)+1,dxpos(2)-30,'X');
140set(h2,'Color','g','FontSize',14);
141h3 = text(dypos(1)-30,dypos(2)+1,'Y');
142set(h3,'Color','g','FontSize',14);
143h4 = text(dzpos(1)-10,dzpos(2)-20,'Z');
144set(h4,'Color','g','FontSize',14);
145plot(x_basis(1,:)+1,x_basis(2,:)+1,'g-','linewidth',2);
146title('Image points (+) and reprojected grid points (o)');
147hold off;
148
149
150fprintf(1,'\n\nExtrinsic parameters:\n\n');
151fprintf(1,'Translation vector: Tc_ext = [ %3.6f \t %3.6f \t %3.6f ]\n',Tc_ext);
152fprintf(1,'Rotation vector: omc_ext = [ %3.6f \t %3.6f \t %3.6f ]\n',omc_ext);
153fprintf(1,'Rotation matrix: Rc_ext = [ %3.6f \t %3.6f \t %3.6f\n',Rc_ext(1,:)');
154fprintf(1,' %3.6f \t %3.6f \t %3.6f\n',Rc_ext(2,:)');
155fprintf(1,' %3.6f \t %3.6f \t %3.6f ]\n',Rc_ext(3,:)');
156fprintf(1,'Pixel error: err = [ %3.5f \t %3.5f ]\n\n',err_std2);
157
158
159
160
161
162return;
163
164
165% Stores the results:
166
167kk = 1;
168
169% Stores location of grid wrt camera:
170
171eval(['omc_' num2str(kk) ' = omc_ext;']);
172eval(['Tc_' num2str(kk) ' = Tc_ext;']);
173
174% Stores the projected points:
175
176eval(['y_' num2str(kk) ' = x_reproj;']);
177eval(['X_' num2str(kk) ' = X_ext;']);
178eval(['x_' num2str(kk) ' = x_ext;']);
179
180
181% Organize the points in a grid:
182
183eval(['n_sq_x_' num2str(kk) ' = n_sq_x;']);
184eval(['n_sq_y_' num2str(kk) ' = n_sq_y;']);
185 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixallvariables.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixallvariables.m
new file mode 100755
index 0000000..b5808f3
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixallvariables.m
@@ -0,0 +1,19 @@
1% Code that clears all empty or NaN variables
2
3varlist = whos;
4
5if ~isempty(varlist),
6
7 Nvar = size(varlist,1);
8
9 for c_var = 1:Nvar,
10
11 var2fix = varlist(c_var).name;
12
13 fixvariable;
14
15 end;
16
17end;
18
19clear varlist var2fix Nvar c_var \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixvariable.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixvariable.m
new file mode 100755
index 0000000..2213431
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/fixvariable.m
@@ -0,0 +1,18 @@
1% Code that clears an empty variable, or a NaN vsriable.
2% Does not clear structures, or cells.
3
4if exist('var2fix'),
5 if eval(['exist(''' var2fix ''') == 1']),
6 if eval(['isempty(' var2fix ')']),
7 eval(['clear ' var2fix ]);
8 else
9 if eval(['~isstruct(' var2fix ')']),
10 if eval(['~iscell(' var2fix ')']),
11 if eval(['isnan(' var2fix '(1))']),
12 eval(['clear ' var2fix ]);
13 end;
14 end;
15 end;
16 end;
17 end;
18end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ginput3.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ginput3.m
new file mode 100755
index 0000000..56fe496
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ginput3.m
@@ -0,0 +1,216 @@
1function [out1,out2,out3] = ginput2(arg1)
2%GINPUT Graphical input from mouse.
3% [X,Y] = GINPUT(N) gets N points from the current axes and returns
4% the X- and Y-coordinates in length N vectors X and Y. The cursor
5% can be positioned using a mouse (or by using the Arrow Keys on some
6% systems). Data points are entered by pressing a mouse button
7% or any key on the keyboard except carriage return, which terminates
8% the input before N points are entered.
9%
10% [X,Y] = GINPUT gathers an unlimited number of points until the
11% return key is pressed.
12%
13% [X,Y,BUTTON] = GINPUT(N) returns a third result, BUTTON, that
14% contains a vector of integers specifying which mouse button was
15% used (1,2,3 from left) or ASCII numbers if a key on the keyboard
16% was used.
17
18% Copyright (c) 1984-96 by The MathWorks, Inc.
19% $Revision: 5.18 $ $Date: 1996/11/10 17:48:08 $
20
21% Fixed version by Jean-Yves Bouguet to have a cross instead of 2 lines
22% More visible for images
23
24P = NaN*ones(16,16);
25P(1:15,1:15) = 2*ones(15,15);
26P(2:14,2:14) = ones(13,13);
27P(3:13,3:13) = NaN*ones(11,11);
28P(6:10,6:10) = 2*ones(5,5);
29P(7:9,7:9) = 1*ones(3,3);
30
31out1 = []; out2 = []; out3 = []; y = [];
32c = computer;
33if ~strcmp(c(1:2),'PC') & ~strcmp(c(1:2),'MA')
34 tp = get(0,'TerminalProtocol');
35else
36 tp = 'micro';
37end
38
39if ~strcmp(tp,'none') & ~strcmp(tp,'x') & ~strcmp(tp,'micro'),
40 if nargout == 1,
41 if nargin == 1,
42 eval('out1 = trmginput(arg1);');
43 else
44 eval('out1 = trmginput;');
45 end
46 elseif nargout == 2 | nargout == 0,
47 if nargin == 1,
48 eval('[out1,out2] = trmginput(arg1);');
49 else
50 eval('[out1,out2] = trmginput;');
51 end
52 if nargout == 0
53 out1 = [ out1 out2 ];
54 end
55 elseif nargout == 3,
56 if nargin == 1,
57 eval('[out1,out2,out3] = trmginput(arg1);');
58 else
59 eval('[out1,out2,out3] = trmginput;');
60 end
61 end
62else
63
64 fig = gcf;
65 figure(gcf);
66
67 if nargin == 0
68 how_many = -1;
69 b = [];
70 else
71 how_many = arg1;
72 b = [];
73 if isstr(how_many) ...
74 | size(how_many,1) ~= 1 | size(how_many,2) ~= 1 ...
75 | ~(fix(how_many) == how_many) ...
76 | how_many < 0
77 error('Requires a positive integer.')
78 end
79 if how_many == 0
80 ptr_fig = 0;
81 while(ptr_fig ~= fig)
82 ptr_fig = get(0,'PointerWindow');
83 end
84 scrn_pt = get(0,'PointerLocation');
85 loc = get(fig,'Position');
86 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
87 out1 = pt(1); y = pt(2);
88 elseif how_many < 0
89 error('Argument must be a positive integer.')
90 end
91 end
92
93pointer = get(gcf,'pointer');
94
95set(gcf,'Pointer','custom','PointerShapeCData',P,'PointerShapeHotSpot',[8,8]);
96%set(gcf,'pointer','crosshair');
97 fig_units = get(fig,'units');
98 char = 0;
99
100 while how_many ~= 0
101 % Use no-side effect WAITFORBUTTONPRESS
102 waserr = 0;
103 eval('keydown = wfbp;', 'waserr = 1;');
104 if(waserr == 1)
105 if(ishandle(fig))
106 set(fig,'pointer',pointer,'units',fig_units);
107 error('Interrupted');
108 else
109 error('Interrupted by figure deletion');
110 end
111 end
112
113 ptr_fig = get(0,'CurrentFigure');
114 if(ptr_fig == fig)
115 if keydown
116 char = get(fig, 'CurrentCharacter');
117 button = abs(get(fig, 'CurrentCharacter'));
118 scrn_pt = get(0, 'PointerLocation');
119 set(fig,'units','pixels')
120 loc = get(fig, 'Position');
121 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
122 set(fig,'CurrentPoint',pt);
123 else
124 button = get(fig, 'SelectionType');
125 if strcmp(button,'open')
126 button = b(length(b));
127 elseif strcmp(button,'normal')
128 button = 1;
129 elseif strcmp(button,'extend')
130 button = 2;
131 elseif strcmp(button,'alt')
132 button = 3;
133 else
134 error('Invalid mouse selection.')
135 end
136 end
137 pt = get(gca, 'CurrentPoint');
138
139 how_many = how_many - 1;
140
141 if(char == 13) % & how_many ~= 0)
142 % if the return key was pressed, char will == 13,
143 % and that's our signal to break out of here whether
144 % or not we have collected all the requested data
145 % points.
146 % If this was an early breakout, don't include
147 % the <Return> key info in the return arrays.
148 % We will no longer count it if it's the last input.
149 break;
150 end
151
152 out1 = [out1;pt(1,1)];
153 y = [y;pt(1,2)];
154 b = [b;button];
155 end
156 end
157
158 set(fig,'pointer',pointer,'units',fig_units);
159
160 if nargout > 1
161 out2 = y;
162 if nargout > 2
163 out3 = b;
164 end
165 else
166 out1 = [out1 y];
167 end
168
169end
170
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172function key = wfbp
173%WFBP Replacement for WAITFORBUTTONPRESS that has no side effects.
174
175% Remove figure button functions
176fprops = {'windowbuttonupfcn','buttondownfcn', ...
177 'windowbuttondownfcn','windowbuttonmotionfcn'};
178fig = gcf;
179fvals = get(fig,fprops);
180set(fig,fprops,{'','','',''})
181
182% Remove all other buttondown functions
183ax = findobj(fig,'type','axes');
184if isempty(ax)
185 ch = {};
186else
187 ch = get(ax,{'Children'});
188end
189for i=1:length(ch),
190 ch{i} = ch{i}(:)';
191end
192h = [ax(:)',ch{:}];
193vals = get(h,{'buttondownfcn'});
194mt = repmat({''},size(vals));
195set(h,{'buttondownfcn'},mt);
196
197% Now wait for that buttonpress, and check for error conditions
198waserr = 0;
199eval(['if nargout==0,', ...
200 ' waitforbuttonpress,', ...
201 'else,', ...
202 ' keydown = waitforbuttonpress;',...
203 'end' ], 'waserr = 1;');
204
205% Put everything back
206if(ishandle(fig))
207 set(fig,fprops,fvals)
208 set(h,{'buttondownfcn'},vals)
209end
210
211if(waserr == 1)
212 error('Interrupted');
213end
214
215if nargout>0, key = keydown; end
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim.m
new file mode 100755
index 0000000..ad19f64
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim.m
@@ -0,0 +1,139 @@
1%go_calib_optim
2%
3%Main calibration function. Computes the intrinsic andextrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% KK: The camera matrix (containing fc and cc)
13% omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
14% Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
15% Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
16%
17%Method: Minimizes the pixel reprojection error in the least squares sense over the intrinsic
18% camera parameters, and the extrinsic parameters (3D locations of the grids in space)
19%
20%Note: If the intrinsic camera parameters (fc, cc, kc) do not exist before, they are initialized through
21% the function init_intrinsic_param.m. Otherwise, the variables in memory are used as initial guesses.
22%
23%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
24% corresponding entry in the active_images vector to zero.
25%
26%VERY IMPORTANT: This function works for 2D and 3D calibration rigs, except for init_intrinsic_param.m
27%that is so far implemented to work only with 2D rigs.
28%In the future, a more general function will be there.
29%For now, if using a 3D calibration rig, set quick_init to 1 for an easy initialization of the focal length
30
31
32if ~exist('n_ima'),
33 data_calib; % Load the images
34 click_calib; % Extract the corners
35end;
36
37
38check_active_images;
39
40check_extracted_images;
41
42check_active_images;
43
44
45desactivated_images = [];
46
47
48if ~exist('center_optim'),
49 center_optim = 1; %%% Set this variable to 0 if your do not want to estimate the principal point
50 %%% Required when using one image, and VERY RECOMMENDED WHEN USING LESS THAN 4 images
51end;
52
53% Check 3D-ness of the calibration rig:
54rig3D = 0;
55for kk = ind_active,
56 eval(['X_kk = X_' num2str(kk) ';']);
57 if is3D(X_kk),
58 rig3D = 1;
59 end;
60end;
61
62
63if center_optim & (length(ind_active) < 2) & ~rig3D,
64 fprintf(1,'\nPrincipal point rejected from the optimization when using one image and planar rig (center_optim = 1).\n');
65 center_optim = 0; %%% when using a single image, please, no principal point estimation!!!
66 est_alpha = 0;
67end;
68
69if ~exist('dont_ask'),
70 dont_ask = 0;
71end;
72
73if center_optim & (length(ind_active) < 5),
74 fprintf(1,'\nThe principal point estimation may be unreliable (using less than 5 images for calibration).\n');
75 if ~dont_ask,
76 quest = input('Are you sure you want to keep the principal point in the optimization process? ([]=yes, other=no) ');
77 center_optim = isempty(quest);
78 end;
79end;
80
81if center_optim,
82 fprintf(1,'\nINFO: To reject the principal point from the optimization, set center_optim = 0 in go_calib_optim.m\n');
83end;
84
85if ~exist('est_alpha'),
86 est_alpha = 0; % by default, do not estimate skew
87end;
88
89if ~center_optim & (est_alpha),
90 fprintf(1,'WARNING: Since there is no principal point estimation, no skew estimation (est_alpha = 0)\n');
91 est_alpha = 0;
92else
93 if ~est_alpha,
94 fprintf(1,'WARNING: Skew not optimized. Check variable est_alpha.\n');
95 alpha_c = 0;
96 else
97 fprintf(1,'WARNING: Skew is optimized. To disable skew estimation, set est_alpha=0.\n');
98 end;
99end;
100
101
102if ~exist('est_dist');
103 est_dist = [1;1;1;1];
104end;
105if ~prod(est_dist),
106 fprintf(1,'\nWARNING: Distortion not fully estimated. Check variable est_dist.\n');
107end;
108
109
110
111
112%%% MAIN OPTIMIZATION CALL!!!!! (look into this function for the details of implementation)
113go_calib_optim_iter;
114
115
116
117if ~isempty(desactivated_images),
118
119 param_list_save = param_list;
120
121 fprintf(1,'\nNew optimization including the images that have been deactivated during the previous optimization.\n');
122 active_images(desactivated_images) = ones(1,length(desactivated_images));
123 desactivated_images = [];
124
125 go_calib_optim_iter;
126
127 if ~isempty(desactivated_images),
128 fprintf(1,['List of images left desactivated: ' num2str(desactivated_images) '\n' ] );
129 end;
130
131 param_list = [param_list_save(:,1:end-1) param_list];
132
133end;
134
135
136%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
137
138%graphout_calib;
139
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim_iter.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim_iter.m
new file mode 100755
index 0000000..e3d22f6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/go_calib_optim_iter.m
@@ -0,0 +1,394 @@
1%go_calib_optim_iter
2%
3%Main calibration function. Computes the intrinsic andextrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% KK: The camera matrix (containing fc and cc)
13% omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
14% Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
15% Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
16%
17%Method: Minimizes the pixel reprojection error in the least squares sense over the intrinsic
18% camera parameters, and the extrinsic parameters (3D locations of the grids in space)
19%
20%Note: If the intrinsic camera parameters (fc, cc, kc) do not exist before, they are initialized through
21% the function init_intrinsic_param.m. Otherwise, the variables in memory are used as initial guesses.
22%
23%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
24% corresponding entry in the active_images vector to zero.
25%
26%VERY IMPORTANT: This function works for 2D and 3D calibration rigs, except for init_intrinsic_param.m
27%that is so far implemented to work only with 2D rigs.
28%In the future, a more general function will be there.
29%For now, if using a 3D calibration rig, quick_init is set to 1 for an easy initialization of the focal length
30
31
32if ~exist('center_optim'),
33 center_optim = 1; %%% Set this variable to 0 if your do not want to estimate the principal point
34end;
35
36if ~exist('est_dist'),
37 est_dist = [1;1;1;1];
38end;
39
40if ~exist('est_alpha'),
41 est_alpha = 0; % by default, do not estimate skew
42end;
43
44
45% Little fix in case of stupid values in the binary variables:
46center_optim = ~~center_optim;
47est_alpha = ~~est_alpha;
48est_dist = ~~est_dist;
49
50
51if ~exist('nx')&~exist('ny'),
52 fprintf(1,'WARNING: No image size (nx,ny) available. Setting nx=640 and ny=480\n');
53 nx = 640;
54 ny = 480;
55end;
56
57
58check_active_images;
59
60
61quick_init = 0; % Set to 1 for using a quick init (necessary when using 3D rigs)
62
63
64if ~center_optim, % In the case where the principal point is not estimated, keep it at the center of the image
65 fprintf(1,'Principal point not optimized (center_optim=0). It is kept at the center of the image.\n');
66 cc = [(nx-1)/2;(ny-1)/2];
67end;
68
69
70if ~prod(est_dist),
71 fprintf(1,'\nDistortion not fully estimated. Check variable est_dist.\n');
72end;
73
74if ~est_alpha,
75 fprintf(1,'Skew not optimized (est_alpha=0).\n');
76 alpha_c = 0;
77end;
78
79
80% Check 3D-ness of the calibration rig:
81rig3D = 0;
82for kk = ind_active,
83 eval(['X_kk = X_' num2str(kk) ';']);
84 if is3D(X_kk),
85 rig3D = 1;
86 end;
87end;
88
89% If the rig is 3D, then no choice: the only valid initialization is manual!
90if rig3D,
91 quick_init = 1;
92end;
93
94
95
96alpha_smooth = 1; % set alpha_smooth = 1; for steepest gradient descent
97
98
99% Conditioning threshold for view rejection
100thresh_cond = 1e6;
101
102
103
104%% Initialization of the intrinsic parameters (if necessary)
105
106if ~exist('cc'),
107 fprintf(1,'Initialization of the principal point at the center of the image.\n');
108 cc = [(nx-1)/2;(ny-1)/2];
109 alpha_smooth = 0.4; % slow convergence
110end;
111
112
113if ~exist('kc'),
114 fprintf(1,'Initialization of the image distortion to zero.\n');
115 kc = zeros(4,1);
116 alpha_smooth = 0.4; % slow convergence
117end;
118
119if ~exist('alpha_c'),
120 fprintf(1,'Initialization of the image skew to zero.\n');
121 alpha_c = 0;
122 alpha_smooth = 0.4; % slow convergence
123end;
124
125if ~exist('fc')& quick_init,
126 FOV_angle = 35; % Initial camera field of view in degrees
127 fprintf(1,['Initialization of the focal length to a FOV of ' num2str(FOV_angle) ' degrees.\n']);
128 fc = (nx/2)/tan(pi*FOV_angle/360) * ones(2,1);
129 alpha_smooth = 0.4; % slow
130end;
131
132
133if ~exist('fc'),
134 % Initialization of the intrinsic parameters:
135 fprintf(1,'Initialization of the intrinsic parameters using the vanishing points of planar patterns.\n')
136 init_intrinsic_param; % The right way to go (if quick_init is not active)!
137 alpha_smooth = 0.4; % slow convergence
138end;
139
140
141if ~prod(est_dist),
142 % If no distortion estimated, set to zero the variables that are not estimated
143 kc = kc .* est_dist;
144end;
145
146
147
148
149
150%% Initialization of the extrinsic parameters for global minimization:
151
152
153init_param = [fc;cc;alpha_c;kc;zeros(6,1)];
154
155
156
157for kk = 1:n_ima,
158
159 if exist(['x_' num2str(kk)]),
160
161 eval(['x_kk = x_' num2str(kk) ';']);
162 eval(['X_kk = X_' num2str(kk) ';']);
163
164 if (isnan(x_kk(1,1))),
165 if active_images(kk),
166 fprintf(1,'Warning: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
167 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
168 end;
169 active_images(kk) = 0;
170 end;
171 if active_images(kk),
172 [omckk,Tckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc,alpha_c);
173 [omckk,Tckk,Rckk,JJ_kk] = compute_extrinsic_refine(omckk,Tckk,x_kk,X_kk,fc,cc,kc,alpha_c,20,thresh_cond);
174 if cond(JJ_kk)> thresh_cond,
175 active_images(kk) = 0;
176 omckk = NaN*ones(3,1);
177 Tckk = NaN*ones(3,1);
178 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
179 desactivated_images = [desactivated_images kk];
180 end;
181 if isnan(omckk(1,1)),
182 %fprintf(1,'\nWarning: Desactivating image %d. Re-activate it later by typing:\nactive_images(%d)=1;\nand re-run optimization\n',[kk kk])
183 active_images(kk) = 0;
184 end;
185 else
186 omckk = NaN*ones(3,1);
187 Tckk = NaN*ones(3,1);
188 end;
189
190 else
191
192 omckk = NaN*ones(3,1);
193 Tckk = NaN*ones(3,1);
194
195 if active_images(kk),
196 fprintf(1,'Warning: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
197 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
198 end;
199
200 active_images(kk) = 0;
201
202 end;
203
204 eval(['omc_' num2str(kk) ' = omckk;']);
205 eval(['Tc_' num2str(kk) ' = Tckk;']);
206
207 init_param = [init_param; omckk ; Tckk];
208
209end;
210
211
212check_active_images;
213
214
215
216%-------------------- Main Optimization:
217
218fprintf(1,'\nMain calibration optimization procedure - Number of images: %d\n',length(ind_active));
219
220
221param = init_param;
222change = 1;
223
224iter = 0;
225
226fprintf(1,'Gradient descent iterations: ');
227
228param_list = param;
229
230MaxIter = 30;
231
232
233while (change > 1e-6)&(iter < MaxIter),
234
235 fprintf(1,'%d...',iter+1);
236
237
238 %% The first step consists of updating the whole vector of knowns (intrinsic + extrinsic of active
239 %% images) through a one step steepest gradient descent.
240
241 JJ = [];
242 ex = [];
243
244 f = param(1:2);
245 c = param(3:4);
246 alpha = param(5);
247 k = param(6:9);
248
249
250 for kk = 1:n_ima,
251
252 if active_images(kk),
253
254 %omckk = param(4+6*(kk-1) + 3:6*kk + 3);
255
256 %Tckk = param(6*kk+1 + 3:6*kk+3 + 3);
257
258 omckk = param(15+6*(kk-1) + 1:15+6*(kk-1) + 3);
259
260 Tckk = param(15+6*(kk-1) + 4:15+6*(kk-1) + 6);
261
262 if isnan(omckk(1)),
263 fprintf(1,'Intrinsic parameters at frame %d do not exist\n',kk);
264 return;
265 end;
266
267 eval(['X_kk = X_' num2str(kk) ';']);
268 eval(['x_kk = x_' num2str(kk) ';']);
269
270 Np = size(X_kk,2);
271
272 JJkk = zeros(2*Np,n_ima * 6 + 15);
273
274 [x,dxdom,dxdT,dxdf,dxdc,dxdk,dxdalpha] = project_points2(X_kk,omckk,Tckk,f,c,k,alpha);
275
276 exkk = x_kk - x;
277
278 ex = [ex;exkk(:)];
279
280 JJkk(:,1:2) = dxdf;
281 JJkk(:,3:4) = dxdc;
282 JJkk(:,5) = dxdalpha;
283 JJkk(:,6:9) = dxdk;
284 JJkk(:,15+6*(kk-1) + 1:15+6*(kk-1) + 3) = dxdom;
285 JJkk(:,15+6*(kk-1) + 4:15+6*(kk-1) + 6) = dxdT;
286
287
288
289 JJ = [JJ;JJkk];
290
291
292 % Check if this view is ill-conditioned:
293 JJ_kk = [dxdom dxdT];
294 if cond(JJ_kk)> thresh_cond,
295 active_images(kk) = 0;
296 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
297 desactivated_images = [desactivated_images kk];
298 param(15+6*(kk-1) + 1:15+6*(kk-1) + 6) = NaN*ones(6,1);
299 end;
300
301
302 end;
303
304 end;
305
306
307 % List of active images (necessary if changed):
308 check_active_images;
309
310
311 % The following vector helps to select the variables to update (for only active images):
312
313 ind_Jac = find([ones(2,1);center_optim*ones(2,1);est_alpha;est_dist;zeros(6,1);reshape(ones(6,1)*active_images,6*n_ima,1)])';
314
315
316 JJ = JJ(:,ind_Jac);
317
318 JJ2 = JJ'*JJ;
319
320
321 % Smoothing coefficient:
322
323 alpha_smooth2 = 1-(1-alpha_smooth)^(iter+1); %set to 1 to undo any smoothing!
324
325
326 param_innov = alpha_smooth2*inv(JJ2)*(JJ')*ex;
327 param_up = param(ind_Jac) + param_innov;
328 param(ind_Jac) = param_up;
329
330
331 % New intrinsic parameters:
332
333 fc_current = param(1:2);
334 cc_current = param(3:4);
335 alpha_current = param(5);
336 kc_current = param(6:9);
337
338
339 % Change on the intrinsic parameters:
340 change = norm([fc_current;cc_current] - [f;c])/norm([fc_current;cc_current]);
341
342
343 %% Second step: (optional) - It makes convergence faster, and the region of convergence LARGER!!!
344 %% Recompute the extrinsic parameters only using compute_extrinsic.m (this may be useful sometimes)
345 %% The complete gradient descent method is useful to precisely update the intrinsic parameters.
346
347 MaxIter2 = 20;
348
349
350 for kk = 1:n_ima,
351 if active_images(kk),
352 omc_current = param(15+6*(kk-1) + 1:15+6*(kk-1) + 3);
353 Tc_current = param(15+6*(kk-1) + 4:15+6*(kk-1) + 6);
354 eval(['X_kk = X_' num2str(kk) ';']);
355 eval(['x_kk = x_' num2str(kk) ';']);
356 [omc_current,Tc_current] = compute_extrinsic_init(x_kk,X_kk,fc_current,cc_current,kc_current,alpha_current);
357 [omckk,Tckk,Rckk,JJ_kk] = compute_extrinsic_refine(omc_current,Tc_current,x_kk,X_kk,fc_current,cc_current,kc_current,alpha_current,MaxIter2,thresh_cond);
358 if cond(JJ_kk)> thresh_cond,
359 active_images(kk) = 0;
360 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
361 desactivated_images = [desactivated_images kk];
362 omckk = NaN*ones(3,1);
363 Tckk = NaN*ones(3,1);
364 end;
365 param(15+6*(kk-1) + 1:15+6*(kk-1) + 3) = omckk;
366 param(15+6*(kk-1) + 4:15+6*(kk-1) + 6) = Tckk;
367 end;
368 end;
369
370 param_list = [param_list param];
371
372 iter = iter + 1;
373
374end;
375
376fprintf(1,'\n');
377
378
379solution = param;
380
381
382%%% Extraction of the final intrinsic and extrinsic paramaters:
383
384extract_parameters;
385
386comp_error_calib;
387
388fprintf(1,'\n\nCalibration results after optimization:\n\n');
389fprintf(1,'Focal Length: fc = [ %3.5f %3.5f ]\n',fc);
390fprintf(1,'Principal point: cc = [ %3.5f %3.5f ]\n',cc);
391fprintf(1,'Skew: alpha_c = [ %3.5f ] => angle of pixel = %3.5f degrees\n',alpha_c,90 - atan(alpha_c)*180/pi);
392fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f ]\n',kc);
393fprintf(1,'Pixel error: err = [ %3.5f %3.5f ]\n\n',err_std);
394
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ima_read_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ima_read_calib.m
new file mode 100755
index 0000000..dbbc4e0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/ima_read_calib.m
@@ -0,0 +1,158 @@
1
2if ~exist('calib_name')|~exist('format_image'),
3 data_calib;
4 return;
5end;
6
7check_directory;
8
9if ~exist('n_ima'),
10 data_calib;
11 return;
12end;
13
14check_active_images;
15
16
17images_read = active_images;
18
19
20if exist('image_numbers'),
21 first_num = image_numbers(1);
22end;
23
24
25% Just to fix a minor bug:
26if ~exist('first_num'),
27 first_num = image_numbers(1);
28end;
29
30
31image_numbers = first_num:n_ima-1+first_num;
32
33no_image_file = 0;
34
35i = 1;
36
37while (i <= n_ima), % & (~no_image_file),
38
39 if active_images(i),
40
41 %fprintf(1,'Loading image %d...\n',i);
42
43 if ~type_numbering,
44 number_ext = num2str(image_numbers(i));
45 else
46 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(i));
47 end;
48
49 ima_name = [calib_name number_ext '.' format_image];
50
51 if i == ind_active(1),
52 fprintf(1,'Loading image ');
53 end;
54
55 if exist(ima_name),
56
57 fprintf(1,'%d...',i);
58
59 if format_image(1) == 'p',
60 if format_image(2) == 'p',
61 Ii = double(loadppm(ima_name));
62 else
63 Ii = double(loadpgm(ima_name));
64 end;
65 else
66 if format_image(1) == 'r',
67 Ii = readras(ima_name);
68 else
69 Ii = double(imread(ima_name));
70 end;
71 end;
72
73
74 if size(Ii,3)>1,
75 Ii = Ii(:,:,2);
76 end;
77
78 eval(['I_' num2str(i) ' = Ii;']);
79
80 else
81
82 fprintf(1,'%d...no image...',i);
83
84 images_read(i) = 0;
85
86 %no_image_file = 1;
87
88 end;
89
90 end;
91
92 i = i+1;
93
94end;
95
96
97ind_read = find(images_read);
98
99
100
101
102if isempty(ind_read),
103
104 fprintf(1,'\nWARNING! No image were read\n');
105
106 no_image_file = 1;
107
108
109else
110
111
112 %fprintf(1,'\nWARNING! Every exsisting image in the directory is set active.\n');
113
114
115 if no_image_file,
116
117 %fprintf(1,'WARNING! Some images were not read properly\n');
118
119 end;
120
121
122 fprintf(1,'\n');
123
124 if size(I_1,1)~=480,
125 small_calib_image = 1;
126 else
127 small_calib_image = 0;
128 end;
129
130 [Hcal,Wcal] = size(I_1); % size of the calibration image
131
132 [ny,nx] = size(I_1);
133
134 clickname = [];
135
136 map = gray(256);
137
138 %string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name Hcal Wcal nx ny map small_calib_image';
139
140 %eval(string_save);
141
142 disp('done');
143 %click_calib;
144
145end;
146
147if ~exist('map'), map = gray(256); end;
148
149active_images = images_read;
150
151% Show all the calibration images:
152
153
154if ~isempty(ind_read),
155
156 mosaic;
157
158end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/init_intrinsic_param.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/init_intrinsic_param.m
new file mode 100755
index 0000000..94a5240
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/init_intrinsic_param.m
@@ -0,0 +1,158 @@
1%init_intrinsic_param
2%
3%Initialization of the intrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% alpha_c: skew coefficient
13% KK: The camera matrix (containing fc, cc and alpha_c)
14%
15%Method: Computes the planar homographies H_1, H_2, H_3, ... and computes
16% the focal length fc from orthogonal vanishing points constraint.
17% The principal point cc is assumed at the center of the image.
18% Assumes no image distortion (kc = [0;0;0;0])
19%
20%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
21% corresponding entry in the active_images vector to zero.
22%
23%
24%Important function called within that program:
25%
26%compute_homography.m: Computes the planar homography between points on the grid in 3D, and the image plane.
27%
28%
29%VERY IMPORTANT: This function works only with 2D rigs.
30%In the future, a more general function will be there (working with 3D rigs as well).
31
32
33
34check_active_images;
35
36if ~exist(['x_' num2str(ind_active(1)) ]),
37 click_calib;
38end;
39
40
41fprintf(1,'\nInitialization of the intrinsic parameters - Number of images: %d\n',length(ind_active));
42
43
44% Initialize the homographies:
45
46for kk = 1:n_ima,
47 eval(['x_kk = x_' num2str(kk) ';']);
48 eval(['X_kk = X_' num2str(kk) ';']);
49 if (isnan(x_kk(1,1))),
50 if active_images(kk),
51 fprintf(1,'WARNING: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
52 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
53 end;
54 active_images(kk) = 0;
55 end;
56 if active_images(kk),
57 eval(['H_' num2str(kk) ' = compute_homography(x_kk,X_kk(1:2,:));']);
58 else
59 eval(['H_' num2str(kk) ' = NaN*ones(3,3);']);
60 end;
61end;
62
63check_active_images;
64
65% initial guess for principal point and distortion:
66
67if ~exist('nx'), [ny,nx] = size(I); end;
68
69c_init = [nx;ny]/2 - 0.5; % initialize at the center of the image
70k_init = [0;0;0;0]; % initialize to zero (no distortion)
71
72
73
74% Compute explicitely the focal length using all the (mutually orthogonal) vanishing points
75% note: The vanihing points are hidden in the planar collineations H_kk
76
77A = [];
78b = [];
79
80% matrix that subtract the principal point:
81Sub_cc = [1 0 -c_init(1);0 1 -c_init(2);0 0 1];
82
83for kk=1:n_ima,
84
85 if active_images(kk),
86
87 eval(['Hkk = H_' num2str(kk) ';']);
88
89 Hkk = Sub_cc * Hkk;
90
91 % Extract vanishing points (direct and diagonals):
92
93 V_hori_pix = Hkk(:,1);
94 V_vert_pix = Hkk(:,2);
95 V_diag1_pix = (Hkk(:,1)+Hkk(:,2))/2;
96 V_diag2_pix = (Hkk(:,1)-Hkk(:,2))/2;
97
98 V_hori_pix = V_hori_pix/norm(V_hori_pix);
99 V_vert_pix = V_vert_pix/norm(V_vert_pix);
100 V_diag1_pix = V_diag1_pix/norm(V_diag1_pix);
101 V_diag2_pix = V_diag2_pix/norm(V_diag2_pix);
102
103 a1 = V_hori_pix(1);
104 b1 = V_hori_pix(2);
105 c1 = V_hori_pix(3);
106
107 a2 = V_vert_pix(1);
108 b2 = V_vert_pix(2);
109 c2 = V_vert_pix(3);
110
111 a3 = V_diag1_pix(1);
112 b3 = V_diag1_pix(2);
113 c3 = V_diag1_pix(3);
114
115 a4 = V_diag2_pix(1);
116 b4 = V_diag2_pix(2);
117 c4 = V_diag2_pix(3);
118
119 A_kk = [a1*a2 b1*b2;
120 a3*a4 b3*b4];
121
122 b_kk = -[c1*c2;c3*c4];
123
124
125 A = [A;A_kk];
126 b = [b;b_kk];
127
128 end;
129
130end;
131
132
133% use all the vanishing points to estimate focal length:
134
135f_init = sqrt(abs(1./(inv(A'*A)*A'*b))); % if using a two-focal model for initial guess
136
137alpha_init = 0;
138
139%f_init = sqrt(b'*(sum(A')') / (b'*b)) * ones(2,1); % if single focal length model is used
140
141
142% Global calibration matrix (initial guess):
143
144KK = [f_init(1) alpha_init*f_init(1) c_init(1);0 f_init(2) c_init(2); 0 0 1];
145inv_KK = inv(KK);
146
147
148cc = c_init;
149fc = f_init;
150kc = k_init;
151alpha_c = alpha_init;
152
153
154fprintf(1,'\n\nCalibration parameters after initialization:\n\n');
155fprintf(1,'Focal Length: fc = [ %3.5f %3.5f ]\n',fc);
156fprintf(1,'Principal point: cc = [ %3.5f %3.5f ]\n',cc);
157fprintf(1,'Skew: alpha_c = [ %3.5f ] => angle of pixel = %3.5f degrees\n',alpha_c,90 - atan(alpha_c)*180/pi);
158fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f ]\n',kc);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/is3D.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/is3D.m
new file mode 100755
index 0000000..ab00b3d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/is3D.m
@@ -0,0 +1,19 @@
1function test = is3D(X),
2
3
4Np = size(X,2);
5
6%% Check for planarity of the structure:
7
8X_mean = mean(X')';
9
10Y = X - (X_mean*ones(1,Np));
11
12YY = Y*Y';
13
14[U,S,V] = svd(YY);
15
16r = S(3,3)/S(2,2);
17
18test = (r > 1e-3);
19
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loading_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loading_calib.m
new file mode 100755
index 0000000..a0f50d2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loading_calib.m
@@ -0,0 +1,10 @@
1if ~exist('Calib_Results.mat'),
2 fprintf(1,'\nCalibration file Calib_Results.mat not found!\n');
3 return;
4end;
5
6fprintf(1,'\nLoading calibration results from Calib_Results.mat\n');
7
8load Calib_Results
9
10fprintf(1,'done\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadinr.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadinr.m
new file mode 100755
index 0000000..91b6f89
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadinr.m
@@ -0,0 +1,52 @@
1%LOADINR Load an INRIMAGE format file
2%
3% LOADINR(filename, im)
4%
5% Load an INRIA image format file and return it as a matrix
6%
7% SEE ALSO: saveinr
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11
12% Peter Corke 1996
13
14function im = loadinr(fname, im)
15
16 fid = fopen(fname, 'r');
17
18 s = fgets(fid);
19 if strcmp(s(1:12), '#INRIMAGE-4#') == 0,
20 error('not INRIMAGE format');
21 end
22
23 % not very complete, only looks for the X/YDIM keys
24 while 1,
25 s = fgets(fid);
26 n = length(s) - 1;
27 if s(1) == '#',
28 break
29 end
30 if strcmp(s(1:5), 'XDIM='),
31 cols = str2num(s(6:n));
32 end
33 if strcmp(s(1:5), 'YDIM='),
34 rows = str2num(s(6:n));
35 end
36 if strcmp(s(1:4), 'CPU='),
37 if strcmp(s(5:n), 'sun') == 0,
38 error('not sun data ordering');
39 end
40 end
41
42 end
43 disp(['INRIMAGE format file ' num2str(rows) ' x ' num2str(cols)])
44
45 % now the binary data
46 fseek(fid, 256, 'bof');
47 [im count] = fread(fid, [cols rows], 'float32');
48 im = im';
49 if count ~= (rows*cols),
50 error('file too short');
51 end
52 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadpgm.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadpgm.m
new file mode 100755
index 0000000..dfa8b61
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadpgm.m
@@ -0,0 +1,89 @@
1%LOADPGM Load a PGM image
2%
3% I = loadpgm(filename)
4%
5% Returns a matrix containing the image loaded from the PGM format
6% file filename. Handles ASCII (P2) and binary (P5) PGM file formats.
7%
8% If the filename has no extension, and open fails, a '.pgm' will
9% be appended.
10%
11%
12% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
13
14
15% Peter Corke 1994
16
17function I = loadpgm(file)
18 white = [' ' 9 10 13]; % space, tab, lf, cr
19 white = setstr(white);
20
21 fid = fopen(file, 'r');
22 if fid < 0,
23 fid = fopen([file '.pgm'], 'r');
24 end
25 if fid < 0,
26 error('Couldn''t open file');
27 end
28
29 magic = fread(fid, 2, 'char');
30 while 1
31 c = fread(fid,1,'char');
32 if c == '#',
33 fgetl(fid);
34 elseif ~any(c == white)
35 fseek(fid, -1, 'cof'); % unputc()
36 break;
37 end
38 end
39 cols = fscanf(fid, '%d', 1);
40 while 1
41 c = fread(fid,1,'char');
42 if c == '#',
43 fgetl(fid);
44 elseif ~any(c == white)
45 fseek(fid, -1, 'cof'); % unputc()
46 break;
47 end
48 end
49 rows = fscanf(fid, '%d', 1);
50 while 1
51 c = fread(fid,1,'char');
52 if c == '#',
53 fgetl(fid);
54 elseif ~any(c == white)
55 fseek(fid, -1, 'cof'); % unputc()
56 break;
57 end
58 end
59 maxval = fscanf(fid, '%d', 1);
60 while 1
61 c = fread(fid,1,'char');
62 if c == '#',
63 fgetl(fid);
64 elseif ~any(c == white)
65 fseek(fid, -1, 'cof'); % unputc()
66 break;
67 end
68 end
69 if magic(1) == 'P',
70 if magic(2) == '2',
71 %disp(['ASCII PGM file ' num2str(rows) ' x ' num2str(cols)])
72 I = fscanf(fid, '%d', [cols rows])';
73 elseif magic(2) == '5',
74 %disp(['Binary PGM file ' num2str(rows) ' x ' num2str(cols)])
75 if maxval == 1,
76 fmt = 'unint1';
77 elseif maxval == 15,
78 fmt = 'uint4';
79 elseif maxval == 255,
80 fmt = 'uint8';
81 elseif maxval == 2^32-1,
82 fmt = 'uint32';
83 end
84 I = fread(fid, [cols rows], fmt)';
85 else
86 disp('Not a PGM file');
87 end
88 end
89 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadppm.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadppm.m
new file mode 100755
index 0000000..0c004fc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/loadppm.m
@@ -0,0 +1,109 @@
1%LOADPPM Load a PPM image
2%
3% I = loadppm(filename)
4%
5% Returns a matrix containing the image loaded from the PPM format
6% file filename. Handles ASCII (P3) and binary (P6) PPM file formats.
7%
8% If the filename has no extension, and open fails, a '.ppm' and
9% '.pnm' extension will be tried.
10%
11% SEE ALSO: saveppm loadpgm
12%
13% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
14
15
16% Peter Corke 1994
17
18function I = loadppm(file)
19 white = [' ' 9 10 13]; % space, tab, lf, cr
20 white = setstr(white);
21
22 fid = fopen(file, 'r');
23 if fid < 0,
24 fid = fopen([file '.ppm'], 'r');
25 end
26 if fid < 0,
27 fid = fopen([file '.pnm'], 'r');
28 end
29 if fid < 0,
30 error('Couldn''t open file');
31 end
32
33 magic = fread(fid, 2, 'char');
34 while 1
35 c = fread(fid,1,'char');
36 if c == '#',
37 fgetl(fid);
38 elseif ~any(c == white)
39 fseek(fid, -1, 'cof'); % unputc()
40 break;
41 end
42 end
43 cols = fscanf(fid, '%d', 1);
44 while 1
45 c = fread(fid,1,'char');
46 if c == '#',
47 fgetl(fid);
48 elseif ~any(c == white)
49 fseek(fid, -1, 'cof'); % unputc()
50 break;
51 end
52 end
53 rows = fscanf(fid, '%d', 1);
54 while 1
55 c = fread(fid,1,'char');
56 if c == '#',
57 fgetl(fid);
58 elseif ~any(c == white)
59 fseek(fid, -1, 'cof'); % unputc()
60 break;
61 end
62 end
63 maxval = fscanf(fid, '%d', 1);
64 while 1
65 c = fread(fid,1,'char');
66 if c == '#',
67 fgetl(fid);
68 elseif ~any(c == white)
69 fseek(fid, -1, 'cof'); % unputc()
70 break;
71 end
72 end
73 if magic(1) == 'P',
74 if magic(2) == '3',
75 %disp(['ASCII PPM file ' num2str(rows) ' x ' num2str(cols)])
76 I = fscanf(fid, '%d', [cols*3 rows]);
77 elseif magic(2) == '6',
78 %disp(['Binary PPM file ' num2str(rows) ' x ' num2str(cols)])
79 if maxval == 1,
80 fmt = 'unint1';
81 elseif maxval == 15,
82 fmt = 'uint4';
83 elseif maxval == 255,
84 fmt = 'uint8';
85 elseif maxval == 2^32-1,
86 fmt = 'uint32';
87 end
88 I = fread(fid, [cols*3 rows], fmt);
89 else
90 disp('Not a PPM file');
91 end
92 end
93 %
94 % now the matrix has interleaved columns of R, G, B
95 %
96 I = I';
97 size(I);
98 R = I(:,1:3:(cols*3));
99 G = I(:,2:3:(cols*3));
100 B = I(:,3:3:(cols*3));
101 fclose(fid);
102
103
104 I = zeros(rows,cols,3);
105 I(:,:,1) = R;
106 I(:,:,2) = G;
107 I(:,:,3) = B;
108 I = uint8(I);
109 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mean_std_robust.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mean_std_robust.m
new file mode 100755
index 0000000..0d18a62
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mean_std_robust.m
@@ -0,0 +1,7 @@
1function [m,s] = mean_std_robust(x);
2
3x = x(:);
4
5m = median(x);
6
7s = median(abs(x - m))*1.4836;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mosaic.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mosaic.m
new file mode 100755
index 0000000..b056661
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/mosaic.m
@@ -0,0 +1,92 @@
1
2if ~exist('I_1'),
3 active_images_save = active_images;
4 ima_read_calib;
5 active_images = active_images_save;
6 check_active_images;
7end;
8
9check_active_images;
10
11if isempty(ind_read),
12 return;
13end;
14
15
16n_col = floor(sqrt(n_ima*nx/ny));
17
18n_row = ceil(n_ima / n_col);
19
20
21ker2 = 1;
22for ii = 1:n_col,
23 ker2 = conv(ker2,[1/4 1/2 1/4]);
24end;
25
26
27II = I_1(1:n_col:end,1:n_col:end);
28
29[ny2,nx2] = size(II);
30
31
32
33kk_c = 1;
34
35II_mosaic = [];
36
37for jj = 1:n_row,
38
39
40 II_row = [];
41
42 for ii = 1:n_col,
43
44 if (exist(['I_' num2str(kk_c)])) & (kk_c <= n_ima),
45
46 if active_images(kk_c),
47 eval(['I = I_' num2str(kk_c) ';']);
48 %I = conv2(conv2(I,ker2,'same'),ker2','same'); % anti-aliasing
49 I = I(1:n_col:end,1:n_col:end);
50 else
51 I = zeros(ny2,nx2);
52 end;
53
54 else
55
56 I = zeros(ny2,nx2);
57
58 end;
59
60
61
62 II_row = [II_row I];
63
64 if ii ~= n_col,
65
66 II_row = [II_row zeros(ny2,3)];
67
68 end;
69
70
71 kk_c = kk_c + 1;
72
73 end;
74
75 nn2 = size(II_row,2);
76
77 if jj ~= n_row,
78 II_row = [II_row; zeros(3,nn2)];
79 end;
80
81 II_mosaic = [II_mosaic ; II_row];
82
83end;
84
85figure(2);
86image(II_mosaic);
87colormap(gray(256));
88title('Calibration images');
89set(gca,'Xtick',[])
90set(gca,'Ytick',[])
91axis('image');
92
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/normalize.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/normalize.m
new file mode 100755
index 0000000..6dc7149
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/normalize.m
@@ -0,0 +1,43 @@
1function [xn] = normalize(x_kk,fc,cc,kc,alpha_c),
2
3%normalize
4%
5%[xn] = normalize(x_kk,fc,cc,kc,alpha_c)
6%
7%Computes the normalized coordinates xn given the pixel coordinates x_kk
8%and the intrinsic camera parameters fc, cc and kc.
9%
10%INPUT: x_kk: Feature locations on the images
11% fc: Camera focal length
12% cc: Principal point coordinates
13% kc: Distortion coefficients
14% alpha_c: Skew coefficient
15%
16%OUTPUT: xn: Normalized feature locations on the image plane (a 2XN matrix)
17%
18%Important functions called within that program:
19%
20%comp_distortion_oulu: undistort pixel coordinates.
21
22if nargin < 5,
23 alpha_c = 0;
24 if nargin < 4;
25 kc = [0;0;0;0];
26 if nargin < 3;
27 cc = [0;0];
28 if nargin < 2,
29 fc = [1;1];
30 end;
31 end;
32 end;
33end;
34
35
36% First subtract principal point, and divide by the focal length:
37temp = (x_kk(2,:) - cc(2))/fc(2);
38x_distort = [(x_kk(1,:) - cc(1))/fc(1) - alpha_c*temp;temp];
39
40
41%Compensate for lens distortion:
42
43xn = comp_distortion_oulu(x_distort,kc);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/pgmread.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/pgmread.m
new file mode 100755
index 0000000..c96ccb7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/pgmread.m
@@ -0,0 +1,26 @@
1function img = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7fid = fopen(filename,'r');
8fscanf(fid, 'P5\n');
9cmt = '#';
10while findstr(cmt, '#'),
11 cmt = fgets(fid);
12 if length(findstr(cmt, '#')) ~= 1,
13 YX = sscanf(cmt, '%d %d');
14 y = YX(1); x = YX(2);
15 end
16end
17
18%fgets(fid);
19
20%img = fscanf(fid,'%d',size);
21%img = img';
22
23img = fread(fid,[y,x],'uint8');
24img = img';
25fclose(fid);
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project2_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project2_oulu.m
new file mode 100755
index 0000000..c5c4a34
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project2_oulu.m
@@ -0,0 +1,53 @@
1function [x] = project2_oulu(X,R,T,f,t,k)
2%PROJECT Subsidiary to calib
3
4% (c) Pietro Perona -- March 24, 1994
5% California Institute of Technology
6% Pasadena, CA
7%
8% Renamed because project exists in matlab 5.2!!!
9% Now uses the more elaborate intrinsic model from Oulu
10
11
12
13[m,n] = size(X);
14
15Y = R*X + T*ones(1,n);
16Z = Y(3,:);
17
18f = f(:); %% make a column vector
19if length(f)==1,
20 f = [f f]';
21end;
22
23x = (Y(1:2,:) ./ (ones(2,1) * Z)) ;
24
25
26radius_2 = x(1,:).^2 + x(2,:).^2;
27
28if length(k) > 1,
29
30 radial_distortion = 1 + ones(2,1) * ((k(1) * radius_2) + (k(2) * radius_2.^2));
31
32 if length(k) < 4,
33
34 delta_x = zeros(2,n);
35
36 else
37
38 delta_x = [2*k(3)*x(1,:).*x(2,:) + k(4)*(radius_2 + 2*x(1,:).^2) ;
39 k(3) * (radius_2 + 2*x(2,:).^2)+2*k(4)*x(1,:).*x(2,:)];
40
41 end;
42
43
44else
45
46 radial_distortion = 1 + ones(2,1) * ((k(1) * radius_2));
47
48 delta_x = zeros(2,n);
49
50end;
51
52
53x = (x .* radial_distortion + delta_x).* (f * ones(1,n)) + t*ones(1,n);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points.m
new file mode 100755
index 0000000..1823490
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points.m
@@ -0,0 +1,276 @@
1function [xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk] = project_points(X,om,T,f,c,k)
2
3%project_points.m
4%
5%[xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk] = project_points(X,om,T,f,c,k)
6%
7%Projects a 3D structure onto the image plane.
8%
9%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
10% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
11% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
12% f: camera focal length in units of horizontal and vertical pixel units (2x1 vector)
13% c: principal point location in pixel units (2x1 vector)
14% k: Distortion coefficients (radial and tangential) (4x1 vector)
15%
16%OUTPUT: xp: Projected pixel coordinates (2xN matrix for N points)
17% dxpdom: Derivative of xp with respect to om ((2N)x3 matrix)
18% dxpdT: Derivative of xp with respect to T ((2N)x3 matrix)
19% dxpdf: Derivative of xp with respect to f ((2N)x2 matrix)
20% dxpdc: Derivative of xp with respect to c ((2N)x2 matrix)
21% dxpdk: Derivative of xp with respect to k ((2N)x4 matrix)
22%
23%Definitions:
24%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
25%The coordinate vector of P in the camera reference frame is: Xc = R*X + T
26%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
27%call x, y and z the 3 coordinates of Xc: x = Xc(1); y = Xc(2); z = Xc(3);
28%The pinehole projection coordinates of P is [a;b] where a=x/z and b=y/z.
29%call r^2 = a^2 + b^2.
30%The distorted point coordinates are: xd = [xx;yy] where:
31%
32%xx = a * (1 + kc(1)*r^2 + kc(2)*r^4) + 2*kc(3)*a*b + kc(4)*(r^2 + 2*a^2);
33%yy = b * (1 + kc(1)*r^2 + kc(2)*r^4) + kc(3)*(r^2 + 2*b^2) + 2*kc(4)*a*b;
34%
35%The left terms correspond to radial distortion, the right terms correspond to tangential distortion
36%
37%Fianlly, convertion into pixel coordinates: The final pixel coordinates vector xp=[xxp;yyp] where:
38%
39%xxp = f(1)*xx + c(1)
40%yyp = f(2)*yy + c(2)
41%
42%
43%NOTE: About 90 percent of the code takes care fo computing the Jacobian matrices
44%
45%
46%Important function called within that program:
47%
48%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
49%
50%rigid_motion.m: Computes the rigid motion transformation of a given structure
51
52
53
54if nargin < 6,
55 k = zeros(4,1);
56 if nargin < 5,
57 c = zeros(2,1);
58 if nargin < 4,
59 f = ones(2,1);
60 if nargin < 3,
61 T = zeros(3,1);
62 if nargin < 2,
63 om = zeros(3,1);
64 if nargin < 1,
65 error('Need at least a 3D structure to project (in project_points.m)');
66 return;
67 end;
68 end;
69 end;
70 end;
71 end;
72end;
73
74
75[m,n] = size(X);
76
77[Y,dYdom,dYdT] = rigid_motion(X,om,T);
78
79
80inv_Z = 1./Y(3,:);
81
82x = (Y(1:2,:) .* (ones(2,1) * inv_Z)) ;
83
84
85bb = (-x(1,:) .* inv_Z)'*ones(1,3);
86cc = (-x(2,:) .* inv_Z)'*ones(1,3);
87
88
89dxdom = zeros(2*n,3);
90dxdom(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(1:3:end,:) + bb .* dYdom(3:3:end,:);
91dxdom(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(2:3:end,:) + cc .* dYdom(3:3:end,:);
92
93dxdT = zeros(2*n,3);
94dxdT(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(1:3:end,:) + bb .* dYdT(3:3:end,:);
95dxdT(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(2:3:end,:) + cc .* dYdT(3:3:end,:);
96
97
98% Add distortion:
99
100r2 = x(1,:).^2 + x(2,:).^2;
101
102
103
104dr2dom = 2*((x(1,:)')*ones(1,3)) .* dxdom(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdom(2:2:end,:);
105dr2dT = 2*((x(1,:)')*ones(1,3)) .* dxdT(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdT(2:2:end,:);
106
107
108r4 = r2.^2;
109
110dr4dom = 2*((r2')*ones(1,3)) .* dr2dom;
111dr4dT = 2*((r2')*ones(1,3)) .* dr2dT;
112
113
114% Radial distortion:
115
116cdist = 1 + k(1) * r2 + k(2) * r4;
117
118dcdistdom = k(1) * dr2dom + k(2) * dr4dom;
119dcdistdT = k(1) * dr2dT+ k(2) * dr4dT;
120dcdistdk = [ r2' r4' zeros(n,2)];
121
122
123xd1 = x .* (ones(2,1)*cdist);
124
125dxd1dom = zeros(2*n,3);
126dxd1dom(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdom;
127dxd1dom(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdom;
128coeff = (reshape([cdist;cdist],2*n,1)*ones(1,3));
129dxd1dom = dxd1dom + coeff.* dxdom;
130
131dxd1dT = zeros(2*n,3);
132dxd1dT(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdT;
133dxd1dT(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdT;
134dxd1dT = dxd1dT + coeff.* dxdT;
135
136dxd1dk = zeros(2*n,4);
137dxd1dk(1:2:end,:) = (x(1,:)'*ones(1,4)) .* dcdistdk;
138dxd1dk(2:2:end,:) = (x(2,:)'*ones(1,4)) .* dcdistdk;
139
140
141
142% tangential distortion:
143
144a1 = 2.*x(1,:).*x(2,:);
145a2 = r2 + 2*x(1,:).^2;
146a3 = r2 + 2*x(2,:).^2;
147
148delta_x = [k(3)*a1 + k(4)*a2 ;
149 k(3) * a3 + k(4)*a1];
150
151
152ddelta_xdx = zeros(2*n,2*n);
153aa = (2*k(3)*x(2,:)+6*k(4)*x(1,:))'*ones(1,3);
154bb = (2*k(3)*x(1,:)+2*k(4)*x(2,:))'*ones(1,3);
155cc = (6*k(3)*x(2,:)+2*k(4)*x(1,:))'*ones(1,3);
156
157ddelta_xdom = zeros(2*n,3);
158ddelta_xdom(1:2:end,:) = aa .* dxdom(1:2:end,:) + bb .* dxdom(2:2:end,:);
159ddelta_xdom(2:2:end,:) = bb .* dxdom(1:2:end,:) + cc .* dxdom(2:2:end,:);
160
161ddelta_xdT = zeros(2*n,3);
162ddelta_xdT(1:2:end,:) = aa .* dxdT(1:2:end,:) + bb .* dxdT(2:2:end,:);
163ddelta_xdT(2:2:end,:) = bb .* dxdT(1:2:end,:) + cc .* dxdT(2:2:end,:);
164
165ddelta_xdk = zeros(2*n,4);
166ddelta_xdk(1:2:end,3) = a1';
167ddelta_xdk(1:2:end,4) = a2';
168ddelta_xdk(2:2:end,3) = a3';
169ddelta_xdk(2:2:end,4) = a1';
170
171
172
173xd2 = xd1 + delta_x;
174
175dxd2dom = dxd1dom + ddelta_xdom ;
176dxd2dT = dxd1dT + ddelta_xdT;
177dxd2dk = dxd1dk + ddelta_xdk ;
178
179
180% Pixel coordinates:
181
182xp = xd2 .* (f * ones(1,n)) + c*ones(1,n);
183
184coeff = reshape(f*ones(1,n),2*n,1);
185
186dxpdom = (coeff*ones(1,3)) .* dxd2dom;
187dxpdT = (coeff*ones(1,3)) .* dxd2dT;
188dxpdk = (coeff*ones(1,4)) .* dxd2dk;
189
190dxpdf = zeros(2*n,2);
191dxpdf(1:2:end,1) = xd2(1,:)';
192dxpdf(2:2:end,2) = xd2(2,:)';
193
194dxpdc = zeros(2*n,2);
195dxpdc(1:2:end,1) = ones(n,1);
196dxpdc(2:2:end,2) = ones(n,1);
197
198
199return;
200
201% Test of the Jacobians:
202
203n = 10;
204
205X = 10*randn(3,n);
206om = randn(3,1);
207T = [10*randn(2,1);40];
208f = 1000*rand(2,1);
209c = 1000*randn(2,1);
210k = 0.5*randn(4,1);
211
212
213[x,dxdom,dxdT,dxdf,dxdc,dxdk] = project_points(X,om,T,f,c,k);
214
215
216% Test on om: NOT OK
217
218dom = 0.000000001 * norm(om)*randn(3,1);
219om2 = om + dom;
220
221[x2] = project_points(X,om2,T,f,c,k);
222
223x_pred = x + reshape(dxdom * dom,2,n);
224
225
226norm(x2-x)/norm(x2 - x_pred)
227
228
229% Test on T: OK!!
230
231dT = 0.0001 * norm(T)*randn(3,1);
232T2 = T + dT;
233
234[x2] = project_points(X,om,T2,f,c,k);
235
236x_pred = x + reshape(dxdT * dT,2,n);
237
238
239norm(x2-x)/norm(x2 - x_pred)
240
241
242
243% Test on f: OK!!
244
245df = 0.001 * norm(f)*randn(2,1);
246f2 = f + df;
247
248[x2] = project_points(X,om,T,f2,c,k);
249
250x_pred = x + reshape(dxdf * df,2,n);
251
252
253norm(x2-x)/norm(x2 - x_pred)
254
255
256% Test on c: OK!!
257
258dc = 0.01 * norm(c)*randn(2,1);
259c2 = c + dc;
260
261[x2] = project_points(X,om,T,f,c2,k);
262
263x_pred = x + reshape(dxdc * dc,2,n);
264
265norm(x2-x)/norm(x2 - x_pred)
266
267% Test on k: OK!!
268
269dk = 0.001 * norm(4)*randn(4,1);
270k2 = k + dk;
271
272[x2] = project_points(X,om,T,f,c,k2);
273
274x_pred = x + reshape(dxdk * dk,2,n);
275
276norm(x2-x)/norm(x2 - x_pred)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points2.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points2.m
new file mode 100755
index 0000000..5bb1b91
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/project_points2.m
@@ -0,0 +1,312 @@
1function [xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk,dxpdalpha] = project_points2(X,om,T,f,c,k,alpha)
2
3%project_points.m
4%
5%[xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk] = project_points2(X,om,T,f,c,k,alpha)
6%
7%Projects a 3D structure onto the image plane.
8%
9%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
10% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
11% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
12% f: camera focal length in units of horizontal and vertical pixel units (2x1 vector)
13% c: principal point location in pixel units (2x1 vector)
14% k: Distortion coefficients (radial and tangential) (4x1 vector)
15% alpha: Skew coefficient between x and y pixel (alpha = 0 <=> square pixels)
16%
17%OUTPUT: xp: Projected pixel coordinates (2xN matrix for N points)
18% dxpdom: Derivative of xp with respect to om ((2N)x3 matrix)
19% dxpdT: Derivative of xp with respect to T ((2N)x3 matrix)
20% dxpdf: Derivative of xp with respect to f ((2N)x2 matrix)
21% dxpdc: Derivative of xp with respect to c ((2N)x2 matrix)
22% dxpdk: Derivative of xp with respect to k ((2N)x4 matrix)
23%
24%Definitions:
25%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
26%The coordinate vector of P in the camera reference frame is: Xc = R*X + T
27%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
28%call x, y and z the 3 coordinates of Xc: x = Xc(1); y = Xc(2); z = Xc(3);
29%The pinehole projection coordinates of P is [a;b] where a=x/z and b=y/z.
30%call r^2 = a^2 + b^2.
31%The distorted point coordinates are: xd = [xx;yy] where:
32%
33%xx = a * (1 + kc(1)*r^2 + kc(2)*r^4) + 2*kc(3)*a*b + kc(4)*(r^2 + 2*a^2);
34%yy = b * (1 + kc(1)*r^2 + kc(2)*r^4) + kc(3)*(r^2 + 2*b^2) + 2*kc(4)*a*b;
35%
36%The left terms correspond to radial distortion, the right terms correspond to tangential distortion
37%
38%Finally, convertion into pixel coordinates: The final pixel coordinates vector xp=[xxp;yyp] where:
39%
40%xxp = f(1)*(xx + alpha*yy) + c(1)
41%yyp = f(2)*yy + c(2)
42%
43%
44%NOTE: About 90 percent of the code takes care fo computing the Jacobian matrices
45%
46%
47%Important function called within that program:
48%
49%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
50%
51%rigid_motion.m: Computes the rigid motion transformation of a given structure
52
53
54if nargin < 7,
55 alpha = 0;
56 if nargin < 6,
57 k = zeros(4,1);
58 if nargin < 5,
59 c = zeros(2,1);
60 if nargin < 4,
61 f = ones(2,1);
62 if nargin < 3,
63 T = zeros(3,1);
64 if nargin < 2,
65 om = zeros(3,1);
66 if nargin < 1,
67 error('Need at least a 3D structure to project (in project_points.m)');
68 return;
69 end;
70 end;
71 end;
72 end;
73 end;
74 end;
75end;
76
77
78[m,n] = size(X);
79
80[Y,dYdom,dYdT] = rigid_motion(X,om,T);
81
82
83inv_Z = 1./Y(3,:);
84
85x = (Y(1:2,:) .* (ones(2,1) * inv_Z)) ;
86
87
88bb = (-x(1,:) .* inv_Z)'*ones(1,3);
89cc = (-x(2,:) .* inv_Z)'*ones(1,3);
90
91
92dxdom = zeros(2*n,3);
93dxdom(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(1:3:end,:) + bb .* dYdom(3:3:end,:);
94dxdom(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(2:3:end,:) + cc .* dYdom(3:3:end,:);
95
96dxdT = zeros(2*n,3);
97dxdT(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(1:3:end,:) + bb .* dYdT(3:3:end,:);
98dxdT(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(2:3:end,:) + cc .* dYdT(3:3:end,:);
99
100
101% Add distortion:
102
103r2 = x(1,:).^2 + x(2,:).^2;
104
105
106
107dr2dom = 2*((x(1,:)')*ones(1,3)) .* dxdom(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdom(2:2:end,:);
108dr2dT = 2*((x(1,:)')*ones(1,3)) .* dxdT(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdT(2:2:end,:);
109
110
111r4 = r2.^2;
112
113dr4dom = 2*((r2')*ones(1,3)) .* dr2dom;
114dr4dT = 2*((r2')*ones(1,3)) .* dr2dT;
115
116
117% Radial distortion:
118
119cdist = 1 + k(1) * r2 + k(2) * r4;
120
121dcdistdom = k(1) * dr2dom + k(2) * dr4dom;
122dcdistdT = k(1) * dr2dT+ k(2) * dr4dT;
123dcdistdk = [ r2' r4' zeros(n,2)];
124
125
126xd1 = x .* (ones(2,1)*cdist);
127
128dxd1dom = zeros(2*n,3);
129dxd1dom(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdom;
130dxd1dom(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdom;
131coeff = (reshape([cdist;cdist],2*n,1)*ones(1,3));
132dxd1dom = dxd1dom + coeff.* dxdom;
133
134dxd1dT = zeros(2*n,3);
135dxd1dT(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdT;
136dxd1dT(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdT;
137dxd1dT = dxd1dT + coeff.* dxdT;
138
139dxd1dk = zeros(2*n,4);
140dxd1dk(1:2:end,:) = (x(1,:)'*ones(1,4)) .* dcdistdk;
141dxd1dk(2:2:end,:) = (x(2,:)'*ones(1,4)) .* dcdistdk;
142
143
144
145% tangential distortion:
146
147a1 = 2.*x(1,:).*x(2,:);
148a2 = r2 + 2*x(1,:).^2;
149a3 = r2 + 2*x(2,:).^2;
150
151delta_x = [k(3)*a1 + k(4)*a2 ;
152 k(3) * a3 + k(4)*a1];
153
154
155ddelta_xdx = zeros(2*n,2*n);
156aa = (2*k(3)*x(2,:)+6*k(4)*x(1,:))'*ones(1,3);
157bb = (2*k(3)*x(1,:)+2*k(4)*x(2,:))'*ones(1,3);
158cc = (6*k(3)*x(2,:)+2*k(4)*x(1,:))'*ones(1,3);
159
160ddelta_xdom = zeros(2*n,3);
161ddelta_xdom(1:2:end,:) = aa .* dxdom(1:2:end,:) + bb .* dxdom(2:2:end,:);
162ddelta_xdom(2:2:end,:) = bb .* dxdom(1:2:end,:) + cc .* dxdom(2:2:end,:);
163
164ddelta_xdT = zeros(2*n,3);
165ddelta_xdT(1:2:end,:) = aa .* dxdT(1:2:end,:) + bb .* dxdT(2:2:end,:);
166ddelta_xdT(2:2:end,:) = bb .* dxdT(1:2:end,:) + cc .* dxdT(2:2:end,:);
167
168ddelta_xdk = zeros(2*n,4);
169ddelta_xdk(1:2:end,3) = a1';
170ddelta_xdk(1:2:end,4) = a2';
171ddelta_xdk(2:2:end,3) = a3';
172ddelta_xdk(2:2:end,4) = a1';
173
174
175
176xd2 = xd1 + delta_x;
177
178dxd2dom = dxd1dom + ddelta_xdom ;
179dxd2dT = dxd1dT + ddelta_xdT;
180dxd2dk = dxd1dk + ddelta_xdk ;
181
182
183% Add Skew:
184
185xd3 = [xd2(1,:) + alpha*xd2(2,:);xd2(2,:)];
186
187% Compute: dxd3dom, dxd3dT, dxd3dk, dxd3dalpha
188
189dxd3dom = zeros(2*n,3);
190dxd3dom(1:2:2*n,:) = dxd2dom(1:2:2*n,:) + alpha*dxd2dom(2:2:2*n,:);
191dxd3dom(2:2:2*n,:) = dxd2dom(2:2:2*n,:);
192dxd3dT = zeros(2*n,3);
193dxd3dT(1:2:2*n,:) = dxd2dT(1:2:2*n,:) + alpha*dxd2dT(2:2:2*n,:);
194dxd3dT(2:2:2*n,:) = dxd2dT(2:2:2*n,:);
195dxd3dk = zeros(2*n,4);
196dxd3dk(1:2:2*n,:) = dxd2dk(1:2:2*n,:) + alpha*dxd2dk(2:2:2*n,:);
197dxd3dk(2:2:2*n,:) = dxd2dk(2:2:2*n,:);
198dxd3dalpha = zeros(2*n,1);
199dxd3dalpha(1:2:2*n,:) = xd2(2,:)';
200
201
202
203% Pixel coordinates:
204
205xp = xd3 .* (f * ones(1,n)) + c*ones(1,n);
206
207coeff = reshape(f*ones(1,n),2*n,1);
208
209dxpdom = (coeff*ones(1,3)) .* dxd3dom;
210dxpdT = (coeff*ones(1,3)) .* dxd3dT;
211dxpdk = (coeff*ones(1,4)) .* dxd3dk;
212dxpdalpha = (coeff) .* dxd3dalpha;
213
214dxpdf = zeros(2*n,2);
215dxpdf(1:2:end,1) = xd2(1,:)';
216dxpdf(2:2:end,2) = xd2(2,:)';
217
218dxpdc = zeros(2*n,2);
219dxpdc(1:2:end,1) = ones(n,1);
220dxpdc(2:2:end,2) = ones(n,1);
221
222
223return;
224
225% Test of the Jacobians:
226
227n = 10;
228
229X = 10*randn(3,n);
230om = randn(3,1);
231T = [10*randn(2,1);40];
232f = 1000*rand(2,1);
233c = 1000*randn(2,1);
234k = 0.5*randn(4,1);
235alpha = 0.01*randn(1,1);
236
237[x,dxdom,dxdT,dxdf,dxdc,dxdk,dxdalpha] = project_points2(X,om,T,f,c,k,alpha);
238
239
240% Test on om: NOT OK
241
242dom = 0.000000001 * norm(om)*randn(3,1);
243om2 = om + dom;
244
245[x2] = project_points2(X,om2,T,f,c,k,alpha);
246
247x_pred = x + reshape(dxdom * dom,2,n);
248
249
250norm(x2-x)/norm(x2 - x_pred)
251
252
253% Test on T: OK!!
254
255dT = 0.0001 * norm(T)*randn(3,1);
256T2 = T + dT;
257
258[x2] = project_points2(X,om,T2,f,c,k,alpha);
259
260x_pred = x + reshape(dxdT * dT,2,n);
261
262
263norm(x2-x)/norm(x2 - x_pred)
264
265
266
267% Test on f: OK!!
268
269df = 0.001 * norm(f)*randn(2,1);
270f2 = f + df;
271
272[x2] = project_points2(X,om,T,f2,c,k,alpha);
273
274x_pred = x + reshape(dxdf * df,2,n);
275
276
277norm(x2-x)/norm(x2 - x_pred)
278
279
280% Test on c: OK!!
281
282dc = 0.01 * norm(c)*randn(2,1);
283c2 = c + dc;
284
285[x2] = project_points2(X,om,T,f,c2,k,alpha);
286
287x_pred = x + reshape(dxdc * dc,2,n);
288
289norm(x2-x)/norm(x2 - x_pred)
290
291% Test on k: OK!!
292
293dk = 0.001 * norm(k)*randn(4,1);
294k2 = k + dk;
295
296[x2] = project_points2(X,om,T,f,c,k2,alpha);
297
298x_pred = x + reshape(dxdk * dk,2,n);
299
300norm(x2-x)/norm(x2 - x_pred)
301
302
303% Test on alpha: OK!!
304
305dalpha = 0.001 * norm(k)*randn(1,1);
306alpha2 = alpha + dalpha;
307
308[x2] = project_points2(X,om,T,f,c,k,alpha2);
309
310x_pred = x + reshape(dxdalpha * dalpha,2,n);
311
312norm(x2-x)/norm(x2 - x_pred)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projectedGrid.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projectedGrid.m
new file mode 100755
index 0000000..561a7d0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projectedGrid.m
@@ -0,0 +1,24 @@
1function [XX,H] = projectedGrid ( P1, P2, P3, P4 , nx, ny);
2
3% new formalism using homographies
4
5a00 = [P1;1];
6a10 = [P2;1];
7a11 = [P3;1];
8a01 = [P4;1];
9
10% Compute the planart collineation:
11
12[H] = compute_collineation (a00, a10, a11, a01);
13
14
15% Build the grid using the planar collineation:
16
17x_l = ((0:(nx-1))'*ones(1,ny))/(nx-1);
18y_l = (ones(nx,1)*(0:(ny-1)))/(ny-1);
19
20pts = [x_l(:) y_l(:) ones(nx*ny,1)]';
21
22XX = H*pts;
23
24XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projector_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projector_calib.m
new file mode 100755
index 0000000..bb4ef86
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/projector_calib.m
@@ -0,0 +1,258 @@
1%%% This code is an additional code that helps doing projector calibration in 3D scanning setup.
2%%% This is not a useful code for anyone else but me.
3%%% I included it in the toolbox for illustration only.
4
5
6load camera_results;
7
8
9proj_name = input('Basename projector calibration images (without number nor suffix): ','s');
10
11
12i = 1;
13
14while (i <= n_ima), % & (~no_image_file),
15
16 if active_images(i),
17
18 %fprintf(1,'Loading image %d...\n',i);
19
20 if ~type_numbering,
21 number_ext = num2str(image_numbers(i));
22 else
23 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(i));
24 end;
25
26 ima_namep = [proj_name number_ext 'p.' format_image];
27 ima_namen = [proj_name number_ext 'n.' format_image];
28
29 if i == ind_active(1),
30 fprintf(1,'Loading image ');
31 end;
32
33 fprintf(1,'%d...',i);
34
35 if format_image(1) == 'p',
36 if format_image(2) == 'p',
37 Ip = double(loadppm(ima_namep));
38 In = double(loadppm(ima_namen));
39 else
40 Ip = double(loadpgm(ima_namep));
41 In = double(loadpgm(ima_namen));
42 end;
43 else
44 if format_image(1) == 'r',
45 Ip = readras(ima_namep);
46 In = readras(ima_namen);
47 else
48 Ip = double(imread(ima_namep));
49 In = double(imread(ima_namen));
50 end;
51 end;
52
53
54 if size(Ip,3)>1,
55 Ip = Ip(:,:,2);
56 In = In(:,:,2);
57 end;
58
59 eval(['Ip_' num2str(i) ' = Ip;']);
60 eval(['In_' num2str(i) ' = In;']);
61
62 end;
63
64 i = i+1;
65
66end;
67
68
69fprintf(1,'\nExtraction of the grid corners on the image\n');
70
71disp('Window size for corner finder (wintx and winty):');
72wintx = input('wintx ([] = 5) = ');
73if isempty(wintx), wintx = 5; end;
74wintx = round(wintx);
75winty = input('winty ([] = 5) = ');
76if isempty(winty), winty = 5; end;
77winty = round(winty);
78fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
79
80
81disp('The projector you are using is the DLP or Intel');
82nx = 800;
83ny = 600;
84
85dX = input('Size dX in x of the squares (in pixels) [50] = ');
86dY = input('Size dY in y of the squares (in pixels) [50] = ');
87
88if isempty(dX), dX=50; end;
89if isempty(dY), dY=50; end;
90
91dXoff = input('Position in x of your reference (in pixels) [399.5] = ');
92dYoff = input('Position in y of your reference (in pixels) [299.5] = ');
93
94if isempty(dXoff), dXoff=399.5; end;
95if isempty(dYoff), dYoff=299.5; end;
96
97end;
98
99
100
101for kk = ind_active,
102
103 eval(['Ip = Ip_' num2str(kk) ';']);
104 eval(['In = In_' num2str(kk) ';']);
105
106 [x,X,n_sq_x,n_sq_y,ind_orig,ind_x,ind_y] = extract_grid(In,wintx,winty,fc,cc,kc,dX,dY);
107 xproj = x;
108
109 Np_proj = size(x,2);
110
111 figure(2);
112 image(Ip);
113 hold on;
114 plot(xproj(1,:)+1,xproj(2,:)+1,'r+');
115 title('Click on your reference point');
116 xlabel('Xc (in camera frame)');
117 ylabel('Yc (in camera frame)');
118 hold off;
119
120 disp('Click on your reference point...');
121
122 [xr,yr] = ginput2(1);
123
124 err = sqrt(sum((xproj - [xr;yr]*ones(1,Np_proj)).^2));
125 ind_ref = find(err == min(err));
126
127 ref_pt = xproj(:,ind_ref);
128
129
130 figure(2);
131 hold on;
132 plot(ref_pt(1)+1,ref_pt(2)+1,'go'); hold off;
133
134
135 nn = floor(ind_ref/(n_sq_x+1));
136 off_x = ind_ref - nn*(n_sq_x+1) - 1;
137 off_y = n_sq_y - nn;
138
139
140 xprojn = xproj - cc * ones(1,Np_proj);
141 xprojn = xprojn ./ (fc * ones(1,Np_proj));
142 xprojn = comp_distortion(xprojn,kc);
143
144 eval(['Rc = Rc_' num2str(kk) ';']);
145 eval(['Tc = Tc_' num2str(kk) ';']);
146
147 Zc = ((Rc(:,3)'*Tc) * (1./(Rc(:,3)' * [xprojn; ones(1,Np_proj)])));
148 Xcp = (ones(3,1)*Zc) .* [xprojn; ones(1,Np_proj)]; % % in the camera frame
149 %Xproj = Rc'* Xcp - (Rc'*Tc)*ones(1,Np); % in the object frame !!! it works!
150 %Xproj(3,:) = zeros(1,Np);
151
152 eval(['X_proj_' num2str(kk) ' = Xcp;']); % coordinates of the points in the
153
154 x_proj = X(1:2,:) + ([dXoff - dX * off_x ; dYoff - dY * off_y]*ones(1,Np_proj));
155
156 eval(['x_proj_' num2str(kk) ' = x_proj;']); % coordinates of the points in the
157
158end;
159
160
161
162X_proj = [];
163x_proj = [];
164
165for kk = ind_active,
166 eval(['X_proj = [X_proj X_proj_' num2str(kk) '];']);
167 eval(['x_proj = [x_proj x_proj_' num2str(kk) '];']);
168end;
169
170
171%Save camera parameters:
172fc_save = fc;
173cc_save = cc;
174kc_save = kc;
175
176omc_1_save = omc_1;
177Rc_1_save = Rc_1;
178Tc_1_save = Tc_1;
179
180
181% Get started to calibrate projector:
182clear fc cc kc
183
184n_ima = 1;
185X_1 = X_proj;
186x_1 = x_proj;
187
188
189% Image size: (may or may not be available)
190
191nx = 800;
192ny = 600;
193
194% No calibration image is available (only the corner coordinates)
195
196no_image = 1;
197
198% Set the toolbox not to prompt the user (choose default values)
199
200dont_ask = 1;
201
202% Do not estimate distortion:
203
204est_dist = [0;0;0;0];
205est_dist = ones(4,1);
206
207center_optim = 1;
208
209% Run the main calibration routine:
210
211go_calib_optim_iter;
212
213% Shows the extrinsic parameters:
214
215dX = 3;
216dY = 3;
217
218ext_calib;
219
220% Reprojection on the original images:
221
222reproject_calib;
223
224
225
226
227%----------------------- Retrieve results:
228
229% Intrinsic:
230
231% Projector:
232fp = fc;
233cp = cc;
234kp = kc;
235
236% Camera:
237fc = fc_save;
238cc = cc_save;
239kc = kc_save;
240
241% Extrinsic:
242
243% Relative position of projector and camera:
244T = Tc_1;
245om = omc_1;
246R = rodrigues(om);
247
248% Relative prosition of camera wrt world:
249omc = omc_1_save;
250Rc = Rc_1_save;
251Tc = Tc_1_save;
252
253% relative position of projector wrt world:
254Rp = R*Rc;
255omp = rodrigues(Rp);
256Tp = T + R*Tc;
257
258eval(['save calib_cam_proj R om T fc fp cc cp kc kp Rc Rp Tc Tp']);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/readras.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/readras.m
new file mode 100755
index 0000000..fc1820b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/readras.m
@@ -0,0 +1,87 @@
1function [X, map] = readras(filename, ys, ye, xs, xe);
2%READRAS Read an image file in sun raster format.
3% READRAS('imagefile.ras') reads a "sun.raster" image file.
4% [X, map] = READRAS('imagefile.ras') returns both the image and a
5% color map, so that
6% [X, map] = readras('imagefile.ras');
7% image(X)
8% colormap(map)
9% axis('equal')
10% will display the result with the proper colors.
11% NOTE: readras cannot deal with complicated color maps.
12% In fact, Matlab doesn't quite allow to work with colormaps
13% with more than 64 entries.
14%
15
16%%
17%% (C) Thomas K. Leung 3/30/93.
18%% California Institute of Technology.
19%% Modified by Andrea Mennucci to deal with color images
20%%
21
22% PC and UNIX version of readras - Jean-Yves Bouguet - Dec. 1998
23
24dot = max(find(filename == '.'));
25suffix = filename(dot+1:dot+3);
26
27if(strcmp(suffix, 'ras')) % raster file format %
28 fp = fopen(filename, 'rb');
29 if(fp<0) error(['Cannot open ' filename '.']), end
30
31 %Read and crack the 32-byte header
32 fseek(fp, 4, -1);
33
34 width = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
35
36 height = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
37
38 depth = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
39
40 length = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
41
42 type = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
43
44 maptype = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
45
46 maplen = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
47
48 maplen = maplen / 3;
49
50 if maptype == 2 % RMT_RAW
51 map = fread(fp, [maplen, 3], 'uchar')/255;
52% if maplen<64, map=[map',zeros(3,64-maplen)]';maplen=64; end;
53 elseif maptype == 1 % RMT_EQUAL_RGB
54 map(:,1) = fread(fp, [maplen], 'uchar');
55 map(:,2) = fread(fp, [maplen], 'uchar');
56 map(:,3) = fread(fp, [maplen], 'uchar');
57 %maxmap = max(max(map));
58 map = map/255;
59 if maplen<64, map=[map',zeros(3,64-maplen)]'; maplen=64; end;
60 else % RMT_NONE
61 map = [];
62 end
63% if maplen>64,
64% map=[map',zeros(3,256-maplen)]';
65% end;
66
67 % Read the image
68
69 if rem(width,2) == 1
70 Xt = fread(fp, [width+1, height], 'uchar');
71 X = Xt(1:width, :)';
72 else
73 Xt = fread(fp, [width, height], 'uchar');
74 X = Xt';
75 end
76 X = X + 1;
77 fclose(fp);
78else
79 error('Image file name must end in either ''ras'' or ''rast''.');
80end
81
82
83if nargin == 5
84
85 X = X(ys:ye, xs:xe);
86
87end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/recomp_corner_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/recomp_corner_calib.m
new file mode 100755
index 0000000..0909c69
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/recomp_corner_calib.m
@@ -0,0 +1,119 @@
1% Re-select te corners after calibration
2
3if ~exist('n_ima')|~exist('fc'),
4 fprintf(1,'No calibration data available.\n');
5 return;
6end;
7
8check_active_images;
9
10flag = 0;
11for kk = ind_active,
12 if ~exist(['y_' num2str(kk)]),
13 flag = 1;
14 else
15 eval(['ykk = y_' num2str(kk) ';']);
16 if isnan(ykk(1,1)),
17 flag = 1;
18 end;
19 end;
20end;
21
22if flag,
23 fprintf(1,'Need to calibrate once before before recomputing image corners. Maybe need to load Calib_Results.mat file.\n');
24 return;
25end;
26
27
28if ~exist(['I_' num2str(ind_active(1))]),
29 n_ima_save = n_ima;
30 active_images_save = active_images;
31 ima_read_calib;
32 n_ima = n_ima_save;
33 active_images = active_images_save;
34 check_active_images;
35 if no_image_file,
36 disp('Cannot extract corners without images');
37 return;
38 end;
39end;
40
41fprintf(1,'\nRe-extraction of the grid corners on the images (after first calibration)\n');
42
43disp('Window size for corner finder (wintx and winty):');
44wintx = input('wintx ([] = 5) = ');
45if isempty(wintx), wintx = 5; end;
46wintx = round(wintx);
47winty = input('winty ([] = 5) = ');
48if isempty(winty), winty = 5; end;
49winty = round(winty);
50
51fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
52
53ima_numbers = input('Number(s) of image(s) to process ([] = all images) = ');
54
55if isempty(ima_numbers),
56 ima_proc = 1:n_ima;
57else
58 ima_proc = ima_numbers;
59end;
60
61q_auto = input('Use the projection of 3D grid or manual click ([]=auto, other=manual): ');
62
63fprintf(1,'Processing image ');
64
65for kk = ima_proc;
66
67 if active_images(kk),
68
69 fprintf(1,'%d...',kk);
70
71 if isempty(q_auto),
72
73 eval(['I = I_' num2str(kk) ';']);
74
75 eval(['y = y_' num2str(kk) ';']);
76
77 xc = cornerfinder(y+1,I,winty,wintx); % the four corners
78
79 eval(['wintx_' num2str(kk) ' = wintx;']);
80 eval(['winty_' num2str(kk) ' = winty;']);
81
82 eval(['x_' num2str(kk) '= xc - 1;']);
83
84 else
85
86 fprintf(1,'\n');
87
88 click_ima_calib;
89
90 end;
91
92 else
93
94 if ~exist(['omc_' num2str(kk)]),
95
96 eval(['dX_' num2str(kk) ' = NaN;']);
97 eval(['dY_' num2str(kk) ' = NaN;']);
98
99 eval(['wintx_' num2str(kk) ' = NaN;']);
100 eval(['winty_' num2str(kk) ' = NaN;']);
101
102 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
103 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
104
105 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
106 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
107
108 end;
109
110 end;
111
112
113end;
114
115% Recompute the error:
116
117comp_error_calib;
118
119fprintf(1,'\ndone\n'); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rect.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rect.m
new file mode 100755
index 0000000..ccac7a5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rect.m
@@ -0,0 +1,127 @@
1function [Irec] = rect(I,R,f,c,k,alpha,KK_new);
2
3
4if nargin < 5,
5 k = 0;
6 if nargin < 4,
7 c = [0;0];
8 if nargin < 3,
9 f = [1;1];
10 if nargin < 2,
11 R = eye(3);
12 if nargin < 1,
13 error('ERROR: Need an image to rectify');
14 break;
15 end;
16 end;
17 end;
18 end;
19end;
20
21
22if nargin < 7,
23 if nargin < 6,
24 KK_new = [f(1) 0 c(1);0 f(2) c(2);0 0 1];
25 else
26 KK_new = alpha; % the 6th argument is actually KK_new
27 end;
28 alpha = 0;
29end;
30
31
32
33% Note: R is the motion of the points in space
34% So: X2 = R*X where X: coord in the old reference frame, X2: coord in the new ref frame.
35
36
37if ~exist('KK_new'),
38 KK_new = [f(1) alpha_c*fc(1) c(1);0 f(2) c(2);0 0 1];
39end;
40
41
42[nr,nc] = size(I);
43
44Irec = 255*ones(nr,nc);
45
46[mx,my] = meshgrid(1:nc, 1:nr);
47px = reshape(mx',nc*nr,1);
48py = reshape(my',nc*nr,1);
49
50rays = inv(KK_new)*[(px - 1)';(py - 1)';ones(1,length(px))];
51
52
53% Rotation: (or affine transformation):
54
55rays2 = R'*rays;
56
57x = [rays2(1,:)./rays2(3,:);rays2(2,:)./rays2(3,:)];
58
59
60% Add distortion:
61
62k1 = k(1);
63k2 = k(2);
64
65p1 = k(3);
66p2 = k(4);
67
68r_2 = sum(x.^2);
69
70delta_x = [2*p1*x(1,:).*x(2,:) + p2*(r_2 + 2*x(1,:).^2) ;
71 p1 * (r_2 + 2*x(2,:).^2)+2*p2*x(1,:).*x(2,:)];
72
73xd = (ones(2,1)*( 1 + k1 * r_2 + k2 * r_2.^2)) .* x + delta_x;
74
75
76% Reconvert in pixels:
77
78px2 = f(1)*(xd(1,:)+alpha_c*xd(2,:))+c(1);
79py2 = f(2)*xd(2,:)+c(2);
80
81
82% Interpolate between the closest pixels:
83
84px_0 = floor(px2);
85px_1 = px_0 + 1;
86alpha_x = px2 - px_0;
87
88py_0 = floor(py2);
89py_1 = py_0 + 1;
90alpha_y = py2 - py_0;
91
92good_points = find((px_0 >= 0) & (px_1 <= (nc-1)) & (py_0 >= 0) & (py_1 <= (nr-1)));
93
94I_lu = I(px_0(good_points) * nr + py_0(good_points) + 1);
95I_ru = I(px_1(good_points) * nr + py_0(good_points) + 1);
96I_ld = I(px_0(good_points) * nr + py_1(good_points) + 1);
97I_rd = I(px_1(good_points) * nr + py_1(good_points) + 1);
98
99
100I_interp = (1 - alpha_y(good_points)).*((1 - alpha_x(good_points)).* I_lu + alpha_x(good_points) .* I_ru) + alpha_y(good_points) .* ((1 - alpha_x(good_points)).* I_ld + alpha_x(good_points) .* I_rd);
101
102
103Irec((px(good_points)-1)*nr + py(good_points)) = I_interp;
104
105
106
107return;
108
109
110% Convert in indices:
111
112fact = 3;
113
114[XX,YY]= meshgrid(1:nc,1:nr);
115[XXi,YYi]= meshgrid(1:1/fact:nc,1:1/fact:nr);
116
117%tic;
118Iinterp = interp2(XX,YY,I,XXi,YYi);
119%toc
120
121[nri,nci] = size(Iinterp);
122
123
124ind_col = round(fact*(f(1)*xd(1,:)+c(1)))+1;
125ind_row = round(fact*(f(2)*xd(2,:)+c(2)))+1;
126
127good_points = find((ind_col >=1)&(ind_col<=nci)&(ind_row >=1)& (ind_row <=nri));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/reproject_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/reproject_calib.m
new file mode 100755
index 0000000..d3ad3d2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/reproject_calib.m
@@ -0,0 +1,121 @@
1%%%%%%%%%%%%%%%%%%%% REPROJECT ON THE IMAGES %%%%%%%%%%%%%%%%%%%%%%%%
2
3if ~exist('n_ima')|~exist('fc'),
4 fprintf(1,'No calibration data available.\n');
5 return;
6end;
7
8if ~exist('no_image'),
9 no_image = 0;
10end;
11
12if ~exist('nx')&~exist('ny'),
13 fprintf(1,'WARNING: No image size (nx,ny) available. Setting nx=640 and ny=480\n');
14 nx = 640;
15 ny = 480;
16end;
17
18
19check_active_images;
20
21
22% Color code for each image:
23
24colors = 'brgkcm';
25
26% Reproject the patterns on the images, and compute the pixel errors:
27
28% Reload the images if necessary
29
30if ~exist(['omc_' num2str(ind_active(1)) ]),
31 fprintf(1,'Need to calibrate before showing image reprojection. Maybe need to load Calib_Results.mat file.\n');
32 return;
33end;
34
35if ~no_image,
36 if ~exist(['I_' num2str(ind_active(1)) ]'),
37 n_ima_save = n_ima;
38 active_images_save = active_images;
39 ima_read_calib;
40 n_ima = n_ima_save;
41 active_images = active_images_save;
42 check_active_images;
43 if no_image_file,
44 fprintf(1,'WARNING: Do not show the original images\n'); %return;
45 end;
46 end;
47else
48 no_image_file = 1;
49end;
50
51
52if ~exist('dont_ask'),
53 dont_ask = 0;
54end;
55
56
57if ~dont_ask,
58 ima_numbers = input('Number(s) of image(s) to show ([] = all images) = ');
59else
60 ima_numbers = [];
61end;
62
63
64if isempty(ima_numbers),
65 ima_proc = 1:n_ima;
66else
67 ima_proc = ima_numbers;
68end;
69
70
71figure(5);
72for kk = ima_proc, %1:n_ima,
73 if exist(['y_' num2str(kk)]),
74 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
75 eval(['plot(ex_' num2str(kk) '(1,:),ex_' num2str(kk) '(2,:),''' colors(rem(kk-1,6)+1) '+'');']);
76 hold on;
77 end;
78 end;
79end;
80hold off;
81axis('equal');
82title('Reprojection error (in pixel)');
83xlabel('x');
84ylabel('y');
85drawnow;
86
87set(5,'Name','error','NumberTitle','off');
88
89
90
91for kk = ima_proc,
92 if exist(['y_' num2str(kk)]),
93 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
94
95 if exist(['I_' num2str(kk)]),
96 eval(['I = I_' num2str(kk) ';']);
97 else
98 I = 255*ones(ny,nx);
99 end;
100
101 figure(5+kk);
102 image(I); hold on;
103 colormap(gray(256));
104 title(['Image ' num2str(kk) ' - Image points (+) and reprojected grid points (o)']);
105 eval(['plot(x_' num2str(kk) '(1,:)+1,x_' num2str(kk) '(2,:)+1,''r+'');']);
106 eval(['plot(y_' num2str(kk) '(1,:)+1,y_' num2str(kk) '(2,:)+1,''' colors(rem(kk-1,6)+1) 'o'');']);
107 zoom on;
108 axis([1 nx 1 ny]);
109 hold off;
110 drawnow;
111
112 set(5+kk,'Name',num2str(kk),'NumberTitle','off');
113
114 end;
115 end;
116end;
117
118
119err_std = std(ex')';
120
121fprintf(1,'Pixel error: err = [%3.5f %3.5f] (all active images)\n\n',err_std);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rigid_motion.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rigid_motion.m
new file mode 100755
index 0000000..473405c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rigid_motion.m
@@ -0,0 +1,66 @@
1function [Y,dYdom,dYdT] = rigid_motion(X,om,T);
2
3%rigid_motion.m
4%
5%[Y,dYdom,dYdT] = rigid_motion(X,om,T)
6%
7%Computes the rigid motion transformation Y = R*X+T, where R = rodrigues(om).
8%
9%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
10% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
11% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
12%
13%OUTPUT: Y: 3D coordinates of the structure points in the camera reference frame (3xN matrix for N points)
14% dYdom: Derivative of Y with respect to om ((3N)x3 matrix)
15% dYdT: Derivative of Y with respect to T ((3N)x3 matrix)
16%
17%Definitions:
18%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
19%The coordinate vector of P in the camera reference frame is: Y = R*X + T
20%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
21%
22%Important function called within that program:
23%
24%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
25
26
27
28if nargin < 3,
29 T = zeros(3,1);
30 if nargin < 2,
31 om = zeros(3,1);
32 if nargin < 1,
33 error('Need at least a 3D structure as input (in rigid_motion.m)');
34 return;
35 end;
36 end;
37end;
38
39
40[R,dRdom] = rodrigues(om);
41
42[m,n] = size(X);
43
44Y = R*X + T*ones(1,n);
45
46if nargout > 1,
47
48
49dYdR = zeros(3*n,9);
50dYdT = zeros(3*n,3);
51
52dYdR(1:3:end,1:3:end) = X';
53dYdR(2:3:end,2:3:end) = X';
54dYdR(3:3:end,3:3:end) = X';
55
56dYdT(1:3:end,1) = ones(n,1);
57dYdT(2:3:end,2) = ones(n,1);
58dYdT(3:3:end,3) = ones(n,1);
59
60dYdom = dYdR * dRdom;
61
62end;
63
64
65
66
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rodrigues.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rodrigues.m
new file mode 100755
index 0000000..9d55337
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rodrigues.m
@@ -0,0 +1,217 @@
1function [out,dout]=rodrigues(in)
2
3% RODRIGUES Transform rotation matrix into rotation vector and viceversa.
4%
5% Sintax: [OUT]=RODRIGUES(IN)
6% If IN is a 3x3 rotation matrix then OUT is the
7% corresponding 3x1 rotation vector
8% if IN is a rotation 3-vector then OUT is the
9% corresponding 3x3 rotation matrix
10%
11
12%%
13%% Copyright (c) March 1993 -- Pietro Perona
14%% California Institute of Technology
15%%
16
17%% ALL CHECKED BY JEAN-YVES BOUGUET, October 1995.
18%% FOR ALL JACOBIAN MATRICES !!! LOOK AT THE TEST AT THE END !!
19
20%% BUG when norm(om)=pi fixed -- April 6th, 1997;
21%% Jean-Yves Bouguet
22
23
24[m,n] = size(in);
25%bigeps = 10e+4*eps;
26bigeps = 10e+20*eps;
27
28if ((m==1) & (n==3)) | ((m==3) & (n==1)) %% it is a rotation vector
29 theta = norm(in);
30 if theta < eps
31 R = eye(3);
32
33 %if nargout > 1,
34
35 dRdin = [0 0 0;
36 0 0 1;
37 0 -1 0;
38 0 0 -1;
39 0 0 0;
40 1 0 0;
41 0 1 0;
42 -1 0 0;
43 0 0 0];
44
45 %end;
46
47 else
48 if n==length(in) in=in'; end; %% make it a column vec. if necess.
49
50 %m3 = [in,theta]
51
52 dm3din = [eye(3);in'/theta];
53
54 omega = in/theta;
55
56 %m2 = [omega;theta]
57
58 dm2dm3 = [eye(3)/theta -in/theta^2; zeros(1,3) 1];
59
60 alpha = cos(theta);
61 beta = sin(theta);
62 gamma = 1-cos(theta);
63 omegav=[[0 -omega(3) omega(2)];[omega(3) 0 -omega(1)];[-omega(2) omega(1) 0 ]];
64 A = omega*omega';
65
66 %m1 = [alpha;beta;gamma;omegav;A];
67
68 dm1dm2 = zeros(21,4);
69 dm1dm2(1,4) = -sin(theta);
70 dm1dm2(2,4) = cos(theta);
71 dm1dm2(3,4) = sin(theta);
72 dm1dm2(4:12,1:3) = [0 0 0 0 0 1 0 -1 0;
73 0 0 -1 0 0 0 1 0 0;
74 0 1 0 -1 0 0 0 0 0]';
75
76 w1 = omega(1);
77 w2 = omega(2);
78 w3 = omega(3);
79
80 dm1dm2(13:21,1) = [2*w1;w2;w3;w2;0;0;w3;0;0];
81 dm1dm2(13: 21,2) = [0;w1;0;w1;2*w2;w3;0;w3;0];
82 dm1dm2(13:21,3) = [0;0;w1;0;0;w2;w1;w2;2*w3];
83
84 R = eye(3)*alpha + omegav*beta + A*gamma;
85
86 dRdm1 = zeros(9,21);
87
88 dRdm1([1 5 9],1) = ones(3,1);
89 dRdm1(:,2) = omegav(:);
90 dRdm1(:,4:12) = beta*eye(9);
91 dRdm1(:,3) = A(:);
92 dRdm1(:,13:21) = gamma*eye(9);
93
94 dRdin = dRdm1 * dm1dm2 * dm2dm3 * dm3din;
95
96
97 end;
98 out = R;
99 dout = dRdin;
100
101 %% it is prob. a rot matr.
102 elseif ((m==n) & (m==3) & (norm(in' * in - eye(3)) < bigeps)...
103 & (abs(det(in)-1) < bigeps))
104 R = in;
105
106
107
108 tr = (trace(R)-1)/2;
109 dtrdR = [1 0 0 0 1 0 0 0 1]/2;
110 theta = real(acos(tr));
111
112
113 if sin(theta) >= 1e-5,
114
115 dthetadtr = -1/sqrt(1-tr^2);
116
117 dthetadR = dthetadtr * dtrdR;
118 % var1 = [vth;theta];
119 vth = 1/(2*sin(theta));
120 dvthdtheta = -vth*cos(theta)/sin(theta);
121 dvar1dtheta = [dvthdtheta;1];
122
123 dvar1dR = dvar1dtheta * dthetadR;
124
125
126 om1 = [R(3,2)-R(2,3), R(1,3)-R(3,1), R(2,1)-R(1,2)]';
127
128 dom1dR = [0 0 0 0 0 1 0 -1 0;
129 0 0 -1 0 0 0 1 0 0;
130 0 1 0 -1 0 0 0 0 0];
131
132 % var = [om1;vth;theta];
133 dvardR = [dom1dR;dvar1dR];
134
135 % var2 = [om;theta];
136 om = vth*om1;
137 domdvar = [vth*eye(3) om1 zeros(3,1)];
138 dthetadvar = [0 0 0 0 1];
139 dvar2dvar = [domdvar;dthetadvar];
140
141
142 out = om*theta;
143 domegadvar2 = [theta*eye(3) om];
144
145 dout = domegadvar2 * dvar2dvar * dvardR;
146
147
148 else
149 if tr > 0; % case norm(om)=0;
150
151 out = [0 0 0]';
152
153 dout = [0 0 0 0 0 1/2 0 -1/2 0;
154 0 0 -1/2 0 0 0 1/2 0 0;
155 0 1/2 0 -1/2 0 0 0 0 0];
156 else % case norm(om)=pi; %% fixed April 6th
157
158
159 out = theta * (sqrt((diag(R)+1)/2).*[1;2*(R(1,2:3)>=0)'-1]);
160 %keyboard;
161
162 if nargout > 1,
163 fprintf(1,'WARNING!!!! Jacobian domdR undefined!!!\n');
164 dout = NaN*ones(3,9);
165 end;
166 end;
167 end;
168
169 else
170 error('Neither a rotation matrix nor a rotation vector were provided');
171 end;
172
173return;
174
175%% test of the Jacobians:
176
177%%%% TEST OF dRdom:
178om = randn(3,1);
179dom = randn(3,1)/1000000;
180
181[R1,dR1] = rodrigues(om);
182R2 = rodrigues(om+dom);
183
184R2a = R1 + reshape(dR1 * dom,3,3);
185
186gain = norm(R2 - R1)/norm(R2 - R2a)
187
188%%% TEST OF dOmdR:
189om = randn(3,1);
190R = rodrigues(om);
191dom = randn(3,1)/10000;
192dR = rodrigues(om+dom) - R;
193
194[omc,domdR] = rodrigues(R);
195[om2] = rodrigues(R+dR);
196
197om_app = omc + domdR*dR(:);
198
199gain = norm(om2 - omc)/norm(om2 - om_app)
200
201
202%%% OTHER BUG: (FIXED NOW!!!)
203
204omu = randn(3,1);
205omu = omu/norm(omu)
206om = pi*omu;
207[R,dR]= rodrigues(om);
208[om2] = rodrigues(R);
209[om om2]
210
211%%% NORMAL OPERATION
212
213om = randn(3,1);
214[R,dR]= rodrigues(om);
215[om2] = rodrigues(R);
216[om om2]
217
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rotation.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rotation.m
new file mode 100755
index 0000000..87ee2fe
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/rotation.m
@@ -0,0 +1,23 @@
1function [] = rotation(st);
2
3if nargin < 1,
4 st= 1;
5end;
6
7
8fig = gcf;
9
10ax = gca;
11
12vv = get(ax,'view');
13
14az = vv(1);
15el = vv(2);
16
17for azi = az:-abs(st):az-360,
18
19 set(ax,'view',[azi el]);
20 figure(fig);
21 drawnow;
22
23end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/run_error_analysis.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/run_error_analysis.m
new file mode 100755
index 0000000..095e17e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/run_error_analysis.m
@@ -0,0 +1,65 @@
1%%% Program that launchs the complete
2
3for N_ima_active = 1:30,
4
5 error_analysis;
6
7end;
8
9
10
11return;
12
13
14f = [];
15f_std = [];
16
17c = [];
18c_std = [];
19
20k = [];
21k_std = [];
22
23NN = 30;
24
25for rr = 1:NN,
26
27 load(['Calib_Accuracies_' num2str(rr)]);
28
29 [m1,s1] = mean_std_robust(fc_list(1,:));
30 [m2,s2] = mean_std_robust(fc_list(2,:));
31
32 f = [f [m1;m2]];
33 f_std = [f_std [s1;s2]];
34
35 [m1,s1] = mean_std_robust(cc_list(1,:));
36 [m2,s2] = mean_std_robust(cc_list(2,:));
37
38 c = [c [m1;m2]];
39 c_std = [c_std [s1;s2]];
40
41 [m1,s1] = mean_std_robust(kc_list(1,:));
42 [m2,s2] = mean_std_robust(kc_list(2,:));
43 [m3,s3] = mean_std_robust(kc_list(3,:));
44 [m4,s4] = mean_std_robust(kc_list(4,:));
45
46 k = [k [m1;m2;m3;m4]];
47 k_std = [k_std [s1;s2;s3;s4]];
48
49end;
50
51figure(1);
52errorbar([1:NN;1:NN]',f',f_std');
53figure(2);
54errorbar([1:NN;1:NN]',c',c_std');
55figure(3);
56errorbar([1:NN;1:NN;1:NN;1:NN]',k',k_std');
57
58figure(4);
59semilogy(f_std');
60
61figure(5);
62semilogy(c_std');
63
64figure(6);
65semilogy(k_std');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveinr.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveinr.m
new file mode 100755
index 0000000..a176e39
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveinr.m
@@ -0,0 +1,46 @@
1%SAVEINR Write an INRIMAGE format file
2%
3% SAVEINR(filename, im)
4%
5% Saves the specified image array in a INRIA image format file.
6%
7% SEE ALSO: loadinr
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11% Peter Corke 1996
12
13function saveinr(fname, im)
14
15 fid = fopen(fname, 'w');
16 [r,c] = size(im');
17
18 % build the header
19 hdr = [];
20 s = sprintf('#INRIMAGE-4#{\n');
21 hdr = [hdr s];
22 s = sprintf('XDIM=%d\n',c);
23 hdr = [hdr s];
24 s = sprintf('YDIM=%d\n',r);
25 hdr = [hdr s];
26 s = sprintf('ZDIM=1\n');
27 hdr = [hdr s];
28 s = sprintf('VDIM=1\n');
29 hdr = [hdr s];
30 s = sprintf('TYPE=float\n');
31 hdr = [hdr s];
32 s = sprintf('PIXSIZE=32\n');
33 hdr = [hdr s];
34 s = sprintf('SCALE=2**0\n');
35 hdr = [hdr s];
36 s = sprintf('CPU=sun\n#');
37 hdr = [hdr s];
38
39 % make it 256 bytes long and write it
40 hdr256 = zeros(1,256);
41 hdr256(1:length(hdr)) = hdr;
42 fwrite(fid, hdr256, 'uchar');
43
44 % now the binary data
45 fwrite(fid, im', 'float32');
46 fclose(fid)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/savepgm.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/savepgm.m
new file mode 100755
index 0000000..0cee75d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/savepgm.m
@@ -0,0 +1,22 @@
1%SAVEPGM Write a PGM format file
2%
3% SAVEPGM(filename, im)
4%
5% Saves the specified image array in a binary (P5) format PGM image file.
6%
7% SEE ALSO: loadpgm
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11
12% Peter Corke 1994
13
14function savepgm(fname, im)
15
16 fid = fopen(fname, 'w');
17 [r,c] = size(im');
18 fprintf(fid, 'P5\n');
19 fprintf(fid, '%d %d\n', r, c);
20 fprintf(fid, '255\n');
21 fwrite(fid, im', 'uchar');
22 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveppm.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveppm.m
new file mode 100755
index 0000000..ece092b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saveppm.m
@@ -0,0 +1,45 @@
1%SAVEPPM Write a PPM format file
2%
3% SAVEPPM(filename, I)
4%
5% Saves the specified red, green and blue planes in a binary (P6)
6% format PPM image file.
7%
8% SEE ALSO: loadppm
9%
10% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
11
12
13% Peter Corke 1994
14
15function saveppm(fname, I)
16
17I = double(I);
18
19if size(I,3) == 1,
20 R = I;
21 G = I;
22 B = I;
23else
24 R = I(:,:,1);
25 G = I(:,:,2);
26 B = I(:,:,3);
27end;
28
29%keyboard;
30
31 fid = fopen(fname, 'w');
32 [r,c] = size(R');
33 fprintf(fid, 'P6\n');
34 fprintf(fid, '%d %d\n', r, c);
35 fprintf(fid, '255\n');
36 R = R';
37 G = G';
38 B = B';
39 im = [R(:) G(:) B(:)];
40 %im = reshape(im,r,c*3);
41 im = im';
42 %im = im(:);
43 fwrite(fid, im, 'uchar');
44 fclose(fid);
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saving_calib.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saving_calib.m
new file mode 100755
index 0000000..3f98a8b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/saving_calib.m
@@ -0,0 +1,95 @@
1
2if ~exist('n_ima')|~exist('fc'),
3 fprintf(1,'No calibration data available.\n');
4 return;
5end;
6
7check_active_images;
8
9if ~exist('solution_init'), solution_init = []; end;
10
11for kk = 1:n_ima,
12 if ~exist(['dX_' num2str(kk)]), eval(['dX_' num2str(kk) '= dX;']); end;
13 if ~exist(['dY_' num2str(kk)]), eval(['dY_' num2str(kk) '= dY;']); end;
14end;
15
16if ~exist('param_list'),
17 param_list = solution;
18end;
19
20if ~exist('wintx'),
21 wintx = [];
22 winty = [];
23end;
24
25if ~exist('dX_default'),
26 dX_default = [];
27 dY_default = [];
28end;
29
30if ~exist('alpha_c'),
31 alpha_c = 0;
32end;
33
34for kk = 1:n_ima,
35 if ~exist(['y_' num2str(kk)]),
36 eval(['y_' num2str(kk) ' = NaN*ones(2,1);']);
37 end;
38 if ~exist(['n_sq_x_' num2str(kk)]),
39 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
40 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
41 end;
42 if ~exist(['wintx_' num2str(kk)]),
43 eval(['wintx_' num2str(kk) ' = NaN;']);
44 eval(['winty_' num2str(kk) ' = NaN;']);
45 end;
46end;
47
48save_name = 'Calib_Results';
49
50if exist([ save_name '.mat'])==2,
51 disp('WARNING: File Calib_Results.mat already exists');
52 pfn = -1;
53 cont = 1;
54 while cont,
55 pfn = pfn + 1;
56 postfix = ['_old'num2str(pfn)];
57 save_name = [ 'Calib_Results' postfix];
58 cont = (exist([ save_name '.mat'])==2);
59 end;
60 copyfile('Calib_Results.mat',[save_name '.mat']);
61 disp(['Copying the current Calib_Results.mat file to ' save_name '.mat']);
62end;
63
64
65save_name = 'Calib_Results';
66
67if exist('calib_name'),
68
69 fprintf(1,['\nSaving calibration results under ' save_name '.mat\n']);
70
71 string_save = ['save ' save_name ' center_optim param_list active_images ind_active center_optim est_alpha est_dist fc kc cc alpha_c ex x y solution solution_init wintx winty n_ima type_numbering N_slots small_calib_image first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default KK inv_KK dX dY'];
72
73 for kk = 1:n_ima,
74 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' H_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
75 end;
76
77else
78
79 fprintf(1,['\nSaving calibration results under ' save_name '.mat (no image version)\n']);
80
81 string_save = ['save ' save_name ' center_optim param_list active_images ind_active center_optim est_alpha est_dist fc kc cc alpha_c ex x y solution solution_init wintx winty n_ima nx ny dX_default dY_default KK inv_KK dX dY'];
82
83 for kk = 1:n_ima,
84 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' H_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
85 end;
86
87end;
88
89
90
91%fprintf(1,'To load later click on Load\n');
92
93eval(string_save);
94
95fprintf(1,'done\n'); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/script_fit_distortion.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/script_fit_distortion.m
new file mode 100755
index 0000000..c5e5430
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/script_fit_distortion.m
@@ -0,0 +1,39 @@
1
2 satis_distort = 0;
3
4 disp(['Estimated focal: ' num2str(f_g) ' pixels']);
5
6 while ~satis_distort,
7
8 k_g = input('Guess for distortion factor kc ([]=0): ');
9
10 if isempty(k_g), k_g = 0; end;
11
12 xy_corners_undist = comp_distortion2([x' - c_g(1);y'-c_g(2)]/f_g,k_g);
13
14 xu = xy_corners_undist(1,:)';
15 yu = xy_corners_undist(2,:)';
16
17 [XXu] = projectedGrid ( [xu(1);yu(1)], [xu(2);yu(2)],[xu(3);yu(3)], [xu(4);yu(4)],n_sq_x+1,n_sq_y+1); % The full grid
18
19 XX = (ones(2,1)*(1 + k_g * sum(XXu.^2))) .* XXu;
20 XX(1,:) = f_g*XX(1,:)+c_g(1);
21 XX(2,:) = f_g*XX(2,:)+c_g(2);
22
23 figure(2);
24 image(I);
25 colormap(map);
26 zoom on;
27 hold on;
28 %plot(f_g*XXu(1,:)+c_g(1),f_g*XXu(2,:)+c_g(2),'ro');
29 plot(XX(1,:),XX(2,:),'r+');
30 title('The red crosses should be on the grid corners...');
31 hold off;
32
33 satis_distort = input('Satisfied with distortion? ([]=no, other=yes) ');
34
35 satis_distort = ~isempty(satis_distort);
36
37
38 end;
39 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/startup.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/startup.m
new file mode 100755
index 0000000..aad0fa4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/startup.m
@@ -0,0 +1,9 @@
1% Main camera calibration toolbox:
2
3calib_gui;
4
5%calib_gui;
6
7path(pwd,path);
8
9format compact
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/undistort_image.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/undistort_image.m
new file mode 100755
index 0000000..d9a7574
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/undistort_image.m
@@ -0,0 +1,193 @@
1%%% INPUT THE IMAGE FILE NAME:
2
3if ~exist('fc')|~exist('cc')|~exist('kc')|~exist('alpha_c'),
4 fprintf(1,'No intrinsic camera parameters available.\n');
5 return;
6end;
7
8KK = [fc(1) alpha_c*fc(1) cc(1);0 fc(2) cc(2) ; 0 0 1];
9
10disp('Program that undistorts images');
11disp('The intrinsic camera parameters are assumed to be known (previously computed)');
12
13fprintf(1,'\n');
14
15quest = input('Do you want to undistort all the calibration images ([],0) or a new image (1)? ');
16
17if isempty(quest),
18 quest = 0;
19end;
20
21if ~quest,
22
23 if ~exist(['I_' num2str(ind_active(1))]),
24 ima_read_calib;
25 end;
26
27 check_active_images;
28
29 format_image2 = format_image;
30 if format_image2(1) == 'j',
31 format_image2 = 'bmp';
32 end;
33
34 for kk = 1:n_ima,
35
36 if exist(['I_' num2str(kk)]),
37
38 eval(['I = I_' num2str(kk) ';']);
39 [I2] = rect(I,eye(3),fc,cc,kc,KK);
40
41 if ~type_numbering,
42 number_ext = num2str(image_numbers(kk));
43 else
44 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(kk));
45 end;
46
47 ima_name2 = [calib_name '_rect' number_ext '.' format_image2];
48
49 fprintf(1,['Saving undistorted image under ' ima_name2 '...\n']);
50
51
52 if format_image2(1) == 'p',
53 if format_images2(2) == 'p',
54 saveppm(ima_name2,uint8(round(I2)));
55 else
56 savepgm(ima_name2,uint8(round(I2)));
57 end;
58 else
59 if format_image2(1) == 'r',
60 writeras(ima_name2,round(I2),gray(256));
61 else
62 imwrite(uint8(round(I2)),gray(256),ima_name2,format_image2);
63 end;
64 end;
65
66
67 end;
68
69 end;
70
71 fprintf(1,'done\n');
72
73else
74
75 dir;
76 fprintf(1,'\n');
77
78 image_name = input('Image name (full name without extension): ','s');
79
80 format_image2 = '0';
81
82while format_image2 == '0',
83
84 format_image2 = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'', ''m''=''ppm'') ','s');
85
86 if isempty(format_image2),
87 format_image2 = 'ras';
88 end;
89
90 if lower(format_image2(1)) == 'm',
91 format_image2 = 'ppm';
92 else
93 if lower(format_image2(1)) == 'b',
94 format_image2 = 'bmp';
95 else
96 if lower(format_image2(1)) == 't',
97 format_image2 = 'tif';
98 else
99 if lower(format_image2(1)) == 'p',
100 format_image2 = 'pgm';
101 else
102 if lower(format_image2(1)) == 'j',
103 format_image2 = 'jpg';
104 else
105 if lower(format_image2(1)) == 'r',
106 format_image2 = 'ras';
107 else
108 disp('Invalid image format');
109 format_image2 = '0'; % Ask for format once again
110 end;
111 end;
112 end;
113 end;
114 end;
115 end;
116end;
117
118ima_name = [image_name '.' format_image2];
119
120
121%%% READ IN IMAGE:
122
123if format_image2(1) == 'p',
124 if format_image2(2) == 'p',
125 I = double(loadppm(ima_name));
126 else
127 I = double(loadpgm(ima_name));
128 end;
129else
130 if format_image2(1) == 'r',
131 I = readras(ima_name);
132 else
133 I = double(imread(ima_name));
134 end;
135end;
136
137if size(I,3)>1,
138 I = I(:,:,2);
139end;
140
141
142if (size(I,1)>ny)|(size(I,2)>nx),
143 I = I(1:ny,1:nx);
144end;
145
146
147 %% SHOW THE ORIGINAL IMAGE:
148
149 figure(2);
150 image(I);
151 colormap(gray(256));
152 title('Original image (with distortion) - Stored in array I');
153 drawnow;
154
155
156 %% UNDISTORT THE IMAGE:
157
158 fprintf(1,'Computing the undistorted image...')
159
160 [I2] = rect(I,eye(3),fc,cc,kc,alpha_c,KK);
161
162 fprintf(1,'done\n');
163
164 figure(3);
165 image(I2);
166 colormap(gray(256));
167 title('Undistorted image - Stored in array I2');
168 drawnow;
169
170
171 %% SAVE THE IMAGE IN FILE:
172
173 ima_name2 = [image_name '_rect.' format_image2];
174
175 fprintf(1,['Saving undistorted image under ' ima_name2 '...']);
176
177 if format_image2(1) == 'p',
178 if format_images2(2) == 'p',
179 saveppm(ima_name2,uint8(round(I2)));
180 else
181 savepgm(ima_name2,uint8(round(I2)));
182 end;
183 else
184 if format_image2(1) == 'r',
185 writeras(ima_name2,round(I2),gray(256));
186 else
187 imwrite(uint8(round(I2)),gray(256),ima_name2,format_image2);
188 end;
189 end;
190
191 fprintf(1,'done\n');
192
193end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_convert.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_convert.m
new file mode 100755
index 0000000..8946349
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_convert.m
@@ -0,0 +1,89 @@
1function [fc,cc,kc,Rc,Tc,omc,nx,ny] = willson_convert(Ncx,Nfx,dx,dy,dpx,dpy,Cx,Cy,sx,f,kappa1,Tx,Ty,Tz,Rx,Ry,Rz,p1,p2);
2
3%Conversion from Reg Willson's calibration format to my format
4
5% Conversion:
6
7% Focal length:
8fc = [sx/dpx ; 1/dpy]*f;
9
10% Principal point;
11cc = [Cx;Cy];
12
13% Extrinsic parameters:
14Rx = rodrigues([Rx;0;0]);
15Ry = rodrigues([0;Ry;0]);
16Rz = rodrigues([0;0;Rz]);
17
18Rc = Rz * Ry * Rx;
19
20omc = rodrigues(Rc);
21
22Tc = [Tx;Ty;Tz];
23
24
25% More tricky: Take care of the distorsion:
26
27Nfy = round(Nfx * 3/4);
28
29nx = Nfx;
30ny = Nfy;
31
32% Select a set of DISTORTED coordinates uniformely distributed across the image:
33
34[xp_dist,yp_dist] = meshgrid(0:Nfx-1,0:Nfy);
35
36xp_dist = xp_dist(:)';
37yp_dist = yp_dist(:)';
38
39
40% Apply UNDISTORTION according to Willson:
41
42xp_sensor_dist = dpx*(xp_dist - Cx)/sx;
43yp_sensor_dist = dpy*(yp_dist - Cy);
44
45dist_fact = 1 + kappa1*(xp_sensor_dist.^2 + yp_sensor_dist.^2);
46
47xp_sensor = xp_sensor_dist .* dist_fact;
48yp_sensor = yp_sensor_dist .* dist_fact;
49
50xp = xp_sensor * sx / dpx + Cx;
51yp = yp_sensor / dpy + Cy;
52
53ind= find((xp > 0) & (xp < Nfx-1) & (yp > 0) & (yp < Nfy-1));
54
55xp = xp(ind);
56yp = yp(ind);
57xp_dist = xp_dist(ind);
58yp_dist = yp_dist(ind);
59
60
61% Now, find my own set of parameters:
62
63x_dist = [(xp_dist - cc(1))/fc(1);(yp_dist - cc(2))/fc(2)];
64x = [(xp - cc(1))/fc(1);(yp - cc(2))/fc(2)];
65
66k = [0;0;0;0];
67
68for kk = 1:5,
69
70 [xd,dxddk] = apply_distortion(x,k);
71
72 err = x_dist - xd;
73
74 %norm(err)
75
76 k_step = inv(dxddk'*dxddk)*(dxddk')*err(:);
77
78 k = k + k_step; %inv(dxddk'*dxddk)*(dxddk')*err(:);
79
80 %norm(k_step)/norm(k)
81
82 if norm(k_step)/norm(k) < 10e-10,
83 break;
84 end;
85
86end;
87
88
89kc = k;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_read.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_read.m
new file mode 100755
index 0000000..bbde63c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/willson_read.m
@@ -0,0 +1,59 @@
1% Read in Reg Willson's data file, and convert it into my data format:
2
3%dir;
4
5%calib_file = input('Reg Willson calibration file name: ','s');
6
7if exist(calib_file),
8
9
10 load(calib_file);
11
12 inddot = find(calib_file == '.');
13
14 if isempty(inddot),
15 varname = calib_file;
16 else
17 varname = calib_file(1:inddot(1)-1);
18 end;
19
20 eval(['calib_params = ' varname ';'])
21
22 Ncx = calib_params(1);
23 Nfx = calib_params(2);
24 dx = calib_params(3);
25 dy = calib_params(4);
26 dpx = calib_params(5);
27 dpy = calib_params(6);
28 Cx = calib_params(7);
29 Cy = calib_params(8);
30 sx = calib_params(9);
31 f = calib_params(10);
32 kappa1 = calib_params(11);
33 Tx = calib_params(12);
34 Ty = calib_params(13);
35 Tz = calib_params(14);
36 Rx = calib_params(15);
37 Ry = calib_params(16);
38 Rz = calib_params(17);
39 p1 = calib_params(18);
40 p2 = calib_params(19);
41
42 % Conversion:
43 [fc,cc,kc,Rc_1,Tc_1,omc_1,nx,ny] = willson_convert(Ncx,Nfx,dx,dy,dpx,dpy,Cx,Cy,sx,f,kappa1,Tx,Ty,Tz,Rx,Ry,Rz,p1,p2);
44
45 KK = [fc(1) 0 cc(1);0 fc(2) cc(2) ; 0 0 1];
46
47 n_ima = 1;
48
49 X_1 = [NaN;NaN;NaN];
50 x_1 = [NaN;NaN];
51
52 map = gray(256);
53
54else
55
56 disp(['WARNING: Calibration file ' calib_file ' not found']);
57
58end;
59
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/writeras.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/writeras.m
new file mode 100755
index 0000000..c7eb7bc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/writeras.m
@@ -0,0 +1,105 @@
1function writeras(filename, image, map);
2%WRITERAS Write an image file in sun raster format.
3% WRITERAS('imagefile.ras', image_matrix, map) writes a
4% "sun.raster" image file.
5
6% Written by Thomas K. Leung 3/30/93.
7% @ California Institute of Technology.
8
9
10% PC and UNIX version of writeras - Jean-Yves Bouguet - Dec. 1998
11
12dot = max(find(filename == '.'));
13suffix = filename(dot+1:dot+3);
14
15if nargin < 3,
16 map = [];
17end;
18
19if(strcmp(suffix, 'ras'))
20 %Write header
21
22 fp = fopen(filename, 'wb');
23 if(fp < 0) error(['Cannot open ' filename '.']), end
24
25 [height, width] = size(image);
26 image = image - 1;
27 mapsize = size(map, 1)*size(map,2);
28 %fwrite(fp, ...
29 % [1504078485, width, height, 8, height*width, 1, 1, mapsize], ...
30 % 'long');
31
32
33 zero_str = '00000000';
34
35 % MAGIC NUMBER:
36
37
38 fwrite(fp,89,'uchar');
39 fwrite(fp,166,'uchar');
40 fwrite(fp,106,'uchar');
41 fwrite(fp,149,'uchar');
42
43 width_str = dec2hex(width);
44 width_str = [zero_str(1:8-length(width_str)) width_str];
45
46 for ii = 1:2:7,
47 fwrite(fp,hex2dec(width_str(ii:ii+1)),'uchar');
48 end;
49
50
51 height_str = dec2hex(height);
52 height_str = [zero_str(1:8-length(height_str)) height_str];
53
54 for ii = 1:2:7,
55 fwrite(fp,hex2dec(height_str(ii:ii+1)),'uchar');
56 end;
57
58 fwrite(fp,0,'uchar');
59 fwrite(fp,0,'uchar');
60 fwrite(fp,0,'uchar');
61 fwrite(fp,8,'uchar');
62
63 ll = height*width;
64 ll_str = dec2hex(ll);
65 ll_str = [zero_str(1:8-length(ll_str)) ll_str];
66
67 for ii = 1:2:7,
68 fwrite(fp,hex2dec(ll_str(ii:ii+1)),'uchar');
69 end;
70
71 fwrite(fp,0,'uchar');
72 fwrite(fp,0,'uchar');
73 fwrite(fp,0,'uchar');
74 fwrite(fp,1,'uchar');
75 fwrite(fp,0,'uchar');
76 fwrite(fp,0,'uchar');
77 fwrite(fp,0,'uchar');
78 fwrite(fp,~~mapsize,'uchar');
79
80 mapsize_str = dec2hex(mapsize);
81 mapsize_str = [zero_str(1:8-length(mapsize_str)) mapsize_str];
82
83 %keyboard;
84
85 for ii = 1:2:7,
86 fwrite(fp,hex2dec(mapsize_str(ii:ii+1)),'uchar');
87 end;
88
89
90 if mapsize ~= 0
91 map = min(255, fix(255*map));
92 fwrite(fp, map, 'uchar');
93 end
94 if rem(width,2) == 1
95 image = [image'; zeros(1, height)]';
96 top = 255 * ones(size(image));
97 fwrite(fp, min(top,image)', 'uchar');
98 else
99 top = 255 * ones(size(image));
100 fwrite(fp, min(top,image)', 'uchar');
101 end
102 fclose(fp);
103else
104 error('Image file name must end in either ''ras'' or ''rast''.');
105end
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 @@
1Top level program is "compute_AD.m". Use "compute_AD_disp.m" if one
2wants to display results as program runs.
3
4The testing programs are called "simulation.m" for synthetic images,
5and "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 @@
1function img = carve_it(I,center,window_size_h)
2
3[size_y,size_x]= size(I);
4min_x = round(center(1)-window_size_h(1));
5max_x = round(center(1)+window_size_h(1));
6min_y = round(center(2)-window_size_h(2));
7max_y = round(center(2)+window_size_h(2));
8window_size = window_size_h*2 +1;
9
10if (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);
20else
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));
23end
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 @@
1function [A,D,mask] =...
2compute_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
27if ~exist('Dest'),
28 Dest = [0,0];
29end
30
31if ~exist('mask'),
32 mask = ones(2*window_size_h+1)';
33end
34
35% set the default num_trans
36if ~exist('num_trans'),
37 num_trans= 3;
38end
39
40% normalize image intensity to the range of 0.0-1.0
41img_i = norm_inten(img_i);
42img_j = norm_inten(img_j);
43
44window_size = 2*window_size_h + 1;
45I = carve_it(img_i,center_i,window_size_h);
46J = carve_it(img_j,center_j,window_size_h);
47
48% init. step
49J_computed = I;
50D_computed = Dest;
51A_computed = eye(2);
52J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h);
53
54%% level of noise
55sig = 0.1;
56
57records = zeros(num_iter,6);
58errs = zeros(1,num_iter);
59
60k = 1;
61% iteration
62while 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;
83end
84
85[tmp,id] = min(errs);
86A = reshape(records(id,1:4),2,2);
87D = reshape(records(id,5:6),1,2);
88
89J_computed = compute_J(A,D,img_i,center_i,window_size_h);
90mask = 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 @@
1function [A,D,mask] =...
2compute_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%
32
33if ~exist('mask'),
34 mask = ones(2*window_size_h+1)';
35end
36
37if ~exist('Dest'),
38 Dest = [0,0];
39end
40
41% set the default num_trans
42if ~exist('num_trans'),
43 num_trans= 3;
44end
45
46% normalize image intensity to the range of 0.0-1.0
47img_i = norm_inten(img_i);
48img_j = norm_inten(img_j);
49
50window_size = 2*window_size_h + 1;
51I = carve_it(img_i,center_i,window_size_h);
52J = carve_it(img_j,center_j,window_size_h);
53
54% init. step
55D_computed = Dest;
56A_computed = eye(2);
57J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h);
58
59
60
61figure(fig_disp);subplot(1,3,1);imagesc(I);colormap(gray);axis('image');
62subplot(1,3,3);imagesc(J);axis('image');
63drawnow;
64
65sig = 0.1;
66
67records = zeros(num_iter,6);
68errs = zeros(1,num_iter);
69
70k = 1;
71% iteration
72while k <= num_iter,
73 [A,D] = iter_AD(J_computed,J,mask,w,k,num_trans);
74
75 A_computed = A*A_computed;
76 D_computed = (A*D_computed')' + D;
77
78 % compute the warped image
79 J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h);
80
81 % compute the SSD error
82 errs(k) = sqrt(sum(sum((mask.*(J_computed-J)).^2)))/prod(size(J))
83
84 % update the mask, discounting possible occlusion region
85 if (k>num_trans+1),
86 mask = exp(-abs(J_computed-J)/sig);
87 end
88
89 % record the A and D
90 records(k,:) = [reshape(A_computed,1,4),reshape(D_computed,1,2)];
91
92 figure(fig_disp);subplot(1,3,2);imagesc(J_computed);axis('image');
93 title(sprintf('iter:%d: dx=%3.3f, dy = %3.3f',k,D_computed(1),D_computed(2)));drawnow;
94
95 k = k+1;
96end
97
98[tmp,id] = min(errs);
99A = reshape(records(id,1:4),2,2);
100D = reshape(records(id,5:6),1,2);
101
102J_computed = compute_J(A,D,img_i,center_i,window_size_h);
103mask = exp(-abs(J_computed-J)/sig);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/compute_J.m b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_J.m
new file mode 100755
index 0000000..80db273
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_J.m
@@ -0,0 +1,31 @@
1function [JJ,mask] = compute_J(A,D,I,center,window_size_h)
2%% function J = compute_J(A,D,I,center,window_size_h)
3%
4
5[size_y,size_x] = size(I);
6
7center_x = center(1);
8center_y = center(2);
9
10[XX,YY] = meshgrid(1:size_x,1:size_y);
11x = reshape(XX,size_x*size_y,1);
12y = reshape(YY,size_x*size_y,1);
13index(:,1) = x-center_x;
14index(:,2) = y-center_y;
15
16position_new = A*index'+ [D(1),0;0,D(2)]*ones(2,size_x*size_y);
17position_new(1,:) = position_new(1,:)+center_x;
18position_new(2,:) = position_new(2,:)+center_y;
19
20position_new_x = reshape(position_new(1,:),size_y,size_x);
21position_new_y = reshape(position_new(2,:),size_y,size_x);
22
23[J,mask]= m_interp4(I,position_new_x,position_new_y);
24
25JJ = J(center(2)-window_size_h(2):center(2)+window_size_h(2),...
26 center(1)-window_size_h(1):center(1)+window_size_h(1));
27mask = mask(center(2)-window_size_h(2):center(2)+window_size_h(2),...
28 center(1)-window_size_h(1):center(1)+window_size_h(1));
29
30
31
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/find_AD.m b/SD-VBS/common/toolbox/toolbox_basic/affine/find_AD.m
new file mode 100755
index 0000000..3cccefb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/find_AD.m
@@ -0,0 +1,82 @@
1function [A,D] = find_AD(I,J,mask,w)
2%
3% [A,D] = find_AD(I,J,mask,w)
4%
5% find the matrix affine transform A and displacement D,
6% such that SSD difference of I(Ax-d)-J(x) is minimized,
7%
8
9%
10% Jianbo Shi
11%
12
13
14[gy1,gx1] = grad(I,w);
15[gy2,gx2] = grad(J,w);
16
17gx = 0.5*(gx1+gx2);
18gy = 0.5*(gy1+gy2);
19
20[size_y,size_x] = size(I);
21[center_y,center_x] = find_center(size_y,size_x);
22mask = mask(w+1:size_y-w,w+1:size_x-w);
23
24[x,y] = meshgrid(1:size_x,1:size_y);
25x = x- center_x;
26y = y-center_y;
27
28x = x(w+1:size_y-w,w+1:size_x-w);
29y = y(w+1:size_y-w,w+1:size_x-w);
30
31gx_sqr = gx.*mask.*gx;
32gx_gy = gx.*mask.*gy;
33gy_sqr = gy.*mask.*gy;
34
35x_sqr = x.*x;
36x_y = x.*y;
37y_sqr = y.*y;
38
39T= zeros(6,6);
40T(1,1) = 0.5*trapz(trapz(gx_sqr.*x_sqr));
41T(2,1) = trapz(trapz(gx_gy.*x_y));
42T(3,1) = trapz(trapz(gx_sqr.*x_y));
43T(4,1) = trapz(trapz(gx_gy.*x_sqr));
44T(5,1) = trapz(trapz(gx_sqr.*x));
45T(6,1) = trapz(trapz(gx_gy.*x));
46T(2,2) = 0.5*trapz(trapz(gy_sqr.*y_sqr));
47T(3,2) = trapz(trapz(gx_gy.*y_sqr));
48T(4,2) = trapz(trapz(gy_sqr.*x_y));
49T(5,2) = trapz(trapz(gx_gy.*y));
50T(6,2) = trapz(trapz(gy_sqr.*y));
51T(3,3) = 0.5*trapz(trapz(gx_sqr.*y_sqr));
52T(4,3) = trapz(trapz(gx_gy.*x_y));
53T(5,3) = trapz(trapz(gx_sqr.*y));
54T(6,3) = trapz(trapz(gx_gy.*y));
55T(4,4) = 0.5*trapz(trapz(gy_sqr.*x_sqr));
56T(5,4) = trapz(trapz(gx_gy.*x));
57T(6,4) = trapz(trapz(gy_sqr.*x));
58T(5,5) = 0.5*trapz(trapz(gx_sqr));
59T(6,5) = trapz(trapz(gx_gy));
60T(6,6) = 0.5*trapz(trapz(gy_sqr));
61
62T = T+T';
63
64J = J(w+1:size_y-w,w+1:size_x-w);
65I = I(w+1:size_y-w,w+1:size_x-w);
66
67
68diff = (J-I).*mask;
69b(1) = trapz(trapz(diff.*gx.*x));
70b(2) = trapz(trapz(diff.*gy.*y));
71b(3) = trapz(trapz(diff.*gx.*y));
72b(4) = trapz(trapz(diff.*gy.*x));
73b(5) = trapz(trapz(diff.*gx));
74b(6) = trapz(trapz(diff.*gy));
75
76a = inv(T)*b';
77
78A = [1+a(1), a(3);
79a(4),1+a(2)];
80
81D= [a(5),a(6)];
82
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m b/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m
new file mode 100755
index 0000000..1e42cb2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m
@@ -0,0 +1,65 @@
1function D = find_D(I,J,mask,w)
2%
3% function D = find_D(I,J,mask,w)
4%
5% find the vector D such that it minimizes then
6% difference between I(Ax-d)-J(x).
7%
8% mask: the weight matrix,
9% w: window size for estimating gradiant, use a large value
10% when A,D are large.
11%
12
13%
14% NOTE: Because gradient values on the boarder regions of
15% I and J can not be computed accuately when using
16% a gaussian of large support, those boarder regions
17% of width w are not used in computing D.
18%
19
20%
21% Jianbo Shi
22%
23
24[gy1,gx1] = grad(I,w);
25[gy2,gx2] = grad(J,w);
26
27gx = 0.5*(gx1+gx2);
28gy = 0.5*(gy1+gy2);
29
30[size_y,size_x] = size(I);
31[center_y,center_x] = find_center(size_y,size_x);
32mask = mask(w+1:size_y-w,w+1:size_x-w);
33
34[x,y] = meshgrid(1:size_x,1:size_y);
35x = x- center_x;
36y = y-center_y;
37
38x = x(w+1:size_y-w,w+1:size_x-w);
39y = y(w+1:size_y-w,w+1:size_x-w);
40
41gx_sqr = gx.*mask.*gx;
42gx_gy = gx.*mask.*gy;
43gy_sqr = gy.*mask.*gy;
44
45
46T= zeros(2,2);
47
48T(1,1) = 0.5*trapz(trapz(gx_sqr));
49T(2,1) = trapz(trapz(gx_gy));
50T(2,2) = 0.5*trapz(trapz(gy_sqr));
51
52T = T+T';
53
54J = J(w+1:size_y-w,w+1:size_x-w);
55I = I(w+1:size_y-w,w+1:size_x-w);
56
57
58diff = (J-I).*mask;
59b(1) = trapz(trapz(diff.*gx));
60b(2) = trapz(trapz(diff.*gy));
61
62a = inv(T)*b';
63
64D= [a(1),a(2)];
65
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/find_center.m b/SD-VBS/common/toolbox/toolbox_basic/affine/find_center.m
new file mode 100755
index 0000000..b12ac7b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/find_center.m
@@ -0,0 +1,4 @@
1function [center_x,center_y] = find_center(size_x,size_y)
2
3center_x = 0.5*(size_x +1);
4center_y = 0.5*(size_y +1);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/gen_feature_s.m b/SD-VBS/common/toolbox/toolbox_basic/affine/gen_feature_s.m
new file mode 100755
index 0000000..3c113e9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/gen_feature_s.m
@@ -0,0 +1,17 @@
1function I = gen_feature_s(size_of_feature)
2% function I = gen_feature(size_of_feature)
3% generates a spherical features with size
4% of "size_of_feature"
5%
6
7ss = round(0.4*size_of_feature);
8[X,Y,II] = hemisphere_s(ss);
9
10II = abs(II);
11II = 1/max(max(II))*II;
12
13I = zeros(size_of_feature,size_of_feature);
14
15t = round((size_of_feature-ss)/2);
16
17I(1+t:1+t+ss,1+t:1+t+ss) = II;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/grad.m b/SD-VBS/common/toolbox/toolbox_basic/affine/grad.m
new file mode 100755
index 0000000..53bab55
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/grad.m
@@ -0,0 +1,24 @@
1% gradient of an image
2% coordinates (r, c) follow matrix convention;
3% the gaussian is truncated at x = +- tail, and there are samples samples
4% inbetween, where samples = hsamples * 2 + 1
5
6function[gr,gc] = gradient(image, hsamples)
7
8tail=4;
9samples = hsamples * 2 + 1;
10
11x = linspace(-tail, tail, samples);
12gauss = exp(-x.^2);
13n = gauss * ones(samples,1);
14gauss = gauss/n;
15
16gaussderiv = -x.*gauss;
17n = -gaussderiv*linspace(1,samples,samples)';
18gaussderiv = gaussderiv/n;
19
20gr = conv2(conv2(image, gaussderiv','valid'), gauss,'valid');
21gc = conv2(conv2(image, gaussderiv,'valid'), gauss','valid');
22
23%gr = conv2(conv2(image, gaussderiv','same'), gauss,'same');
24%gc = conv2(conv2(image, gaussderiv,'same'), gauss','same');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/hemisphere_s.m b/SD-VBS/common/toolbox/toolbox_basic/affine/hemisphere_s.m
new file mode 100755
index 0000000..5300183
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/hemisphere_s.m
@@ -0,0 +1,27 @@
1function [x,y,z] = hemisphere(r)
2%HEMISPHERE Generate sphere and transform from spherical coordinates.
3%
4% [X,Y,Z] = HEMISPHERE(N) generates three (n+1)-by-(n+1)
5% matrices so that SURF(X,Y,Z) produces a sphere.
6%
7% [X,Y,Z] = HEMISPHERE(R,N) generates three (n+1)-by-(n+1)
8% matrices so that SURF(X,Y,Z,R) produces a sphere colored by R
9%
10% [X,Y,Z] = HEMISPHERE(R,THETA,PHI) converts from spherical coordinates
11% to cartesian coordinates.
12
13% Modified from
14% Clay M. Thompson 4-24-91
15% Copyright (c) 1991-92 by the MathWorks, Inc.
16% by Carlo Tomasi
17
18error(nargchk(1,3,nargin));
19
20n = r;
21% 0 <= theta <= 2*pi and 0 <= phi <= pi/2
22[theta,phi] = meshgrid((pi/n/2)*[-n:2:n],(pi/2/n)*[-n:2:n]);
23r = ones(n+1,n+1);
24
25x = r .* cos(phi) .* sin(theta);
26y = r .* sin(phi);
27z = r .* cos(phi) .* cos(theta).*phi.*theta;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/im.m b/SD-VBS/common/toolbox/toolbox_basic/affine/im.m
new file mode 100755
index 0000000..6450120
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/im.m
@@ -0,0 +1,3 @@
1function im(I)
2
3imagesc(I);axis('image');drawnow; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/iter_AD.m b/SD-VBS/common/toolbox/toolbox_basic/affine/iter_AD.m
new file mode 100755
index 0000000..50bdae1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/iter_AD.m
@@ -0,0 +1,26 @@
1function [A,D] = iter_AD(I,J,mask,w,k,num_trans)
2%
3% function [A,D] = iter_AD(I,J,mask,w,k,num_trans)
4%
5% find the affine motion A, and displacement D,
6% such that difference between I(Ax-D) and J(x) is minimized.
7% If k <= num_trans, only translation is computed. This is useful
8% in practice, when translation is relative large.
9%
10% mask: the weight matrix,
11% w: window size for estimating gradiant, use a large value
12% when A,D are large.
13%
14
15%
16% Jianbo Shi
17%
18
19
20if k <= num_trans,
21 D = find_D(I,J,mask,w);
22 A = eye(2);
23else
24 [A,D] = find_AD(I,J,mask,w);
25end
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m b/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m
new file mode 100755
index 0000000..314f140
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/m_interp4.m
@@ -0,0 +1,49 @@
1function [F,mask] = m_interp4(z,s,t)
2%INTERP4 2-D bilinear data interpolation.
3% ZI = INTERP4(Z,XI,YI) assumes X = 1:N and Y = 1:M, where
4% [M,N] = SIZE(Z).
5%
6% Copyright (c) 1984-93 by The MathWorks, Inc.
7% Clay M. Thompson 4-26-91, revised 7-3-91, 3-22-93 by CMT.
8%
9% modified to
10
11
12[nrows,ncols] = size(z);
13
14
15if any(size(z)<[3 3]), error('Z must be at least 3-by-3.'); end
16if size(s)~=size(t), error('XI and YI must be the same size.'); end
17
18% Check for out of range values of s and set to 1
19sout = find((s<1)|(s>ncols));
20if length(sout)>0, s(sout) = ones(size(sout)); end
21
22% Check for out of range values of t and set to 1
23tout = find((t<1)|(t>nrows));
24if length(tout)>0, t(tout) = ones(size(tout)); end
25
26% Matrix element indexing
27ndx = floor(t)+floor(s-1)*nrows;
28
29% Compute intepolation parameters, check for boundary value.
30d = find(s==ncols);
31s(:) = (s - floor(s));
32if length(d)>0, s(d) = s(d)+1; ndx(d) = ndx(d)-nrows; end
33
34% Compute intepolation parameters, check for boundary value.
35d = find(t==nrows);
36t(:) = (t - floor(t));
37if length(d)>0, t(d) = t(d)+1; ndx(d) = ndx(d)-1; end
38d = [];
39
40% Now interpolate, reuse u and v to save memory.
41F = ( z(ndx).*(1-t) + z(ndx+1).*t ).*(1-s) + ...
42 ( z(ndx+nrows).*(1-t) + z(ndx+(nrows+1)).*t ).*s;
43
44mask = ones(size(z));
45
46% Now set out of range values to zeros.
47if length(sout)>0, F(sout) = zeros(size(sout));mask(sout)=zeros(size(sout));end
48if length(tout)>0, F(tout) = zeros(size(tout));mask(tout)=zeros(size(tout));end
49
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/norm_inten.m b/SD-VBS/common/toolbox/toolbox_basic/affine/norm_inten.m
new file mode 100755
index 0000000..8e8865b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/norm_inten.m
@@ -0,0 +1,11 @@
1function I = norm_inten(J)
2%
3% I = norm_inten(J)
4%
5% normalize image intensity to the range of 0.0-1.0
6%
7
8max_J = max(max(J));
9min_J = min(min(J));
10
11I = (J-min_J)/(max_J-min_J);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/pan.0.pgm b/SD-VBS/common/toolbox/toolbox_basic/affine/pan.0.pgm
new file mode 100755
index 0000000..2e7b5f6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/pan.0.pgm
@@ -0,0 +1,53 @@
1P5
2# CREATOR: XV Version 3.10a Rev: 12/29/94
3128 96
4255
5qquvvvvwzyz{}~€‚‚‚ƒ„††…†‡ˆˆŠŠŽŒŽ‘’“•–”–——›œž ¡ ­©¤¢£¥¥¥¥§¥§©««¬­°±²²¶¶µ´³²´³³¶¹»ÀÀ¿ÁÃÄÂÄÄÃÄÃÅÆÊÇÆÆÅÊÉÈÊÏÞËÄÃÄÂÂÃÃÀÁ»qrrsvxwxyzzz{{|~~€‚ƒƒ…………†‡†‡ˆ‰ŠŒŽŽŽ‘’’“”•–•“•˜™šœœŸŸŸ¡¡Ÿª°¥¤¦§¥©«ªªª«¬­®°³´¶¶¹·¶··¸¸¹¹º½½¾¿»¼¿ÀÀÂÂÃÈÇÈÊËÉÈÊÊËÎÍÉØ×ÈÆÄÄÃÅÅÃÂÃÀtuwuruzzyzz{}}}‚„„„†‡‡‰‰‰‰‹‹‘”’’““•—–˜——™š›žžŸŸ¡¤¥¦¤¦·¬§¨©ª¬ª­¬­¯¯²³³¶·¹¹¹½¼½½¼¼¼¾¿ÀÁÃÃÁÄÄÃÆÇÇÈÉÊÉÉÊÊÎÍËËÌËÍÞÌÂÄÂÂÃÅÅÃÁÃÂtvwxyxwwz{{z|{|}‚„„…‡ˆˆ‰‰Š‹‹Œ‘‘’“•—˜˜™™š›œžžž ¢¢¡¢£¢±º¬©ªª«¬®®®°³´µ¸¹¹¹»¿¾¾½¾¾¾½¿¿ÂÂÁÀÀ¿¿¿ÂÆÈËÎÒÔÖ×ÖÔÓÐÎÎÎßâÒÕØÜááááàÜÙÕtvwwyz{ywz}}‚‚ƒ†‰‰ˆˆ‡‡ˆŒ‘“”’“–—˜™š™šš›œœ›œžœœž Ÿ š ´œ•™š¡¥¨¬®®®­­­ª©ªª­¬ª¨¦¥¢ÇÕÃÄÅÅÅÇÅÅÅÂÅÆÇÇÊËËÍÊÍÐÐÑÐÑâÖÓÓÔÖ×Ô×ÖÖ××Ðm„zuuvvvurvuwxz{{{}€ƒ„ƒ„††‡‰Šˆ‰ŠŒŽ“•™šœœ›œžž¡¢££¤¤¦¦©¨§¨§µ³¢¦ª®±³®¢žžžŸŸŸŸ ¤§©©ªª§ËÚÁÁÀÂÅÄÅÇÆÇËÍÎÏÐÏÍÏÑÒÔ×ÙÙãèÝÛÜÝÜÛÛÝÚØÙØÓBUw…xz}~}~{{€€‚„„ƒ…‡†ˆ‡Š‹‹Ž‘“”““•—˜˜š›Ÿ¡ Ÿ¢¤¦¦§¦ªª«®®±Á®­­±³µ°¡šš™š™™›¡¥§¨©«¥ÃàÈÇÊÎÍËÎÐÑÒÔÖÖÕØÖÖÚÞàáãâáîéâæåçéåâÞàâààÝGcZW„}}~}~ƒƒ„…„†‰‰‰‹‹‹‘‘’’’“••–—˜œŸŸžŸ ¡££¥¨§§ªª«®°°°¯ÅÀ¨­³·µ­ š¡¢¡  ŸŸ ¤ª«­¯¨ÄèÑÏÑÓÔרØ×ÛßÞßââãæéêêêêéíòéëììîíëíîïïííêGeoxae“~€‚‚ƒ~„ˆ‡‰‰ˆ‰‰‹Š’“”—šššœ ¡¢¡¡£¥¦¦¦¨¬­®¯®¯°²²²²³´»Î·°¸¹µ­¥ œš›œœž¢¦ª¬®®²¸²ÇëØ×××ÝàáåæéêìëïîìïîðððóóöôðñóôóôôööõõóòîFakswvey‚ƒ„……„€ƒˆ‰Š‹‹ŒŒ‘‘’”•–˜˜™š›Ÿ ¢£¥¨©ª¬¬¬®°°³´µ¹ºº½¾ÁÁ¿ÊÓº¿Ã¹±«¥§­±²±®©©­±´²³´±ËñáßáãæèìðòõõõöøùøõîæßØÏÓõðïñóõ÷ùõôöîëççïIbjnpu|x_‹Ž„††‡‰ˆ„‰Ž‘‘’”–———›œž ¢¤¥§ª©ª¬®¯°²¯®³´µ³²´¸º¼¿ÅÎâ¡nbb_eq†¦Â¿Ìå÷ýýýýýüüüüýýýýþþþþþþþþýýýýüüüüçæ¼­®ã–½øúú§>¸áq±}̶Gbjkloqw|pn‹rcbbehq…‡ˆ‰‹Ž‘’”•–ššœžŸ¢¤¦©ª«®°¥Œ› “ »ÂÄÅÅÆÊÍÏÓ×ÙÜç«Õûúúü÷‹.ÃýýýýýýýüüøíüýÚÞîØüÝÈþþ«¨î–Ù»“ô臞‰fšb€’Žf0^xF_VYqH^ehkoopqy€f†ðþþþûä‹|”–˜–‹“¢£ ŸŸŸ¢¤§¨ª¬²±°°x;33>AV¨ËÐÒ×ÞáÌÆçñúã•ÄyÂýýýÉi5!q¸¬ŽcMi<2<3WWB=XFoZMqeHNtMdfV„wNi…v\uat}ˆŽc*dHY]ZtG]aced`C233++%)(*59:@7B>F>FEA=<\g^gb\^Ya][\PD83.2<Fgua?>X_=Hj?42)Wh3%GkgpD8€…€xb`vJQjFktVR|LvtTytLU{OdoU…}N]‡sSwZl‚Š‘[+e€IVYRqI[^___W?519+&'112>;9G<@;E8BG<:5V[FYYLPIHHMA4=A83:PMd{m@BdmUOi?$ByC!'Q_pS$l„‚|hSrJMqG^ugp‡Os~Rq|QRN\wM}€SYŒyQuPe‡’X#_€NQ_RpFX\]^YK512:)&(032>?9B=E:G7AJ@B;W\GRWHOHEJIB5>C@:4NQ^xp<5[njF€lJ, %pIQk]L*&X€w{qReNBnIGe’Ô¨Yj‡KayPR€XQ€Qu‚XQOtUb‰Ž”^%[QPcRoGUY]YNC445=)%+.01?98EAG=E6>H@B<S\KPY?LFKOKG9GA8>7BFRwvN\r>itK2WRJmRZ9(AepvPZ[BpVCf‡Î¨U]ŠN[zSKgU‡Pj‰bJ‘QpX\‹Ž”d%U…VPhNmFUYYTG>26;?*'+247><;HCM@I7<LCE:T[JKWAJJMVJMAGB394<GLny]#HpGY‡Y:!Eh-(ekhG'2zli{_UkBgfAXl³§YLˆWP~cO€qQ‚T_rM…†TlaZŒŽ”m'LƒYMiMrGVYVNC?368@.)+123?<9JEL@K;;K?D;QXNL\FOTQYOVKB@3:26FHg}o/
63oXKŒrJ*4r=UzhI'-%lzp|mWtF[n<GZŸžhIbO„nVSx]X~MŽUgkZŽŽ“u,H†^MoPqHTTPH?</4<?*),.+2><<I>J@H:;JAF>O[SM_PR]XVLSJ8>8565BD_v>)hiEwU-"lLGpcaHA$U~o~wRjLJrCCZ†ŒuDtsF}yPq„SmlT…MsY`tZŒŽ“~2CƒeMrRqIRSMGMXPF>A.**0.<C>APIR>L?9K;DEQ]XP`VS]\[OML5?C8?7BDX|~R[sBm‚_7[_"=cqfj_W;Is|~T\[HvRCa^DxGj…HqPg…W\yX‰ŠSe”e^ZŠ•„9@„kLrPmGOOIM[\MC>@+(*-,7>;<MDM=G<7G>GAJYUU_ZU^ZOKGP?IH2?5>GRu€e&KuK]”gH#DoNXhj]FE]jb|rvZRmIp_?fbCxV[‘NdƒQ\…[U…Qy‹W`”o[Š\‚‘”ˆA<qNvPmHOKFM[\NB>?)(,,+>BBDSHP@FA8ICG@F\WV]bS_\KLISOED2:4:FNpˆt85teTœhQ+*ENWOG6*+;PVm|x…kPpK`pVp–zuoZ–YW…_Z‹hP…PmŽ`[•{[“\}‘—ŽL;~wSvQiFIHDLXVJ@<>(''+)7AEESGO<GE;HBG@B_a[^^RTURVNWUGC3789KNh„}F*lxM‚zV3)7/5FHD:*"7JKTy~†yOiKQn69.bƒR„hR‡oW‡uT†Ve“m[–ˆ^‹]s‘–‘Q3t|PuRdDFECJTM?3 
7
8")+8ABBSFN=FD8HFHFB`a]^UONRRYRWVH=:787AA_‚ƒ`!aMd‘gN,!*5?>4*))(ATq~†„Q[VIt<6:RTq}U‚VV|a^˜x]^af‘–“V+nOoS]EFEELOB/&5?ABREK=CI;KLIH=b_\YVPMT[cZVVGDA4<6>BT}‡m+N|\[šf/"$');GGC7,%2W]l€ƒ^UhHk:+DE‡Z`ŽWw†Tr‡Vmn]˜ƒXŠ”byeb”•–\%h†QlV]GGHDJL;+.%%1'1-!<?BRIH>?L@GMIN@\aYTVVQWgaWPMKIC1:6<ES}|><€pY‚;%%"&/BPF<>9* ,NUVzƒmV{GW5 #FBuhZUj‹\c‹XiX“‹W}•epmc–•—c(^†Pf[[EEFDJH4$&(COEZsW.<CCNEFEAN?FQHM?Z_UTSZYc_`^QVTNI3726BKo‹ƒO+t}O<*-,2<@=71-*($%9GJn„}XlKD2";Dc}X‹^]‹b\ˆ^]ŒZˆUv—ijwd••˜k'XˆTbaXDDECJD+3N<.Av‚h:8B?NIDE>Q=GQDR:V]U^]`_`\^[M]VOI8868CIfˆ‰_!a‚_.')/3:1-35.+)#,DPFcƒƒbdY:1,;M[ŠXv\m\‹k[”\~•Wo˜pg‚a“–s(TŠUafUBCGBF:&&""$.ReV4 8A?NHDJ>O>DPISAP][dcb[ZSZfX`QBH?37/AD\„u0F~T.31./:?:'9DBGJW}…dVj@5"3@XXŒWo„^Ž}_…xY[n™bjžyjŒdŽ”—|+RŠ[ZlWDFGDA3+,!12'6FDIKJO>RBGUMUCQdcjfaWWT^gZXYFHK291<FW}’‚D6sC%8LPFFpmM,39j†t]qH'1LfT_d–\„_ŒY~egœlh¤gf‘”„4Q‡a[s[CDECB.'+ -3'7EFLNKR?QDGRDMDJadh[UVY_ecUMXPTM18*2FQwˆU+^..?Xga\o„d4+8i„~aoN$RvUpsaœasŠ\qŽ^wmcŸzj¥Ši’g‡”–Œ>K‰hZuWHGDDE.# 
9!"9HGJOLUCPEHRKMFJaf`XW^_e`^aUa^KI5:.,FLkd$I#:WRQXXiy|wz‹s;1/]ƒaf]%! DuZg…\˜g`ŒWhŒ_i}e™‚c¡Žje|—˜’EDiXzVEGFDC1-)%0ZdH')3;=HGEMKVBQJJTJNHHfc`WOjg_X]dXabOK674+EId‹p6 +!Njv„†„}}‚›v>-"S~ƒvŠ‚zˆ{šc…sbŽb`ˆfd„g˜a“o‹hx–••XA€s\[GFFFC/44,-ZkL+*0=AGFCILUHQLJPAMHA^ZX[OkcVXdfYX]LLA3:1>K^‡“„C $Tgmt{vuz{}‡”–|>%R|ž¦¦©¨«­¯²©pn‚hŠs^ˆqb‰m‹’Zz”kfr–“”]<vw[}_EGIJSK>AOUaga^bcehnppprvvvtw{xz{x~€ƒƒ„‚„‡‡‡‰‰‡ŠŠŠ‹Œ‘”šœ˜’v)+UL>516HZU?8?QhsE!cª¯°®¯®¯°²±²²²´³´´³³³´µ³²µ³´µ±°±¯±°¯¯®®­««¬«ªFFIL[bcfjlnoqruwyyz|~~}}„€€€€€€„……ƒƒƒƒ„………„‚ƒƒ‚ƒ„ƒ‚‚‚€‚zE:\?+)69:“|=.0BTx^28^nmkijiiijfffdbcb`aa`_]^^``_\\\\]^`__a`b`bdb_GHJM[XPNOQTTVVWYZZ[[\\^]]^_`aabbbbbbcdfgfggghikllmoppqqrqqrrsrB>eSLIE:[²˜C<LahjDZ~‡Š‹‹ŒŽŽ‘‘‘’’“”“”••——––———˜˜™˜˜˜˜˜˜—–•IJKK_kmmoqrsuwyz}~‚ƒ‚„†ˆˆ‰ˆ‰Œ‹‹ŒŒ’’‘’““”••—™›š››œ›ššžW.Ex†wft‹ £„aq‰œœg8Xž©¨«ª¬¬­®­®¯¬««­«¬®­®®¬««­«ªª¬ª««ª©ªª©©ª¨¨¦¥¢HHJKZddcfhkmopttvxyz}~}}~‚‚ƒ‚„†……†‡‡ˆˆ‡ŠŠŠŠŠŠŠŒŒŒŒŒŠŠŠ‹Œs@;kž˜ŸŸ‰¥±®¬¢´·bNp‰‰‰‰ˆ‡††††…†„„ƒ€~}{zxwwwttrrppmmihhfdb`_][VIKMLI5
10
11 
12
13
14
15 
16  
17 
18 5H]vˆŸ§˜‚‹Ž´¸®¢‰bW* #$$&&%'&%$&'%$##&$$$#$$$##$$#!##$"IIIHG=*
19  
20  (KUf~•žv1GCV¨´§—ƒvN$! -01*  ! ! ! ILLJLE2  
21
22
23   
24
25 
26
27  ;R]qŠ–vHE`…¨¨™ŠsF'&0/!=?B'   JJLJGB8(3>2,94>BB.7AB11< ''
28"5 $EXg€‘Œ~p€š©¤•ˆ|W5((..!!%GHN)   <YT:EBMXS\jcIM\kfKJJJIE?)5B42@;FKH3@IG9;D
29 
30#nf$!"
31;Xfx€’µ­š˜š‘†|yr:T¤‰47A3,MSQ*  $2 TigRMHYc]]ieMLbonIKLLIGB4DR;;HAVXY9M]^CN^'
32  "^Z%!"<iTIªœ<h–G:’œ™W7YcmZ<).+1LtŠ„{€‚=F†€Cy—o6…šs'  Bk*B]RSKSr|qWSRhxqnvq\et€ƒLKJJKGE:VeCK\TkokBcruL[q/
33
34  *m`%06$?hRJ§žBn—EQÃÈÈ΂0W`adw•–¥¡‡„otp5RŠt9^X7£Ê‡jßï­Ùæ1@1;QOQP`Š“|`d`„™‹ƒ“‰xŠž‘JLMLIHG;YoJUg]t}pEn}~L^o(  *n[,PdC M©™?q—DT½ÄÄÌ!EY\bYQZ^hy}|wcql3T“u.5ªÏ_¾Õ¨º¿×€/C5LPTXNi‘—‰qpoš£ŒŽ•Šˆš¨ŽIKMKKIG<\rGZg^zmDpz~Mcn%
35   /td0g|K  O¬—<xœBYÅÉÈÊ{?UXWL<4C_v{yyixo1\—w.;¯ÏzX º®È½áz>5*U{`<S“”€qs{¦ ‹’ІŒš¬ˆJLMNNKG>_uH\h_xfDt|~Ngk!  /t_$$&T¬’={ž@^ÇÈÊËz @U\iux†’’‚xzx—s3Z”s-AµËyj«´­ÄÁÛvO@2RRIQMx™“xst¢ž–Œ‚¦¬~KNNNOO_WesG_jbx‚fHw}Nnj  
365|]$##Z²’?—?bËÊÎÍpQdPY`inr}‡„|u}e¨š7V”u%OÀÏvl§¶¿»Ëz8HwgMeZƒ˜•xvr„£›•£¥•Œ¤¢rLNNNVgjYgvKegcy„gJx}~Qsi   !#3_O#>EL™¥­§\cOONWWRT]kqkozdÀ¯:1><"2LTSq«·¹ÐÙÀgM=FNHFIUŽ£‘qrq‰¥œ‘ œ–Ž–£œpOPRRdmkXfuQjhg~ˆjLzPxf
37
38
39#&!]½mOKIOY_badin\‚ùø¨G:6$<WZ_y• Â¿ÔµH^\EKEAA[“¦‘rrsš±˜“£™•”›¦›oMMPTellUewWqfa€‰lLz€~S|b  
40"$5—ÆÁŸOMMJFMXafdVlãùûûöÃs1#">WZb§ÇÇܬNRJDKB>Bg›¨qvv•­–˜« •—œ¥oMNQVgolUiv[sdc€‰qN}ƒ€S|b 
41 
42%%Ÿôêۼ׎GOPMKQ\\SSÖøùûûûûûû¸=&FX[f€¦ÍÉá¶\<R^MVL?s¤¬rwwŸ®”žªœ–©§‡pMOPWhnmNez]we_€ŠtO|‚|Zƒ^ 
43 
44$%J×ÚÛôè»ÄàwHMMLNOHZ«óøúûûùöûûûý¾l\]o•¡­×çíˆ>KWZOUOF|ª­‰uzz£­”¡¨›™œ¥¨~tMPRXjqlJb|e{eby†zV~„|[†\
45  
46 !$' ÷ôãäóòص»¢nILJG;q¦Vªöüüüû÷úûûúúúÉfqœ²kCY‚aDGZbOVWQ“²©†zƒ¬°˜©¦ž›¡ª§wzKMPXinkC[}awhbˆ|Y‡|\‡Z
47    $%>¬ôüüôèæôõë·—\{€S@F‡•b„å÷üüüûôõûûúúúúûç¾¥lY\Z<=5czK^nb³¥{}†­©–­®§Ÿ¢§ t{KMQXjojFW€fyqf„Œ…`‡|_ŽY 
48  '& KåôøüüüôêçôöôØžh]j<w¤‰v¾ïýüüüüùùûûúúúúûûûû°SPO5>7PŠwO|w©¸¤~€‚´ª˜¬­ª¢¡¨›pzLNOZloh>N‚csyh††[|‰}aY    %&NÐýûùüüüüôîìôööï·œˆexh´òú¿Îüýüüüûøùûûúúù÷úûûûôôôºG?5Lp^;^zµ·˜s€~•À« µ³­©««‘qwLMOZloh>F…cpƒm†’c~‹€b”_   '%8Ìûøøöõ÷÷÷÷÷ïï÷õõõ鼸ª—åúìãÊ÷úüüüüùùúúýýýóóûûûýýý§9><Sa`FZž¾¿˜sƒ¤Ë¨¨¶´±¬¬¶ŽvnLNPYmpi@AƒjhŒl‘’]{‡^j 
49$%6Ðûûøø÷óö÷÷÷÷ðï÷õõõõéÒßàãííúöìóúüüüûõöúúýýüòõûûûýúø±RJTXOFKEˆÁÁ‘w…‚«Ñ±«º³±®°´„}qIMNYknhG>~p^”k}—žbz‘’\ˆw!
50  )' Ÿûûûøøóð÷÷÷÷÷óîõõõõõåÖñòýýýýõéôúüüüûöøúúýýüòôûûúûúúÈxŒf\WVIH”ÅÇŒz…|²Ï´´¿º²«²³{…kMOOZoqhE9~`pwšžbv’•a€|* 
51 ()aÚäêûøøóðö÷÷÷÷óïõõõõõïÙîøýýýýøõ÷úüüüû÷÷úúýýõçóûúøýøú÷Ã`‰µ“›´£ÂÊ|„³É°¸Ã½µ°´¬q‚bNNP^ppiC0{a„yu¡jq“™l…4 %
52"*(ÙÚØñùùöõöööö÷ôòöööööêÜîõúúúúùö÷ùûûûûøøûûüüùëñøóñýêòûÕgaG]uV­Á¸‚‚‡‹ÀÅ­ºÇù¶º¦q‚SMNQ^qohI&jYfˆu•œqd“—szˆ6
53 ! !)+ >ÌïáÒßùù÷òôööö÷ôóöööööïçïôúúúúøõ÷ùûûûû÷÷ûûüüûêñøîïýòîöÑS‡Å_˜¨s¾Â²{†ŠÁ¿£¼ÈÁ¸µ´–p~JMMO_wwpcVapXWkWr{OKƒ‘fpk' $!#..!^ÄóáÈÙùùùóóööö÷õñõööööòëðõúúúúøö÷ùûûûûøøûûüüûðôøíñýðèñáef}rWh„ÅÂ¥x†„’¸¤ÅÅ¿¸·²‘x{DKOQbrrtwy|€„ˆ‹’“–——™œ¡¤¥¨ª«ª«ª©¨§¨¨¥£¡£¡žš”¥»ìéÂÑøù÷ìîööö÷ôðôööööôïïî÷úúúôñ÷ùûûûû÷÷ûûüü÷ëóøööýûáßû„GNBF7s»±‰gkwšÅ­¨Â¼·´¥†s?MPRYF997:<><>>><<;;:<<?@BCGKQTV[_bhmuz…‰¥ÊÅáÚ¸Ëøøõëñ÷÷÷÷òíöööööõëè×ðùùùôð÷øúúúùóöûûûûùîóøðòýýÖÎýîÔÖÖÕ×ÕÕÕÙÛÛÙÙÙÙÖÕÖÖÕØÚÛÚÜÚLNR_jkhilmmoqtttuuvussrpoommlkjigedbba^\ZXXUCҿȸÏÂóøöïñ÷÷÷÷óåðööööôéåÕóùùùôðöøúúúúøøûûûûúëò÷îóýüÚØýë—€€ƒƒ„††‡ˆ‰‹Œ‘’‘’““”•——LLQbrsuvy{}‚†‰ŠŽ‘’“”••–˜˜™šž žžž ¡¤¤¢¥§¥§§˜Ì×ÁÇ´íÃîøòçóöö÷÷öäîööööõéêâùùùùòòøøúúúúùùûûûûûîòøéðýüßåýüµz{ywvvtstuqpqponmlkkjljigHMMH2 "%*,17;>AEINS[aflqtx}v¹Í½ÉÄÖÅìøõéï÷÷÷÷ôäïööööõéãìøøøùíî÷øúúúúùúûûûûûù÷ôÁãú÷ÙåýýëÌÈÈÈÇÇÆÇÇÆÆÅÄÃÁÁÀ¾½¾»º¸¸¶ILLMB$ LÒâÎØÝÔ²æøøíî÷÷÷õòæî÷÷÷÷öïàòøøøøëéøøúúú÷÷ûûû÷÷÷÷ûôºåðåØñýý÷žƒƒˆ‹”˜žŸ£¦ª®°³´·¹»½¿Á¿IKKJD-  TÐæÕÐä×¶Ù÷÷êé÷÷÷õóæë÷÷÷÷öðäîøøøøéå÷øúúúôóùûû÷÷÷÷úùÜçßÖÑ÷ýýý“#&$# ! !  !!JKLIF7  PÐóèÎßÓ»Ööøîî÷÷÷õõêç÷÷÷÷öïàîøøøøòîøøúúúòíùûû÷÷÷òùòÎÕÕÔàýýýýÎC&$#"  !""!"""!"#"%$EJLHC;' ]ÔöñÔÚñÖõøñð÷÷÷õõéç÷÷÷÷öíÝðøøø÷îìøøúúúðç÷ûû÷÷õéïðÙÈÍÖáüýýýõw%&%##"!#"!"#"#""""#$$&'IJIHF?. uÚùôÜØÂ›Çôøòíöøøõõëæ÷÷÷÷øîÌéøøø÷íð÷÷úúúïÝöýýúú÷ìòàľÒÜàöüüüü¨2)&$"#$#!"""#"#&%%&)(()HJKGDA7$  &‹ØùöâÖÆ¯ÅñøóæôøøõõçÞõ÷÷÷÷êÞöøøøöëñ÷÷úúúïÞóøýúúôÞïß²«Óß×èüüüüâW,(%%%$"#$####$&&()(+.0GHJJHB=, @¯áùøé×À¥¸êøóéôøøõóåÅë÷÷ôðæÜóøøøöéï÷÷úúúèÙ÷ýýúúõàò衤Üèßäüüüüú‡$('''%%&''&%&&'(),*,/2FGFGEB?2 [ÌëùùïÔ¯œ¤Üòñçôøøòïã¿ßóòìßÝòøøøøòåñ÷÷øöö×âýýýúúñßôâÖðêàúüüüúÀ9-))('%'''&&((+---.022GHHGFB?7& oÜóøùíϦœ—ÍëïêöøöóïÛ»ÛïðæÛäöøùùùõåóûûüüûæíùùùûûèÑéÊ™©ÔöóÖêûûûüîn+++(()'&%&'*+--.04333FFFGFB?9*~Ýó÷ùó×§¤œÂÙáØòøõðëÖ·ÑëçÞßðö÷ùùùôäöûûüûéÈçùùùûùÔ×õ§°ËùñØêûûûüüŸ.-+*((')()+,-./013444FGJIGDA;0  "—âùùùõݵ±£ÁÖÑÎóøöïêâÃËæÞÕäñóôùùùïÞ÷ûûüûêÐëùùùûùäîð³·½ÚùùÜãûûûüüÛS5/++,+++-/./10362251DGGGEB@<4& B»ñ÷óôõÒ°³¢¹ËÊ´àøôâÔÖÁÆáââðêðòøùùïÛ÷ûûüüïÜóùùùùóØîâ¡¶ÛõùùíÛóûûüüü…)-.,,+*,.00122244444FFEEDA@=8- _Öôôíëôླྀ£´À±ÇÞÖÍÏÒźÔÜêóáìòùùùïÖòøøüüìëûûûúøèØõÑ›´à÷ùúõÞêúúûûû¹60,,-.../0334555553/BBDDCB?;6." yÐéèæÞÝìܵ›°À̹ÀÚÞÔÊÒǹÑàïðâîñòñ÷íÙõøøüüíéúûúúúçÛøÄ‘µæöùùöàáøúûûûîn-.-/../112333335421EDDEB@?<80% 6–á÷÷÷öèÃÓÑ•¨¸ÆÂÀÚÏÈÈÑIJÌäòíÛëóùùùíÚôøøüøàãûûûú÷ÔÙú¿Œ¶èøúúúèÌéúûûûû¥6.,/121134464543244ADECAA?<93' N—Ñö÷÷÷øëÖⲫ½ÈĹÒÓÍÐØÌ¬ÉëôçØîò÷õöÜÐôøøüôÓâúúúùïÓãô¸‰©ÑôùúúïÙìúûùùûßZ20012/233121132122@?B@A?A=:4+!d‡†ÏÍ·¼¼œ¥½®¬ÂÌȵÈÒО¿¨ÁæòãÕïñö÷÷ãÃñøøüöÑåùûöôïÜìö°˜¹ñøðíñæàýýýýû™/44314442034532441BABBCB@><82& ‚ÆÞô÷õÑ™”˜†˜³ÂĬ´³›‘Ÿ««¾ëòáÏßðòò÷îËîøøüøÔàø÷ðøîÝíö¤}Ÿ°äêæçîõòûýýýýúÐQ84443444222333121>@CDDCB?<93(DÀúÝ÷÷÷ùúÝŠb‚¯¬™‹“§n‚ž®ÃìòáÓêð÷÷öíËáøøüüÝäüüûûöàìç€t¡¸¼áúúýúìöýýýýû÷…88432421255422122=>@AABA@<94+"nݱ³Ùô÷캙”™vkwwy„œ¯¢yWp’¥ÐòÜÍéò÷÷õçÈØôøüøæîñìêéæÍæævp›±òúúúýý÷öüýð½‹U973222122233220252@AABCB@><97.#(®rH 9ltvpmb\ZZr™³¢T !&¡ËÊñòìô÷ïÎÓïöýîÞíåàëìçÊëÞnkœ¥ÖúúúûÝs2.BS@78423322312311221/11>@ABABA=<;72'(0&;_ggea\SQU]i™¯žSˆÆÌÝæôõõíÎÏëöýùè÷üûúûöâñÖfl–¡ÆÅV7@CDK<3443223322334443233110=>CCBBAB@<94)!  ""!!"""##%"#&'!(AW^_``\XY^XWb‚Ÿ“P%¤µÈñøöøøðÐÍáôýýýýüüûùôæñÒxmŒ—€Z8:>FNI:899:7878557677766777554>?@BABB@?<95. !!"""##$%%##$%%&((''(-5@LSWYXVTRKDI^`hz`5*, /“©´øüøøøóÑÑßðüýüüüüüøíÛîÎuaƒ‹X=;=DOYI889:9::999879::999:98886 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/pan.1.pgm b/SD-VBS/common/toolbox/toolbox_basic/affine/pan.1.pgm
new file mode 100755
index 0000000..9d57f70
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/pan.1.pgm
@@ -0,0 +1,59 @@
1P5
2# CREATOR: XV Version 3.10a Rev: 12/29/94
3128 96
4255
5prsrxxwxz{{||||}~~‚‚‚„ƒ„…ˆ‡‰‰‰ŠŠŠ‹‘’’’””–™ššœžœœžž¡ «§££¤¦¦§¨¨§¨««¬¬«¯°±³µ·µ³´´µ´·¸¹¼¿¾¿ÂÅÄÄÄÄÂÂÃÃÄÉÈÇÆÆÈÊÈÈÌØÅ¿Ã¿À¿¾¸prsttuyxyyz{|{{|~ƒƒƒ„†…††‡‡‰‰Š‰ŒŽŽ‘‘’“’“””“—ššš›žŸŸ¡¢¢Ÿ«®£¤¤§§¨©««¬­®­¯°°°µ·¹¸·¸¸¹¸¶º»½¾¾¿»¼¾¿ÀÀÂÄÇÇÇÊËËÉÊÊÊÌÌÉרÇÅÂÁÀÂÁÀ¼tuuuwwvwyxzz{|}€€ƒ‚„†‡ˆˆŠ‹‹ŒŽŒ’’’”•–•˜”•š›™šŸž¢££¤£¦·ª¨©©ªªª­¬®°­²²±³¶¹¹¹¾½½¿¼¼¼ÀÃÂÂÂÁÃÃÆÄÄÅÆÇÊÉÆÇÊÈËÍÌËÊÊÆÚÊÀÀ¿¿¾ÁÀ¿¼tuwwxxzyy{{{{||}~ƒ†…„†‡ˆ‰ŠŠŒŽŽ‘““••”•–—˜™šœœžŸŸŸ  ¢£££¥¡°¹¬ª«ª¬®®­¯±³µµ···º¼¾¾¿½¼½¾¿¿¿ÃÁÁÀ¿À¿ÁÄÇËÍÓÖÖ×ÖÕÔÒÑÑÑÏÞäÕÖÖÙÛØÕÓÒËuvuwyyz{~{z~~~€€‚ƒ……†ˆ‰‰ˆ‡ŠŠ‹Œ“••—˜˜š›œ›œœœŸŸŸŸ  ¡¡¡Ÿ››¡³œ—˜œ¢£¦ª®­­¯¬¬¬ª¨©«ª©§¦¥¥ÌÕÄÃÁÂÅÉÅÄÆÃÅÇÊÊÍÍÌÎÊÍÎÏÑÑÓâ×ÕÔÓÕ×ÓÔÖÕÏ_`k€{x{{zzywzyz{{{}~~€‚„……†††‡‡‰‰‰ŠŠ‹“•™šœžŸ¡¢££¤¥¦§©¨©ª¦¶µ£§©®³µ®£œœžžŸŸŸ¡£¦©¨«¬ªÎÚÁÂÁÂÅÅÇÈÈÇËÍÏÏÐÍÍÑÒÓÕרÙâèÞÜÛÜÜÛÚÚרÕ8:E[‡{|€‚‚}…„ƒ„…‡…‡‰‰‹ŒŒŽŽ’’’””˜˜˜˜š›Ÿ  £Ÿ¢¤¨§¨ªªª«¬­­¾¬­®±µµ¯¢™™šš›››œ›Ÿ¤¨¨©¬§ÆâÊÇÌÎÌÊÍÐÒÒÒÕÕÕÕÔÕÛÝáááááïæâäãäåãàßááÛ57@_WY…„€€‚‚€ƒƒ……‡ˆˆˆŠŒŒŒ‘‘’“”•––™šžž   ¡¡¢£¥§¨¨ª««­¯¯²±Ä¿¨­´·´­¢š¢¡ ¡ŸžŸ £ª¬­°©ÅéÑÏÑÓÓ×ØØØÛÞÞàäããåèèèëéèìóéèééëìêìííîê:9D`ny_i”ƒ€‚ƒ†‚‡‰‡‡‡Š‹Š‰‹ŒŽŽŽ‘’“•–™™™›œž ¡¤¤£¥§¨©©®¯°¯®±³´³³´µ¾Î´¯·¹³®¨ ›žŸžŸ¡¦¬¯°¯´¸°ÈëÖØÙÙßßàèèëìëëïííññðððòîïôòôóôóõöö÷öóí8:B^kryxc}„……††ˆ„†ŠŠ‹ŒŒŽ‘‘’••˜˜˜™š›Ÿ¡£¦§©«­¬¬­°±³´¶»½½¿¿¿Á¼ÈÑ·¿Â¸°¬§¨¯³³²¯¨ª®±´³´´¯ÇïÜÜßâæéìòôôöøøøøøóìæâÜÒÉ÷õóô÷ø÷÷îëôÝÛÚ8;C[gorv}wb‘…ˆŠŠ‹ˆ†‹Ž‘’“““’”——˜š›žŸ¡£¤¤¦ª«­°±²²²´²³·¸·µ¶¹»¹½ÄÊà ned_gx­ÇÊÙñüýýýüüüüüüüüþþþþýýýýýýýýüüüüûûÕÑÀ®¥ß·øúø¥0­çmšt9;D^iloquz~nq’xifdefq€„…ˆŠ‹’“•—˜™›Ÿ¡¢¦§§ª­°ª’Ÿ¥—¤½ÂÄÅÆÉËÍÐÓØÙÜç¨Õûûûü÷†1ÅýýýýýüüüüõèûüÚÞíÕûÛÀüýª¦ï‘ͺŒäØx—„^Ž[r‚‡ˆk4\|JSZ87A[gjknqtw{€f”öýýýû䀔–˜”•œŸžž ¢¡£¨¨«­°¯°°y962??XªÉÏÑÔÛßÍÇîñúà•ÁvÃøøüÃb0 n® ’WGa7-84Z`HA`Hu_NulKQwIaiTƒxNc‡w]uZm|‡i&[~KQ_8:BZdeffcK5850)%)09::B6BAIAGIEB>]linhbc[e_^aRC71/4=Eera?=Y_=He<30(Wd0$FkenD9„y_]wKQlImuVS|LvvSvrKT{MbqSƒ|R[ŠvSvUb€‰]$\KM`;;CX`cba[A2/41)&2-/=74C<?9G9AE=;5U`BVTDJBDEJB6<A7,4RNc{l?BenWOi?"Bu@#$M[lP'mƒyfWtLNsK`vkv‡St}NmSQ€MZ~Nz}UT‹{OrQcƒ‰b$XRIb:;CU^__\Q:226-%'/03=75C<C:D7@J??8V]DPVBIE@DI@2=A@;5NS^xn;9`lgH‚kH+$lBSi]I((Z~tzpNaQErKGe”Ú¨Wj‡L`wPQ€ZPOpZNŽOqV\ˆŒ’e$QVKl;=EVZ]\RF7559.+)32/:;9C>C8H8?H<?<TYFMY=MFHPLF9FB9?6DHRsuK ]p?lqJ5\UIiNX9'C‚fnuPYZBpWCg‡ÐªUZˆNYyVNjV†Qf‹kK‹ƒNi]YŠŽ”n(I…^Go<=DQYZVLA579<*'+1-4=66E@H=D7;LCE<TZGGU=GJLULL@DA5:4=FLpyZ HqH\‡X:!Fe)$agiG&0yjgz]TlCgfDZk³¥ZK†WM}fQ€tQ€W^tK‚ˆSgeW‹Œ“w.D€aJp>?EUYVQF>7:>A,%(2-6A:;N@KBL:7L?G@UYJ@XEMQP\GTF@@4:58EHh}m/ 6nXOmG*3q<S{jJ$)&lwqnUvG[n>FU™hJƒcLƒqV|ƒStbW…MzTcoY‹Œ’~3C‚iLq??ESURJA=46<?,)+2,6A<=J?H=H;:J?G=OVMK`NQ]YWIRI8?8875CF`u=)kiGƒqO,"nL*Vn]T)*T~n~xNiLKsDC\ˆŠuErtG|yOm„ShpUއLm’_\{V‡”†::}oLtA@FSSNFFTSFA@+*,.-;=?AOBO:F=6L?IDQ^WN]RP_YTKIJ2@D8<6FFY|zN]vFpƒ^6$^cDSYjlt;0@‚s|T]^GuRBb`FyGh‡Ko}NgƒWV|T„‹Wd—jY‹[€”ŠJ6xsMq@BFQQKL[[QD>A+)*+*7>>>LEL>I?7G<GBL\ZQ_YS\XKHBL;GG3?8@HSw€c$ItP_•hG4RgqgRJ]q{G&%5|rv€[RlHoaAfcBxWZ’OaR[†`V†Pu‹[`—u[ŽZyŽ”J2vzPu=@GNLJN]]QD<>+,,0+<>>ES@KDGC;GBHBF^^X]aP[WEKBRNGC0969GKo„q45teWjJERTOC3,7O_K*#h}{‡oRqJanUi†rwqW—]U„`WkR†Qne[–…Z]sŽ”T1t~PrACEJIFKYWLB>>'#(-*8>>@REM<EF:HBEEC`a\\[MOPMSITPED6847KMhƒ{E+mzO}_53CMKB.#6FKH3+Vƒ€‡{PiJOm69.aƒOjP†oT†xVƒXb•s[”\…]j‘••T)l‚Nl@?DFFDISQG>)
6 &':=@CSDJ>GH<HFHI@ab\VPJFNMVSVXG<<696AA_…^a~S6(#'3BJ</(*'>UC/ Gˆ~„ƒPZWIr:37Q“SnV}V~Tyf_˜{\”b|ca•”•\&a‚MeACEHGELUF6&6<@BREH;?K<JLII>caYUSNLRX`YWUEDB4;7?EVˆm*O{P'$&)8DIG;.'.S[E'2}„^RiGh:*ED„[^Vt†To‡Tjr\–…V‚•cqj`’“•b"[‡Oa?CHIGELQ?/1) -#+'&7=DTHI==L>GOFO=^\WRPUSYd^PKIHHC062;EP{‹}7
7=S*# (>RG9?9/ @VJ3'j~~ƒmUyGX1!FCujYŽUf†ZaXgƒYŽVz“ffub”•—k'UˆR]ACDEFFKL8'&#@UERnX-9BCNEDC=L=FPFL:X\RRSZYc]]YKPPOI3616CLn‰ƒL".),*-8A@;53/*%$8HH;R„}„~YmLC/#;Ec~YŒa[ˆ`[‰b\ŽY‚Vp˜mgc““—r%RˆWXCCEFHFKG-+OA3;t„n98@@QFEJAS?GRGR:S`W]\_b`W[[P]VNH8845BIf…ˆ`" #&+/40/78/,+%!8NE>#B„„‚^aW;2.9NY‹W~v]q^ˆq^•Ys•^lui‡dŽ–˜{+O†_UACEEFCE>''')',JeZ=!7A<JHFL>Q@EPEP?P^Ycdc]WOXd\cSDG>46.CF[„s4!!,42-.7;8)-<CJKJ26z|~„dXmB5$6CYXŒXn†]‹`…}Z‹]h™igŸ}hg‹”–0K‡eWEFFHHGE7..! %&34$2C>EKEP@THIULTAMbajebUUV`h[XUFIN2;-;FW}‘F%(4HPH=blQ49:1$f}w‡uZrF%.MjX€ee˜^‡^{]hc›ul¥…hf†“•‰?G„lVBDDEHFC1(-
8)2%0@DEKHS>SFIUFLCHachZYXW`fbUOYPUO19*2GPu„B'8Od`Ue€l<)51U†zƒ}`qN&QuTpwaœaoŠYm]tr`f¡i’e~”—’EAƒqWEEGIHEG0!
9#"6FEHQKTEQDERKMDEae^UR^^d\V[P`^KI3</.GNmŒŠB/LMEMTcu{zv…‘ŽzJ53/Bˆy€ƒ\aY  Dw[eŒ]–faVd‹`c‚h˜Š_š‘jŒcy——–J<|tXEFGIIIG3+(%+O`H'(2:>IIFOLU@NIHTKKDCe_ZTMkg\UXcW^^JH6:6+DGbЉ<@es€…††€~‚žŸ“|I0*3.2y}ƒs‡Œ…„|ˆ‚z›a„ue‘eaŠe_ˆh•’`Œ—k„hr–”—]:z}YFEFIIJI323()UkO*(.9AIDBKGOCNJKRCNHA^UT[Jg`WVbdZV[JNA5<0>I\†.Ehpx}yxz{‹™£ž„I'!,$#g~‚z£¦«¬®¬©®¥nl„gŠt[†qcŠh€Yu™fwii””i;oYEGIKLIPI;:GM[c^X[]acgklmmqpoqswuvwt{zy}z€‚†………‡†ˆ‡‰‹Œ’›“BKSG<69G[ZI@EUlwT(I¦±¯¯±²°®®®°±±±¯¯°²´µ¶µµ´³²±±³³±²°°¯¯°¯¯®­¬¬ªª§FEFILMYgiikoprvwy}€}‚……†…†„…††…††‡†‡‡ˆ††‡‡‡‰‰‰ˆŠˆ‡‡‡ˆ‰ˆ†…„ƒY-UM2)-88{}B/'8Xsi4(Imnnmnmlhhigeccecb__`a^^\^]\\\]^]]][\^^``bbceebFGGJLLZYOMNOOQRTTSUVYYYZ[[\\^^___^^^`abbcegffffgijiknnnonooqY(2`TGCA=K¦©K9>V_xwHPo…†ˆ‰‰‰‹‹ŽŽŽ“’’““•••———™˜—˜™™˜™š›šš™š›š˜HIJMMN^lqopqrsuwzz}ƒ‚‚„†‰ŒŒŒŽŽ‘’“”””““”–••–˜››œ›œœšn4Ajymeiƒœ¨†`_v“žM@‚¦©©ªªª¬«­¬¬­®®«¬¯­®®®®°°¯­¬®®®®­ªª©¨©¨©©ªªª©¨§FGHJKKZghgilnoruwwz|}~‚ƒ‚ƒ„………………†‡ˆ‰ˆˆ‰Š‹ŒŽŽŽŽŽŽ~M;aŠ—˜¡­¬«š­º¨wWj‚ŠŠ‰ˆ‰ˆˆ‡……‚ƒ„ƒ‚€€~}|{yxwvtrpomlkhffebaaa_\[YWTKMMLNMK8"
10 
11
12
13
14
15
16
17
18
19 
20  ,?Qt‰œ§š†˜ž·»´«”taA!!"$&%$&'''&(&'&'(&%%#%$"$$%#!"##"HKKJJKI?+   
21
22    
23
24ASd|“ ƒ>AGR¡¶®ž‰ve5"++!$" .12,!! "! ! JJLMLLKD5 
25   
26 
27 
283P\m†•|E?Ww¤®Ÿz¦ƒ*11''1/ =AB)  KKNMKKID;%->5-:3:@C.5AC52=  (+ 3 !?Wf{Ž~o{˜©¨™‹²~(00&%-. #$EDN+   8WX=GCMZTZfdIL]IJLJKKKJA+1D3,@8FKL.9GG64F    kj(#$4S`u‚“¿Â£šž”ˆ|œÄx3qq;S¤Š69G6*MQQ( +
29NeeRMDRd^]feGG[JJKLONMKE2>S@9LAVXY9H[]CG_)
30
31
32 \[%"$<hSF¨š=j—F:|\bmdJ1005QuŒ…|ŸÀt:ƒ?FˆDz™r6…œu' 
33 <l,=^SUMOq{rXUNdvpmwu^_qKKKKONMJE6JgLEbSmopC]rtORo,
34   &kb'-4%@gTI¦›:k˜CNÄ©caa[exp„„„´Ås:vq6RŒt8[|Z0ŸË‰gÝò›ªÜé”3A2:QPQU_ˆ•€hd]™‡‘Žy{ƒIKLLNMLJH:QoOOm`s}xFg|NWt-
35  (l`*QfDK§˜;o˜ES¼¹|[_d_Xccfx€x‡ÁËt;vl2T–x-4ªÑ‚_¾Ö¦·¿×„,D5JOSYQf–ˆrqj˜¤‹‹”‰ˆ”LLJKOLLJH=TsKToc{vFm{€N[r( 
36 +rc.g€NP­—<vŸG[ÆÉ™YWUPB9C]pwxv’ÅÆp<yq3Y—w-:­ÕY¡¸©É¿å~;6(Nt_<Rz’–€nurŸŠ‹“ŠƒŠ—LLLMNOOKI=XuITk_x€pEo{€Ods%  
37
38 -tb%&)!T­“;{ŸB^ÆÈŸZ[eqr~‰‘…xxo¥Åp=u3X˜u,AµÎye«³ªÄ¾ÞuK=.QQDOKv™“xrv{ŸžŽ•‰†žLLNPRQPO[V\zJWi`{‚qGu|„Rlq"  
39 3{`$"%Y±“>˜>cÊÃUYbksw‚ŒŠwx_’Þp:{s3O–v-I¿Óvj¥°¾¼Î€z7GuhLc[–˜{ts£Ÿ”¡¤ŽŠ’žJLNNOOUfkW`zL\ia|ƒoHv~Soo  #& 5bR$AHM˜¡pMNUXSSZhqlkx^›ër0QK-.<:#2NUQmª´µÏÖÀeO:FMGCHR¥”ssq†¥ŽŸž’Œ–¡PORRRSdnmYb|Naj_}†rJx„Tsj  
40$%  ˆyFLIQY]dhbgnvlÚú±=77*,43$8UZ\lŽ”½¼Ï¸IY\DNHBF\”¥oop’³š‘ š–“— MOOOORdnmV`|Sgk^~‡uKw‚Tuh  #%+€¸¦UKKHEJS^dda[Ëûûýñ°^/1:8':VX`|˜¤ÆÃÖªKPICMD?Abš¨Žnrq«—•ª¡“–˜¢NNMQSUgpoU^SgiZ‰{Mx‚„Sye
41
42
43 
44%%!¤çٺɒBJNMKQ[\WL·ûûûýýýýû«G9$ ! >W[bx˜¡ËÅÛ³Z5G_LZN@q¢«Šnvs˜°”™¬ž˜œ¥¤MNOQQTgpnP^Zni\~†}QuU|c 
45
46
47$& _×ÒáäÆÂÛyFKLKLNKO­ùúûûýýýýûûù¹K'%%EX[kœª×èîˆ<HR`RTODx¨®‰pwt™¬“œ¨™•ž¤©OONOQWiqoJRbul[}‡„Vzƒ„Z€a 
48  &'‡øõäîîÞ¹ÙÎpHLKFB[`©õúúüüüüýýýýü½<)HY[o™±g?W_BCUgGMZJŒ±¬‡wvz¥®•¡¦œ™¡¨¥NOOPQViqmEQ‚_nk\‰„Xz†„[†a   
49&' -”ðúúöêóóê™]svM>Azqv×ôúúüüùùýýýýüüüÊ…^^vœ¢jT[[;;*UzKYn^›´ª}x{©§’¥©£ž£¦ŸLMNOQViqkDN„bqt_…‹^z‰ƒ_‹_  %&AÒïúúúúõèóõóà¢f]kAjŸ†n¯êúúúüüûûýýýýüüüüùø§‚Ç¡nOOP7</H‰yKyt¢¹¦z}ƒ‰­¬”¨¯¨¡ ¤œLNNPQYkplFHƒbk~e‚Ž‘\v‹„`Œ`   
50%'SÔý÷ùýúúú÷ìóõõó½—ˆhzg«òúÓÖúúúúüüüüýýýýüüüüùùùõÖÀìë»D>.Do[6^t³ºr½«š¯°ª¦§£“PMMPRVjokIBilŽn~Ž•]xŠad 
51%'!?Ñøø÷ô÷÷öööôñôôôõ渲Ÿ‹‘ÝüííÛîûûûýýýýüüüüúùùúýýýýüÄÇØá¨7<3La^CV”·¼—l€šÇ¨¥´´±««µ”MNOQRYlpmK>€rc‘lx–^vŽ[ˆo  
52')`êøøø÷õö÷öööóïóôôõõëÔÖÝäðë÷üúúûûûýýýýüüüüúøøúýýýýüßÉÒì¨QEMTQFHB¿Á“s‚~¢Ñ³¨¹´²®­µ‰NMPOOYmpkN8|~`‘kv–at•^„z'
53  '&:Éøøøø÷òó÷öööõñóôôõõîåõõøúüüüüûûûûýýýýüüüüúúúúýýýýüùñùûYƒ[[UTG@‡ÅÊŽw…zªÏ´®¼¶³ª¯µƒLMNPPYnrlO6zŠ]‡tp›Ÿcn’—`z€- 
54   ))–ìïõøø÷ôõ÷öööõñóôôõõñæóùùúüüüüûûûûýýýýüüüüù÷÷úýýýüûü˵٠­a€²˜²ˆ—ÀÇzƒ|­Ç±´Â¼µ±³²uNPQPQ]qtlN+o‘`{}t›žmg•šmw‹7 &
55! !/MÈàáè÷÷ø÷÷øùùùøòôööõõóìðöööûûûûûûûûûûûûùùùùù÷÷ùúùúøùû¸OHnµlZFZ}Q¤Â¾„€†·Æª³Ã¿·´¸ªmNNMNQ]qtlP$a^]Žrvb•™xv9   !!xúæÙâ÷÷øõöøùùùøõõööõõôóôöööûûûûûûûûûûûûùùùùùøøùõóúø÷úàkD\‹P|Ã]’­p¸À¸~„‰‰»Ã¡µÇÁµ±²›lLNPRR_wytgYbs]XpYk~UF{ees, $!!6æèÕØ÷÷ø÷÷øùùùùóôööõõõóõöööûûûûûûûûûûûûùùùùùøùùôõúúùøùû¶™–RazrVi‡ÇƬxˆ‡’ÅÀ¸³­‘nKLMPS`rssvy|ƒ†‹‘“•™šœŸ£¥§©©«¬­««ª¨§¦¥¤£ ›°¼ÖðÛÏó÷øõõøùùùùôôööõõõôôôõöûûúúûûûûûûûûùùùùùøøùúúúúõëøð†LZ?HKDG:r¾±kny•Ƴ§Â½¶´¥‹wKLNPRZH9:99<=<>=@=::<;;==?@BGLORUY_ciosx~ƒ„€±ÄÏãоï÷øôóøöööõóöööõõõñóéó÷øøø÷ûûûûûûûûøøøøûûûû÷÷ùùôÓùùÜÑÑÒÔÔÕÖÖÕÔÔ×ÙÞÜÛÙ×ÖÖÙØ×ÙÚÜÙLKMOP^lnlllmnopsuuuwwvutsqpopnmmjhgeeb`__]\_»ÀÐÇÛÂç÷øõõøöööõðòööõõôïëÞô÷øøø÷ûûûûûûûûøøøøûùúûîñøù÷Ùúü¶x{}}~€ƒ…‡ŠŠ‹Œ“”••–—˜–JLMKN\nrsru{}€…‡‹ŒŽ’“•”•—˜—˜™›Ÿž  Ÿ¡££££¢£¯ßÆÚÂÚÐß÷øôôøõõöôîóööõõõðìä÷÷øøøøûûûûûûûûøøøøûûûûðòùùøâüüÕ…{zvvtrrqpprqpoommmmkkihgheLKJNOK:
56
57  $',048:>CHNTX^chd—æÉÍÇÂÇáöøôôøöööôíñööõõõîëñ÷÷ø÷õöûûûûûûûûøøøøûûûûÑßøõêàüüùØÉÇÅÅÄÄÄÄÅÃÄÄÄÄÂÁÁ¿¿¿½»º¸·´LMLLMNH*  }èÖËÚՏɸùõôùõõõóíñ÷÷öööðêöùùööòôûûûûúúúúùùùùûûûûÅÖöñÝäùùý¶o{…ˆ•™ ¢¥©®´¸·¸¹¼ÀÃÆÂLJJLJJG4
58 †ëæÇâá½É÷ùõñøõõõôïð÷÷öööïé÷ùùööíðûûûûúúúúùùùùûûûûáêëáÍäùùýÐE(%!KKLLIIH>% ˆíïÓÚÙ¼Îõù÷ñ÷õõõõðñ÷÷öööïç÷ùùööóôûûûûúùùúùùùùûûûúãâåâÞôùùýõ{&#!! !!!!" !#LLKLKIE?-  êóàÒÏ­Éóùøõøõõõôðð÷÷öööðçõùùööòóûûûûúøøúùùùùûö÷÷æÙÍÚÜôùùýý¯2&$#""!!! !!""!!"!#""$MKLMJFGB5   4¬ðöèÓÖ¥»ðøöôøõõõõñï÷÷÷÷÷ðâòøøööòôûûûûûùôúûûûûüüüæÏÊËÞàôüüûûì`+$#$$!$$""#! ######%'&KIJJIGEB:( N¾ñöìØÎ¶¿ëø÷òõõõõõïêö÷÷÷õëæ÷ø÷öôñôûûûûûöðùúûûûùíöâÉ»Îåéïûüûûû#)'%$"###""#####!#%%&%&)KHHJIIFC?/ lÒò÷ñßɪ­áööô÷õõõòãÈì÷÷õðéê÷øøöôòöûûûûûìåúûûûûùêùá°¡ÚíöðûüûûûÃ<+($$$'&&$#$$%$#$%&&&),+KIHJJHGD?4# …Þô÷ôäÁ¦ ÒñõòöõóïëÛÃâóòíááóøøøöòîöûú÷øõäòûûûûûîáùâ«—Îìøìöüûûûós(*(&'&&&&&&&&&'('&)*,..IHHIJFECA9(-¢æö÷õฤžÅéòðõôïëèÚÄÙñòçßç÷øøøõðíóýýýýùôúûùùù÷ßÓëÚ¬§Éïûåèüúúúú¨7-,)(''&'''')(&'*-./123IIIHEFECA<0 =¹ìõ÷÷뾬¢¸×èæñóïëçÖ½Óëèßãòøøøøõíêôýýýüïãöûùùù÷ØØóЫºÈóüïðûúúúúã\0-*)(''''('')*+,--0123HHGHHIGEC>4%UÙùöö÷îó¥ºÖÜàôõòìçÜÉÏåÞ×çòøøøøõìèõýýýýéÜöûùùùõâèôÁ¦ÀÓúüòçùúúúúû(,*+)))*+***+,-/223365GEHIFFDDB?7)kàúóñõí¶¡®ËÓÆæôòåÒÑÇÌáâäñòö÷øøôçäõýýýýöñúûùùøðÚïì°¯ÏëüüúïõúúúúûÈD0,**((*+++++./0344223GGHGGFIFCA</"ìøðëïïÑ»¤®ÂɾÍßÍ¿ÅËÈÈÙßêïîùøúúöæâöüüüü÷÷ûûúúøèßöÛ¡®Õõýûûòðûûûûüòz-,-.-)+,,-./131343343EDDFEEEDC@<2&3¬åìêæÜèëÆŸ©ÀÎÃÃÕ×ÍÅÐÊÃÕãðñïùõòóõåâöüüüüõöûûúúøãàøÐ™¬×öýûûòíúûûûüü­6.,---,,..0/023332222CCDFGHGEA><6-!FÁúúööóÚËØ©£»ÌÐÉÐÇÃÇÔÌÀÓçòñí÷ùúúöãßöüüüûïõûûúúöÜçú‘¬Ùöýûû÷éóûûûüüîk0/-/.,-./01212342243DDDEGGECB@<7."`¯÷úöööóáÞĪ»ÆÉ¼ÊÎÈÍÚλÓëõïí÷÷ø÷óÕßöüüüùèóûúùøîÛêò¹‹¦Ìðüûûûìîûûúûüü 1.-.--.-0/0223310110CBDDECDB??<80$,{w³Ù¼µ¿® ¯°§ºÅʶ¶¿Ç¼²º±ÆçóëèñóùùôÕÍôüüü÷âòûûòóòèõ÷¶‚”­àûúúúïÙòûûüüüÜZ111/./0110111310110BABDEEFC@?=;4)  7§Ïðúûí²‘–ެºÆº°¥”Š™§³ÉìôæÚêöôõõâÑòüüüøãíõôðõõñ÷÷ªy˜¤ÐííçÜÛìûûûüüüú’0200010011331110121D?ACEDEECA>;7,#lͺÎ÷ûûûûô®qy¢ ‘‰“§›qw’¢¼ìóßÜíôùùóâÌíüüüüòöûöóúúãîð–n›´È½ÝøúúûûûûüüüüÌM5331121/1220100220?=@BDDDDB@=97.%!¢Ì¯ÐñûŒ™ˆjrut˜¯¥~UhŠ¢ÆìÕÕëõùøðÝÇæüüüùëîìêíìäÚðìˆj’¤Ôýúúúúûûûûü÷ÍŸ`9431121212111100/00@=AAEHGDC@>:62&R¯…A*\qsrmaYWUk•±¤T#’ÊÚòóñøõçÉß÷úúñéñíï÷öíÚòæ€j Àþøøøøû¿j;=UG7322243122112100110-.?=>@CDEDCA><83* ,0$,Rfgeb_URU]h¨™S
59 ŽÈ×ÜïõöóåËÚóùúöôûüøøüöîøæ|b‘«›Çð¹X5?BIL;2222201232332111221011/?<=>BDDA@BA>;4+!  !" !""!$$%$'&(6Q\\_b]ZXZXR^yœ Y (œ¬ÁíõùùõçÍÓîúúúüüüûúú÷ñøÜŠo‡ Œ|Z:;AJOE7355356866544565565553311>=??BBCDCA@>950! "!!#"!""$$%#$$%%&*29GQUWYUTTLDEVWZeX9180>Ž£°òøùùöìÒÕæöúúüüüüùöñìõךry•M==AJTS<6799788768987677886676765 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/readpgm.m b/SD-VBS/common/toolbox/toolbox_basic/affine/readpgm.m
new file mode 100755
index 0000000..a5fd7f2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/readpgm.m
@@ -0,0 +1,26 @@
1function img = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7
8fid = fopen(filename,'r');
9fscanf(fid, 'P5\n');
10cmt = '#';
11while findstr(cmt, '#'),
12 cmt = fgets(fid);
13 if length(findstr(cmt, '#')) ~= 1,
14 YX = sscanf(cmt, '%d %d');
15 y = YX(1); x = YX(2);
16 end
17end
18
19fgets(fid);
20
21%img = fscanf(fid,'%d',size);
22%img = img';
23
24img = fread(fid,[y,x],'uint8');
25img = img';
26fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/simulation.m b/SD-VBS/common/toolbox/toolbox_basic/affine/simulation.m
new file mode 100755
index 0000000..2186a6d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/simulation.m
@@ -0,0 +1,42 @@
1clear
2
3figure(1);colormap(gray);
4
5%------------ Parameters --------------------------
6window_size_h = 40;
7window_size = 2*window_size_h+1;
8noise_level = 40/256;
9
10% define A and D
11x_ext = -0.423;
12ext = 1.232;
13A = [ext+x_ext, 0.2534; 0.3423,ext];
14
15D = [3,1];
16
17%------------- compute image I and J ---------------
18disp('generating I')
19I_init = gen_feature_s(window_size);
20[size_y,size_x] = size(I_init);
21
22%define image center
23[center_x,center_y] = find_center(size_x,size_y);
24
25% adding noise to image I
26I = I_init+noise_level*rand(size_y,size_x);
27% make sure all intensities are positive
28I = I.*(I>0);
29
30disp('computing J')
31J_init = compute_J(A,D,I_init,[center_x,center_y],[window_size_h,window_size_h]);
32J = J_init+noise_level*rand(size_y,size_x);
33J = J.*(J>0);
34
35
36%------------- compute A and residue ----------------
37c = [center_x,center_y];
38num_iter = 8; w = 9;win_h = [window_size_h,window_size_h];
39
40fig_disp = 1;
41[Ac,Dc,mask] = compute_AD_disp(I,J,c,c,win_h,num_iter,w,fig_disp);
42
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/sports1_11_28.jpeg b/SD-VBS/common/toolbox/toolbox_basic/affine/sports1_11_28.jpeg
new file mode 100755
index 0000000..39ebed5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/sports1_11_28.jpeg
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/test_affine.m b/SD-VBS/common/toolbox/toolbox_basic/affine/test_affine.m
new file mode 100755
index 0000000..41b48b9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/test_affine.m
@@ -0,0 +1,33 @@
1%%% This is a test program for Affine tracker %%%%
2
3disp(sprintf('This is a test program of Affine tracker'));
4
5%% read in images
6
7disp(sprintf('read in images'));
8I = readpgm('pan.0.pgm');
9J = readpgm('pan.1.pgm');
10
11figure(1); im(I); colormap(gray);
12figure(2); im(J); colormap(gray);
13
14
15figure(1);disp(sprintf('click on the center of a image window'));
16c = round(ginput(1));
17
18%% compute the displacement of that image window
19disp(sprintf('computing...'));
20
21win_hsize_temp = [8,8];
22w = 3;
23num_iter = 6;
24
25disp_flag = 1;
26
27win_h = win_hsize_temp + [w,w];
28if disp_flag == 1,
29 figure_id = 3;
30 [A,D,mask] = compute_AD_disp(I,J,c,c,win_h,num_iter,w,figure_id);
31else
32 [A,D,mask] = compute_AD(I,J,c,c,win_h,num_iter,w);
33end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affinityic.c b/SD-VBS/common/toolbox/toolbox_basic/affinityic.c
new file mode 100755
index 0000000..e48762a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affinityic.c
@@ -0,0 +1,186 @@
1/*================================================================
2* function w = affinityic(emag,ephase,pi,pj,sigma)
3* Input:
4* emag = edge strength at each pixel
5* ephase = edge phase at each pixel
6* [pi,pj] = index pair representation for MALTAB sparse matrices
7* sigma = sigma for IC energy
8* Output:
9* w = affinity with IC at [pi,pj]
10*
11
12% test sequence
13f = synimg(10);
14[i,j] = cimgnbmap(size(f),2);
15[ex,ey,egx,egy] = quadedgep(f);
16a = affinityic(ex,ey,egx,egy,i,j)
17show_dist_w(f,a);
18
19* Jianbo Shi, Stella X. Yu, Nov 19, 2001.
20*=================================================================*/
21
22# include "mex.h"
23# include "math.h"
24
25void mexFunction(
26 int nargout,
27 mxArray *out[],
28 int nargin,
29 const mxArray *in[]
30)
31{
32 /* declare variables */
33 int nr, nc, np, total;
34 int i, j, k, ix, iy, jx, jy, ii, jj, iip1, jjp1, iip2, jjp2, step;
35 double sigma, di, dj, a, z, maxori, phase1, phase2, slope;
36 int *ir, *jc;
37 unsigned long *pi, *pj;
38 double *emag, *ephase, *w;
39
40 /* check argument */
41 if (nargin<4) {
42 mexErrMsgTxt("Four input arguments required");
43 }
44 if (nargout>1) {
45 mexErrMsgTxt("Too many output arguments");
46 }
47
48 /* get edgel information */
49 nr = mxGetM(in[0]);
50 nc = mxGetN(in[0]);
51 if ( nr*nc ==0 || nr != mxGetM(in[1]) || nc != mxGetN(in[1]) ) {
52 mexErrMsgTxt("Edge magnitude and phase shall be of the same image size");
53 }
54 emag = mxGetPr(in[0]);
55 ephase = mxGetPr(in[1]);
56 np = nr * nc;
57
58 /* get new index pair */
59 if (!mxIsUint32(in[2]) | !mxIsUint32(in[3])) {
60 mexErrMsgTxt("Index pair shall be of type UINT32");
61 }
62 if (mxGetM(in[3]) * mxGetN(in[3]) != np + 1) {
63 mexErrMsgTxt("Wrong index representation");
64 }
65 pi = mxGetData(in[2]);
66 pj = mxGetData(in[3]);
67
68 /* create output */
69 out[0] = mxCreateSparse(np,np,pj[np],mxREAL);
70 if (out[0]==NULL) {
71 mexErrMsgTxt("Not enough memory for the output matrix");
72 }
73 w = mxGetPr(out[0]);
74 ir = mxGetIr(out[0]);
75 jc = mxGetJc(out[0]);
76
77 /* find my sigma */
78 if (nargin<5) {
79 sigma = 0;
80 for (k=0; k<np; k++) {
81 if (emag[k]>sigma) { sigma = emag[k]; }
82 }
83 sigma = sigma / 10;
84 printf("sigma = %6.5f",sigma);
85 } else {
86 sigma = mxGetScalar(in[4]);
87 }
88 a = 1.0/ (sigma);
89
90 /* computation */
91 total = 0;
92 for (j=0; j<np; j++) {
93
94 jc[j] = total;
95 jx = j / nr; /* col */
96 jy = j % nr; /* row */
97
98 for (k=pj[j]; k<pj[j+1]; k++) {
99
100 i = pi[k];
101
102 if (i==j) {
103 maxori = 1;
104
105 } else {
106
107 ix = i / nr;
108 iy = i % nr;
109
110 /* scan */
111 di = (double) (iy - jy);
112 dj = (double) (ix - jx);
113
114 maxori = 0.;
115 phase1 = ephase[j];
116
117
118 /* sample in i direction */
119 if (abs(di) >= abs(dj)) {
120 slope = dj / di;
121 step = (iy>=jy) ? 1 : -1;
122
123 iip1 = jy;
124 jjp1 = jx;
125
126
127 for (ii=0;ii<abs(di);ii++){
128 iip2 = iip1 + step;
129 jjp2 = (int)(0.5 + slope*(iip2-jy) + jx);
130
131 phase2 = ephase[iip2+jjp2*nr];
132
133 if (phase1 != phase2) {
134 z = (emag[iip1+jjp1*nr] + emag[iip2+jjp2*nr]);
135 if (z > maxori){
136 maxori = z;
137 }
138 }
139
140 iip1 = iip2;
141 jjp1 = jjp2;
142 phase1 = phase2;
143 }
144
145 /* sample in j direction */
146 } else {
147 slope = di / dj;
148 step = (ix>=jx) ? 1: -1;
149
150 jjp1 = jx;
151 iip1 = jy;
152
153
154 for (jj=0;jj<abs(dj);jj++){
155 jjp2 = jjp1 + step;
156 iip2 = (int)(0.5+ slope*(jjp2-jx) + jy);
157
158 phase2 = ephase[iip2+jjp2*nr];
159
160 if (phase1 != phase2){
161 z = (emag[iip1+jjp1*nr] + emag[iip2+jjp2*nr]);
162 if (z > maxori){
163 maxori = z;
164 }
165
166 }
167
168 iip1 = iip2;
169 jjp1 = jjp2;
170 phase1 = phase2;
171 }
172 }
173
174 maxori = 0.5 * maxori*a;
175 maxori = exp(-maxori*maxori);
176 }
177 ir[total] = i;
178
179 w[total] = maxori + 0.005;
180 total = total + 1;
181
182 } /* i */
183 } /* j */
184
185 jc[np] = total;
186}
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib/TOOLBOX_calib.tar b/SD-VBS/common/toolbox/toolbox_basic/calib/TOOLBOX_calib.tar
new file mode 100755
index 0000000..92ab3a0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib/TOOLBOX_calib.tar
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Distor2Calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Distor2Calib.m
new file mode 100755
index 0000000..a82f583
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Distor2Calib.m
@@ -0,0 +1,391 @@
1function [fc_2,Rc_2,Tc_2,H_2,distance,V_vert,V_hori,x_all_c,V_hori_pix,V_vert_pix,V_diag1_pix,V_diag2_pix]=Distor2Calib(k_dist,grid_pts_centered,n_sq_x,n_sq_y,Np,W,L,Xgrid_2,f_ini,N_iter,two_focal);
2
3% Computes the calibration parameters knowing the
4% distortion factor k_dist
5
6% grid_pts_centered are the grid point coordinates after substraction of
7% the optical center.
8
9% can give an optional guess for the focal length f_ini (can set to [])
10% can provide the number of iterations for the Iterative Vanishing Point Algorithm
11
12% if the focal length is known perfectly, then, there is no need to iterate,
13% and therefore, one can fix: N_iter = 0;
14
15% California Institute of Technology
16% (c) Jean-Yves Bouguet - October 7th, 1997
17
18
19
20%keyboard;
21
22if exist('two_focal'),
23 if isempty(two_focal),
24 two_focal=0;
25 end;
26else
27 two_focal = 0;
28end;
29
30
31if exist('N_iter'),
32 if ~isempty(N_iter),
33 disp('Use number of iterations provided');
34 else
35 N_iter = 10;
36 end;
37else
38 N_iter = 10;
39end;
40
41if exist('f_ini'),
42 if ~isempty(f_ini),
43 disp('Use focal provided');
44 if length(f_ini)<2, f_ini=[f_ini;f_ini]; end;
45 fc_2 = f_ini;
46 x_all_c = [grid_pts_centered(1,:)/fc_2(1);grid_pts_centered(2,:)/fc_2(2)];
47 x_all_c = comp_distortion(x_all_c,k_dist); % we can this time!!!
48 else
49 fc_2 = [1;1];
50 x_all_c = grid_pts_centered;
51 end;
52else
53 fc_2 = [1;1];
54 x_all_c = grid_pts_centered;
55end;
56
57
58dX = W/n_sq_x;
59dY = L/n_sq_y;
60
61
62N_x = n_sq_x+1;
63N_y = n_sq_y+1;
64
65
66x_grid = zeros(N_x,N_y);
67y_grid = zeros(N_x,N_y);
68
69
70
71
72
73%%% Computation of the four vanishing points in pixels
74
75
76 x_grid(:) = grid_pts_centered(1,:);
77 y_grid(:) = grid_pts_centered(2,:);
78
79 for k=1:n_sq_x+1,
80 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
81 vert(:,k) = U(:,3);
82 end;
83
84 for k=1:n_sq_y+1,
85 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
86 hori(:,k) = U(:,3);
87 end;
88
89 % 2 principle Vanishing points:
90 [U,S,V] = svd(vert);
91 V_vert = U(:,3);
92 [U,S,V] = svd(hori);
93 V_hori = U(:,3);
94
95
96
97 % Square warping:
98
99
100 vert_first = vert(:,1) - dot(V_vert,vert(:,1))/dot(V_vert,V_vert) * V_vert;
101 vert_last = vert(:,n_sq_x+1) - dot(V_vert,vert(:,n_sq_x+1))/dot(V_vert,V_vert) * V_vert;
102
103 hori_first = hori(:,1) - dot(V_hori,hori(:,1))/dot(V_hori,V_hori) * V_hori;
104 hori_last = hori(:,n_sq_y+1) - dot(V_hori,hori(:,n_sq_y+1))/dot(V_hori,V_hori) * V_hori;
105
106
107 x1 = cross(hori_first,vert_first);
108 x2 = cross(hori_first,vert_last);
109 x3 = cross(hori_last,vert_last);
110 x4 = cross(hori_last,vert_first);
111
112 x1 = x1/x1(3);
113 x2 = x2/x2(3);
114 x3 = x3/x3(3);
115 x4 = x4/x4(3);
116
117
118
119 [square] = Rectangle2Square([x1 x2 x3 x4],W,L);
120
121 y1 = square(:,1);
122 y2 = square(:,2);
123 y3 = square(:,3);
124 y4 = square(:,4);
125
126 H2 = cross(V_vert,V_hori);
127
128 V_diag1 = cross(cross(y1,y3),H2);
129 V_diag2 = cross(cross(y2,y4),H2);
130
131 V_diag1 = V_diag1 / norm(V_diag1);
132 V_diag2 = V_diag2 / norm(V_diag2);
133
134 V_hori_pix = V_hori;
135 V_vert_pix = V_vert;
136 V_diag1_pix = V_diag1;
137 V_diag2_pix = V_diag2;
138
139
140% end of computation of the vanishing points in pixels.
141
142
143
144
145
146
147
148
149if two_focal, % only if we attempt to estimate two focals...
150 % Use diagonal lines also to add two extra vanishing points (?)
151 N_min = min(N_x,N_y);
152
153 if N_min < 2,
154 use_diag = 0;
155 two_focal = 0;
156 disp('Cannot estimate two focals (no existing diagonals)');
157 else
158 use_diag = 1;
159 Delta_N = abs(N_x-N_y);
160 N_extra = round((N_min - Delta_N - 1)/2);
161 diag_list = -N_extra:Delta_N+N_extra;
162 N_diag = length(diag_list);
163 diag_1 = zeros(3,N_diag);
164 diag_2 = zeros(3,N_diag);
165 end;
166else
167 % Give up the use of the diagonals (so far)
168 % it seems that the error is increased
169 use_diag = 0;
170end;
171
172
173
174% The vertical lines: vert, Horizontal lines: hori
175vert = zeros(3,n_sq_x+1);
176hori = zeros(3,n_sq_y+1);
177
178for counter_k = 1:N_iter, % the Iterative Vanishing Points Algorithm to
179 % estimate the focal length accurately
180
181 x_grid(:) = x_all_c(1,:);
182 y_grid(:) = x_all_c(2,:);
183
184 for k=1:n_sq_x+1,
185 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
186 vert(:,k) = U(:,3);
187 end;
188
189 for k=1:n_sq_y+1,
190 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
191 hori(:,k) = U(:,3);
192 end;
193
194 % 2 principle Vanishing points:
195 [U,S,V] = svd(vert);
196 V_vert = U(:,3);
197 [U,S,V] = svd(hori);
198 V_hori = U(:,3);
199
200
201
202 % Square warping:
203
204
205 vert_first = vert(:,1) - dot(V_vert,vert(:,1))/dot(V_vert,V_vert) * V_vert;
206 vert_last = vert(:,n_sq_x+1) - dot(V_vert,vert(:,n_sq_x+1))/dot(V_vert,V_vert) * V_vert;
207
208 hori_first = hori(:,1) - dot(V_hori,hori(:,1))/dot(V_hori,V_hori) * V_hori;
209 hori_last = hori(:,n_sq_y+1) - dot(V_hori,hori(:,n_sq_y+1))/dot(V_hori,V_hori) * V_hori;
210
211
212 x1 = cross(hori_first,vert_first);
213 x2 = cross(hori_first,vert_last);
214 x3 = cross(hori_last,vert_last);
215 x4 = cross(hori_last,vert_first);
216
217 x1 = x1/x1(3);
218 x2 = x2/x2(3);
219 x3 = x3/x3(3);
220 x4 = x4/x4(3);
221
222
223
224 [square] = Rectangle2Square([x1 x2 x3 x4],W,L);
225
226 y1 = square(:,1);
227 y2 = square(:,2);
228 y3 = square(:,3);
229 y4 = square(:,4);
230
231 H2 = cross(V_vert,V_hori);
232
233 V_diag1 = cross(cross(y1,y3),H2);
234 V_diag2 = cross(cross(y2,y4),H2);
235
236 V_diag1 = V_diag1 / norm(V_diag1);
237 V_diag2 = V_diag2 / norm(V_diag2);
238
239
240
241
242 % Estimation of the focal length, and normalization:
243
244 % Compute the ellipsis of (1/f^2) positions:
245 % a * (1/fx)^2 + b * (1/fx)^2 = -c
246
247
248 a1 = V_hori(1);
249 b1 = V_hori(2);
250 c1 = V_hori(3);
251
252 a2 = V_vert(1);
253 b2 = V_vert(2);
254 c2 = V_vert(3);
255
256 a3 = V_diag1(1);
257 b3 = V_diag1(2);
258 c3 = V_diag1(3);
259
260 a4 = V_diag2(1);
261 b4 = V_diag2(2);
262 c4 = V_diag2(3);
263
264
265 if two_focal,
266
267
268 A = [a1*a2 b1*b2;a3*a4 b3*b4];
269 b = -[c1*c2;c3*c4];
270
271 f = sqrt(abs(1./(inv(A)*b)));
272
273 else
274
275 f = sqrt(abs(-(c1*c2*(a1*a2 + b1*b2) + c3*c4*(a3*a4 + b3*b4))/(c1^2*c2^2 + c3^2*c4^2)));
276
277 f = [f;f];
278
279 end;
280
281
282
283 % REMARK:
284 % if both a and b are small, the calibration is impossible.
285 % if one of them is small, only the other focal length is observable
286 % if none is small, both focals are observable
287
288
289 fc_2 = fc_2 .* f;
290
291
292 % DEBUG PART: fix focal to 500...
293 %fc_2= [500;500]; disp('Line 293 to be earased in Distor2Calib.m');
294
295
296 % end of focal compensation
297
298 % normalize by the current focal:
299
300 x_all = [grid_pts_centered(1,:)/fc_2(1);grid_pts_centered(2,:)/fc_2(2)];
301
302 % Compensate by the distortion factor:
303
304 x_all_c = comp_distortion(x_all,k_dist);
305
306end;
307
308% At that point, we hope that the distortion is gone...
309
310x_grid(:) = x_all_c(1,:);
311y_grid(:) = x_all_c(2,:);
312
313for k=1:n_sq_x+1,
314 [U,S,V] = svd([x_grid(k,:);y_grid(k,:);ones(1,n_sq_y+1)]);
315 vert(:,k) = U(:,3);
316end;
317
318for k=1:n_sq_y+1,
319 [U,S,V] = svd([x_grid(:,k)';y_grid(:,k)';ones(1,n_sq_x+1)]);
320 hori(:,k) = U(:,3);
321end;
322
323% Vanishing points:
324[U,S,V] = svd(vert);
325V_vert = U(:,3);
326[U,S,V] = svd(hori);
327V_hori = U(:,3);
328
329% Horizon:
330
331H_2 = cross(V_vert,V_hori);
332
333% H_2 = cross(V_vert,V_hori);
334
335% pick a plane in front of the camera (positive depth)
336if H_2(3) < 0, H_2 = -H_2; end;
337
338
339% Rotation matrix:
340
341if V_hori(1) < 0, V_hori = -V_hori; end;
342
343V_hori = V_hori/norm(V_hori);
344H_2 = H_2/norm(H_2);
345
346V_hori = V_hori - dot(V_hori,H_2)*H_2;
347
348Rc_2 = [V_hori cross(H_2,V_hori) H_2];
349
350Rc_2 = Rc_2 / det(Rc_2);
351
352%omc_2 = rodrigues(Rc_2);
353
354%Rc_2 = rodrigues(omc_2);
355
356% Find the distance of the plane for translation vector:
357
358xc_2 = [x_all_c;ones(1,Np)];
359
360Zc_2 = 1./sum(xc_2 .* (Rc_2(:,3)*ones(1,Np)));
361
362Xo_2 = [sum(xc_2 .* (Rc_2(:,1)*ones(1,Np))).*Zc_2 ; sum(xc_2 .* (Rc_2(:,2)*ones(1,Np))).*Zc_2];
363
364XXo_2 = Xo_2 - mean(Xo_2')'*ones(1,Np);
365
366distance_x = norm(Xgrid_2(1,:))/norm(XXo_2(1,:));
367distance_y = norm(Xgrid_2(2,:))/norm(XXo_2(2,:));
368
369
370distance = sum(sum(XXo_2(1:2,:).*Xgrid_2(1:2,:)))/sum(sum(XXo_2(1:2,:).^2));
371
372alpha = abs(distance_x - distance_y)/distance;
373
374if (alpha>0.1)&~two_focal,
375 disp('Should use two focals in x and y...');
376end;
377
378% Deduce the translation vector:
379
380Tc_2 = distance * H_2;
381
382
383
384
385
386return;
387
388 V_hori_pix/V_hori_pix(3)
389 V_vert_pix/V_vert_pix(3)
390 V_diag1_pix/V_diag1_pix(3)
391 V_diag2_pix/V_diag2_pix(3)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Multi_Calib_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Multi_Calib_oulu.m
new file mode 100755
index 0000000..62ca9ae
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Multi_Calib_oulu.m
@@ -0,0 +1,12 @@
1
2% enter image names, numbers, ...
3data_calib;
4
5%read images from files
6ima_read_calib;
7
8click_calib;
9
10%go_calib; % the original version
11
12go_calib_optim;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Rectangle2Square.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Rectangle2Square.m
new file mode 100755
index 0000000..a6bbbe5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/Rectangle2Square.m
@@ -0,0 +1,19 @@
1function [square] = Rectangle2Square(rectangle,L,W);
2
3% Generate the square from a rectangle of known segment lengths
4% from pt1 to pt2 : L
5% from pt2 to pt3 : W
6
7[u_hori,u_vert] = UnWarpPlane(rectangle);
8
9coeff_x = sqrt(W/L);
10coeff_y = 1/coeff_x;
11
12x_coord = [ 0 coeff_x coeff_x 0];
13y_coord = [ 0 0 coeff_y coeff_y];
14
15
16square = rectangle(:,1) * ones(1,4) + u_hori*x_coord + u_vert*y_coord;
17square = square ./ (ones(3,1)*square(3,:));
18
19
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/UnWarpPlane.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/UnWarpPlane.m
new file mode 100755
index 0000000..8addf52
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/UnWarpPlane.m
@@ -0,0 +1,54 @@
1function [u_hori,u_vert] = UnWarpPlane(x1,x2,x3,x4);
2
3% Recovers the two 3D directions of the rectangular patch x1x2x3x4
4% x1 is the origin point, ie any point of planar coordinate (x,y) on the
5% rectangular patch will be projected on the image plane at:
6% x1 + x * u_hori + y * u_vert
7%
8% Note: u_hori and u_vert are also the two vanishing points.
9
10
11if nargin < 4,
12
13 x4 = x1(:,4);
14 x3 = x1(:,3);
15 x2 = x1(:,2);
16 x1 = x1(:,1);
17
18end;
19
20
21% Image Projection:
22L1 = cross(x1,x2);
23L2 = cross(x4,x3);
24L3 = cross(x2,x3);
25L4 = cross(x1,x4);
26
27% Vanishing point:
28V1 = cross(L1,L2);
29V2 = cross(L3,L4);
30
31% Horizon line:
32H = cross(V1,V2);
33
34if H(3) < 0, H = -H; end;
35
36
37H = H / norm(H);
38
39
40X1 = x1 / dot(H,x1);
41X2 = x2 / dot(H,x2);
42X3 = x3 / dot(H,x3);
43X4 = x4 / dot(H,x4);
44
45scale = X1(3);
46
47X1 = X1/scale;
48X2 = X2/scale;
49X3 = X3/scale;
50X4 = X4/scale;
51
52
53u_hori = X2 - X1;
54u_vert = X4 - X1;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/add_suppress.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/add_suppress.m
new file mode 100755
index 0000000..b9bcc57
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/add_suppress.m
@@ -0,0 +1,91 @@
1 check_active_images;
2
3
4fprintf(1,'\nThis function is useful to select a subset of images to calibrate\n');
5
6 fprintf(1,'\nThere are currently %d active images selected for calibration (out of %d):\n',length(ind_active),n_ima);
7
8 if ~isempty(ind_active),
9
10 for ii = 1:length(ind_active)-2,
11
12 fprintf(1,'%d, ',ind_active(ii));
13
14 end;
15
16 fprintf(1,'%d and %d.',ind_active(end-1),ind_active(end));
17
18 end;
19
20 fprintf(1,'\n');
21
22
23fprintf(1,'\nDo you want to suppress or add images from that list?\n');
24
25choice = 2;
26
27while (choice~=0)&(choice~=1),
28 choice = input('For suppressing images enter 0, for adding images enter 1 ([]=no change): ');
29 if isempty(choice),
30 fprintf(1,'No change applied to the list of active images.\n');
31 return;
32 end;
33 if (choice~=0)&(choice~=1),
34 disp('Bad entry. Try again.');
35 end;
36end;
37
38
39if choice,
40
41 ima_numbers = input('Number(s) of image(s) to add ([] = all images) = ');
42
43if isempty(ima_numbers),
44 fprintf(1,'All %d images are now active\n',n_ima);
45 ima_proc = 1:n_ima;
46 else
47 ima_proc = ima_numbers;
48 end;
49
50else
51
52
53 ima_numbers = input('Number(s) of image(s) to suppress ([] = no image) = ');
54
55 if isempty(ima_numbers),
56 fprintf(1,'No image has been suppressed. No modication of the list of active images.\n',n_ima);
57 ima_proc = [];
58 else
59 ima_proc = ima_numbers;
60 end;
61
62end;
63
64if ~isempty(ima_proc),
65
66 active_images(ima_proc) = choice * ones(1,length(ima_proc));
67
68end;
69
70
71 check_active_images;
72
73
74 fprintf(1,'\nThere is now a total of %d active images for calibration:\n',length(ind_active));
75
76 if ~isempty(ind_active),
77
78 for ii = 1:length(ind_active)-2,
79
80 fprintf(1,'%d, ',ind_active(ii));
81
82 end;
83
84 fprintf(1,'%d and %d.',ind_active(end-1),ind_active(end));
85
86 end;
87
88 fprintf(1,'\n\nYou may now run ''Calibration'' to recalibrate based on this new set of images.\n');
89
90
91 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/analyse_error.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/analyse_error.m
new file mode 100755
index 0000000..5bfa3b5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/analyse_error.m
@@ -0,0 +1,104 @@
1% Color code for each image:
2
3check_active_images;
4
5if ~exist(['ex_' num2str(ind_active(1)) ]),
6 fprintf(1,'Need to calibrate before analysing reprojection error. Maybe need to load Calib_Results.mat file.\n');
7 return;
8end;
9
10
11if ~exist('no_grid'),
12 no_grid = 0;
13end;
14
15colors = 'brgkcm';
16
17
18figure(5);
19
20for kk = 1:n_ima,
21 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
22 eval(['plot(ex_' num2str(kk) '(1,:),ex_' num2str(kk) '(2,:),''' colors(rem(kk-1,6)+1) '+'');']);
23 hold on;
24 end;
25end;
26hold off;
27axis('equal');
28if 1, %~no_grid,
29 title('Reprojection error (in pixel) - To exit: right button');
30else
31 title('Reprojection error (in pixel)');
32end;
33xlabel('x');
34ylabel('y');
35
36set(5,'Name','error','NumberTitle','off');
37
38
39
40%err_std = std(ex')';
41
42%fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
43
44b = 1;
45
46while b==1,
47
48[xp,yp,b] = ginput3(1);
49
50if b==1,
51ddd = (ex(1,:)-xp).^2 + (ex(2,:)-yp).^2;
52
53[mind,indmin] = min(ddd);
54
55
56done = 0;
57kk_ima = 1;
58while (~done)&(kk_ima<=n_ima),
59 %fprintf(1,'%d...',kk_ima);
60 eval(['ex_kk = ex_' num2str(kk_ima) ';']);
61 sol_kk = find((ex_kk(1,:) == ex(1,indmin))&(ex_kk(2,:) == ex(2,indmin)));
62 if isempty(sol_kk),
63 kk_ima = kk_ima + 1;
64 else
65 done = 1;
66 end;
67end;
68
69if ~no_grid,
70
71eval(['n_sq_x = n_sq_x_' num2str(kk_ima) ';']);
72eval(['n_sq_y = n_sq_y_' num2str(kk_ima) ';']);
73
74Nx = n_sq_x+1;
75Ny = n_sq_y+1;
76
77y1 = floor((sol_kk-1)./Nx);
78x1 = sol_kk - 1 - Nx*y1; %rem(sol_kk-1,Nx);
79
80y1 = (n_sq_y+1) - y1;
81x1 = x1 + 1;
82
83fprintf(1,'\nSelected image: %d\nSelected point: (col,row)=(%d,%d)\nNcol=%d, Nrow=%d\n',[kk_ima x1 y1 Nx Ny]);
84fprintf(1,'Pixel error = (%3.5f,%3.5f)\n',[ex(1,indmin) ex(2,indmin)]);
85
86else
87
88 eval(['x_kk = x_' num2str(kk_ima) ';']);
89
90 xpt = x_kk(:,sol_kk);
91
92fprintf(1,'\nSelected image: %d\nImage coordinates (in pixel): (%3.2f,%3.2f)\n',[kk_ima xpt']);
93fprintf(1,'Pixel error = (%3.5f,%3.5f)\n',[ex(1,indmin) ex(2,indmin)]);
94
95
96end;
97
98
99end;
100
101end;
102
103disp('done');
104
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib.m
new file mode 100755
index 0000000..5b0fdac
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib.m
@@ -0,0 +1,74 @@
1if ~exist('instructions'), instructions = 1; end;
2
3if instructions,
4
5fprintf(1,'\n');
6fprintf(1,'*----------------------------------------------------------------------------------------------------*\n');
7fprintf(1,'| Main Calibration toolbox (2D and 3D rigs) |\n');
8fprintf(1,'| (c) Jean-Yves Bouguet - September 9th, 1999 |\n');
9fprintf(1,'*----------------------------------------------------------------------------------------------------*\n\n\n');
10
11fprintf(1,'CLICK ON:\n\n');
12
13fprintf(1,'2D: To perform camera calibration from multiple views of a 2D planar grid. \n');
14fprintf(1,' Set default size of grid (in dX_default and dY_default) in click_calib.m.\n');
15fprintf(1,'3D: To perform camera calibration from multiple views of a 3D grid corner. \n');
16fprintf(1,' Set default size of grids (in dX_default and dY_default) in click_calib3D.m.\n');
17fprintf(1,'Exit: To close the calibration tool. \n');
18
19end;
20
21instructions = 0;
22
23fig_number = 1;
24
25n_row = 1;
26n_col = 3;
27
28string_list = cell(n_row,n_col);
29callback_list = cell(n_row,n_col);
30
31x_size = 40;
32y_size = 20;
33
34title_figure = 'Calibration tool';
35
36string_list{1,1} = '2D rig';
37string_list{1,2} = '3D rig';
38string_list{1,3} = 'Exit';
39
40callback_list{1,1} = 'calib_gui;';
41callback_list{1,2} = 'calib3D_gui;';
42callback_list{1,3} = ['disp(''Bye. To run again, type calib.''); close(' num2str(fig_number) ');'];
43
44
45figure(fig_number); clf;
46pos = get(fig_number,'Position');
47
48fig_size_x = x_size*n_col+(n_col+1)*2;
49fig_size_y = y_size*n_row+(n_row+1)*2;
50
51set(fig_number,'Units','points', ...
52 'BackingStore','off', ...
53 'Color',[0.8 0.8 0.8], ...
54 'MenuBar','none', ...
55 'Resize','off', ...
56 'Name',title_figure, ...
57'Position',[pos(1) pos(2) fig_size_x fig_size_y], ...
58'NumberTitle','off');
59
60
61for i=n_row:-1:1,
62 for j = n_col:-1:1,
63 if (~isempty(callback_list{i,j}))&(~isempty(string_list{i,j})),
64 uicontrol('Parent',fig_number, ...
65 'Units','points', ...
66 'Callback',callback_list{i,j}, ...
67 'ListboxTop',0, ...
68 'Position',[(2+(j-1)*(x_size+2)) (fig_size_y - i*(2+y_size)) x_size y_size], ...
69 'String',string_list{i,j}, ...
70 'Tag','Pushbutton1');
71 end;
72 end;
73end;
74
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib3D_gui.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib3D_gui.m
new file mode 100755
index 0000000..ff24f6b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib3D_gui.m
@@ -0,0 +1,115 @@
1if ~exist('instructions3D'), instructions3D = 1; end;
2
3if instructions3D,
4
5fprintf(1,'\n');
6fprintf(1,'*----------------------------------------------------------------------------------------------------*\n');
7fprintf(1,'| Canera calibration from multiple images of the Intel 3D calibration rig |\n');
8fprintf(1,'| (c) Jean-Yves Bouguet - September 2nd, 1999 |\n');
9fprintf(1,'*----------------------------------------------------------------------------------------------------*\n\n\n');
10
11fprintf(1,'LIST OF CALIBRATION COMMANDS (to be executed from 1 to 5):\n\n');
12
13fprintf(1,'1- Image names: Lets the user enter the file names of the calibration images (max = 30 images).\n');
14fprintf(1,' It includes basename, image type (''tif'', ''bmp'' or ''ras''), numbering scheme.\n');
15fprintf(1,' Automatically launchs the next step (Read images).\n');
16fprintf(1,'2- Read images: Reads in the calibration images from files.\n');
17fprintf(1,' Does not automatically launch the next step (Extract grid corners).\n');
18fprintf(1,'3- Extract grid corners: Extracts the grid corners from the image.\n');
19fprintf(1,' Based six maual clicks per image.\n');
20fprintf(1,' The calibration data is saved under ''calib_data.mat''.\n');
21fprintf(1,' Automatically launchs the next step (Run calibration).\n');
22fprintf(1,'4- Run calibration: Main calibration procedure.\n');
23fprintf(1,' Optimization of intrinsic and extrinsic parameters to minimize\n');
24fprintf(1,' the reprojection error (in the least squares sense.\n');
25fprintf(1,' Estimated parameters: 2 focal lengths, principal point,\n');
26fprintf(1,' radial (2 coeff. -> 4 degree model) and tangential (2 coeff.) distortion,\n');
27fprintf(1,' and extrinsic parameters (6 parameters per image).\n');
28fprintf(1,' The final solution is saved under ''Calib_Results.mat''.\n');
29fprintf(1,' For a description of the intrinsic camera model, refer to the reference:\n');
30fprintf(1,' "A Four-step Camera Calibration Procedure with implicit Image Correction"\n');
31fprintf(1,' Janne Heikkila and Olli Silven, Infotech Oulu and Department of EE\n');
32fprintf(1,' University of Oulu, Appeared in CVPR''97, Puerto Rico.\n');
33fprintf(1,' Visit http://www.ee.oulu.fi/~jth/calibr/Calibration.html\n');
34fprintf(1,' Automatically launchs the next step (Graphic out).\n');
35fprintf(1,'5- Graphic out: Generates the graphical output associated to the current calibration solution.\n');
36fprintf(1,' It shows the 3D locations of the grids, and reprojects the 3D patterns on the\n');
37fprintf(1,' original calibration images.\n');
38fprintf(1,'6- sol. with center: Lets the user select the calibration solution with computed principal point.\n');
39fprintf(1,' This is the default case (solution retained after Run calibration).\n');
40fprintf(1,' Automatically (re)generates the graphical output associated to that solution.\n');
41fprintf(1,'7- sol. without center: Lets the users select the calibration solution without computed principal point.\n');
42fprintf(1,' In that case, the principal point is assumed at the center of the image.\n');
43fprintf(1,' Automatically generates the graphical output associated to that solution.\n');
44fprintf(1,' This option is sometimes useful when the principal point is difficult to\n');
45fprintf(1,' estimate (in particular when the camera field of view is small).\n');
46fprintf(1,'8- Back to main: Goes back to the main calbration toolbox window.\n\n\n');
47
48end;
49
50instructions3D = 0;
51
52global X_1 x_1 X_2 x_2 X_3 x_3 X_4 x_4 X_5 x_5 X_6 x_6 X_7 x_7 X_8 x_8 X_9 x_9 X_10 x_10 X_11 x_11 X_12 x_12 X_13 x_13 X_14 x_14 X_15 x_15 X_16 x_16 X_17 x_17 X_18 x_18 X_19 x_19 X_20 x_20 X_21 x_21 X_22 x_22 X_23 x_23 X_24 x_24 X_25 x_25 X_26 x_26 X_27 x_27 X_28 x_28 X_29 x_29 X_30 x_30
53
54
55fig_number = 1;
56
57n_row = 2;
58n_col = 4;
59
60string_list = cell(n_row,n_col);
61callback_list = cell(n_row,n_col);
62
63x_size = 85;
64y_size = 20;
65
66title_figure = 'Camera calibration tool (3D rig)';
67
68string_list{1,1} = 'Image names';
69string_list{1,2} = 'Read images';
70string_list{1,3} = 'Extract grid corners';
71string_list{1,4} = 'Run calibration';
72string_list{2,1} = 'Graphic out';
73string_list{2,2} = 'sol. with center';
74string_list{2,3} = 'sol. without center';
75string_list{2,4} = 'Back to main';
76
77callback_list{1,1} = 'data_calib;';
78callback_list{1,2} = 'ima_read_calib;';
79callback_list{1,3} = 'click_calib3D;';
80callback_list{1,4} = 'go_calib_optim3D;';
81callback_list{2,1} = 'graphout_calib3D;';
82callback_list{2,2} = 'select_sol_with_center3D;';
83callback_list{2,3} = 'select_sol_no_center3D;';
84callback_list{2,4} = 'calib;';
85
86
87figure(fig_number); clf;
88pos = get(fig_number,'Position');
89
90fig_size_x = x_size*n_col+(n_col+1)*2;
91fig_size_y = y_size*n_row+(n_row+1)*2;
92
93set(fig_number,'Units','points', ...
94 'BackingStore','off', ...
95 'Color',[0.8 0.8 0.8], ...
96 'MenuBar','none', ...
97 'Resize','off', ...
98 'Name',title_figure, ...
99'Position',[pos(1) pos(2) fig_size_x fig_size_y], ...
100'NumberTitle','off');
101
102
103for i=n_row:-1:1,
104 for j = n_col:-1:1,
105 if (~isempty(callback_list{i,j}))&(~isempty(string_list{i,j})),
106 uicontrol('Parent',fig_number, ...
107 'Units','points', ...
108 'Callback',callback_list{i,j}, ...
109 'ListboxTop',0, ...
110 'Position',[(2+(j-1)*(x_size+2)) (fig_size_y - i*(2+y_size)) x_size y_size], ...
111 'String',string_list{i,j}, ...
112 'Tag','Pushbutton1');
113 end;
114 end;
115end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib_gui.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib_gui.m
new file mode 100755
index 0000000..62a45dd
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/calib_gui.m
@@ -0,0 +1,81 @@
1fig_number = 1;
2
3n_row = 5;
4n_col = 4;
5
6string_list = cell(n_row,n_col);
7callback_list = cell(n_row,n_col);
8
9x_size = 85;
10y_size = 20;
11
12title_figure = 'Camera calibration tool (2D rig)';
13
14string_list{1,1} = 'Image names';
15string_list{1,2} = 'Read images';
16string_list{1,3} = 'Extract grid corners';
17%string_list{1,4} = 'Initialization';
18string_list{1,4} = 'Calibration';
19string_list{2,1} = 'Show Extrinsic';
20string_list{2,2} = 'Reproject on images';
21string_list{2,3} = 'Analyse error';
22string_list{2,4} = 'Recomp. corners';
23string_list{3,1} = 'Add/Suppress images';
24string_list{3,2} = 'Save';
25string_list{3,3} = 'Load';
26string_list{3,4} = 'Exit';
27
28string_list{5,1} = 'Comp. Extrinsic';
29string_list{5,2} = 'Undistort image';
30
31
32callback_list{1,1} = 'data_calib;';
33callback_list{1,2} = 'ima_read_calib;';
34callback_list{1,3} = 'click_calib;';
35%callback_list{1,4} = 'init_calib_param;';
36callback_list{1,4} = 'go_calib_optim;';
37callback_list{2,1} = 'ext_calib;';
38callback_list{2,2} = 'reproject_calib;';
39callback_list{2,3} = 'analyse_error;';
40callback_list{2,4} = 'recomp_corner_calib;';
41callback_list{3,1} = 'add_suppress;';
42callback_list{3,2} = 'saving_calib;';
43callback_list{3,3} = 'loading_calib;';
44callback_list{3,4} = ['disp(''Bye. To run again, type calib_gui.''); close(' num2str(fig_number) ');'];
45
46callback_list{5,1} = 'extrinsic_computation;';
47callback_list{5,2} = 'undistort_image;';
48
49
50figure(fig_number); clf;
51pos = get(fig_number,'Position');
52
53fig_size_x = x_size*n_col+(n_col+1)*2;
54fig_size_y = y_size*n_row+(n_row+1)*2;
55
56set(fig_number,'Units','points', ...
57 'BackingStore','off', ...
58 'Color',[0.8 0.8 0.8], ...
59 'MenuBar','none', ...
60 'Resize','off', ...
61 'Name',title_figure, ...
62'Position',[pos(1) pos(2) fig_size_x fig_size_y], ...
63'NumberTitle','off'); %,'WindowButtonMotionFcn',['figure(' num2str(fig_number) ');']);
64
65
66for i=n_row:-1:1,
67 for j = n_col:-1:1,
68 if (~isempty(callback_list{i,j}))&(~isempty(string_list{i,j})),
69 uicontrol('Parent',fig_number, ...
70 'Units','points', ...
71 'Callback',callback_list{i,j}, ...
72 'ListboxTop',0, ...
73 'Position',[(2+(j-1)*(x_size+2)) (fig_size_y - i*(2+y_size)) x_size y_size], ...
74 'String',string_list{i,j}, ...
75 'Tag','Pushbutton1');
76 end;
77 end;
78end;
79
80
81clear callback_list string_list fig_number fig_size_x fig_size_y i j n_col n_row pos string_list title_figure x_size y_size
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_active_images.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_active_images.m
new file mode 100755
index 0000000..4f09b62
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_active_images.m
@@ -0,0 +1,14 @@
1
2if ~exist('active_images'),
3 active_images = ones(1,n_ima);
4end;
5n_act = length(active_images);
6if n_act < n_ima,
7 active_images = [active_images ones(1,n_ima-n_act)];
8else
9 if n_act > n_ima,
10 active_images = active_images(1:n_ima);
11 end;
12end;
13
14ind_active = find(active_images);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_convergence.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_convergence.m
new file mode 100755
index 0000000..8602c39
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_convergence.m
@@ -0,0 +1,17 @@
1%%% Replay the set of solution vectors:
2
3N_iter = size(param_list,2);
4
5for nn = 1:N_iter,
6
7 solution = param_list(:,nn);
8
9 extract_parameters;
10 comp_error_calib;
11
12 ext_calib;
13
14 drawnow;
15
16
17end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_planarity.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_planarity.m
new file mode 100755
index 0000000..be0410b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/check_planarity.m
@@ -0,0 +1,41 @@
1% Check the planarity of a structure:
2
3X = X_1;
4N = size(X,2);
5
6%X(3,:) = 0.1*randn(1,N);
7
8om = rand(3,1);
9T = 10*rand(3,1);
10R = rodrigues(om);
11
12X = R * X + T*ones(1,N);
13
14
15
16
17
18
19N = size(X,2);
20X_mean = mean(X')';
21
22Y = X - (X_mean*ones(1,N));
23
24YY = Y*Y';
25
26[U,S,V] = svd(YY);
27
28r = S(3,3)/S(2,2);
29
30% if r is less than 1e-4:
31
32R_transform = V';
33T_transform = -(V')*X_mean;
34
35
36% Thresh for r: 1e-4
37
38X_new = R_transform*X + T_transform*ones(1,N);
39
40
41% If Xc = Rc * X_new + Tc, then Xc = Rc * R_transform * X + Tc + T_transform
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib.m
new file mode 100755
index 0000000..047cc7b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib.m
@@ -0,0 +1,99 @@
1
2if ~exist('I_1'),
3 ima_read_calib;
4 if no_image_file,
5 disp('Cannot extract corners without images');
6 return;
7 end;
8end;
9
10check_active_images;
11
12%wintx = 10; % neigborhood of integration for
13%winty = 10; % the corner finder
14
15fprintf(1,'\nExtraction of the grid corners on the images\n');
16
17disp('Window size for corner finder (wintx and winty):');
18wintx = input('wintx ([] = 5) = ');
19if isempty(wintx), wintx = 5; end;
20wintx = round(wintx);
21winty = input('winty ([] = 5) = ');
22if isempty(winty), winty = 5; end;
23winty = round(winty);
24
25fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
26
27if ~exist('map'), map = gray(256); end;
28
29
30disp('WARNING!!! Do not forget to change dX_default and dY_default in click_calib.m!!!')
31
32
33% Default size of the pattern squares;
34
35% Setup of JY (old at Caltech)
36dX_default = 21.9250/11;
37dY_default = 18.1250/9;
38
39% Setup of JY (new at Intel)
40dX_default = 1.9750;
41dY_default = 1.9865;
42
43
44% Setup of Luis and Enrico
45dX_default = 67.7/16;
46dY_default = 50.65/12;
47
48
49% Setup of German
50dX_default = 10.16;
51dY_default = 10.16;
52
53% Setup of JY (new at Intel)
54dX_default = 1.9750*2.54;
55dY_default = 1.9865*2.54;
56
57% Setup of JY - 3D calibration rig at Intel (new at Intel)
58dX_default = 3;
59dY_default = 3;
60
61% Useful option to add images:
62kk_first = input('Start image number ([]=1=first): ');
63
64if isempty(kk_first), kk_first = 1; end;
65
66for kk = kk_first:n_ima,
67 if active_images(kk),
68 click_ima_calib;
69 else
70 eval(['dX_' num2str(kk) ' = NaN;']);
71 eval(['dY_' num2str(kk) ' = NaN;']);
72
73 eval(['wintx_' num2str(kk) ' = NaN;']);
74 eval(['winty_' num2str(kk) ' = NaN;']);
75
76 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
77 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
78
79 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
80 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
81 end;
82end;
83
84
85
86string_save = 'save calib_data active_images ind_active wintx winty n_ima type_numbering N_slots first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default dX dY';
87
88for kk = 1:n_ima,
89 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
90end;
91
92eval(string_save);
93
94disp('done');
95
96return;
97
98go_calib_optim;
99
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib3D.m
new file mode 100755
index 0000000..e761cd1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_calib3D.m
@@ -0,0 +1,79 @@
1
2if ~exist('I_1'),
3 ima_read_calib;
4 if no_image_file,
5 disp('Cannot extract corners without images');
6 return;
7 end;
8end;
9
10%wintx = 10; % neigborhood of integration for
11%winty = 10; % the corner finder
12
13fprintf(1,'\nExtraction of the grid corners on the images\n');
14
15disp('Window size for corner finder (wintx and winty):');
16wintx = input('wintx ([] = 5) = ');
17if isempty(wintx), wintx = 5; end;
18wintx = round(wintx);
19winty = input('winty ([] = 5) = ');
20if isempty(winty), winty = 5; end;
21winty = round(winty);
22
23
24fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
25
26
27disp('WARNNG!!! Do not forget to change dX_default and dY_default in click_calib.m!!!')
28
29
30% Default size of the pattern squares;
31
32% Setup of JY (old at Caltech)
33dX_default = 21.9250/11;
34dY_default = 18.1250/9;
35
36% Setup of JY (new at Intel)
37dX_default = 1.9750;
38dY_default = 1.9865;
39
40
41% Setup of Luis and Enrico
42dX_default = 67.7/16;
43dY_default = 50.65/12;
44
45
46% Setup of German
47dX_default = 10.16;
48dY_default = 10.16;
49
50% Setup of JY (new at Intel)
51dX_default = 1.9750*2.54;
52dY_default = 1.9865*2.54;
53
54
55% Setup of JY - 3D calibration rig at Intel (new at Intel)
56dX_default = 3;
57dY_default = 3;
58
59% Useful option to add images:
60kk_first = input('Start image number ([]=1=first): ');
61
62if isempty(kk_first), kk_first = 1; end;
63
64for kk = kk_first:n_ima,
65 click_ima_calib3D; %Simple version
66 %init_calib; %advanced vesion (more messy)
67end;
68
69
70
71string_save = 'save calib_data wintx winty n_ima type_numbering N_slots first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default dX dY';
72
73for kk = 1:n_ima,
74 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' Hl_' num2str(kk) ' nl_sq_x_' num2str(kk) ' nl_sq_y_' num2str(kk) ' Hr_' num2str(kk) ' nr_sq_x_' num2str(kk) ' nr_sq_y_' num2str(kk)];
75end;
76
77eval(string_save);
78
79go_calib_optim3D;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib.m
new file mode 100755
index 0000000..5197870
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib.m
@@ -0,0 +1,218 @@
1 % Cleaned-up version of init_calib.m
2
3 fprintf(1,'\nProcessing image %d...\n',kk);
4
5 eval(['I = I_' num2str(kk) ';']);
6
7 figure(2);
8 image(I);
9 colormap(map);
10
11 title(['Click on the four extreme corners of the rectangular pattern... Image ' num2str(kk)]);
12
13 disp('Click on the four extreme corners of the rectangular complete pattern...');
14
15 [x,y] = ginput3(4);
16
17 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
18
19 x = Xc(1,:)';
20 y = Xc(2,:)';
21
22 [y,indy] = sort(y);
23 x = x(indy);
24
25 if (x(2) > x(1)),
26 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
27 else
28 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
29 end;
30 if (x(3) > x(4)),
31 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
32 else
33 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
34 end;
35
36 x = [x1;x2;x3;x4];
37 y = [y1;y2;y3;y4];
38
39
40 figure(2); hold on;
41 plot([x;x(1)],[y;y(1)],'g-');
42 plot(x,y,'og');
43 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
44 set(hx,'color','g','Fontsize',14);
45 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
46 set(hy,'color','g','Fontsize',14);
47 hold off;
48
49
50 % Try to automatically count the number of squares in the grid
51
52 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
53 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
54 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
55 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
56
57
58
59 % If could not count the number of squares, enter manually
60
61 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
62
63
64 disp('Could not count the number of squares in the grid. Enter manually.');
65 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
66 if isempty(n_sq_x), n_sq_x = 10; end;
67 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
68 if isempty(n_sq_y), n_sq_y = 10; end;
69
70 else
71
72 n_sq_x = n_sq_x1;
73 n_sq_y = n_sq_y1;
74
75 end;
76
77
78 % Enter the size of each square
79
80 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'cm) = ']);
81 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'cm) = ']);
82 if isempty(dX), dX = dX_default; else dX_default = dX; end;
83 if isempty(dY), dY = dY_default; else dY_default = dY; end;
84
85 % Compute the inside points through computation of the planar homography (collineation)
86
87 a00 = [x(1);y(1);1];
88 a10 = [x(2);y(2);1];
89 a11 = [x(3);y(3);1];
90 a01 = [x(4);y(4);1];
91
92
93 % Compute the planar collineation: (return the normalization matrix as well)
94
95 [Homo,Hnorm,inv_Hnorm] = compute_homography ([a00 a10 a11 a01],[0 1 1 0;0 0 1 1;1 1 1 1]);
96
97
98 % Build the grid using the planar collineation:
99
100 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
101 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
102 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
103
104 XX = Homo*pts;
105 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
106
107
108 % Complete size of the rectangle
109
110 W = n_sq_x*dX;
111 L = n_sq_y*dY;
112
113
114
115
116 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
117 figure(2);
118 hold on;
119 plot(XX(1,:),XX(2,:),'r+');
120 title('The red crosses should be close to the image corners');
121 hold off;
122
123 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
124 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
125 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
126
127 quest_distort = ~isempty(quest_distort);
128
129 if quest_distort,
130 % Estimation of focal length:
131 c_g = [size(I,2);size(I,1)]/2 + .5;
132 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
133 f_g = mean(f_g);
134 script_fit_distortion;
135 end;
136 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
137
138
139
140
141
142 Np = (n_sq_x+1)*(n_sq_y+1);
143
144 disp('Corner extraction...');
145
146 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
147
148
149
150 %save all_corners x y grid_pts
151
152 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
153
154
155 % Global Homography from plane to pixel coordinates:
156
157
158
159
160 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
161 ind_orig = (n_sq_x+1)*n_sq_y + 1;
162 xorig = grid_pts(1,ind_orig);
163 yorig = grid_pts(2,ind_orig);
164 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
165 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
166
167
168 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
169 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
170
171
172 figure(3);
173 image(I); colormap(map); hold on;
174 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
175 plot(x_box_kk+1,y_box_kk+1,'-b');
176 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
177 plot(xorig+1,yorig+1,'*m');
178 h = text(xorig-15,yorig-15,'O');
179 set(h,'Color','m','FontSize',14);
180 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
181 set(h2,'Color','g','FontSize',14);
182 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
183 set(h3,'Color','g','FontSize',14);
184 xlabel('Xc (in camera frame)');
185 ylabel('Yc (in camera frame)');
186 title('Extracted corners');
187 zoom on;
188 drawnow;
189 hold off;
190
191
192 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
193 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
194 Zi = zeros(1,Np);
195
196 Xgrid = [Xi;Yi;Zi];
197
198
199 % All the point coordinates (on the image, and in 3D) - for global optimization:
200
201 x = grid_pts;
202 X = Xgrid;
203
204
205 % Saves all the data into variables:
206
207 eval(['dX_' num2str(kk) ' = dX;']);
208 eval(['dY_' num2str(kk) ' = dY;']);
209
210 eval(['wintx_' num2str(kk) ' = wintx;']);
211 eval(['winty_' num2str(kk) ' = winty;']);
212
213 eval(['x_' num2str(kk) ' = x;']);
214 eval(['X_' num2str(kk) ' = X;']);
215
216 eval(['n_sq_x_' num2str(kk) ' = n_sq_x;']);
217 eval(['n_sq_y_' num2str(kk) ' = n_sq_y;']);
218 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib3D.m
new file mode 100755
index 0000000..7718268
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/click_ima_calib3D.m
@@ -0,0 +1,482 @@
1 % Cleaned-up version of init_calib.m
2
3 eval(['I = I_' num2str(kk) ';']);
4
5 figure(2);
6 image(I);
7 colormap(map);
8
9
10
11
12
13 %%%%%%%%%%%%%%%%%%%%%%%%% LEFT PATTERN ACQUISITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15
16
17 title(['Click on the four extreme corners of the left rectangular pattern... Image ' num2str(kk)]);
18
19 disp('Click on the four extreme corners of the left rectangular pattern...');
20
21 [x,y] = ginput3(4);
22
23 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
24
25 x = Xc(1,:)';
26 y = Xc(2,:)';
27
28 [y,indy] = sort(y);
29 x = x(indy);
30
31 if (x(2) > x(1)),
32 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
33 else
34 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
35 end;
36 if (x(3) > x(4)),
37 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
38 else
39 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
40 end;
41
42 x = [x1;x2;x3;x4];
43 y = [y1;y2;y3;y4];
44
45
46 figure(2); hold on;
47 plot([x;x(1)],[y;y(1)],'g-');
48 plot(x,y,'og');
49 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
50 set(hx,'color','g','Fontsize',14);
51 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
52 set(hy,'color','g','Fontsize',14);
53 hold off;
54
55 drawnow;
56
57
58 % Try to automatically count the number of squares in the grid
59
60 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
61 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
62 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
63 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
64
65
66
67 % If could not count the number of squares, enter manually
68
69 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
70
71
72 disp('Could not count the number of squares in the grid. Enter manually.');
73 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
74 if isempty(n_sq_x), n_sq_x = 10; end;
75 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
76 if isempty(n_sq_y), n_sq_y = 10; end;
77
78 else
79
80 n_sq_x = n_sq_x1;
81 n_sq_y = n_sq_y1;
82
83 end;
84
85
86 if 1,
87 % Enter the size of each square
88
89 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'cm) = ']);
90 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'cm) = ']);
91 if isempty(dX), dX = dX_default; else dX_default = dX; end;
92 if isempty(dY), dY = dY_default; else dY_default = dY; end;
93
94 else
95
96 dX = 3;
97 dY = 3;
98
99 end;
100
101
102 % Compute the inside points through computation of the planar homography (collineation)
103
104 a00 = [x(1);y(1);1];
105 a10 = [x(2);y(2);1];
106 a11 = [x(3);y(3);1];
107 a01 = [x(4);y(4);1];
108
109
110 % Compute the planart collineation: (return the normalization matrice as well)
111
112 [Homo,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
113
114
115 % Build the grid using the planar collineation:
116
117 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
118 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
119 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
120
121 XX = Homo*pts;
122 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
123
124
125 % Complete size of the rectangle
126
127 W = n_sq_x*dX;
128 L = n_sq_y*dY;
129
130
131
132 if 1,
133 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
134 figure(2);
135 hold on;
136 plot(XX(1,:),XX(2,:),'r+');
137 title('The red crosses should be close to the image corners');
138 hold off;
139
140 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
141 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
142 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
143
144 quest_distort = ~isempty(quest_distort);
145
146 if quest_distort,
147 % Estimation of focal length:
148 c_g = [size(I,2);size(I,1)]/2 + .5;
149 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
150 f_g = mean(f_g);
151 script_fit_distortion;
152 end;
153 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
154 end;
155
156
157 Np = (n_sq_x+1)*(n_sq_y+1);
158
159 disp('Corner extraction...');
160
161 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
162
163 %save all_corners x y grid_pts
164
165 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
166
167
168 % Global Homography from plane to pixel coordinates:
169
170 H_total = [1 0 -1 ; 0 1 -1 ; 0 0 1]*Homo*[1 0 0;0 -1 1;0 0 1]*[1/W 0 0 ; 0 1/L 0; 0 0 1];
171 % WARNING!!! the first matrix (on the left side) takes care of the transformation of the pixel cooredinates by -1 (previous line)
172 % If it is not done, then this matrix should not appear (in C)
173 H_total = H_total / H_total(3,3);
174
175
176 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
177 ind_orig = (n_sq_x+1)*n_sq_y + 1;
178 xorig = grid_pts(1,ind_orig);
179 yorig = grid_pts(2,ind_orig);
180 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
181 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
182
183
184 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
185 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
186
187
188 figure(3);
189 image(I); colormap(map); hold on;
190 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
191 plot(x_box_kk+1,y_box_kk+1,'-b');
192 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
193 plot(xorig+1,yorig+1,'*m');
194 h = text(xorig-15,yorig-15,'O');
195 set(h,'Color','m','FontSize',14);
196 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
197 set(h2,'Color','g','FontSize',14);
198 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
199 set(h3,'Color','g','FontSize',14);
200 xlabel('Xc (in camera frame)');
201 ylabel('Yc (in camera frame)');
202 title('Extracted corners');
203 zoom on;
204 drawnow;
205 hold off;
206
207
208 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
209 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
210 Zi = zeros(1,Np);
211
212 Xgrid = [Xi;Yi;Zi];
213
214
215 % All the point coordinates (on the image, and in 3D) - for global optimization:
216
217 x = grid_pts;
218 X = Xgrid;
219
220
221 % The left pannel info:
222
223 xl = x;
224 Xl = X;
225 nl_sq_x = n_sq_x;
226 nl_sq_y = n_sq_y;
227 Hl = H_total;
228
229
230
231
232
233
234 %%%%%%%%%%%%%%%%%%%%%%%%% RIGHT PATTERN ACQUISITION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
236
237 x1 = a10(1)/a10(3);
238 x4 = a11(1)/a11(3);
239
240 y1 = a10(2)/a10(3);
241 y4 = a11(2)/a11(3);
242
243
244 figure(2);
245 hold on;
246 plot([x1 x4],[y1 y4],'c-');
247 plot([x1 x4],[y1 y4],'co');
248 hold off;
249
250 title(['Click on the two remaining extreme corners of the right rectangular pattern... Image ' num2str(kk)]);
251
252 disp('Click on the two remaining extreme corners of the right rectangular pattern...');
253
254 [x,y] = ginput3(2);
255
256 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
257
258 x = Xc(1,:)';
259 y = Xc(2,:)';
260
261 [y,indy] = sort(y);
262 x = x(indy);
263
264 x2 = x(2);
265 x3 = x(1);
266
267 y2 = y(2);
268 y3 = y(1);
269
270
271 x = [x1;x2;x3;x4];
272 y = [y1;y2;y3;y4];
273
274 figure(2); hold on;
275 plot([x;x(1)],[y;y(1)],'c-');
276 plot(x,y,'oc');
277 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
278 set(hx,'color','c','Fontsize',14);
279 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
280 set(hy,'color','c','Fontsize',14);
281 hold off;
282 drawnow;
283
284
285 % Try to automatically count the number of squares in the grid
286
287 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
288 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
289 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
290 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
291
292
293
294 % If could not count the number of squares, enter manually
295
296 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
297
298
299 disp('Could not count the number of squares in the grid. Enter manually.');
300 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
301 if isempty(n_sq_x), n_sq_x = 10; end;
302 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
303 if isempty(n_sq_y), n_sq_y = 10; end;
304
305 else
306
307 n_sq_x = n_sq_x1;
308 n_sq_y = n_sq_y1;
309
310 end;
311
312
313 if 1,
314 % Enter the size of each square
315
316 dX = input(['Size dX of each square along the X direction ([]=' num2str(dX_default) 'cm) = ']);
317 dY = input(['Size dY of each square along the Y direction ([]=' num2str(dY_default) 'cm) = ']);
318 if isempty(dX), dX = dX_default; else dX_default = dX; end;
319 if isempty(dY), dY = dY_default; else dY_default = dY; end;
320
321 else
322
323 dX = 3;
324 dY = 3;
325
326 end;
327
328
329 % Compute the inside points through computation of the planar homography (collineation)
330
331 a00 = [x(1);y(1);1];
332 a10 = [x(2);y(2);1];
333 a11 = [x(3);y(3);1];
334 a01 = [x(4);y(4);1];
335
336
337 % Compute the planart collineation: (return the normalization matrice as well)
338
339 [Homo,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
340
341
342 % Build the grid using the planar collineation:
343
344 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
345 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
346 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
347
348 XX = Homo*pts;
349 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
350
351
352 % Complete size of the rectangle
353
354 W = n_sq_x*dX;
355 L = n_sq_y*dY;
356
357
358
359 if 1,
360 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
361 figure(2);
362 hold on;
363 plot(XX(1,:),XX(2,:),'r+');
364 title('The red crosses should be close to the image corners');
365 hold off;
366
367 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
368 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
369 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
370
371 quest_distort = ~isempty(quest_distort);
372
373 if quest_distort,
374 % Estimation of focal length:
375 c_g = [size(I,2);size(I,1)]/2 + .5;
376 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
377 f_g = mean(f_g);
378 script_fit_distortion;
379 end;
380 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
381 end;
382
383
384 Np = (n_sq_x+1)*(n_sq_y+1);
385
386 disp('Corner extraction...');
387
388 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
389
390 %save all_corners x y grid_pts
391
392 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
393
394
395 % Global Homography from plane to pixel coordinates:
396
397 H_total = [1 0 -1 ; 0 1 -1 ; 0 0 1]*Homo*[1 0 0;0 -1 1;0 0 1]*[1/W 0 0 ; 0 1/L 0; 0 0 1];
398 % WARNING!!! the first matrix (on the left side) takes care of the transformation of the pixel cooredinates by -1 (previous line)
399 % If it is not done, then this matrix should not appear (in C)
400 H_total = H_total / H_total(3,3);
401
402
403 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
404 ind_orig = (n_sq_x+1)*n_sq_y + 1;
405 xorig = grid_pts(1,ind_orig);
406 yorig = grid_pts(2,ind_orig);
407 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
408 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
409
410
411 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
412 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
413
414
415 figure(3);
416 hold on;
417 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
418 plot(x_box_kk+1,y_box_kk+1,'-b');
419 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
420 plot(xorig+1,yorig+1,'*m');
421 h = text(xorig-15,yorig-15,'O');
422 set(h,'Color','m','FontSize',14);
423 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
424 set(h2,'Color','g','FontSize',14);
425 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
426 set(h3,'Color','g','FontSize',14);
427 xlabel('Xc (in camera frame)');
428 ylabel('Yc (in camera frame)');
429 title('Extracted corners');
430 zoom on;
431 drawnow;
432 hold off;
433
434
435 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
436 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
437 Zi = zeros(1,Np);
438
439 Xgrid = [Xi;Yi;Zi];
440
441
442 % All the point coordinates (on the image, and in 3D) - for global optimization:
443
444 x = grid_pts;
445 X = Xgrid;
446
447
448 % The right pannel info:
449
450 xr = x;
451 Xr = X;
452 nr_sq_x = n_sq_x;
453 nr_sq_y = n_sq_y;
454 Hr = H_total;
455
456
457
458%%%%%%%% REGROUP THE LEFT AND RIHT PATTERNS %%%%%%%%%%%%%
459
460
461Xr2 = [0 0 1;0 1 0;-1 0 0]*Xr + [dX*nl_sq_x;0;0]*ones(1,length(Xr));
462
463
464x = [xl xr];
465
466X = [Xl Xr2];
467
468
469
470 eval(['x_' num2str(kk) ' = x;']);
471 eval(['X_' num2str(kk) ' = X;']);
472
473 eval(['nl_sq_x_' num2str(kk) ' = nl_sq_x;']);
474 eval(['nl_sq_y_' num2str(kk) ' = nl_sq_y;']);
475
476 eval(['nr_sq_x_' num2str(kk) ' = nr_sq_x;']);
477 eval(['nr_sq_y_' num2str(kk) ' = nr_sq_y;']);
478
479 % Save the global planar homography:
480
481 eval(['Hl_' num2str(kk) ' = Hl;']);
482 eval(['Hr_' num2str(kk) ' = Hr;']); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion.m
new file mode 100755
index 0000000..a0f03de
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion.m
@@ -0,0 +1,38 @@
1function [x_comp] = comp_distortion(x_dist,k2);
2
3% [x_comp] = comp_distortion(x_dist,k2);
4%
5% compensates the radial distortion of the camera
6% on the image plane.
7%
8% x_dist : the image points got without considering the
9% radial distortion.
10% x : The image plane points after correction for the distortion
11%
12% x and x_dist are 2xN arrays
13%
14% NOTE : This compensation has to be done after the substraction
15% of the center of projection, and division by the focal
16% length.
17%
18% (do it up to a second order approximation)
19
20[two,N] = size(x_dist);
21
22if (two ~= 2 ),
23 error('ERROR : The dimension of the points should be 2xN');
24end;
25
26if length(k2) > 2,
27 [x_comp] = comp_distortion_oulu(x_dist,k2);
28else
29
30radius_2= x_dist(1,:).^2 + x_dist(2,:).^2;
31radial_distortion = 1 + ones(2,1)*(k2 * radius_2);
32radius_2_comp = (x_dist(1,:).^2 + x_dist(2,:).^2) ./ radial_distortion(1,:);
33radial_distortion = 1 + ones(2,1)*(k2 * radius_2_comp);
34x_comp = x_dist ./ radial_distortion;
35
36end;
37
38%% Function completely checked : It works fine !!! \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion2.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion2.m
new file mode 100755
index 0000000..532ee9a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion2.m
@@ -0,0 +1,71 @@
1function [x_comp] = comp_distortion(x_dist,k2);
2
3% [x_comp] = comp_distortion(x_dist,k2);
4%
5% compensates the radial distortion of the camera
6% on the image plane.
7%
8% x_dist : the image points got without considering the
9% radial distortion.
10% k2: Radial distortion factor
11%
12% x : The image plane points after correction for the distortion
13%
14% x and x_dist are 2xN arrays
15%
16% NOTE : This compensation has to be done after the substraction
17% of the center of projection, and division by the focal
18% length.
19%
20% Solve for cubic roots using method from Numerical Recipes in C 2nd Ed.
21% pages 184-185.
22
23
24% California Institute of Technology
25% (c) Jean-Yves Bouguet - April 27th, 1998
26
27% fully checked! JYB, april 27th, 1998 - 2am
28
29if k2 ~= 0,
30
31[two,N] = size(x_dist);
32
33if (two ~= 2 ),
34 error('ERROR : The dimension of the points should be 2xN');
35end;
36
37
38ph = atan2(x_dist(2,:),x_dist(1,:));
39
40Q = -1/(3*k2);
41R = -x_dist(1,:)./(2*k2*cos(ph));
42
43R2 = R.^2;
44Q3 = Q^3;
45
46
47if k2 < 0,
48
49 % this works in all practical situations (it starts failing for very large
50 % values of k2)
51
52 th = acos(R./sqrt(Q3));
53 r = -2*sqrt(Q)*cos((th-2*pi)/3);
54
55else
56
57 % note: this always works, even for ridiculous values of k2
58
59 A = (sqrt(R2-Q3)-R).^(1/3);
60 B = Q*(1./A);
61 r = (A+B);
62
63end;
64
65x_comp = [r.*cos(ph); r.*sin(ph)];
66
67else
68
69 x_comp = x_dist;
70
71end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion_oulu.m
new file mode 100755
index 0000000..67d02d5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_distortion_oulu.m
@@ -0,0 +1,47 @@
1function [x] = comp_distortion_oulu(xd,k);
2
3%comp_distortion_oulu.m
4%
5%[x] = comp_distortion_oulu(xd,k)
6%
7%Compensates for radial and tangential distortion. Model From Oulu university.
8%For more informatino about the distortion model, check the forward projection mapping function:
9%project_points.m
10%
11%INPUT: xd: distorted (normalized) point coordinates in the image plane (2xN matrix)
12% k: Distortion coefficients (radial and tangential) (4x1 vector)
13%
14%OUTPUT: x: undistorted (normalized) point coordinates in the image plane (2xN matrix)
15%
16%Method: Iterative method for compensation.
17%
18%NOTE: This compensation has to be done after the subtraction
19% of the principal point, and division by the focal length.
20
21
22if length(k) < 4,
23
24 [x] = comp_distortion(xd,k);
25
26else
27
28
29 k1 = k(1);
30 k2 = k(2);
31 p1 = k(3);
32 p2 = k(4);
33
34 x = xd; % initial guess
35
36 for kk=1:5;
37
38 r_2 = sum(x.^2);
39 k_radial = 1 + k1 * r_2 + k2 * r_2.^2;
40 delta_x = [2*p1*x(1,:).*x(2,:) + p2*(r_2 + 2*x(1,:).^2) ;
41 p1 * (r_2 + 2*x(2,:).^2)+2*p2*x(1,:).*x(2,:)];
42 x = (xd - delta_x)./(ones(2,1)*k_radial);
43
44 end;
45
46end;
47
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_error_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_error_calib.m
new file mode 100755
index 0000000..f8d6fde
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/comp_error_calib.m
@@ -0,0 +1,40 @@
1%%%%%%%%%%%%%%%%%%%% RECOMPUTES THE REPROJECTION ERROR %%%%%%%%%%%%%%%%%%%%%%%%
2
3check_active_images;
4
5% Reproject the patterns on the images, and compute the pixel errors:
6
7ex = []; % Global error vector
8x = []; % Detected corners on the image plane
9y = []; % Reprojected points
10
11for kk = 1:n_ima,
12
13 eval(['omckk = omc_' num2str(kk) ';']);
14 eval(['Tckk = Tc_' num2str(kk) ';']);
15
16 if active_images(kk) & (~isnan(omckk(1,1))),
17
18 Rkk = rodrigues(omckk);
19
20 eval(['y_' num2str(kk) ' = project2_oulu(X_' num2str(kk) ',Rkk,Tckk,fc,cc,kc);']);
21
22 eval(['ex_' num2str(kk) ' = x_' num2str(kk) ' -y_' num2str(kk) ';']);
23
24 eval(['x_kk = x_' num2str(kk) ';']);
25
26 eval(['ex = [ex ex_' num2str(kk) '];']);
27 eval(['x = [x x_' num2str(kk) '];']);
28 eval(['y = [y y_' num2str(kk) '];']);
29
30 else
31
32 eval(['y_' num2str(kk) ' = NaN*ones(2,1);']);
33
34 eval(['ex_' num2str(kk) ' = NaN*ones(2,1);']);
35
36 end;
37
38end;
39
40err_std = std(ex')';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_collineation.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_collineation.m
new file mode 100755
index 0000000..809c309
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_collineation.m
@@ -0,0 +1,66 @@
1function [H,Hnorm,inv_Hnorm] = compute_collineation (a00, a10, a11, a01);
2
3% new formalism using homographies
4
5a00 = a00 / a00(3);
6a10 = a10 / a10(3);
7a11 = a11 / a11(3);
8a01 = a01 / a01(3);
9
10
11% Prenormalization of point coordinates (very important):
12% (Affine normalization)
13
14ax = [a00(1);a10(1);a11(1);a01(1)];
15ay = [a00(2);a10(2);a11(2);a01(2)];
16
17mxx = mean(ax);
18myy = mean(ay);
19ax = ax - mxx;
20ay = ay - myy;
21
22scxx = mean(abs(ax));
23scyy = mean(abs(ay));
24
25
26Hnorm = [1/scxx 0 -mxx/scxx;0 1/scyy -myy/scyy;0 0 1];
27inv_Hnorm = [scxx 0 mxx ; 0 scyy myy; 0 0 1];
28
29
30a00n = Hnorm*a00;
31a10n = Hnorm*a10;
32a11n = Hnorm*a11;
33a01n = Hnorm*a01;
34
35
36% Computation of the vanishing points:
37
38V1n = cross(cross(a00n,a10n),cross(a01n,a11n));
39V2n = cross(cross(a00n,a01n),cross(a10n,a11n));
40
41V1 = inv_Hnorm*V1n;
42V2 = inv_Hnorm*V2n;
43
44
45% Normalizaion of the vanishing points:
46
47V1n = V1n/norm(V1n);
48V2n = V2n/norm(V2n);
49
50
51% Closed-form solution of the coefficients:
52
53alpha_x = (a10n(2)*a00n(1) - a10n(1)*a00n(2))/(V1n(2)*a10n(1)-V1n(1)*a10n(2));
54
55alpha_y = (a01n(2)*a00n(1) - a01n(1)*a00n(2))/(V2n(2)*a01n(1)-V2n(1)*a01n(2));
56
57
58% Remaining Homography
59
60Hrem = [alpha_x*V1n alpha_y*V2n a00n];
61
62
63% Final homography:
64
65H = inv_Hnorm*Hrem;
66
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic.m
new file mode 100755
index 0000000..4b4d7dd
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic.m
@@ -0,0 +1,123 @@
1function [omckk,Tckk,Rckk,H,x,ex,JJ] = compute_extrinsic(x_kk,X_kk,fc,cc,kc,MaxIter,thresh_cond),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk,H,x,ex] = compute_extrinsic(x_kk,X_kk,fc,cc,kc,refine)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16% refine: set to 1 for refining the extrinsic parameters iteratively
17% [OPTIONAL: Default value: 1]
18%
19%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
20% Tckk: 3D translation vector attached to the grid positions in space
21% Rckk: 3D rotation matrices corresponding to the omc vectors
22% H: Homography between points on the grid and points on the image plane (in pixel)
23% This makes sense only if the planar that is used in planar.
24% x: Reprojections of the points on the image plane
25% ex: Reprojection error: ex = x_kk - x;
26%
27%Method: Computes the normalized point coordinates, then computes the 3D pose
28%
29%Important functions called within that program:
30%
31%normalize: Computes the normalize image point coordinates.
32%
33%pose3D: Computes the 3D pose of the structure given the normalized image projection.
34%
35%project_points.m: Computes the 2D image projections of a set of 3D points
36
37
38
39if nargin < 7,
40 thresh_cond = inf;
41end;
42
43
44if nargin < 6,
45 MaxIter = 20;
46end;
47
48
49
50if nargin < 5,
51 kc = zeros(4,1);
52 if nargin < 4,
53 cc = zeros(2,1);
54 if nargin < 3,
55 fc = ones(2,1);
56 if nargin < 2,
57 error('Need 2D projections and 3D points (in compute_extrinsic.m)');
58 return;
59 end;
60 end;
61 end;
62end;
63
64
65% Initialization:
66
67[omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc);
68
69% Refinement:
70
71[omckk,Tckk,Rckk,JJ] = compute_extrinsic_refine(omckk,Tckk,x_kk,X_kk,fc,cc,kc,MaxIter,thresh_cond);
72
73
74% computation of the homography (not useful in the end)
75
76H = [Rckk(:,1:2) Tckk];
77
78% Computes the reprojection error in pixels:
79
80x = project_points(X_kk,omckk,Tckk,fc,cc,kc);
81
82ex = x_kk - x;
83
84
85% Converts the homography in pixel units:
86
87KK = [fc(1) 0 cc(1);0 fc(2) cc(2); 0 0 1];
88
89H = KK*H;
90
91
92
93
94return;
95
96
97% Test of compte extrinsic:
98
99Np = 4;
100sx = 10;
101sy = 10;
102sz = 5;
103
104om = randn(3,1);
105T = [0;0;100];
106
107noise = 2/1000;
108
109XX = [sx*randn(1,Np);sy*randn(1,Np);sz*randn(1,Np)];
110xx = project_points(XX,om,T);
111
112xxn = xx + noise * randn(2,Np);
113
114[omckk,Tckk] = compute_extrinsic(xxn,XX);
115
116[om omckk om-omckk]
117[T Tckk T-Tckk]
118
119figure(3);
120plot(xx(1,:),xx(2,:),'r+');
121hold on;
122plot(xxn(1,:),xxn(2,:),'g+');
123hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_init.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_init.m
new file mode 100755
index 0000000..207ea30
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_init.m
@@ -0,0 +1,149 @@
1function [omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16%
17%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
18% Tckk: 3D translation vector attached to the grid positions in space
19% Rckk: 3D rotation matrices corresponding to the omc vectors
20%
21%Method: Computes the normalized point coordinates, then computes the 3D pose
22%
23%Important functions called within that program:
24%
25%normalize: Computes the normalize image point coordinates.
26%
27%pose3D: Computes the 3D pose of the structure given the normalized image projection.
28%
29%project_points.m: Computes the 2D image projections of a set of 3D points
30
31
32
33
34if nargin < 5,
35 kc = zeros(4,1);
36 if nargin < 4,
37 cc = zeros(2,1);
38 if nargin < 3,
39 fc = ones(2,1);
40 if nargin < 2,
41 error('Need 2D projections and 3D points (in compute_extrinsic.m)');
42 return;
43 end;
44 end;
45 end;
46end;
47
48
49
50% Compute the normalized coordinates:
51
52xn = normalize(x_kk,fc,cc,kc);
53
54
55
56Np = size(xn,2);
57
58%% Check for planarity of the structure:
59
60X_mean = mean(X_kk')';
61
62Y = X_kk - (X_mean*ones(1,Np));
63
64YY = Y*Y';
65
66[U,S,V] = svd(YY);
67
68r = S(3,3)/S(2,2);
69
70if (r < 1e-3)|(Np < 6), %1e-3, %1e-4, %norm(X_kk(3,:)) < eps, % Test of planarity
71
72 %fprintf(1,'Planar structure detected: r=%f\n',r);
73
74 % Transform the plane to bring it in the Z=0 plane:
75
76 R_transform = V';
77
78 if det(R_transform) < 0, R_transform = -R_transform; end;
79
80 T_transform = -(R_transform)*X_mean;
81
82 X_new = R_transform*X_kk + T_transform*ones(1,Np);
83
84
85 % Compute the planar homography:
86
87 H = compute_homography (xn,X_new(1:2,:));
88
89 % De-embed the motion parameters from the homography:
90
91 sc = mean([norm(H(:,1));norm(H(:,2))]);
92
93 H = H/sc;
94
95 omckk = rodrigues([H(:,1:2) cross(H(:,1),H(:,2))]);
96 Rckk = rodrigues(omckk);
97 Tckk = H(:,3);
98
99 %If Xc = Rckk * X_new + Tckk, then Xc = Rckk * R_transform * X_kk + Tckk + T_transform
100
101 Tckk = Tckk + Rckk* T_transform;
102 Rckk = Rckk * R_transform;
103
104 omckk = rodrigues(Rckk);
105 Rckk = rodrigues(omckk);
106
107
108else
109
110 %fprintf(1,'Non planar structure detected: r=%f\n',r);
111
112 % Computes an initial guess for extrinsic parameters (works for general 3d structure, not planar!!!):
113 % The DLT method is applied here!!
114
115 J = zeros(2*Np,12);
116
117 xX = (ones(3,1)*xn(1,:)).*X_kk;
118 yX = (ones(3,1)*xn(2,:)).*X_kk;
119
120 J(1:2:end,[1 4 7]) = -X_kk';
121 J(2:2:end,[2 5 8]) = X_kk';
122 J(1:2:end,[3 6 9]) = xX';
123 J(2:2:end,[3 6 9]) = -yX';
124 J(1:2:end,12) = xn(1,:)';
125 J(2:2:end,12) = -xn(2,:)';
126 J(1:2:end,10) = -ones(Np,1);
127 J(2:2:end,11) = ones(Np,1);
128
129 JJ = J'*J;
130 [U,S,V] = svd(JJ);
131
132 RR = reshape(V(1:9,12),3,3);
133
134 if det(RR) < 0,
135 V(:,12) = -V(:,12);
136 RR = -RR;
137 end;
138
139 [Ur,Sr,Vr] = svd(RR);
140
141 Rckk = Ur*Vr';
142
143 sc = norm(V(1:9,12)) / norm(Rckk(:));
144 Tckk = V(10:12,12)/sc;
145
146 omckk = rodrigues(Rckk);
147 Rckk = rodrigues(omckk);
148
149end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_refine.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_refine.m
new file mode 100755
index 0000000..69474c4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_extrinsic_refine.m
@@ -0,0 +1,110 @@
1function [omckk,Tckk,Rckk,JJ] = compute_extrinsic_refine(omc_init,Tc_init,x_kk,X_kk,fc,cc,kc,MaxIter,thresh_cond),
2
3%compute_extrinsic
4%
5%[omckk,Tckk,Rckk] = compute_extrinsic_refine(x_kk,X_kk,fc,cc,kc,MaxIter)
6%
7%Computes the extrinsic parameters attached to a 3D structure X_kk given its projection
8%on the image plane x_kk and the intrinsic camera parameters fc, cc and kc.
9%Works with planar and non-planar structures.
10%
11%INPUT: x_kk: Feature locations on the images
12% X_kk: Corresponding grid coordinates
13% fc: Camera focal length
14% cc: Principal point coordinates
15% kc: Distortion coefficients
16% MaxIter: Maximum number of iterations
17%
18%OUTPUT: omckk: 3D rotation vector attached to the grid positions in space
19% Tckk: 3D translation vector attached to the grid positions in space
20% Rckk: 3D rotation matrices corresponding to the omc vectors
21
22%
23%Method: Computes the normalized point coordinates, then computes the 3D pose
24%
25%Important functions called within that program:
26%
27%normalize: Computes the normalize image point coordinates.
28%
29%pose3D: Computes the 3D pose of the structure given the normalized image projection.
30%
31%project_points.m: Computes the 2D image projections of a set of 3D points
32
33
34if nargin < 9,
35 thresh_cond = inf;
36end;
37
38
39if nargin < 8,
40 MaxIter = 20;
41end;
42
43
44if nargin < 7,
45 kc = zeros(4,1);
46 if nargin < 6,
47 cc = zeros(2,1);
48 if nargin < 5,
49 fc = ones(2,1);
50 if nargin < 4,
51 error('Need 2D projections and 3D points (in compute_extrinsic_refine.m)');
52 return;
53 end;
54 end;
55 end;
56end;
57
58
59% Initialization:
60
61omckk = omc_init;
62Tckk = Tc_init;
63
64
65% Final optimization (minimize the reprojection error in pixel):
66% through Gradient Descent:
67
68param = [omckk;Tckk];
69
70change = 1;
71
72iter = 0;
73
74%keyboard;
75
76%fprintf(1,'Gradient descent iterations: ');
77
78while (change > 1e-10)&(iter < MaxIter),
79
80 %fprintf(1,'%d...',iter+1);
81
82 [x,dxdom,dxdT] = project_points(X_kk,omckk,Tckk,fc,cc,kc);
83
84 ex = x_kk - x;
85
86 %keyboard;
87
88 JJ = [dxdom dxdT];
89
90 if cond(JJ) > thresh_cond,
91 change = 0;
92 else
93
94 JJ2 = JJ'*JJ;
95
96 param_innov = inv(JJ2)*(JJ')*ex(:);
97 param_up = param + param_innov;
98 change = norm(param_innov)/norm(param_up);
99 param = param_up;
100 iter = iter + 1;
101
102 omckk = param(1:3);
103 Tckk = param(4:6);
104 end;
105
106end;
107
108%fprintf(1,'\n');
109
110Rckk = rodrigues(omckk);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_homography.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_homography.m
new file mode 100755
index 0000000..fcc9003
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/compute_homography.m
@@ -0,0 +1,163 @@
1function [H,Hnorm,inv_Hnorm] = compute_homography (m,M);
2
3%compute_homography
4%
5%[H,Hnorm,inv_Hnorm] = compute_homography (m,M)
6%
7%Computes the planar homography between the point coordinates on the plane (M) and the image
8%point coordinates (m).
9%
10%INPUT: m: homogeneous coordinates in the image plane (3xN matrix)
11% M: homogeneous coordinates in the plane in 3D (3xN matrix)
12%
13%OUTPUT: H: Homography matrix (3x3 homogeneous matrix)
14% Hnorm: Normlization matrix used on the points before homography computation
15% (useful for numerical stability is points in pixel coordinates)
16% inv_Hnorm: The inverse of Hnorm
17%
18%Definition: m ~ H*M where "~" means equal up to a non zero scalar factor.
19%
20%Method: First computes an initial guess for the homography through quasi-linear method.
21% Then, if the total number of points is larger than 4, optimize the solution by minimizing
22% the reprojection error (in the least squares sense).
23%
24%
25%Important functions called within that program:
26%
27%comp_distortion_oulu: Undistorts pixel coordinates.
28%
29%compute_homography.m: Computes the planar homography between points on the grid in 3D, and the image plane.
30%
31%project_points.m: Computes the 2D image projections of a set of 3D points, and also returns te Jacobian
32% matrix (derivative with respect to the intrinsic and extrinsic parameters).
33% This function is called within the minimization loop.
34
35
36
37
38Np = size(m,2);
39
40if size(m,1)<3,
41 m = [m;ones(1,Np)];
42end;
43
44if size(M,1)<3,
45 M = [M;ones(1,Np)];
46end;
47
48
49m = m ./ (ones(3,1)*m(3,:));
50M = M ./ (ones(3,1)*M(3,:));
51
52% Prenormalization of point coordinates (very important):
53% (Affine normalization)
54
55ax = m(1,:);
56ay = m(2,:);
57
58mxx = mean(ax);
59myy = mean(ay);
60ax = ax - mxx;
61ay = ay - myy;
62
63scxx = mean(abs(ax));
64scyy = mean(abs(ay));
65
66
67Hnorm = [1/scxx 0 -mxx/scxx;0 1/scyy -myy/scyy;0 0 1];
68inv_Hnorm = [scxx 0 mxx ; 0 scyy myy; 0 0 1];
69
70mn = Hnorm*m;
71
72% Compute the homography between m and mn:
73
74% Build the matrix:
75
76L = zeros(2*Np,9);
77
78L(1:2:2*Np,1:3) = M';
79L(2:2:2*Np,4:6) = M';
80L(1:2:2*Np,7:9) = -((ones(3,1)*mn(1,:)).* M)';
81L(2:2:2*Np,7:9) = -((ones(3,1)*mn(2,:)).* M)';
82
83if Np > 4,
84 L = L'*L;
85end;
86
87[U,S,V] = svd(L);
88
89hh = V(:,9);
90hh = hh/hh(9);
91
92Hrem = reshape(hh,3,3)';
93%Hrem = Hrem / Hrem(3,3);
94
95% Final homography:
96
97H = inv_Hnorm*Hrem;
98
99
100%%% Homography refinement if there are more than 4 points:
101
102if Np > 4,
103
104 % Final refinement:
105
106 hhv = reshape(H',9,1);
107 hhv = hhv(1:8);
108
109 for iter=1:10,
110
111 mrep = H * M;
112
113 J = zeros(2*Np,8);
114
115 MMM = (M ./ (ones(3,1)*mrep(3,:)));
116
117 J(1:2:2*Np,1:3) = -MMM';
118 J(2:2:2*Np,4:6) = -MMM';
119
120 mrep = mrep ./ (ones(3,1)*mrep(3,:));
121
122 m_err = m(1:2,:) - mrep(1:2,:);
123 m_err = m_err(:);
124
125 MMM2 = (ones(3,1)*mrep(1,:)) .* MMM;
126 MMM3 = (ones(3,1)*mrep(2,:)) .* MMM;
127
128 J(1:2:2*Np,7:8) = MMM2(1:2,:)';
129 J(2:2:2*Np,7:8) = MMM3(1:2,:)';
130
131 MMM = (M ./ (ones(3,1)*mrep(3,:)))';
132
133 hh_innov = inv(J'*J)*J'*m_err;
134
135 hhv_up = hhv - hh_innov;
136
137 H_up = reshape([hhv_up;1],3,3)';
138
139 %norm(m_err)
140 %norm(hh_innov)
141
142 hhv = hhv_up;
143 H = H_up;
144
145 end;
146
147end;
148
149
150
151
152
153return;
154
155%test of Jacobian
156
157mrep = H*M;
158mrep = mrep ./ (ones(3,1)*mrep(3,:));
159
160m_err = mrep(1:2,:) - m(1:2,:);
161figure(8);
162plot(m_err(1,:),m_err(2,:),'r+');
163std(m_err')
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/convert_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/convert_oulu.m
new file mode 100755
index 0000000..726806e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/convert_oulu.m
@@ -0,0 +1,35 @@
1%% Converts data file from oulu to mine:
2
3load cademo,
4n_ima = 0;
5
6no_error = 1;
7
8ii = 1;
9
10while no_error,
11
12 dataname = ['data' num2str(ii)];
13
14 if exist(dataname),
15
16 n_ima = n_ima +1;
17
18 eval(['x_' num2str(ii) '= ' dataname '(:,4:5)'';'])
19 eval(['X_' num2str(ii) '= ' dataname '(:,1:3)'';'])
20
21 else
22 no_error = 0;
23 end;
24
25 ii = ii + 1;
26
27end;
28
29nx = 500;
30ny = 500;
31
32no_image = 1;
33no_grid = 1;
34
35save data n_ima x_1 X_1 x_2 X_2 x_3 X_3 nx ny no_image no_grid
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/cornerfinder.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/cornerfinder.m
new file mode 100755
index 0000000..9bfa51f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/cornerfinder.m
@@ -0,0 +1,215 @@
1function [xc,good,bad,type] = cornerfinder(xt,I,wintx,winty,wx2,wy2);
2
3%[xc] = cornerfinder(xt,I);
4%
5%Finds the sub-pixel corners on the image I with initial guess xt
6%xt and xc are 2xN matrices. The first component is the x coordinate
7%(horizontal) and the second component is the y coordinate (vertical)
8%
9%Based on Harris corner finder method
10%
11%Finds corners to a precision below .1 pixel!
12%Oct. 14th, 1997 - UPDATED to work with vertical and horizontal edges as well!!!
13%Sept 1998 - UPDATED to handle diverged points: we keep the original points
14%good is a binary vector indicating wether a feature point has been properly
15%found.
16%
17%Add a zero zone of size wx2,wy2
18%July 15th, 1999 - Bug on the mask building... fixed + change to Gaussian mask with higher
19%resolution and larger number of iterations.
20
21
22% California Institute of Technology
23% (c) Jean-Yves Bouguet -- Oct. 14th, 1997
24
25
26
27line_feat = 1; % set to 1 to allow for extraction of line features.
28
29xt = xt';
30xt = fliplr(xt);
31
32
33if nargin < 4,
34 winty = 5;
35 if nargin < 3,
36 wintx = 5;
37 end;
38end;
39
40
41if nargin < 6,
42 wx2 = -1;
43 wy2 = -1;
44end;
45
46
47%mask = ones(2*wintx+1,2*winty+1);
48mask = exp(-((-wintx:wintx)'/(wintx)).^2) * exp(-((-winty:winty)/(winty)).^2);
49
50
51if (wx2>0) & (wy2>0),
52 if ((wintx - wx2)>=2)&((winty - wy2)>=2),
53 mask(wintx+1-wx2:wintx+1+wx2,winty+1-wy2:winty+1+wy2)= zeros(2*wx2+1,2*wy2+1);
54 end;
55end;
56
57offx = [-wintx:wintx]'*ones(1,2*winty+1);
58offy = ones(2*wintx+1,1)*[-winty:winty];
59
60resolution = 0.005;
61
62MaxIter = 10;
63
64[nx,ny] = size(I);
65N = size(xt,1);
66
67xc = xt; % first guess... they don't move !!!
68
69type = zeros(1,N);
70
71
72for i=1:N,
73
74 v_extra = resolution + 1; % just larger than resolution
75
76 compt = 0; % no iteration yet
77
78 while (norm(v_extra) > resolution) & (compt<MaxIter),
79
80 cIx = xc(i,1); %
81 cIy = xc(i,2); % Coords. of the point
82 crIx = round(cIx); % on the initial image
83 crIy = round(cIy); %
84 itIx = cIx - crIx; % Coefficients
85 itIy = cIy - crIy; % to compute
86 if itIx > 0, % the sub pixel
87 vIx = [itIx 1-itIx 0]'; % accuracy.
88 else
89 vIx = [0 1+itIx -itIx]';
90 end;
91 if itIy > 0,
92 vIy = [itIy 1-itIy 0];
93 else
94 vIy = [0 1+itIy -itIy];
95 end;
96
97
98 % What if the sub image is not in?
99
100 if (crIx-wintx-2 < 1), xmin=1; xmax = 2*wintx+5;
101 elseif (crIx+wintx+2 > nx), xmax = nx; xmin = nx-2*wintx-4;
102 else
103 xmin = crIx-wintx-2; xmax = crIx+wintx+2;
104 end;
105
106 if (crIy-winty-2 < 1), ymin=1; ymax = 2*winty+5;
107 elseif (crIy+winty+2 > ny), ymax = ny; ymin = ny-2*winty-4;
108 else
109 ymin = crIy-winty-2; ymax = crIy+winty+2;
110 end;
111
112
113 SI = I(xmin:xmax,ymin:ymax); % The necessary neighborhood
114 SI = conv2(conv2(SI,vIx,'same'),vIy,'same');
115 SI = SI(2:2*wintx+4,2:2*winty+4); % The subpixel interpolated neighborhood
116 [gy,gx] = gradient(SI); % The gradient image
117 gx = gx(2:2*wintx+2,2:2*winty+2); % extraction of the useful parts only
118 gy = gy(2:2*wintx+2,2:2*winty+2); % of the gradients
119
120 px = cIx + offx;
121 py = cIy + offy;
122
123 gxx = gx .* gx .* mask;
124 gyy = gy .* gy .* mask;
125 gxy = gx .* gy .* mask;
126
127
128 bb = [sum(sum(gxx .* px + gxy .* py)); sum(sum(gxy .* px + gyy .* py))];
129
130 a = sum(sum(gxx));
131 b = sum(sum(gxy));
132 c = sum(sum(gyy));
133
134 dt = a*c - b^2;
135
136 xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
137
138
139 %keyboard;
140
141 if line_feat,
142
143 G = [a b;b c];
144 [U,S,V] = svd(G);
145
146 %keyboard;
147
148 % If non-invertible, then project the point onto the edge orthogonal:
149
150 if (S(1,1)/S(2,2) > 50),
151 % projection operation:
152 xc2 = xc2 + sum((xc(i,:)-xc2).*(V(:,2)'))*V(:,2)';
153 type(i) = 1;
154 end;
155
156 end;
157
158
159 %keyboard;
160
161% G = [a b;b c];
162% [U,S,V] = svd(G);
163
164
165% if S(1,1)/S(2,2) > 150,
166% bb2 = U'*bb;
167% xc2 = (V*[bb2(1)/S(1,1) ;0])';
168% else
169% xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
170% end;
171
172
173 %if (abs(a)> 50*abs(c)),
174% xc2 = [(c*bb(1)-b*bb(2))/dt xc(i,2)];
175% elseif (abs(c)> 50*abs(a))
176% xc2 = [xc(i,1) (a*bb(2)-b*bb(1))/dt];
177% else
178% xc2 = [c*bb(1)-b*bb(2) a*bb(2)-b*bb(1)]/dt;
179% end;
180
181 %keyboard;
182
183 v_extra = xc(i,:) - xc2;
184
185 xc(i,:) = xc2;
186
187% keyboard;
188
189 compt = compt + 1;
190
191 end
192end;
193
194
195% check for points that diverge:
196
197delta_x = xc(:,1) - xt(:,1);
198delta_y = xc(:,2) - xt(:,2);
199
200%keyboard;
201
202
203bad = (abs(delta_x) > wintx) | (abs(delta_y) > winty);
204good = ~bad;
205in_bad = find(bad);
206
207% For the diverged points, keep the original guesses:
208
209xc(in_bad,:) = xt(in_bad,:);
210
211xc = fliplr(xc);
212xc = xc';
213
214bad = bad';
215good = good';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/count_squares.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/count_squares.m
new file mode 100755
index 0000000..0e226c0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/count_squares.m
@@ -0,0 +1,74 @@
1function ns = count_squares(I,x1,y1,x2,y2,win);
2
3%keyboard;
4
5[ny,nx] = size(I);
6
7lambda = [y1 - y2;x2 - x1;x1*y2 - x2*y1];
8
9lambda = 1/sqrt(lambda(1)^2 + lambda(2)^2) * lambda;
10
11l1 = lambda + [0;0;win];
12l2 = lambda - [0;0;win];
13
14
15dx = x2-x1;
16dy = y2 - y1;
17
18
19if abs(dx) > abs(dy),
20
21 if x2 > x1,
22 xs = x1:x2;
23 else
24 xs = x1:-1:x2;
25 end;
26
27 ys = -(lambda(3) + lambda(1)*xs)/lambda(2);
28
29else
30
31 if y2 > y1,
32 ys = y1:y2;
33 else
34 ys = y1:-1:y2;
35 end;
36 xs = -(lambda(3) + lambda(2)*ys)/lambda(1);
37
38end;
39
40
41
42 Np = length(xs);
43
44 xs_mat = ones(2*win + 1,1)*xs;
45 ys_mat = ones(2*win + 1,1)*ys;
46
47 win_mat = (-win:win)'*ones(1,Np);
48
49
50 xs_mat2 = round(xs_mat - win_mat * lambda(1));
51 ys_mat2 = round(ys_mat - win_mat * lambda(2));
52
53 ind_mat = (xs_mat2 - 1) * ny + ys_mat2;
54
55 ima_patch = zeros(2*win + 1,Np);
56
57 ima_patch(:) = I(ind_mat(:));
58
59 %ima2 = ima_patch(:,win+1:end-win);
60
61 filtk = [ones(win,Np);zeros(1,Np);-ones(win,Np)];
62
63 out_f = sum(filtk.*ima_patch);
64
65 out_f_f = conv2(out_f,[1/4 1/2 1/4],'same');
66
67 out_f_f = out_f_f(win+1:end-win);
68
69 ns = length(find(((out_f_f(2:end)>=0)&(out_f_f(1:end-1)<0)) | ((out_f_f(2:end)<=0)&(out_f_f(1:end-1)>0))))+1;
70
71
72
73
74return;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/data_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/data_calib.m
new file mode 100755
index 0000000..318ec15
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/data_calib.m
@@ -0,0 +1,89 @@
1%%% This script alets the user enter the name of the images (base name, numbering scheme,...
2
3dir;
4
5%disp('Camera Calibration using multiple images of a planar checkerboard pattern');
6%disp('Model: 2 focals, 2 radial dist. coeff., 2 tangential dist. coeff. and principle point');
7%disp(' => 8DOF intrinsic model ([Heikkila and Silven, University of Oulu])');
8
9fprintf(1,'\n');
10calib_name = input('Basename camera calibration images (without number nor suffix): ','s');
11
12format_image = '0';
13
14while format_image == '0',
15
16 format_image = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'') ','s');
17
18 if isempty(format_image),
19 format_image = 'ras';
20 end;
21
22 if lower(format_image(1)) == 'b',
23 format_image = 'bmp';
24 else
25 if lower(format_image(1)) == 't',
26 format_image = 'tif';
27 else
28 if lower(format_image(1)) == 'p',
29 format_image = 'pgm';
30 else
31 if lower(format_image(1)) == 'j',
32 format_image = 'jpg';
33 else
34 if lower(format_image(1)) == 'r',
35 format_image = 'ras';
36 else
37 disp('Invalid image format');
38 format_image = '0'; % Ask for format once again
39 end;
40 end;
41 end;
42 end;
43 end;
44
45end;
46
47
48n_ima = 1000;
49while n_ima > 30,
50 n_ima = input('Number of calibration images: ');
51 n_ima = round(n_ima);
52end;
53
54type_numbering = input('Type of numbering (ex: []=4,other=04): ');
55
56type_numbering = ~isempty(type_numbering);
57
58if type_numbering,
59
60 N_slots = input('Number of spaces for numbers? (ex: 2 -> 04, 3 -> 004), ([]=3) ');
61
62 if isempty(N_slots), N_slots = 3; end;
63
64else
65
66 N_slots = 1; % not used anyway, but useful for saving
67
68end;
69
70
71first_num = input('First image number? (0,1,2...) ([]=0) ');
72
73if isempty(first_num), first_num = 0; end;
74
75image_numbers = first_num:n_ima-1+first_num;
76
77
78%%% By default, all the images are active for calibration:
79
80active_images = ones(1,n_ima);
81
82%string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name first_num';
83
84%eval(string_save);
85
86% Reading images:
87
88ima_read_calib;
89
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/error_analysis.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/error_analysis.m
new file mode 100755
index 0000000..85feac5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/error_analysis.m
@@ -0,0 +1,182 @@
1%%% ERROR_ANALYSIS
2%%% This simulation helps coputing the acturacies of calibration
3%%% Run it after the main calibration
4
5
6
7N_runs = 200;
8
9%N_ima_active = 4;
10
11saving = 1;
12
13if 1, %~exist('fc_list'), % initialization
14
15 % Initialization:
16
17 load Calib_Results;
18 check_active_images;
19
20 fc_list = [];
21 cc_list = [];
22 kc_list = [];
23 active_images_list = [];
24
25
26 for kk=1:n_ima,
27
28 eval(['omc_list_' num2str(kk) ' = [];']);
29 eval(['Tc_list_' num2str(kk) ' = [];']);
30
31 end;
32
33 %sx = median(abs(ex(1,:)))*1.4836;
34 %sy = median(abs(ex(2,:)))*1.4836;
35
36 sx = std(ex(1,:));
37 sy = std(ex(2,:));
38
39 % Saving the feature locations:
40
41 for kk = 1:n_ima,
42
43 eval(['x_save_' num2str(kk) ' = x_' num2str(kk) ';']);
44 eval(['y_save_' num2str(kk) ' = y_' num2str(kk) ';']);
45
46 end;
47
48 active_images_save = active_images;
49 ind_active_save = ind_active;
50
51 fc_save = fc;
52 cc_save = cc;
53 kc_save = kc;
54 KK_save = KK;
55
56
57end;
58
59
60
61
62%%% The main loop:
63
64
65for ntrial = 1:N_runs,
66
67 fprintf(1,'\nRun number: %d\n',ntrial);
68 fprintf(1, '----------\n');
69
70 for kk = 1:n_ima,
71
72 eval(['y_kk = y_save_' num2str(kk) ';'])
73
74 if active_images(kk) & ~isnan(y_kk(1,1)),
75
76 Nkk = size(y_kk,2);
77
78 x_kk_new = y_kk + [sx * randn(1,Nkk);sy*randn(1,Nkk)];
79
80 eval(['x_' num2str(kk) ' = x_kk_new;']);
81
82 end;
83
84 end;
85
86 N_active = length(ind_active_save);
87 junk = randn(1,N_active);
88 [junk,junk2] = sort(junk);
89
90 active_images = zeros(1,n_ima);
91 active_images(ind_active_save(junk2(1:N_ima_active))) = ones(1,N_ima_active);
92
93 fc = fc_save;
94 cc = cc_save;
95 kc = kc_save;
96 KK = KK_save;
97
98 go_calib_optim;
99
100 fc_list = [fc_list fc];
101 cc_list = [cc_list cc];
102 kc_list = [kc_list kc];
103 active_images_list = [active_images_list active_images'];
104
105 for kk=1:n_ima,
106
107 eval(['omc_list_' num2str(kk) ' = [ omc_list_' num2str(kk) ' omc_' num2str(kk) ' ];']);
108 eval(['Tc_list_' num2str(kk) ' = [ Tc_list_' num2str(kk) ' Tc_' num2str(kk) ' ];']);
109
110 end;
111
112end;
113
114
115
116
117if 0,
118
119% Restoring the feature locations:
120
121for kk = 1:n_ima,
122
123 eval(['x_' num2str(kk) ' = x_save_' num2str(kk) ';']);
124
125end;
126
127fprintf(1,'\nFinal run (with the real data)\n');
128fprintf(1, '------------------------------\n');
129
130active_images = active_images_save;
131ind_active = ind_active_save;
132
133go_calib_optim;
134
135fc_list = [fc_list fc];
136cc_list = [cc_list cc];
137kc_list = [kc_list kc];
138active_images_list = [active_images_list active_images'];
139
140for kk=1:n_ima,
141
142 eval(['omc_list_' num2str(kk) ' = [ omc_list_' num2str(kk) ' omc_' num2str(kk) ' ];']);
143 eval(['Tc_list_' num2str(kk) ' = [ Tc_list_' num2str(kk) ' Tc_' num2str(kk) ' ];']);
144
145end;
146
147end;
148
149
150
151
152
153if saving,
154
155disp(['Save Calibration accuracy results under Calib_Accuracies_' num2str(N_ima_active) '.mat']);
156
157string_save = ['save Calib_Accuracies_' num2str(N_ima_active) ' active_images n_ima N_ima_active N_runs active_images_list fc cc kc fc_list cc_list kc_list'];
158
159for kk = 1:n_ima,
160 string_save = [string_save ' Tc_list_' num2str(kk) ' omc_list_' num2str(kk) ' Tc_' num2str(kk) ' omc_' num2str(kk) ];
161end;
162
163eval(string_save);
164
165end;
166
167
168return;
169
170std(fc_list')
171
172std(cc_list')
173
174std(kc_list')
175
176for kk = 1:n_ima,
177
178 eval(['std(Tc_list_' num2str(kk) ''')'])
179
180end;
181
182
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ext_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ext_calib.m
new file mode 100755
index 0000000..d41d068
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ext_calib.m
@@ -0,0 +1,130 @@
1
2%%%%%%%%%%%%%%%%%%%% SHOW EXTRINSIC RESULTS %%%%%%%%%%%%%%%%%%%%%%%%
3
4check_active_images;
5
6if ~exist(['omc_' num2str(ind_active(1))]),
7 fprintf(1,'Need to calibrate before showing extrinsic results. Maybe need to load Calib_Results.mat file.\n');
8 return;
9end;
10
11%if ~exist('no_grid'),
12 no_grid = 0;
13%end;
14
15if ~exist(['n_sq_x_' num2str(ind_active(1))]),
16 no_grid = 1;
17end;
18
19
20if 0,
21
22err_std = std(ex');
23
24fprintf(1,'\n\nCalibration results without principal point estimation:\n\n');
25fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
26fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
27fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
28fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
29
30end;
31
32
33% Color code for each image:
34
35colors = 'brgkcm';
36
37
38%%% Show the extrinsic parameters
39
40if ~exist('dX'),
41 eval(['dX = norm(Tc_' num2str(ind_active(1)) ')/10;']);
42 dY = dX;
43end;
44
45IP = 5*dX*([0 nx-1 nx-1 0 0 ; 0 0 ny-1 ny-1 0;1 1 1 1 1] - [cc;0]*ones(1,5)) ./ ([fc;1]*ones(1,5));
46BASE = 5*dX*([0 1 0 0 0 0;0 0 0 1 0 0;0 0 0 0 0 1]);
47IP = reshape([IP;BASE(:,1)*ones(1,5);IP],3,15);
48
49figure(4);
50[a,b] = view;
51
52figure(4);
53plot3(BASE(1,:),BASE(3,:),-BASE(2,:),'b-','linewidth',2');
54hold on;
55plot3(IP(1,:),IP(3,:),-IP(2,:),'r-','linewidth',2);
56text(6*dX,0,0,'X_c');
57text(-dX,5*dX,0,'Z_c');
58text(0,0,-6*dX,'Y_c');
59text(-dX,-dX,dX,'O_c');
60
61
62for kk = 1:n_ima,
63
64 if active_images(kk);
65
66 eval(['XX_kk = X_' num2str(kk) ';']);
67 eval(['omc_kk = omc_' num2str(kk) ';']);
68 eval(['Tc_kk = Tc_' num2str(kk) ';']);
69 N_kk = size(XX_kk,2);
70
71 if ~exist(['n_sq_x_' num2str(kk)]),
72 no_grid = 1;
73 end;
74
75 if ~no_grid,
76 eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
77 eval(['n_sq_y = n_sq_y_' num2str(kk) ';']);
78 if (N_kk ~= ((n_sq_x+1)*(n_sq_y+1))),
79 no_grid = 1;
80 end;
81 end;
82
83 if ~isnan(omc_kk(1,1)),
84
85 R_kk = rodrigues(omc_kk);
86
87 YY_kk = R_kk * XX_kk + Tc_kk * ones(1,length(XX_kk));
88
89 uu = [-dX;-dY;0]/2;
90 uu = R_kk * uu + Tc_kk;
91
92 if ~no_grid,
93 YYx = zeros(n_sq_x+1,n_sq_y+1);
94 YYy = zeros(n_sq_x+1,n_sq_y+1);
95 YYz = zeros(n_sq_x+1,n_sq_y+1);
96
97 YYx(:) = YY_kk(1,:);
98 YYy(:) = YY_kk(2,:);
99 YYz(:) = YY_kk(3,:);
100
101 %keyboard;
102
103 figure(4);
104 hhh= mesh(YYx,YYz,-YYy);
105 set(hhh,'edgecolor',colors(rem(kk-1,6)+1),'linewidth',1); %,'facecolor','none');
106 %plot3(YY_kk(1,:),YY_kk(3,:),-YY_kk(2,:),['o' colors(rem(kk-1,6)+1)]);
107 text(uu(1),uu(3),-uu(2),num2str(kk),'fontsize',14,'color',colors(rem(kk-1,6)+1));
108 else
109
110 figure(4);
111 plot3(YY_kk(1,:),YY_kk(3,:),-YY_kk(2,:),['.' colors(rem(kk-1,6)+1)]);
112 text(uu(1),uu(3),-uu(2),num2str(kk),'fontsize',14,'color',colors(rem(kk-1,6)+1));
113
114 end;
115
116 end;
117
118 end;
119
120end;
121
122figure(4);rotate3d on;
123axis('equal');
124title('Extrinsic parameters');
125%view(60,30);
126view(a,b);
127hold off;
128
129set(4,'Name','3D','NumberTitle','off');
130
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_grid.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_grid.m
new file mode 100755
index 0000000..1e3cbdb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_grid.m
@@ -0,0 +1,227 @@
1function [x,X,n_sq_x,n_sq_y,ind_orig,ind_x,ind_y] = extract_grid(I,wintx,winty,fc,cc,kc);
2
3map = gray(256);
4
5 figure(2);
6 image(I);
7 colormap(map);
8
9
10 if nargin < 2,
11
12 disp('Window size for corner finder (wintx and winty):');
13 wintx = input('wintx ([] = 5) = ');
14 if isempty(wintx), wintx = 5; end;
15 wintx = round(wintx);
16 winty = input('winty ([] = 5) = ');
17 if isempty(winty), winty = 5; end;
18 winty = round(winty);
19
20 fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
21
22 end;
23
24
25
26 title('Click on the four extreme corners of the rectangular pattern...');
27
28 disp('Click on the four extreme corners of the rectangular complete pattern...');
29
30 [x,y] = ginput3(4);
31
32 [Xc,good,bad,type] = cornerfinder([x';y'],I,winty,wintx); % the four corners
33
34 x = Xc(1,:)';
35 y = Xc(2,:)';
36
37 [y,indy] = sort(y);
38 x = x(indy);
39
40 if (x(2) > x(1)),
41 x4 = x(1);y4 = y(1); x3 = x(2); y3 = y(2);
42 else
43 x4 = x(2);y4 = y(2); x3 = x(1); y3 = y(1);
44 end;
45 if (x(3) > x(4)),
46 x2 = x(3);y2 = y(3); x1 = x(4); y1 = y(4);
47 else
48 x2 = x(4);y2 = y(4); x1 = x(3); y1 = y(3);
49 end;
50
51 x = [x1;x2;x3;x4];
52 y = [y1;y2;y3;y4];
53
54
55 figure(2); hold on;
56 plot([x;x(1)],[y;y(1)],'g-');
57 plot(x,y,'og');
58 hx=text((x(4)+x(3))/2,(y(4)+y(3))/2 - 20,'X');
59 set(hx,'color','g','Fontsize',14);
60 hy=text((x(4)+x(1))/2-20,(y(4)+y(1))/2,'Y');
61 set(hy,'color','g','Fontsize',14);
62 hold off;
63
64
65 % Try to automatically count the number of squares in the grid
66
67 n_sq_x1 = count_squares(I,x1,y1,x2,y2,wintx);
68 n_sq_x2 = count_squares(I,x3,y3,x4,y4,wintx);
69 n_sq_y1 = count_squares(I,x2,y2,x3,y3,wintx);
70 n_sq_y2 = count_squares(I,x4,y4,x1,y1,wintx);
71
72
73
74 % If could not count the number of squares, enter manually
75
76 if (n_sq_x1~=n_sq_x2)|(n_sq_y1~=n_sq_y2),
77
78
79 disp('Could not count the number of squares in the grid. Enter manually.');
80 n_sq_x = input('Number of squares along the X direction ([]=10) = '); %6
81 if isempty(n_sq_x), n_sq_x = 10; end;
82 n_sq_y = input('Number of squares along the Y direction ([]=10) = '); %6
83 if isempty(n_sq_y), n_sq_y = 10; end;
84
85 else
86
87 n_sq_x = n_sq_x1;
88 n_sq_y = n_sq_y1;
89
90 end;
91
92
93 % Enter the size of each square
94
95 dX = input(['Size dX of each square along the X direction ([]=3cm) = ']);
96 dY = input(['Size dY of each square along the Y direction ([]=3cm) = ']);
97 if isempty(dX), dX = 3; end;
98 if isempty(dY), dY = 3; end;
99
100
101
102 % Compute the inside points through computation of the planar homography (collineation)
103
104 a00 = [x(1);y(1);1];
105 a10 = [x(2);y(2);1];
106 a11 = [x(3);y(3);1];
107 a01 = [x(4);y(4);1];
108
109
110 % Compute the planart collineation: (return the normalization matrice as well)
111
112 [Homo,Hnorm,inv_Hnorm] = compute_homography ([a00 a10 a11 a01],[0 1 1 0;0 0 1 1;1 1 1 1]);
113
114
115 % Build the grid using the planar collineation:
116
117 x_l = ((0:n_sq_x)'*ones(1,n_sq_y+1))/n_sq_x;
118 y_l = (ones(n_sq_x+1,1)*(0:n_sq_y))/n_sq_y;
119 pts = [x_l(:) y_l(:) ones((n_sq_x+1)*(n_sq_y+1),1)]';
120
121 XX = Homo*pts;
122 XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
123
124
125 % Complete size of the rectangle
126
127 W = n_sq_x*dX;
128 L = n_sq_y*dY;
129
130
131
132 if nargin < 6,
133
134 %%%%%%%%%%%%%%%%%%%%%%%% ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
135 figure(2);
136 hold on;
137 plot(XX(1,:),XX(2,:),'r+');
138 title('The red crosses should be close to the image corners');
139 hold off;
140
141 disp('If the guessed grid corners (red crosses on the image) are not close to the actual corners,');
142 disp('it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)');
143 quest_distort = input('Need of an initial guess for distortion? ([]=no, other=yes) ');
144
145 quest_distort = ~isempty(quest_distort);
146
147 if quest_distort,
148 % Estimation of focal length:
149 c_g = [size(I,2);size(I,1)]/2 + .5;
150 f_g = Distor2Calib(0,[[x(1) x(2) x(4) x(3)] - c_g(1);[y(1) y(2) y(4) y(3)] - c_g(2)],1,1,4,W,L,[-W/2 W/2 W/2 -W/2;L/2 L/2 -L/2 -L/2; 0 0 0 0],100,1,1);
151 f_g = mean(f_g);
152 script_fit_distortion;
153 end;
154 %%%%%%%%%%%%%%%%%%%%% END ADDITIONAL STUFF IN THE CASE OF HIGHLY DISTORTED IMAGES %%%%%%%%%%%%%
155
156 else
157
158 xy_corners_undist = comp_distortion_oulu([(x' - cc(1))/fc(1);(y'-cc(2))/fc(1)],kc);
159
160 xu = xy_corners_undist(1,:)';
161 yu = xy_corners_undist(2,:)';
162
163 [XXu] = projectedGrid ( [xu(1);yu(1)], [xu(2);yu(2)],[xu(3);yu(3)], [xu(4);yu(4)],n_sq_x+1,n_sq_y+1); % The full grid
164
165 r2 = sum(XXu.^2);
166 XX = (ones(2,1)*(1 + kc(1) * r2 + kc(2) * (r2.^2))) .* XXu;
167 XX(1,:) = fc(1)*XX(1,:)+cc(1);
168 XX(2,:) = fc(2)*XX(2,:)+cc(2);
169
170 end;
171
172
173 Np = (n_sq_x+1)*(n_sq_y+1);
174
175 disp('Corner extraction...');
176
177 grid_pts = cornerfinder(XX,I,winty,wintx); %%% Finds the exact corners at every points!
178
179 grid_pts = grid_pts - 1; % subtract 1 to bring the origin to (0,0) instead of (1,1) in matlab (not necessary in C)
180
181 ind_corners = [1 n_sq_x+1 (n_sq_x+1)*n_sq_y+1 (n_sq_x+1)*(n_sq_y+1)]; % index of the 4 corners
182 ind_orig = (n_sq_x+1)*n_sq_y + 1;
183 xorig = grid_pts(1,ind_orig);
184 yorig = grid_pts(2,ind_orig);
185 dxpos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig+1)]');
186 dypos = mean([grid_pts(:,ind_orig) grid_pts(:,ind_orig-n_sq_x-1)]');
187
188
189 ind_x = (n_sq_x+1)*(n_sq_y + 1);
190 ind_y = 1;
191
192 x_box_kk = [grid_pts(1,:)-(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)+(wintx+.5);grid_pts(1,:)-(wintx+.5);grid_pts(1,:)-(wintx+.5)];
193 y_box_kk = [grid_pts(2,:)-(winty+.5);grid_pts(2,:)-(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)+(winty+.5);grid_pts(2,:)-(winty+.5)];
194
195
196 figure(3);
197 image(I); colormap(map); hold on;
198 plot(grid_pts(1,:)+1,grid_pts(2,:)+1,'r+');
199 plot(x_box_kk+1,y_box_kk+1,'-b');
200 plot(grid_pts(1,ind_corners)+1,grid_pts(2,ind_corners)+1,'mo');
201 plot(xorig+1,yorig+1,'*m');
202 h = text(xorig-15,yorig-15,'O');
203 set(h,'Color','m','FontSize',14);
204 h2 = text(dxpos(1)-10,dxpos(2)-10,'dX');
205 set(h2,'Color','g','FontSize',14);
206 h3 = text(dypos(1)-25,dypos(2)-3,'dY');
207 set(h3,'Color','g','FontSize',14);
208 xlabel('Xc (in camera frame)');
209 ylabel('Yc (in camera frame)');
210 title('Extracted corners');
211 zoom on;
212 drawnow;
213 hold off;
214
215
216 Xi = reshape(([0:n_sq_x]*dX)'*ones(1,n_sq_y+1),Np,1)';
217 Yi = reshape(ones(n_sq_x+1,1)*[n_sq_y:-1:0]*dY,Np,1)';
218 Zi = zeros(1,Np);
219
220 Xgrid = [Xi;Yi;Zi];
221
222
223 % All the point coordinates (on the image, and in 3D) - for global optimization:
224
225 x = grid_pts;
226 X = Xgrid;
227
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters.m
new file mode 100755
index 0000000..8e0e1f1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters.m
@@ -0,0 +1,46 @@
1
2%%% Extraction of the final intrinsic and extrinsic paramaters:
3
4check_active_images;
5
6fc = solution(1:2);
7kc = solution(3:6);
8cc = solution(6*n_ima + 4 +3:6*n_ima + 5 +3);
9
10% Calibration matrix:
11
12KK = [fc(1) 0 cc(1);0 fc(2) cc(2); 0 0 1];
13inv_KK = inv(KK);
14
15% Extract the extrinsic paramters, and recomputer the collineations
16
17for kk = 1:n_ima,
18
19 if active_images(kk),
20
21 omckk = solution(4+6*(kk-1) + 3:6*kk + 3);
22 Tckk = solution(6*kk+1 + 3:6*kk+3 + 3);
23
24 Rckk = rodrigues(omckk);
25
26 Hkk = KK * [Rckk(:,1) Rckk(:,2) Tckk];
27
28 Hkk = Hkk / Hkk(3,3);
29
30 else
31
32 omckk = NaN*ones(3,1);
33 Tckk = NaN*ones(3,1);
34 Rckk = NaN*ones(3,3);
35 Hkk = NaN*ones(3,3);
36
37 end;
38
39 eval(['omc_' num2str(kk) ' = omckk;']);
40 eval(['Rc_' num2str(kk) ' = Rckk;']);
41 eval(['Tc_' num2str(kk) ' = Tckk;']);
42 eval(['H_' num2str(kk) '= Hkk;']);
43
44end;
45
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters3D.m
new file mode 100755
index 0000000..841c6ab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extract_parameters3D.m
@@ -0,0 +1,36 @@
1
2%%% Extraction of the final intrinsic and extrinsic paramaters:
3
4
5fc = solution(1:2);
6kc = solution(3:6);
7cc = solution(6*n_ima + 4 +3:6*n_ima + 5 +3);
8
9% Calibration matrix:
10
11KK = [fc(1) 0 cc(1);0 fc(2) cc(2); 0 0 1];
12inv_KK = inv(KK);
13
14% Extract the extrinsic paramters, and recomputer the collineations
15
16for kk = 1:n_ima,
17
18 omckk = solution(4+6*(kk-1) + 3:6*kk + 3);
19
20 Tckk = solution(6*kk+1 + 3:6*kk+3 + 3);
21
22 Rckk = rodrigues(omckk);
23
24 Hlkk = KK * [Rckk(:,1) Rckk(:,2) Tckk];
25
26 Hlkk = Hlkk / Hlkk(3,3);
27
28 eval(['omc_' num2str(kk) ' = omckk;']);
29 eval(['Rc_' num2str(kk) ' = Rckk;']);
30 eval(['Tc_' num2str(kk) ' = Tckk;']);
31
32 eval(['Hl_' num2str(kk) '=Hlkk;']);
33
34end;
35
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extrinsic_computation.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extrinsic_computation.m
new file mode 100755
index 0000000..8cf10db
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/extrinsic_computation.m
@@ -0,0 +1,173 @@
1%%% INPUT THE IMAGE FILE NAME:
2
3dir;
4
5fprintf(1,'\n');
6disp('Computation of the extrinsic parameters from an image of a pattern');
7disp('The intrinsic camera parameters are assumed to be known (previously computed)');
8
9fprintf(1,'\n');
10image_name = input('Image name (full name without extension): ','s');
11
12format_image2 = '0';
13
14while format_image2 == '0',
15
16 format_image2 = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'') ','s');
17
18 if isempty(format_image2),
19 format_image2 = 'ras';
20 end;
21
22 if lower(format_image2(1)) == 'b',
23 format_image2 = 'bmp';
24 else
25 if lower(format_image2(1)) == 't',
26 format_image2 = 'tif';
27 else
28 if lower(format_image2(1)) == 'p',
29 format_image2 = 'pgm';
30 else
31 if lower(format_image2(1)) == 'j',
32 format_image2 = 'jpg';
33 else
34 if lower(format_image2(1)) == 'r',
35 format_image2 = 'ras';
36 else
37 disp('Invalid image format');
38 format_image2 = '0'; % Ask for format once again
39 end;
40 end;
41 end;
42 end;
43 end;
44end;
45
46ima_name = [image_name '.' format_image];
47
48
49
50%%% READ IN IMAGE:
51
52if format_image(1) == 'p',
53 I = double(pgmread(ima_name));
54else
55 if format_image(1) == 'r',
56 I = readras(ima_name);
57 else
58 I = double(imread(ima_name));
59 end;
60end;
61
62if size(I,3)>1,
63 I = I(:,:,2);
64end;
65
66
67%%% EXTRACT GRID CORNERS:
68
69fprintf(1,'\nExtraction of the grid corners on the image\n');
70
71disp('Window size for corner finder (wintx and winty):');
72wintx = input('wintx ([] = 5) = ');
73if isempty(wintx), wintx = 5; end;
74wintx = round(wintx);
75winty = input('winty ([] = 5) = ');
76if isempty(winty), winty = 5; end;
77winty = round(winty);
78
79fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
80
81[x_ext,X_ext,n_sq_x,n_sq_y,ind_orig,ind_x,ind_y] = extract_grid(I,wintx,winty,fc,cc,kc);
82
83
84
85%%% Computation of the Extrinsic Parameters attached to the grid:
86
87[omc_ext,Tc_ext,Rc_ext,H_ext] = compute_extrinsic(x_ext,X_ext,fc,cc,kc);
88
89
90%%% Reproject the points on the image:
91
92[x_reproj] = project_points(X_ext,omc_ext,Tc_ext,fc,cc,kc);
93
94err_reproj = x_ext - x_reproj;
95
96err_std2 = std(err_reproj')';
97
98
99Basis = [X_ext(:,[ind_orig ind_x ind_orig ind_y ind_orig ])];
100
101VX = Basis(:,2) - Basis(:,1);
102VY = Basis(:,4) - Basis(:,1);
103
104nX = norm(VX);
105nY = norm(VY);
106
107VZ = min(nX,nY) * cross(VX/nX,VY/nY);
108
109Basis = [Basis VZ];
110
111[x_basis] = project_points(Basis,omc_ext,Tc_ext,fc,cc,kc);
112
113dxpos = (x_basis(:,2) + x_basis(:,1))/2;
114dypos = (x_basis(:,4) + x_basis(:,3))/2;
115dzpos = (x_basis(:,6) + x_basis(:,5))/2;
116
117
118
119figure(2);
120image(I);
121colormap(gray(256));
122hold on;
123plot(x_ext(1,:)+1,x_ext(2,:)+1,'r+');
124plot(x_reproj(1,:)+1,x_reproj(2,:)+1,'yo');
125h = text(x_ext(1,ind_orig)-25,x_ext(2,ind_orig)-25,'O');
126set(h,'Color','g','FontSize',14);
127h2 = text(dxpos(1)+1,dxpos(2)-30,'X');
128set(h2,'Color','g','FontSize',14);
129h3 = text(dypos(1)-30,dypos(2)+1,'Y');
130set(h3,'Color','g','FontSize',14);
131h4 = text(dzpos(1)-10,dzpos(2)-20,'Z');
132set(h4,'Color','g','FontSize',14);
133plot(x_basis(1,:)+1,x_basis(2,:)+1,'g-','linewidth',2);
134title('Image points (+) and reprojected grid points (o)');
135hold off;
136
137
138fprintf(1,'\n\nExtrinsic parameters:\n\n');
139fprintf(1,'Translation vector: Tc_ext = [ %3.6f \t %3.6f \t %3.6f ]\n',Tc_ext);
140fprintf(1,'Rotation vector: omc_ext = [ %3.6f \t %3.6f \t %3.6f ]\n',omc_ext);
141fprintf(1,'Rotation matrix: Rc_ext = [ %3.6f \t %3.6f \t %3.6f\n',Rc_ext(1,:)');
142fprintf(1,' %3.6f \t %3.6f \t %3.6f\n',Rc_ext(2,:)');
143fprintf(1,' %3.6f \t %3.6f \t %3.6f ]\n',Rc_ext(3,:)');
144fprintf(1,'Pixel error: err = [ %3.5f \t %3.5f ]\n\n',err_std2);
145
146
147
148
149
150return;
151
152
153% Stores the results:
154
155kk = 1;
156
157% Stores location of grid wrt camera:
158
159eval(['omc_' num2str(kk) ' = omc_ext;']);
160eval(['Tc_' num2str(kk) ' = Tc_ext;']);
161
162% Stores the projected points:
163
164eval(['y_' num2str(kk) ' = x_reproj;']);
165eval(['X_' num2str(kk) ' = X_ext;']);
166eval(['x_' num2str(kk) ' = x_ext;']);
167
168
169% Organize the points in a grid:
170
171eval(['n_sq_x_' num2str(kk) ' = n_sq_x;']);
172eval(['n_sq_y_' num2str(kk) ' = n_sq_y;']);
173 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ginput3.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ginput3.m
new file mode 100755
index 0000000..56fe496
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ginput3.m
@@ -0,0 +1,216 @@
1function [out1,out2,out3] = ginput2(arg1)
2%GINPUT Graphical input from mouse.
3% [X,Y] = GINPUT(N) gets N points from the current axes and returns
4% the X- and Y-coordinates in length N vectors X and Y. The cursor
5% can be positioned using a mouse (or by using the Arrow Keys on some
6% systems). Data points are entered by pressing a mouse button
7% or any key on the keyboard except carriage return, which terminates
8% the input before N points are entered.
9%
10% [X,Y] = GINPUT gathers an unlimited number of points until the
11% return key is pressed.
12%
13% [X,Y,BUTTON] = GINPUT(N) returns a third result, BUTTON, that
14% contains a vector of integers specifying which mouse button was
15% used (1,2,3 from left) or ASCII numbers if a key on the keyboard
16% was used.
17
18% Copyright (c) 1984-96 by The MathWorks, Inc.
19% $Revision: 5.18 $ $Date: 1996/11/10 17:48:08 $
20
21% Fixed version by Jean-Yves Bouguet to have a cross instead of 2 lines
22% More visible for images
23
24P = NaN*ones(16,16);
25P(1:15,1:15) = 2*ones(15,15);
26P(2:14,2:14) = ones(13,13);
27P(3:13,3:13) = NaN*ones(11,11);
28P(6:10,6:10) = 2*ones(5,5);
29P(7:9,7:9) = 1*ones(3,3);
30
31out1 = []; out2 = []; out3 = []; y = [];
32c = computer;
33if ~strcmp(c(1:2),'PC') & ~strcmp(c(1:2),'MA')
34 tp = get(0,'TerminalProtocol');
35else
36 tp = 'micro';
37end
38
39if ~strcmp(tp,'none') & ~strcmp(tp,'x') & ~strcmp(tp,'micro'),
40 if nargout == 1,
41 if nargin == 1,
42 eval('out1 = trmginput(arg1);');
43 else
44 eval('out1 = trmginput;');
45 end
46 elseif nargout == 2 | nargout == 0,
47 if nargin == 1,
48 eval('[out1,out2] = trmginput(arg1);');
49 else
50 eval('[out1,out2] = trmginput;');
51 end
52 if nargout == 0
53 out1 = [ out1 out2 ];
54 end
55 elseif nargout == 3,
56 if nargin == 1,
57 eval('[out1,out2,out3] = trmginput(arg1);');
58 else
59 eval('[out1,out2,out3] = trmginput;');
60 end
61 end
62else
63
64 fig = gcf;
65 figure(gcf);
66
67 if nargin == 0
68 how_many = -1;
69 b = [];
70 else
71 how_many = arg1;
72 b = [];
73 if isstr(how_many) ...
74 | size(how_many,1) ~= 1 | size(how_many,2) ~= 1 ...
75 | ~(fix(how_many) == how_many) ...
76 | how_many < 0
77 error('Requires a positive integer.')
78 end
79 if how_many == 0
80 ptr_fig = 0;
81 while(ptr_fig ~= fig)
82 ptr_fig = get(0,'PointerWindow');
83 end
84 scrn_pt = get(0,'PointerLocation');
85 loc = get(fig,'Position');
86 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
87 out1 = pt(1); y = pt(2);
88 elseif how_many < 0
89 error('Argument must be a positive integer.')
90 end
91 end
92
93pointer = get(gcf,'pointer');
94
95set(gcf,'Pointer','custom','PointerShapeCData',P,'PointerShapeHotSpot',[8,8]);
96%set(gcf,'pointer','crosshair');
97 fig_units = get(fig,'units');
98 char = 0;
99
100 while how_many ~= 0
101 % Use no-side effect WAITFORBUTTONPRESS
102 waserr = 0;
103 eval('keydown = wfbp;', 'waserr = 1;');
104 if(waserr == 1)
105 if(ishandle(fig))
106 set(fig,'pointer',pointer,'units',fig_units);
107 error('Interrupted');
108 else
109 error('Interrupted by figure deletion');
110 end
111 end
112
113 ptr_fig = get(0,'CurrentFigure');
114 if(ptr_fig == fig)
115 if keydown
116 char = get(fig, 'CurrentCharacter');
117 button = abs(get(fig, 'CurrentCharacter'));
118 scrn_pt = get(0, 'PointerLocation');
119 set(fig,'units','pixels')
120 loc = get(fig, 'Position');
121 pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
122 set(fig,'CurrentPoint',pt);
123 else
124 button = get(fig, 'SelectionType');
125 if strcmp(button,'open')
126 button = b(length(b));
127 elseif strcmp(button,'normal')
128 button = 1;
129 elseif strcmp(button,'extend')
130 button = 2;
131 elseif strcmp(button,'alt')
132 button = 3;
133 else
134 error('Invalid mouse selection.')
135 end
136 end
137 pt = get(gca, 'CurrentPoint');
138
139 how_many = how_many - 1;
140
141 if(char == 13) % & how_many ~= 0)
142 % if the return key was pressed, char will == 13,
143 % and that's our signal to break out of here whether
144 % or not we have collected all the requested data
145 % points.
146 % If this was an early breakout, don't include
147 % the <Return> key info in the return arrays.
148 % We will no longer count it if it's the last input.
149 break;
150 end
151
152 out1 = [out1;pt(1,1)];
153 y = [y;pt(1,2)];
154 b = [b;button];
155 end
156 end
157
158 set(fig,'pointer',pointer,'units',fig_units);
159
160 if nargout > 1
161 out2 = y;
162 if nargout > 2
163 out3 = b;
164 end
165 else
166 out1 = [out1 y];
167 end
168
169end
170
171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172function key = wfbp
173%WFBP Replacement for WAITFORBUTTONPRESS that has no side effects.
174
175% Remove figure button functions
176fprops = {'windowbuttonupfcn','buttondownfcn', ...
177 'windowbuttondownfcn','windowbuttonmotionfcn'};
178fig = gcf;
179fvals = get(fig,fprops);
180set(fig,fprops,{'','','',''})
181
182% Remove all other buttondown functions
183ax = findobj(fig,'type','axes');
184if isempty(ax)
185 ch = {};
186else
187 ch = get(ax,{'Children'});
188end
189for i=1:length(ch),
190 ch{i} = ch{i}(:)';
191end
192h = [ax(:)',ch{:}];
193vals = get(h,{'buttondownfcn'});
194mt = repmat({''},size(vals));
195set(h,{'buttondownfcn'},mt);
196
197% Now wait for that buttonpress, and check for error conditions
198waserr = 0;
199eval(['if nargout==0,', ...
200 ' waitforbuttonpress,', ...
201 'else,', ...
202 ' keydown = waitforbuttonpress;',...
203 'end' ], 'waserr = 1;');
204
205% Put everything back
206if(ishandle(fig))
207 set(fig,fprops,fvals)
208 set(h,{'buttondownfcn'},vals)
209end
210
211if(waserr == 1)
212 error('Interrupted');
213end
214
215if nargout>0, key = keydown; end
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim.m
new file mode 100755
index 0000000..6eb1c82
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim.m
@@ -0,0 +1,60 @@
1%go_calib_optim
2%
3%Main calibration function. Computes the intrinsic andextrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% KK: The camera matrix (containing fc and cc)
13% omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
14% Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
15% Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
16%
17%Method: Minimizes the pixel reprojection error in the least squares sense over the intrinsic
18% camera parameters, and the extrinsic parameters (3D locations of the grids in space)
19%
20%Note: If the intrinsic camera parameters (fc, cc, kc) do not exist before, they are initialized through
21% the function init_intrinsic_param.m. Otherwise, the variables in memory are used as initial guesses.
22%
23%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
24% corresponding entry in the active_images vector to zero.
25%
26%VERY IMPORTANT: This function works for 2D and 3D calibration rigs, except for init_intrinsic_param.m
27%that is so far implemented to work only with 2D rigs.
28%In the future, a more general function will be there.
29%For now, if using a 3D calibration rig, set quick_init to 1 for an easy initialization of the focal length
30
31
32desactivated_images = [];
33
34
35go_calib_optim_iter;
36
37
38if ~isempty(desactivated_images),
39
40 param_list_save = param_list;
41
42 fprintf(1,'\nNew optimization including the images that have been deactivated during the previous optimization.\n');
43 active_images(desactivated_images) = ones(1,length(desactivated_images));
44 desactivated_images = [];
45
46 go_calib_optim_iter;
47
48 if ~isempty(desactivated_images),
49 fprintf(1,['List of images left desactivated: ' num2str(desactivated_images) '\n' ] );
50 end;
51
52 param_list = [param_list_save(:,1:end-1) param_list];
53
54end;
55
56
57%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
58
59%graphout_calib;
60
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim3D.m
new file mode 100755
index 0000000..8cc5e30
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim3D.m
@@ -0,0 +1,264 @@
1% Simplified version of go_calib.m
2
3
4if ~exist('x_1'),
5 click_calib;
6end;
7
8
9fprintf(1,'\nMain calibration procedure\n');
10
11% initial guess for principal point and distortion:
12c_init = [nx;ny]/2 - 0.5; % initialize at the center of the image
13k_init = [0;0;0;0]; % initialize to zero (no distortion)
14
15
16% Compute explicitely the focal lentgh using all the (mutually orthogonal) vanishing points
17% note: The vanihing points are hidden in the planar collineations H_kk
18
19A = [];
20b = [];
21
22% matrix that subtract the principal point:
23Sub_cc = [1 0 -c_init(1);0 1 -c_init(2);0 0 1];
24
25
26for kk=1:n_ima,
27
28 % left Pattern:
29
30 eval(['Hlkk = Hl_' num2str(kk) ';']);
31
32 Hlkk = Sub_cc * Hlkk;
33
34 % Extract vanishing points (direct and diagonals):
35
36 Vl_hori_pix = Hlkk(:,1);
37 Vl_vert_pix = Hlkk(:,2);
38 Vl_diag1_pix = (Hlkk(:,1)+Hlkk(:,2))/2;
39 Vl_diag2_pix = (Hlkk(:,1)-Hlkk(:,2))/2;
40
41 Vl_hori_pix = Vl_hori_pix/norm(Vl_hori_pix);
42 Vl_vert_pix = Vl_vert_pix/norm(Vl_vert_pix);
43 Vl_diag1_pix = Vl_diag1_pix/norm(Vl_diag1_pix);
44 Vl_diag2_pix = Vl_diag2_pix/norm(Vl_diag2_pix);
45
46 al1 = Vl_hori_pix(1);
47 bl1 = Vl_hori_pix(2);
48 cl1 = Vl_hori_pix(3);
49
50 al2 = Vl_vert_pix(1);
51 bl2 = Vl_vert_pix(2);
52 cl2 = Vl_vert_pix(3);
53
54 al3 = Vl_diag1_pix(1);
55 bl3 = Vl_diag1_pix(2);
56 cl3 = Vl_diag1_pix(3);
57
58 al4 = Vl_diag2_pix(1);
59 bl4 = Vl_diag2_pix(2);
60 cl4 = Vl_diag2_pix(3);
61
62 % right Pattern:
63
64 eval(['Hrkk = Hr_' num2str(kk) ';']);
65
66 Hrkk = Sub_cc * Hrkk;
67
68 % Extract vanishing points (direct and diagonals):
69
70 Vr_hori_pix = Hrkk(:,1);
71 Vr_vert_pix = Hrkk(:,2);
72 Vr_diag1_pix = (Hrkk(:,1)+Hrkk(:,2))/2;
73 Vr_diag2_pix = (Hrkk(:,1)-Hrkk(:,2))/2;
74
75 Vr_hori_pix = Vr_hori_pix/norm(Vl_hori_pix);
76 Vr_vert_pix = Vr_vert_pix/norm(Vl_vert_pix);
77 Vr_diag1_pix = Vr_diag1_pix/norm(Vr_diag1_pix);
78 Vr_diag2_pix = Vr_diag2_pix/norm(Vr_diag2_pix);
79
80 ar1 = Vr_hori_pix(1);
81 br1 = Vr_hori_pix(2);
82 cr1 = Vr_hori_pix(3);
83
84 ar2 = Vr_vert_pix(1);
85 br2 = Vr_vert_pix(2);
86 cr2 = Vr_vert_pix(3);
87
88 ar3 = Vr_diag1_pix(1);
89 br3 = Vr_diag1_pix(2);
90 cr3 = Vr_diag1_pix(3);
91
92 ar4 = Vr_diag2_pix(1);
93 br4 = Vr_diag2_pix(2);
94 cr4 = Vr_diag2_pix(3);
95
96
97 % Collect all the constraints:
98
99 A_kk = [al1*al2 bl1*bl2;
100 al3*al4 bl3*bl4;
101 ar1*ar2 br1*br2;
102 ar3*ar4 br3*br4;
103 al1*ar1 bl1*br1];
104
105 b_kk = -[cl1*cl2;cl3*cl4;cr1*cr2;cr3*cr4;cl1*cr1];
106
107
108 A = [A;A_kk];
109 b = [b;b_kk];
110
111end;
112
113% use all the vanishing points to estimate focal length:
114
115f_init = sqrt(abs(1./(inv(A'*A)*A'*b))); % if using a two-focal model for initial guess
116
117%f_init = sqrt(b'*(sum(A')') / (b'*b)) * ones(2,1); % if single focal length model is used
118
119
120% Global calibration matrix (initial guess):
121
122KK = [f_init(1) 0 c_init(1);0 f_init(2) c_init(2); 0 0 1];
123inv_KK = inv(KK);
124
125
126% Computing of the extrinsic parameters (from the collineations)
127
128for kk = 1:n_ima,
129
130 eval(['Hlkk = Hl_' num2str(kk) ';']);
131
132 Hl2 = inv_KK*Hlkk;
133
134 sc = mean([norm(Hl2(:,1));norm(Hl2(:,2))]);
135
136 Hl2 = Hl2/sc;
137
138 eval(['Hrkk = Hr_' num2str(kk) ';']);
139
140 Hr2 = inv_KK*Hrkk;
141
142 sc = mean([norm(Hr2(:,1));norm(Hr2(:,2))]);
143
144 Hr2 = Hr2/sc;
145
146 omcl = rodrigues([Hl2(:,1:2) cross(Hl2(:,1),Hl2(:,2))]);
147 Tcl = Hl2(:,3);
148
149 %omcr = rodrigues([Hr2(:,1:2) cross(Hr2(:,1),Hr2(:,2))]);
150 %Tcr = Hr2(:,3);
151
152
153 omckk = omcl; %rodrigues([H2(:,1:2) cross(H2(:,1),H2(:,2))]);
154 Tckk = Tcl; %H2(:,3);
155
156 eval(['omc_' num2str(kk) ' = omckk;']);
157 eval(['Tc_' num2str(kk) ' = Tckk;']);
158
159end;
160
161
162
163% Initialisation of the parameters for global minimization:
164
165init_param = [f_init;k_init];
166
167for kk = 1:n_ima,
168 eval(['init_param = [init_param; omc_' num2str(kk) '; Tc_' num2str(kk) '];']);
169end;
170
171if ~exist('lsqnonlin'),
172
173 options = [1 1e-4 1e-4 1e-6 0 0 0 0 0 0 0 0 0 6000 0 1e-8 0.1 0];
174
175 if exist('leastsq'),
176 sss = ['[param,opt] = leastsq(''multi_error_oulu'',init_param,options,[],n_ima,c_init);'];
177 else
178 sss = ['[param,opt] = leastsq2(''multi_error_oulu'',init_param,options,[],n_ima,c_init);'];
179 end;
180
181else
182
183 options = optimset('lsqnonlin');
184 options.MaxIter = 6000;
185 options.Display = 'iter';
186 sss = ['[param,opt] = lsqnonlin(''multi_error_oulu'',init_param,[],[],options,n_ima,c_init);'];
187
188end;
189
190
191fprintf(1,'\nOptimization not including the principal point...\n')
192eval(sss);
193
194history = [[init_param;c_init] [param;c_init]];
195
196sol_no_center = [param;c_init];
197
198init_param = sol_no_center;
199
200fprintf(1,'\nOptimization including the principal point...\n')
201
202eval(sss);
203
204history = [history param];
205
206
207sol_with_center = param;
208
209
210
211
212%%% Extraction of the final intrinsic and extrinsic paramaters (in the no-center case):
213
214solution = sol_no_center;
215extract_parameters3D;
216
217fprintf(1,'\n\nCalibration results without principal point estimation:\n\n');
218fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
219fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
220fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
221fprintf(1,['Pixel error: [click on ''sol. without center'']\n']);
222
223
224
225
226% Pick the solution with principal point
227%%% NOTE: At that point, the user can choose which solution to pick: with or without
228%%% principal point estimation. By default, we pick the solution with principal point.
229
230solution = sol_with_center;
231
232
233
234%%% Extraction of the final intrinsic and extrinsic paramaters:
235
236extract_parameters3D;
237
238
239fprintf(1,'\n\nCalibration results with principal point estimation:\n\n');
240fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
241fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
242fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
243
244
245%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
246
247graphout_calib3D;
248
249
250
251fprintf(1,'Note: If the solution is not satisfactory, select solution without center estimation.\n\n');
252
253
254%%%%%%%%%%%%%% Save all the Calibration results:
255
256disp('Save calibration results under Calib_Results.mat');
257
258string_save = 'save Calib_Results fc kc cc ex x y solution sol_with_center sol_no_center history wintx winty n_ima type_numbering N_slots small_calib_image first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default KK inv_KK dX dY';
259
260for kk = 1:n_ima,
261 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Tc_' num2str(kk) ' Hl_' num2str(kk) ' nl_sq_x_' num2str(kk) ' nl_sq_y_' num2str(kk) ' Hr_' num2str(kk) ' nr_sq_x_' num2str(kk) ' nr_sq_y_' num2str(kk)];
262end;
263
264eval(string_save);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_cont.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_cont.m
new file mode 100755
index 0000000..9ff3f0b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_cont.m
@@ -0,0 +1,142 @@
1% Simplified version of go_calib.m
2
3if ~exist('x_1'),
4 click_calib;
5end;
6
7
8% Initialisation of the parameters for global minimization:
9
10init_param = [fc;kc];
11
12for kk = 1:n_ima,
13
14 if ~exist(['omc_' num2str(kk)]),
15 eval(['Hkk = H_' num2str(kk) ';']);
16 H2 = inv_KK*Hkk;
17 sc = mean([norm(H2(:,1));norm(H2(:,2))]);
18 H2 = H2/sc;
19 omckk = rodrigues([H2(:,1:2) cross(H2(:,1),H2(:,2))]);
20 Tckk = H2(:,3);
21 eval(['omc_' num2str(kk) ' = omckk;']);
22 eval(['Tc_' num2str(kk) ' = Tckk;']);
23 end;
24
25 eval(['init_param = [init_param; omc_' num2str(kk) '; Tc_' num2str(kk) '];']);
26end;
27
28init_param = [init_param;cc];
29
30
31
32%-------------------- Main Optimization:
33
34fprintf(1,'\nRe-Optimization...\n')
35
36
37param = init_param;
38change = 1;
39
40iter = 0;
41
42fprintf(1,'Iteration ');
43
44while (change > 1e-6)&(iter < 10),
45
46 fprintf(1,'%d...',iter+1);
47
48 JJ = [];
49 ex = [];
50
51 c = param(6*n_ima + 4 + 3:6*n_ima + 5 + 3);
52 f = param(1:2);
53 k = param(3:6);
54
55 for kk = 1:n_ima,
56
57 omckk = param(4+6*(kk-1) + 3:6*kk + 3);
58
59 Tckk = param(6*kk+1 + 3:6*kk+3 + 3);
60
61 eval(['X_kk = X_' num2str(kk) ';']);
62 eval(['x_kk = x_' num2str(kk) ';']);
63
64 Np = size(X_kk,2);
65
66 JJkk = zeros(2*Np,n_ima * 6 + 8);
67
68 [x,dxdom,dxdT,dxdf,dxdc,dxdk] = project_points(X_kk,omckk,Tckk,f,c,k);
69
70 exkk = x_kk - x;
71
72 ex = [ex;exkk(:)];
73
74 JJkk(:,1:2) = dxdf;
75 JJkk(:,3:6) = dxdk;
76 JJkk(:,4+6*(kk-1) + 3:6*kk + 3) = dxdom;
77 JJkk(:,6*kk+1 + 3:6*kk+3 + 3) = dxdT;
78 JJkk(:,6*n_ima + 4 + 3:6*n_ima + 5 + 3) = dxdc;
79
80 JJ = [JJ;JJkk];
81
82 end;
83
84 param_innov = inv(JJ'*JJ)*(JJ')*ex;
85 param_up = param + param_innov;
86 change = norm(param_innov)/norm(param_up);
87 param = param_up;
88 iter = iter + 1;
89
90end;
91
92fprintf(1,'\n');
93
94
95sol_with_center = param;
96
97solution = sol_with_center;
98
99
100%%% Extraction of the final intrinsic and extrinsic paramaters:
101
102extract_parameters;
103comp_error_calib;
104
105fprintf(1,'\n\nCalibration results with principal point estimation:\n\n');
106fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
107fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
108fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
109fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
110
111
112%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
113
114graphout_calib;
115
116
117
118fprintf(1,'Note: If the solution is not satisfactory, select solution without center estimation.\n\n');
119
120
121%%%%%%%%%%%%%% Save all the Calibration results:
122
123disp('Save calibration results under Calib_Results.mat');
124
125string_save = 'save Calib_Results fc kc cc ex x y solution sol_with_center solution_init history wintx winty n_ima type_numbering N_slots small_calib_image first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default KK inv_KK dX dY';
126
127for kk = 1:n_ima,
128 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' H_' num2str(kk) ' Hini_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
129end;
130
131eval(string_save);
132
133return;
134
135if exist('calib_data.mat'),
136 ccc = computer;
137 if ccc(1)=='P',
138 eval('!del calib_data.mat');
139 else
140 eval('!rm calib_data.mat');
141 end;
142end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_iter.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_iter.m
new file mode 100755
index 0000000..a076214
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/go_calib_optim_iter.m
@@ -0,0 +1,332 @@
1%go_calib_optim_iter
2%
3%Main calibration function. Computes the intrinsic andextrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% KK: The camera matrix (containing fc and cc)
13% omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
14% Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
15% Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
16%
17%Method: Minimizes the pixel reprojection error in the least squares sense over the intrinsic
18% camera parameters, and the extrinsic parameters (3D locations of the grids in space)
19%
20%Note: If the intrinsic camera parameters (fc, cc, kc) do not exist before, they are initialized through
21% the function init_intrinsic_param.m. Otherwise, the variables in memory are used as initial guesses.
22%
23%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
24% corresponding entry in the active_images vector to zero.
25%
26%VERY IMPORTANT: This function works for 2D and 3D calibration rigs, except for init_intrinsic_param.m
27%that is so far implemented to work only with 2D rigs.
28%In the future, a more general function will be there.
29%For now, if using a 3D calibration rig, quick_init is set to 1 for an easy initialization of the focal length
30
31
32check_active_images;
33
34
35
36quick_init = 0; % Set to 1 for using a quick init (necessary when using 3D rigs)
37
38
39
40% Check 3D-ness of the calibration rig:
41rig3D = 0;
42for kk = ind_active,
43 eval(['X_kk = X_' num2str(kk) ';']);
44 if is3D(X_kk),
45 rig3D = 1;
46 end;
47end;
48
49
50
51% If the rig is 3D, then no choice: the only valid initialization is manual!
52if rig3D,
53 quick_init = 1;
54end;
55
56
57
58
59alpha = 0.4; % set alpha = 1; for steepest gradient descent
60
61
62% Conditioning threshold for view rejection
63thresh_cond = 1e6;
64
65
66
67
68%% Initialization of the intrinsic parameters (if necessary)
69
70if ~exist('cc'),
71 fprintf(1,'Initialization of the principal point at the center of the image.\n');
72 cc = [(nx-1)/2;(ny-1)/2];
73end;
74
75
76if ~exist('kc'),
77 fprintf(1,'Initialization of the image distortion to zero.\n');
78 kc = zeros(4,1);
79end;
80
81
82if ~exist('fc')& quick_init,
83 FOV_angle = 35; % Initial camera field of view in degrees
84 fprintf(1,['Initialization of the focal length to a FOV of ' num2str(FOV_angle) ' degrees.\n']);
85 fc = (nx/2)/tan(pi*FOV_angle/360) * ones(2,1);
86end;
87
88
89if ~exist('fc'),
90 % Initialization of the intrinsic parameters:
91 fprintf(1,'Initialization of the intrinsic parameters using the vanishing points of planar patterns.\n')
92 init_intrinsic_param; % The right way to go (if quick_init is not active)!
93end;
94
95
96
97%% Initialization of the extrinsic parameters for global minimization:
98
99init_param = [fc;kc];
100
101for kk = 1:n_ima,
102
103 if exist(['x_' num2str(kk)]),
104
105 eval(['x_kk = x_' num2str(kk) ';']);
106 eval(['X_kk = X_' num2str(kk) ';']);
107
108 if (isnan(x_kk(1,1))),
109 if active_images(kk),
110 fprintf(1,'Warning: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
111 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
112 end;
113 active_images(kk) = 0;
114 end;
115 if active_images(kk),
116 [omckk,Tckk] = compute_extrinsic_init(x_kk,X_kk,fc,cc,kc);
117 [omckk,Tckk,Rckk,JJ_kk] = compute_extrinsic_refine(omckk,Tckk,x_kk,X_kk,fc,cc,kc,20,thresh_cond);
118 if cond(JJ_kk)> thresh_cond,
119 active_images(kk) = 0;
120 omckk = NaN*ones(3,1);
121 Tckk = NaN*ones(3,1);
122 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
123 desactivated_images = [desactivated_images kk];
124 end;
125 if isnan(omckk(1,1)),
126 %fprintf(1,'\nWarning: Desactivating image %d. Re-activate it later by typing:\nactive_images(%d)=1;\nand re-run optimization\n',[kk kk])
127 active_images(kk) = 0;
128 end;
129 else
130 omckk = NaN*ones(3,1);
131 Tckk = NaN*ones(3,1);
132 end;
133
134 else
135
136 omckk = NaN*ones(3,1);
137 Tckk = NaN*ones(3,1);
138
139 if active_images(kk),
140 fprintf(1,'Warning: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
141 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
142 end;
143
144 active_images(kk) = 0;
145
146 end;
147
148 eval(['omc_' num2str(kk) ' = omckk;']);
149 eval(['Tc_' num2str(kk) ' = Tckk;']);
150
151 eval(['init_param = [init_param; omc_' num2str(kk) '; Tc_' num2str(kk) '];']);
152
153end;
154
155
156check_active_images;
157
158init_param = [init_param;cc];
159
160%-------------------- Main Optimization:
161
162fprintf(1,'\nMain calibration optimization procedure - Number of images: %d\n',length(ind_active));
163
164
165% The following vector helps to select the variables to update:
166ind_Jac = find([ones(6,1);reshape(ones(6,1)*active_images,6*n_ima,1);ones(2,1)])';
167
168param = init_param;
169change = 1;
170
171iter = 0;
172
173fprintf(1,'Gradient descent iterations: ');
174
175param_list = param;
176
177MaxIter = 30;
178
179
180while (change > 1e-6)&(iter < MaxIter),
181
182 fprintf(1,'%d...',iter+1);
183
184
185 %% The first step consists of updating the whole vector of knowns (intrinsic + extrinsic of active
186 %% images) through a one step steepest gradient descent.
187
188 JJ = [];
189 ex = [];
190
191 c = param(6*n_ima + 4 + 3:6*n_ima + 5 + 3);
192 f = param(1:2);
193 k = param(3:6);
194
195 for kk = 1:n_ima,
196
197 if active_images(kk),
198
199 omckk = param(4+6*(kk-1) + 3:6*kk + 3);
200
201 Tckk = param(6*kk+1 + 3:6*kk+3 + 3);
202
203 if isnan(omckk(1)),
204 fprintf(1,'Intrinsic parameters at frame %d do not exist\n',kk);
205 return;
206 end;
207
208 eval(['X_kk = X_' num2str(kk) ';']);
209 eval(['x_kk = x_' num2str(kk) ';']);
210
211 Np = size(X_kk,2);
212
213 JJkk = zeros(2*Np,n_ima * 6 + 8);
214
215 [x,dxdom,dxdT,dxdf,dxdc,dxdk] = project_points(X_kk,omckk,Tckk,f,c,k);
216
217 exkk = x_kk - x;
218
219 ex = [ex;exkk(:)];
220
221 JJkk(:,1:2) = dxdf;
222 JJkk(:,3:6) = dxdk;
223 JJkk(:,4+6*(kk-1) + 3:6*kk + 3) = dxdom;
224 JJkk(:,6*kk+1 + 3:6*kk+3 + 3) = dxdT;
225 JJkk(:,6*n_ima + 4 + 3:6*n_ima + 5 + 3) = dxdc;
226
227 JJ = [JJ;JJkk];
228
229
230 % Check if this view is ill-conditioned:
231 JJ_kk = [dxdom dxdT];
232 if cond(JJ_kk)> thresh_cond,
233 active_images(kk) = 0;
234 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
235 desactivated_images = [desactivated_images kk];
236 param(4+6*(kk-1) + 3:6*kk+3 + 3) = NaN*ones(6,1);
237 end;
238
239
240 end;
241
242 end;
243
244
245 % List of active images (necessary if changed):
246 check_active_images;
247 ind_Jac = find([ones(6,1);reshape(ones(6,1)*active_images,6*n_ima,1);ones(2,1)])';
248
249
250 JJ = JJ(:,ind_Jac);
251
252 JJ2 = JJ'*JJ;
253
254
255 % Smoothing coefficient:
256
257 alpha2 = 1-(1-alpha)^(iter+1); %set to 1 to undo any smoothing!
258
259
260 param_innov = alpha2*inv(JJ2)*(JJ')*ex;
261 param_up = param(ind_Jac) + param_innov;
262 param(ind_Jac) = param_up;
263
264
265 % New intrinsic parameters:
266
267 fc_current = param(1:2);
268 cc_current = param(6*n_ima + 4 + 3:6*n_ima + 5 + 3);
269 kc_current = param(3:6);
270
271
272 % Change on the intrinsic parameters:
273 change = norm([fc_current;cc_current] - [f;c])/norm([fc_current;cc_current]);
274
275
276 %% Second step: (optional) - It makes convergence faster, and the region of convergence LARGER!!!
277 %% Recompute the extrinsic parameters only using compute_extrinsic.m (this may be useful sometimes)
278 %% The complete gradient descent method is useful to precisely update the intrinsic parameters.
279
280 MaxIter2 = 20;
281
282 for kk = 1:n_ima,
283 if active_images(kk),
284 omc_current = param(4+6*(kk-1) + 3:6*kk + 3);
285 Tc_current = param(6*kk+1 + 3:6*kk+3 + 3);
286 eval(['X_kk = X_' num2str(kk) ';']);
287 eval(['x_kk = x_' num2str(kk) ';']);
288 [omc_current,Tc_current] = compute_extrinsic_init(x_kk,X_kk,fc_current,cc_current,kc_current);
289 [omckk,Tckk,Rckk,JJ_kk] = compute_extrinsic_refine(omc_current,Tc_current,x_kk,X_kk,fc_current,cc_current,kc_current,MaxIter2,thresh_cond);
290 if cond(JJ_kk)> thresh_cond,
291 active_images(kk) = 0;
292 fprintf(1,'\nWarning: View #%d ill-conditioned. This image is now set inactive.\n',kk)
293 desactivated_images = [desactivated_images kk];
294 omckk = NaN*ones(3,1);
295 Tckk = NaN*ones(3,1);
296 end;
297 param(4+6*(kk-1) + 3:6*kk + 3) = omckk;
298 param(6*kk+1 + 3:6*kk+3 + 3) = Tckk;
299 end;
300 end;
301
302 %fprintf(1,'\n\nCalibration results after optimization:\n\n');
303 %fprintf(1,'focal = [%3.5f %3.5f]\n',fc_current);
304 %fprintf(1,'center = [%3.5f %3.5f]\n',cc_current);
305 %fprintf(1,'distortion = [%3.5f %3.5f %3.5f %3.5f]\n\n',kc_current);
306
307
308 param_list = [param_list param];
309
310 iter = iter + 1;
311
312end;
313
314fprintf(1,'\n');
315
316
317sol_with_center = param;
318
319solution = param;
320
321
322%%% Extraction of the final intrinsic and extrinsic paramaters:
323
324extract_parameters;
325comp_error_calib;
326
327fprintf(1,'\n\nCalibration results after optimization:\n\n');
328fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
329fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
330fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
331fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
332
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib.m
new file mode 100755
index 0000000..a3f7040
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib.m
@@ -0,0 +1,12 @@
1
2
3%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
4
5%%%%%%%%%%%%%%%%%%%% SHOW EXTRINSIC RESULTS %%%%%%%%%%%%%%%%%%%%%%%%
6
7ext_calib;
8
9%%%%%%%%%%%%%%%%%%%% REPROJECT ON THE IMAGES %%%%%%%%%%%%%%%%%%%%%%%%
10
11reproject_calib;
12
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib3D.m
new file mode 100755
index 0000000..b7edf43
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/graphout_calib3D.m
@@ -0,0 +1,153 @@
1
2
3%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
4
5
6% Color code for each image:
7
8colors = 'brgkcm';
9
10
11%%% Show the extrinsic parameters
12
13IP = 8*dX*([0 nx-1 nx-1 0 0 ; 0 0 ny-1 ny-1 0;1 1 1 1 1] - [cc;0]*ones(1,5)) ./ ([fc;1]*ones(1,5));
14
15
16figure(4);
17[a,b] = view;
18
19figure(4);
20plot3(5*[0 dX 0 0 0 0 ],5*[0 0 0 0 0 dX],-5*[0 0 0 dX 0 0 ],'b-','linewidth',2');
21hold on;
22plot3(IP(1,:),IP(3,:),-IP(2,:),'r-','linewidth',2);
23text(6*dX,0,0,'X_c');
24text(-dX,5*dX,0,'Z_c');
25text(0,0,-6*dX,'Y_c');
26text(-dX,-dX,dX,'O_c');
27
28
29for kk = 1:n_ima,
30
31 eval(['XX_kk = X_' num2str(kk) ';']);
32 eval(['omc_kk = omc_' num2str(kk) ';']);
33 eval(['Tc_kk = Tc_' num2str(kk) ';']);
34
35 eval(['nl_sq_x = nl_sq_x_' num2str(kk) ';']);
36 eval(['nl_sq_y = nl_sq_y_' num2str(kk) ';']);
37
38 eval(['nr_sq_x = nr_sq_x_' num2str(kk) ';']);
39 eval(['nr_sq_y = nr_sq_y_' num2str(kk) ';']);
40
41 R_kk = rodrigues(omc_kk);
42
43 YY_kk = R_kk * XX_kk + Tc_kk * ones(1,length(XX_kk));
44
45 YYl_kk = YY_kk(:,1:(nl_sq_x+1)*(nl_sq_y+1));
46 YYr_kk = YY_kk(:,(nl_sq_x+1)*(nl_sq_y+1)+1:end);
47
48
49 eval(['YYl_' num2str(kk) ' = YYl_kk;']);
50 eval(['YYr_' num2str(kk) ' = YYr_kk;']);
51
52 uu = [-dX;-dY;0]/2;
53 uu = R_kk * uu + Tc_kk;
54
55 YYlx = zeros(nl_sq_x+1,nl_sq_y+1);
56 YYly = zeros(nl_sq_x+1,nl_sq_y+1);
57 YYlz = zeros(nl_sq_x+1,nl_sq_y+1);
58
59 YYrx = zeros(nr_sq_x+1,nr_sq_y+1);
60 YYry = zeros(nr_sq_x+1,nr_sq_y+1);
61 YYrz = zeros(nr_sq_x+1,nr_sq_y+1);
62
63 YYlx(:) = YYl_kk(1,:);
64 YYly(:) = YYl_kk(2,:);
65 YYlz(:) = YYl_kk(3,:);
66
67 YYrx(:) = YYr_kk(1,:);
68 YYry(:) = YYr_kk(2,:);
69 YYrz(:) = YYr_kk(3,:);
70
71
72 %keyboard;
73
74 figure(4);
75 hhh= mesh(YYlx,YYlz,-YYly);
76 set(hhh,'edgecolor',colors(rem(kk-1,6)+1),'linewidth',1); %,'facecolor','none');
77 %plot3(YY_kk(1,:),YY_kk(3,:),-YY_kk(2,:),['o' colors(rem(kk-1,6)+1)]);
78 hhh= mesh(YYrx,YYrz,-YYry);
79 set(hhh,'edgecolor',colors(rem(kk-1,6)+1),'linewidth',1);
80 text(uu(1),uu(3),-uu(2),num2str(kk),'fontsize',14,'color',colors(rem(kk-1,6)+1));
81
82end;
83
84figure(4);rotate3d on;
85axis('equal');
86title('Extrinsic parameters');
87%view(60,30);
88view(a,b);
89hold off;
90
91
92
93% Reproject the patterns on the images, and compute the pixel errors:
94
95% Reload the images if necessary
96
97if ~exist('I_1'),
98 ima_read_calib;
99 if no_image_file,
100 return;
101 end;
102end;
103
104
105ex = []; % Global error vector
106x = []; % Detected corners on the image plane
107y = []; % Reprojected points
108
109for kk = 1:n_ima,
110
111 eval(['omckk = omc_' num2str(kk) ';']);
112 eval(['Tckk = Tc_' num2str(kk) ';']);
113
114 Rkk = rodrigues(omckk);
115
116 eval(['y_' num2str(kk) ' = project2_oulu(X_' num2str(kk) ',Rkk,Tckk,fc,cc,kc);']);
117
118 eval(['ex_' num2str(kk) ' = x_' num2str(kk) ' -y_' num2str(kk) ';']);
119
120 eval(['x_kk = x_' num2str(kk) ';']);
121
122 figure(4+kk);
123 eval(['I = I_' num2str(kk) ';']);
124 image(I); hold on;
125 colormap(gray(256));
126 title(['Image ' num2str(kk) ' - Image points (+) and reprojected grid points (o)']);
127 eval(['plot(x_' num2str(kk) '(1,:)+1,x_' num2str(kk) '(2,:)+1,''r+'');']);
128 eval(['plot(y_' num2str(kk) '(1,:)+1,y_' num2str(kk) '(2,:)+1,''' colors(rem(kk-1,6)+1) 'o'');']);
129 zoom on;
130 hold off;
131
132
133 eval(['ex = [ex ex_' num2str(kk) '];']);
134 eval(['x = [x x_' num2str(kk) '];']);
135 eval(['y = [y y_' num2str(kk) '];']);
136
137end;
138
139
140figure(5+n_ima);
141for kk = 1:n_ima,
142 eval(['plot(ex_' num2str(kk) '(1,:),ex_' num2str(kk) '(2,:),''' colors(rem(kk-1,6)+1) '+'');']);
143 hold on;
144end;
145hold off;
146axis('equal');
147title('Reprojection error (in pixel)');
148xlabel('x');
149ylabel('y');
150
151err_std = std(ex')';
152
153fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ima_read_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ima_read_calib.m
new file mode 100755
index 0000000..09cef59
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/ima_read_calib.m
@@ -0,0 +1,107 @@
1
2if ~exist('calib_name'),
3 data_calib;
4end;
5
6check_active_images;
7
8images_read = active_images;
9
10image_numbers = first_num:n_ima-1+first_num;
11
12no_image_file = 0;
13
14i = 1;
15
16while (i <= n_ima), % & (~no_image_file),
17
18 if active_images(i),
19
20 %fprintf(1,'Loading image %d...\n',i);
21
22 if ~type_numbering,
23 number_ext = num2str(image_numbers(i));
24 else
25 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(i));
26 end;
27
28 ima_name = [calib_name number_ext '.' format_image]
29
30 if i == ind_active(1),
31 fprintf(1,'Loading image ');
32 end;
33
34 if exist(ima_name),
35
36 fprintf(1,'%d...',i);
37
38 if format_image(1) == 'p',
39 Ii = double(pgmread(ima_name));
40 else
41 if format_image(1) == 'r',
42 Ii = readras(ima_name);
43 else
44 Ii = double(imread(ima_name));
45 end;
46 end;
47
48 if size(Ii,3)>1,
49 Ii = Ii(:,:,2);
50 end;
51
52 eval(['I_' num2str(i) ' = Ii;']);
53
54 else
55
56 fprintf(1,'%d...',i);
57
58 images_read(i) = 0;
59
60 no_image_file = 1;
61
62 end;
63
64 end;
65
66 i = i+1;
67
68end;
69
70
71if no_image_file,
72
73 fprintf(1,'\nWARNING! Cannot load calibration images\n');
74
75else
76
77 fprintf(1,'\n');
78
79 if size(I_1,1)~=480,
80 small_calib_image = 1;
81 else
82 small_calib_image = 0;
83 end;
84
85 [Hcal,Wcal] = size(I_1); % size of the calibration image
86
87 [ny,nx] = size(I_1);
88
89 clickname = [];
90
91 map = gray(256);
92
93 %string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name Hcal Wcal nx ny map small_calib_image';
94
95 %eval(string_save);
96
97 disp('done');
98 %click_calib;
99
100end;
101
102if ~exist('map'), map = gray(256); end;
103
104
105
106
107
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_calib_param.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_calib_param.m
new file mode 100755
index 0000000..92e14be
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_calib_param.m
@@ -0,0 +1,210 @@
1%init_calib_param
2%
3%Initialization of the intrinsic and extrinsic parameters.
4%Runs as a script.
5%
6%This function is obsolete with init_intrinsic_param called from go_calib_optim
7%
8%INPUT: x_1,x_2,x_3,...: Feature locations on the images
9% X_1,X_2,X_3,...: Corresponding grid coordinates
10%
11%OUTPUT: fc: Camera focal length
12% cc: Principal point coordinates
13% kc: Distortion coefficients
14% KK: The camera matrix (containing fc and cc)
15% omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
16% Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
17% Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
18%
19%Method: Compute the planar homographies H_1, H_2, H_3, ... and computes
20% the focal length fc from orthogonal vanishing points constraint.
21% The principal point cc is assumed at the center of the image.
22% Assumes no image distortion (kc = [0;0;0;0])
23% Once the intrinsic parameters are estimated, the extrinsic parameters
24% are computed for each image.
25%
26%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
27% corresponding entry in the active_images vector to zero.
28%
29%
30%Important functions called within that program:
31%
32%compute_homography.m: Computes the planar homography between points on the grid in 3D, and the image plane.
33%
34%compute_extrinsic.m: Computes the location of a grid assuming known intrinsic parameters.
35% This function is called at the initialization step.
36
37
38
39
40check_active_images;
41
42if ~exist(['x_' num2str(ind_active(1)) ]),
43 click_calib;
44end;
45
46
47fprintf(1,'\nInitialization of the calibration parameters - Number of images: %d\n',length(ind_active));
48
49
50% Initialize the homographies:
51
52for kk = 1:n_ima,
53 eval(['x_kk = x_' num2str(kk) ';']);
54 eval(['X_kk = X_' num2str(kk) ';']);
55 if (isnan(x_kk(1,1))),
56 if active_images(kk),
57 fprintf(1,'WARNING: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
58 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
59 end;
60 active_images(kk) = 0;
61 end;
62 if active_images(kk),
63 eval(['H_' num2str(kk) ' = compute_homography(x_kk,X_kk(1:2,:));']);
64 else
65 eval(['H_' num2str(kk) ' = NaN*ones(3,3);']);
66 end;
67end;
68
69check_active_images;
70
71% initial guess for principal point and distortion:
72
73if ~exist('nx'), [ny,nx] = size(I); end;
74
75c_init = [nx;ny]/2 - 0.5; % initialize at the center of the image
76k_init = [0;0;0;0]; % initialize to zero (no distortion)
77
78
79
80% Compute explicitely the focal length using all the (mutually orthogonal) vanishing points
81% note: The vanihing points are hidden in the planar collineations H_kk
82
83A = [];
84b = [];
85
86% matrix that subtract the principal point:
87Sub_cc = [1 0 -c_init(1);0 1 -c_init(2);0 0 1];
88
89for kk=1:n_ima,
90
91 if active_images(kk),
92
93 eval(['Hkk = H_' num2str(kk) ';']);
94
95 Hkk = Sub_cc * Hkk;
96
97 % Extract vanishing points (direct and diagonals):
98
99 V_hori_pix = Hkk(:,1);
100 V_vert_pix = Hkk(:,2);
101 V_diag1_pix = (Hkk(:,1)+Hkk(:,2))/2;
102 V_diag2_pix = (Hkk(:,1)-Hkk(:,2))/2;
103
104 V_hori_pix = V_hori_pix/norm(V_hori_pix);
105 V_vert_pix = V_vert_pix/norm(V_vert_pix);
106 V_diag1_pix = V_diag1_pix/norm(V_diag1_pix);
107 V_diag2_pix = V_diag2_pix/norm(V_diag2_pix);
108
109 a1 = V_hori_pix(1);
110 b1 = V_hori_pix(2);
111 c1 = V_hori_pix(3);
112
113 a2 = V_vert_pix(1);
114 b2 = V_vert_pix(2);
115 c2 = V_vert_pix(3);
116
117 a3 = V_diag1_pix(1);
118 b3 = V_diag1_pix(2);
119 c3 = V_diag1_pix(3);
120
121 a4 = V_diag2_pix(1);
122 b4 = V_diag2_pix(2);
123 c4 = V_diag2_pix(3);
124
125 A_kk = [a1*a2 b1*b2;
126 a3*a4 b3*b4];
127
128 b_kk = -[c1*c2;c3*c4];
129
130
131 A = [A;A_kk];
132 b = [b;b_kk];
133
134 end;
135
136end;
137
138
139% use all the vanishing points to estimate focal length:
140
141f_init = sqrt(abs(1./(inv(A'*A)*A'*b))); % if using a two-focal model for initial guess
142
143%f_init = sqrt(b'*(sum(A')') / (b'*b)) * ones(2,1); % if single focal length model is used
144
145
146% Global calibration matrix (initial guess):
147
148KK = [f_init(1) 0 c_init(1);0 f_init(2) c_init(2); 0 0 1];
149inv_KK = inv(KK);
150
151
152cc = c_init;
153fc = f_init;
154kc = k_init;
155
156
157% Computing of the extrinsic parameters (from the collineations)
158
159for kk = 1:n_ima,
160
161 if active_images(kk),
162
163
164 eval(['x_kk = x_' num2str(kk) ';']);
165 eval(['X_kk = X_' num2str(kk) ';']);
166
167 [omckk,Tckk] = compute_extrinsic(x_kk,X_kk,fc,cc,kc);
168
169 Rckk = rodrigues(omc_kk);
170
171 else
172
173 omckk = NaN*ones(3,1);
174 Tckk = NaN*ones(3,1);
175 Rckk = NaN*ones(3,3);
176
177 end;
178
179 eval(['omc_' num2str(kk) ' = omckk;']);
180 eval(['Rc_' num2str(kk) ' = Rckk;']);
181 eval(['Tc_' num2str(kk) ' = Tckk;']);
182
183end;
184
185
186% Initialization of the parameters for global minimization:
187
188init_param = [f_init;k_init];
189
190for kk = 1:n_ima,
191 eval(['init_param = [init_param; omc_' num2str(kk) '; Tc_' num2str(kk) '];']);
192end;
193
194solution_init = [init_param;c_init];
195
196solution = solution_init;
197
198comp_error_calib;
199
200fprintf(1,'\n\nCalibration parameters after initialization:\n\n');
201fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
202fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
203fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
204fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
205
206
207%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
208
209%graphout_calib;
210
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_intrinsic_param.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_intrinsic_param.m
new file mode 100755
index 0000000..eac21ba
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/init_intrinsic_param.m
@@ -0,0 +1,153 @@
1%init_intrinsic_param
2%
3%Initialization of the intrinsic parameters.
4%Runs as a script.
5%
6%INPUT: x_1,x_2,x_3,...: Feature locations on the images
7% X_1,X_2,X_3,...: Corresponding grid coordinates
8%
9%OUTPUT: fc: Camera focal length
10% cc: Principal point coordinates
11% kc: Distortion coefficients
12% KK: The camera matrix (containing fc and cc)
13%
14%Method: Computes the planar homographies H_1, H_2, H_3, ... and computes
15% the focal length fc from orthogonal vanishing points constraint.
16% The principal point cc is assumed at the center of the image.
17% Assumes no image distortion (kc = [0;0;0;0])
18%
19%Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
20% corresponding entry in the active_images vector to zero.
21%
22%
23%Important function called within that program:
24%
25%compute_homography.m: Computes the planar homography between points on the grid in 3D, and the image plane.
26%
27%
28%VERY IMPORTANT: This function works onyl with 2D rigs.
29%In the future, a more general function will be there (working with 3D rigs as well).
30
31
32
33check_active_images;
34
35if ~exist(['x_' num2str(ind_active(1)) ]),
36 click_calib;
37end;
38
39
40fprintf(1,'\nInitialization of the intrinsic parameters - Number of images: %d\n',length(ind_active));
41
42
43% Initialize the homographies:
44
45for kk = 1:n_ima,
46 eval(['x_kk = x_' num2str(kk) ';']);
47 eval(['X_kk = X_' num2str(kk) ';']);
48 if (isnan(x_kk(1,1))),
49 if active_images(kk),
50 fprintf(1,'WARNING: Cannot calibrate with image %d. Need to extract grid corners first.\n',kk)
51 fprintf(1,' Set active_images(%d)=1; and run Extract grid corners.\n',kk)
52 end;
53 active_images(kk) = 0;
54 end;
55 if active_images(kk),
56 eval(['H_' num2str(kk) ' = compute_homography(x_kk,X_kk(1:2,:));']);
57 else
58 eval(['H_' num2str(kk) ' = NaN*ones(3,3);']);
59 end;
60end;
61
62check_active_images;
63
64% initial guess for principal point and distortion:
65
66if ~exist('nx'), [ny,nx] = size(I); end;
67
68c_init = [nx;ny]/2 - 0.5; % initialize at the center of the image
69k_init = [0;0;0;0]; % initialize to zero (no distortion)
70
71
72
73% Compute explicitely the focal length using all the (mutually orthogonal) vanishing points
74% note: The vanihing points are hidden in the planar collineations H_kk
75
76A = [];
77b = [];
78
79% matrix that subtract the principal point:
80Sub_cc = [1 0 -c_init(1);0 1 -c_init(2);0 0 1];
81
82for kk=1:n_ima,
83
84 if active_images(kk),
85
86 eval(['Hkk = H_' num2str(kk) ';']);
87
88 Hkk = Sub_cc * Hkk;
89
90 % Extract vanishing points (direct and diagonals):
91
92 V_hori_pix = Hkk(:,1);
93 V_vert_pix = Hkk(:,2);
94 V_diag1_pix = (Hkk(:,1)+Hkk(:,2))/2;
95 V_diag2_pix = (Hkk(:,1)-Hkk(:,2))/2;
96
97 V_hori_pix = V_hori_pix/norm(V_hori_pix);
98 V_vert_pix = V_vert_pix/norm(V_vert_pix);
99 V_diag1_pix = V_diag1_pix/norm(V_diag1_pix);
100 V_diag2_pix = V_diag2_pix/norm(V_diag2_pix);
101
102 a1 = V_hori_pix(1);
103 b1 = V_hori_pix(2);
104 c1 = V_hori_pix(3);
105
106 a2 = V_vert_pix(1);
107 b2 = V_vert_pix(2);
108 c2 = V_vert_pix(3);
109
110 a3 = V_diag1_pix(1);
111 b3 = V_diag1_pix(2);
112 c3 = V_diag1_pix(3);
113
114 a4 = V_diag2_pix(1);
115 b4 = V_diag2_pix(2);
116 c4 = V_diag2_pix(3);
117
118 A_kk = [a1*a2 b1*b2;
119 a3*a4 b3*b4];
120
121 b_kk = -[c1*c2;c3*c4];
122
123
124 A = [A;A_kk];
125 b = [b;b_kk];
126
127 end;
128
129end;
130
131
132% use all the vanishing points to estimate focal length:
133
134f_init = sqrt(abs(1./(inv(A'*A)*A'*b))); % if using a two-focal model for initial guess
135
136%f_init = sqrt(b'*(sum(A')') / (b'*b)) * ones(2,1); % if single focal length model is used
137
138
139% Global calibration matrix (initial guess):
140
141KK = [f_init(1) 0 c_init(1);0 f_init(2) c_init(2); 0 0 1];
142inv_KK = inv(KK);
143
144
145cc = c_init;
146fc = f_init;
147kc = k_init;
148
149
150fprintf(1,'\n\nCalibration parameters after initialization:\n\n');
151fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
152fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
153fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n\n',kc);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/is3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/is3D.m
new file mode 100755
index 0000000..ab00b3d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/is3D.m
@@ -0,0 +1,19 @@
1function test = is3D(X),
2
3
4Np = size(X,2);
5
6%% Check for planarity of the structure:
7
8X_mean = mean(X')';
9
10Y = X - (X_mean*ones(1,Np));
11
12YY = Y*Y';
13
14[U,S,V] = svd(YY);
15
16r = S(3,3)/S(2,2);
17
18test = (r > 1e-3);
19
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loading_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loading_calib.m
new file mode 100755
index 0000000..a0f50d2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loading_calib.m
@@ -0,0 +1,10 @@
1if ~exist('Calib_Results.mat'),
2 fprintf(1,'\nCalibration file Calib_Results.mat not found!\n');
3 return;
4end;
5
6fprintf(1,'\nLoading calibration results from Calib_Results.mat\n');
7
8load Calib_Results
9
10fprintf(1,'done\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadinr.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadinr.m
new file mode 100755
index 0000000..91b6f89
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadinr.m
@@ -0,0 +1,52 @@
1%LOADINR Load an INRIMAGE format file
2%
3% LOADINR(filename, im)
4%
5% Load an INRIA image format file and return it as a matrix
6%
7% SEE ALSO: saveinr
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11
12% Peter Corke 1996
13
14function im = loadinr(fname, im)
15
16 fid = fopen(fname, 'r');
17
18 s = fgets(fid);
19 if strcmp(s(1:12), '#INRIMAGE-4#') == 0,
20 error('not INRIMAGE format');
21 end
22
23 % not very complete, only looks for the X/YDIM keys
24 while 1,
25 s = fgets(fid);
26 n = length(s) - 1;
27 if s(1) == '#',
28 break
29 end
30 if strcmp(s(1:5), 'XDIM='),
31 cols = str2num(s(6:n));
32 end
33 if strcmp(s(1:5), 'YDIM='),
34 rows = str2num(s(6:n));
35 end
36 if strcmp(s(1:4), 'CPU='),
37 if strcmp(s(5:n), 'sun') == 0,
38 error('not sun data ordering');
39 end
40 end
41
42 end
43 disp(['INRIMAGE format file ' num2str(rows) ' x ' num2str(cols)])
44
45 % now the binary data
46 fseek(fid, 256, 'bof');
47 [im count] = fread(fid, [cols rows], 'float32');
48 im = im';
49 if count ~= (rows*cols),
50 error('file too short');
51 end
52 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadpgm.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadpgm.m
new file mode 100755
index 0000000..9386111
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadpgm.m
@@ -0,0 +1,89 @@
1%LOADPGM Load a PGM image
2%
3% I = loadpgm(filename)
4%
5% Returns a matrix containing the image loaded from the PGM format
6% file filename. Handles ASCII (P2) and binary (P5) PGM file formats.
7%
8% If the filename has no extension, and open fails, a '.pgm' will
9% be appended.
10%
11%
12% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
13
14
15% Peter Corke 1994
16
17function I = loadpgm(file)
18 white = [' ' 9 10 13]; % space, tab, lf, cr
19 white = setstr(white);
20
21 fid = fopen(file, 'r');
22 if fid < 0,
23 fid = fopen([file '.pgm'], 'r');
24 end
25 if fid < 0,
26 error('Couldn''t open file');
27 end
28
29 magic = fread(fid, 2, 'char');
30 while 1
31 c = fread(fid,1,'char');
32 if c == '#',
33 fgetl(fid);
34 elseif ~any(c == white)
35 fseek(fid, -1, 'cof'); % unputc()
36 break;
37 end
38 end
39 cols = fscanf(fid, '%d', 1);
40 while 1
41 c = fread(fid,1,'char');
42 if c == '#',
43 fgetl(fid);
44 elseif ~any(c == white)
45 fseek(fid, -1, 'cof'); % unputc()
46 break;
47 end
48 end
49 rows = fscanf(fid, '%d', 1);
50 while 1
51 c = fread(fid,1,'char');
52 if c == '#',
53 fgetl(fid);
54 elseif ~any(c == white)
55 fseek(fid, -1, 'cof'); % unputc()
56 break;
57 end
58 end
59 maxval = fscanf(fid, '%d', 1);
60 while 1
61 c = fread(fid,1,'char');
62 if c == '#',
63 fgetl(fid);
64 elseif ~any(c == white)
65 fseek(fid, -1, 'cof'); % unputc()
66 break;
67 end
68 end
69 if magic(1) == 'P',
70 if magic(2) == '2',
71 disp(['ASCII PGM file ' num2str(rows) ' x ' num2str(cols)])
72 I = fscanf(fid, '%d', [cols rows])';
73 elseif magic(2) == '5',
74 disp(['Binary PGM file ' num2str(rows) ' x ' num2str(cols)])
75 if maxval == 1,
76 fmt = 'unint1';
77 elseif maxval == 15,
78 fmt = 'uint4';
79 elseif maxval == 255,
80 fmt = 'uint8';
81 elseif maxval == 2^32-1,
82 fmt = 'uint32';
83 end
84 I = fread(fid, [cols rows], fmt)';
85 else
86 disp('Not a PGM file');
87 end
88 end
89 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadppm.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadppm.m
new file mode 100755
index 0000000..6dd7ca4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/loadppm.m
@@ -0,0 +1,101 @@
1%LOADPPM Load a PPM image
2%
3% [R,G,B] = loadppm(filename)
4%
5% Returns a matrix containing the image loaded from the PPM format
6% file filename. Handles ASCII (P3) and binary (P6) PPM file formats.
7%
8% If the filename has no extension, and open fails, a '.ppm' and
9% '.pnm' extension will be tried.
10%
11% SEE ALSO: saveppm loadpgm
12%
13% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
14
15
16% Peter Corke 1994
17
18function [R,G,B] = loadppm(file)
19 white = [' ' 9 10 13]; % space, tab, lf, cr
20 white = setstr(white);
21
22 fid = fopen(file, 'r');
23 if fid < 0,
24 fid = fopen([file '.ppm'], 'r');
25 end
26 if fid < 0,
27 fid = fopen([file '.pnm'], 'r');
28 end
29 if fid < 0,
30 error('Couldn''t open file');
31 end
32
33 magic = fread(fid, 2, 'char');
34 while 1
35 c = fread(fid,1,'char');
36 if c == '#',
37 fgetl(fid);
38 elseif ~any(c == white)
39 fseek(fid, -1, 'cof'); % unputc()
40 break;
41 end
42 end
43 cols = fscanf(fid, '%d', 1);
44 while 1
45 c = fread(fid,1,'char');
46 if c == '#',
47 fgetl(fid);
48 elseif ~any(c == white)
49 fseek(fid, -1, 'cof'); % unputc()
50 break;
51 end
52 end
53 rows = fscanf(fid, '%d', 1);
54 while 1
55 c = fread(fid,1,'char');
56 if c == '#',
57 fgetl(fid);
58 elseif ~any(c == white)
59 fseek(fid, -1, 'cof'); % unputc()
60 break;
61 end
62 end
63 maxval = fscanf(fid, '%d', 1);
64 while 1
65 c = fread(fid,1,'char');
66 if c == '#',
67 fgetl(fid);
68 elseif ~any(c == white)
69 fseek(fid, -1, 'cof'); % unputc()
70 break;
71 end
72 end
73 if magic(1) == 'P',
74 if magic(2) == '3',
75 disp(['ASCII PPM file ' num2str(rows) ' x ' num2str(cols)])
76 I = fscanf(fid, '%d', [cols*3 rows]);
77 elseif magic(2) == '6',
78 disp(['Binary PPM file ' num2str(rows) ' x ' num2str(cols)])
79 if maxval == 1,
80 fmt = 'unint1';
81 elseif maxval == 15,
82 fmt = 'uint4';
83 elseif maxval == 255,
84 fmt = 'uint8';
85 elseif maxval == 2^32-1,
86 fmt = 'uint32';
87 end
88 I = fread(fid, [cols*3 rows], fmt);
89 else
90 disp('Not a PPM file');
91 end
92 end
93 %
94 % now the matrix has interleaved columns of R, G, B
95 %
96 I = I';
97 size(I)
98 R = I(:,1:3:(cols*3));
99 G = I(:,2:3:(cols*3));
100 B = I(:,3:3:(cols*3));
101 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/mean_std_robust.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/mean_std_robust.m
new file mode 100755
index 0000000..0d18a62
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/mean_std_robust.m
@@ -0,0 +1,7 @@
1function [m,s] = mean_std_robust(x);
2
3x = x(:);
4
5m = median(x);
6
7s = median(abs(x - m))*1.4836;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/multi_error_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/multi_error_oulu.m
new file mode 100755
index 0000000..8657158
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/multi_error_oulu.m
@@ -0,0 +1,49 @@
1function ex = multi_error_oulu(param,n_ima,cc);
2
3global X_1 x_1 X_2 x_2 X_3 x_3 X_4 x_4 X_5 x_5 X_6 x_6 X_7 x_7 X_8 x_8 X_9 x_9 X_10 x_10 X_11 x_11 X_12 x_12 X_13 x_13 X_14 x_14 X_15 x_15 X_16 x_16 X_17 x_17 X_18 x_18 X_19 x_19 X_20 x_20 X_21 x_21 X_22 x_22 X_23 x_23 X_24 x_24 X_25 x_25 X_26 x_26 X_27 x_27 X_28 x_28 X_29 x_29 X_30 x_30
4
5fc = param(1:2);
6kc = param(3:6);
7%ppc = param(5:6);
8
9if length(param) > 6*n_ima + 3 + 3,
10
11 cc = param(6*n_ima + 4 + 3:6*n_ima + 5 + 3);
12
13 if length(param) > 6*n_ima + 5 + 3,
14
15 c_d = param(6*n_ima + 6 + 3 :6*n_ima + 7 + 3);
16
17 else
18
19 c_d = [0;0];
20
21 end;
22
23else
24
25 c_d = [0;0];
26
27end;
28
29
30
31ex = [];
32
33%keyboard;
34
35for kk = 1:n_ima,
36
37 omckk = param(4+6*(kk-1) + 3:6*kk + 3);
38
39 Tckk = param(6*kk+1 + 3:6*kk+3 + 3);
40
41 Rkk = rodrigues(omckk);
42
43 eval(['ykk = project2_oulu(X_' num2str(kk) ',Rkk,Tckk,fc,cc,kc);']);
44
45 eval(['exkk = x_' num2str(kk) ' -ykk;']);
46
47 ex = [ex;exkk(:)];
48
49end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/normalize.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/normalize.m
new file mode 100755
index 0000000..0a37378
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/normalize.m
@@ -0,0 +1,32 @@
1function [xn] = normalize(x_kk,fc,cc,kc),
2
3%normalize
4%
5%[xn] = normalize(x_kk,fc,cc,kc)
6%
7%Computes the normalized coordinates xn given the pixel coordinates x_kk
8%and the intrinsic camera parameters fc, cc and kc.
9%
10%INPUT: x_kk: Feature locations on the images
11% fc: Camera focal length
12% cc: Principal point coordinates
13% kc: Distortion coefficients
14%
15%OUTPUT: xn: Normalized feature locations on the image plane (a 2XN matrix)
16%
17%Important functions called within that program:
18%
19%comp_distortion_oulu: undistort pixel coordinates.
20
21
22
23% First subtract principal point, and divide by the focal length:
24
25x_distort = [(x_kk(1,:) - cc(1))/fc(1);(x_kk(2,:) - cc(2))/fc(2)];
26
27
28%Compensate for lens distortion:
29
30xn = comp_distortion_oulu(x_distort,kc);
31
32
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/pgmread.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/pgmread.m
new file mode 100755
index 0000000..c96ccb7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/pgmread.m
@@ -0,0 +1,26 @@
1function img = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7fid = fopen(filename,'r');
8fscanf(fid, 'P5\n');
9cmt = '#';
10while findstr(cmt, '#'),
11 cmt = fgets(fid);
12 if length(findstr(cmt, '#')) ~= 1,
13 YX = sscanf(cmt, '%d %d');
14 y = YX(1); x = YX(2);
15 end
16end
17
18%fgets(fid);
19
20%img = fscanf(fid,'%d',size);
21%img = img';
22
23img = fread(fid,[y,x],'uint8');
24img = img';
25fclose(fid);
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project2_oulu.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project2_oulu.m
new file mode 100755
index 0000000..c5c4a34
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project2_oulu.m
@@ -0,0 +1,53 @@
1function [x] = project2_oulu(X,R,T,f,t,k)
2%PROJECT Subsidiary to calib
3
4% (c) Pietro Perona -- March 24, 1994
5% California Institute of Technology
6% Pasadena, CA
7%
8% Renamed because project exists in matlab 5.2!!!
9% Now uses the more elaborate intrinsic model from Oulu
10
11
12
13[m,n] = size(X);
14
15Y = R*X + T*ones(1,n);
16Z = Y(3,:);
17
18f = f(:); %% make a column vector
19if length(f)==1,
20 f = [f f]';
21end;
22
23x = (Y(1:2,:) ./ (ones(2,1) * Z)) ;
24
25
26radius_2 = x(1,:).^2 + x(2,:).^2;
27
28if length(k) > 1,
29
30 radial_distortion = 1 + ones(2,1) * ((k(1) * radius_2) + (k(2) * radius_2.^2));
31
32 if length(k) < 4,
33
34 delta_x = zeros(2,n);
35
36 else
37
38 delta_x = [2*k(3)*x(1,:).*x(2,:) + k(4)*(radius_2 + 2*x(1,:).^2) ;
39 k(3) * (radius_2 + 2*x(2,:).^2)+2*k(4)*x(1,:).*x(2,:)];
40
41 end;
42
43
44else
45
46 radial_distortion = 1 + ones(2,1) * ((k(1) * radius_2));
47
48 delta_x = zeros(2,n);
49
50end;
51
52
53x = (x .* radial_distortion + delta_x).* (f * ones(1,n)) + t*ones(1,n);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project_points.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project_points.m
new file mode 100755
index 0000000..1823490
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/project_points.m
@@ -0,0 +1,276 @@
1function [xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk] = project_points(X,om,T,f,c,k)
2
3%project_points.m
4%
5%[xp,dxpdom,dxpdT,dxpdf,dxpdc,dxpdk] = project_points(X,om,T,f,c,k)
6%
7%Projects a 3D structure onto the image plane.
8%
9%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
10% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
11% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
12% f: camera focal length in units of horizontal and vertical pixel units (2x1 vector)
13% c: principal point location in pixel units (2x1 vector)
14% k: Distortion coefficients (radial and tangential) (4x1 vector)
15%
16%OUTPUT: xp: Projected pixel coordinates (2xN matrix for N points)
17% dxpdom: Derivative of xp with respect to om ((2N)x3 matrix)
18% dxpdT: Derivative of xp with respect to T ((2N)x3 matrix)
19% dxpdf: Derivative of xp with respect to f ((2N)x2 matrix)
20% dxpdc: Derivative of xp with respect to c ((2N)x2 matrix)
21% dxpdk: Derivative of xp with respect to k ((2N)x4 matrix)
22%
23%Definitions:
24%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
25%The coordinate vector of P in the camera reference frame is: Xc = R*X + T
26%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
27%call x, y and z the 3 coordinates of Xc: x = Xc(1); y = Xc(2); z = Xc(3);
28%The pinehole projection coordinates of P is [a;b] where a=x/z and b=y/z.
29%call r^2 = a^2 + b^2.
30%The distorted point coordinates are: xd = [xx;yy] where:
31%
32%xx = a * (1 + kc(1)*r^2 + kc(2)*r^4) + 2*kc(3)*a*b + kc(4)*(r^2 + 2*a^2);
33%yy = b * (1 + kc(1)*r^2 + kc(2)*r^4) + kc(3)*(r^2 + 2*b^2) + 2*kc(4)*a*b;
34%
35%The left terms correspond to radial distortion, the right terms correspond to tangential distortion
36%
37%Fianlly, convertion into pixel coordinates: The final pixel coordinates vector xp=[xxp;yyp] where:
38%
39%xxp = f(1)*xx + c(1)
40%yyp = f(2)*yy + c(2)
41%
42%
43%NOTE: About 90 percent of the code takes care fo computing the Jacobian matrices
44%
45%
46%Important function called within that program:
47%
48%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
49%
50%rigid_motion.m: Computes the rigid motion transformation of a given structure
51
52
53
54if nargin < 6,
55 k = zeros(4,1);
56 if nargin < 5,
57 c = zeros(2,1);
58 if nargin < 4,
59 f = ones(2,1);
60 if nargin < 3,
61 T = zeros(3,1);
62 if nargin < 2,
63 om = zeros(3,1);
64 if nargin < 1,
65 error('Need at least a 3D structure to project (in project_points.m)');
66 return;
67 end;
68 end;
69 end;
70 end;
71 end;
72end;
73
74
75[m,n] = size(X);
76
77[Y,dYdom,dYdT] = rigid_motion(X,om,T);
78
79
80inv_Z = 1./Y(3,:);
81
82x = (Y(1:2,:) .* (ones(2,1) * inv_Z)) ;
83
84
85bb = (-x(1,:) .* inv_Z)'*ones(1,3);
86cc = (-x(2,:) .* inv_Z)'*ones(1,3);
87
88
89dxdom = zeros(2*n,3);
90dxdom(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(1:3:end,:) + bb .* dYdom(3:3:end,:);
91dxdom(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdom(2:3:end,:) + cc .* dYdom(3:3:end,:);
92
93dxdT = zeros(2*n,3);
94dxdT(1:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(1:3:end,:) + bb .* dYdT(3:3:end,:);
95dxdT(2:2:end,:) = ((inv_Z')*ones(1,3)) .* dYdT(2:3:end,:) + cc .* dYdT(3:3:end,:);
96
97
98% Add distortion:
99
100r2 = x(1,:).^2 + x(2,:).^2;
101
102
103
104dr2dom = 2*((x(1,:)')*ones(1,3)) .* dxdom(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdom(2:2:end,:);
105dr2dT = 2*((x(1,:)')*ones(1,3)) .* dxdT(1:2:end,:) + 2*((x(2,:)')*ones(1,3)) .* dxdT(2:2:end,:);
106
107
108r4 = r2.^2;
109
110dr4dom = 2*((r2')*ones(1,3)) .* dr2dom;
111dr4dT = 2*((r2')*ones(1,3)) .* dr2dT;
112
113
114% Radial distortion:
115
116cdist = 1 + k(1) * r2 + k(2) * r4;
117
118dcdistdom = k(1) * dr2dom + k(2) * dr4dom;
119dcdistdT = k(1) * dr2dT+ k(2) * dr4dT;
120dcdistdk = [ r2' r4' zeros(n,2)];
121
122
123xd1 = x .* (ones(2,1)*cdist);
124
125dxd1dom = zeros(2*n,3);
126dxd1dom(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdom;
127dxd1dom(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdom;
128coeff = (reshape([cdist;cdist],2*n,1)*ones(1,3));
129dxd1dom = dxd1dom + coeff.* dxdom;
130
131dxd1dT = zeros(2*n,3);
132dxd1dT(1:2:end,:) = (x(1,:)'*ones(1,3)) .* dcdistdT;
133dxd1dT(2:2:end,:) = (x(2,:)'*ones(1,3)) .* dcdistdT;
134dxd1dT = dxd1dT + coeff.* dxdT;
135
136dxd1dk = zeros(2*n,4);
137dxd1dk(1:2:end,:) = (x(1,:)'*ones(1,4)) .* dcdistdk;
138dxd1dk(2:2:end,:) = (x(2,:)'*ones(1,4)) .* dcdistdk;
139
140
141
142% tangential distortion:
143
144a1 = 2.*x(1,:).*x(2,:);
145a2 = r2 + 2*x(1,:).^2;
146a3 = r2 + 2*x(2,:).^2;
147
148delta_x = [k(3)*a1 + k(4)*a2 ;
149 k(3) * a3 + k(4)*a1];
150
151
152ddelta_xdx = zeros(2*n,2*n);
153aa = (2*k(3)*x(2,:)+6*k(4)*x(1,:))'*ones(1,3);
154bb = (2*k(3)*x(1,:)+2*k(4)*x(2,:))'*ones(1,3);
155cc = (6*k(3)*x(2,:)+2*k(4)*x(1,:))'*ones(1,3);
156
157ddelta_xdom = zeros(2*n,3);
158ddelta_xdom(1:2:end,:) = aa .* dxdom(1:2:end,:) + bb .* dxdom(2:2:end,:);
159ddelta_xdom(2:2:end,:) = bb .* dxdom(1:2:end,:) + cc .* dxdom(2:2:end,:);
160
161ddelta_xdT = zeros(2*n,3);
162ddelta_xdT(1:2:end,:) = aa .* dxdT(1:2:end,:) + bb .* dxdT(2:2:end,:);
163ddelta_xdT(2:2:end,:) = bb .* dxdT(1:2:end,:) + cc .* dxdT(2:2:end,:);
164
165ddelta_xdk = zeros(2*n,4);
166ddelta_xdk(1:2:end,3) = a1';
167ddelta_xdk(1:2:end,4) = a2';
168ddelta_xdk(2:2:end,3) = a3';
169ddelta_xdk(2:2:end,4) = a1';
170
171
172
173xd2 = xd1 + delta_x;
174
175dxd2dom = dxd1dom + ddelta_xdom ;
176dxd2dT = dxd1dT + ddelta_xdT;
177dxd2dk = dxd1dk + ddelta_xdk ;
178
179
180% Pixel coordinates:
181
182xp = xd2 .* (f * ones(1,n)) + c*ones(1,n);
183
184coeff = reshape(f*ones(1,n),2*n,1);
185
186dxpdom = (coeff*ones(1,3)) .* dxd2dom;
187dxpdT = (coeff*ones(1,3)) .* dxd2dT;
188dxpdk = (coeff*ones(1,4)) .* dxd2dk;
189
190dxpdf = zeros(2*n,2);
191dxpdf(1:2:end,1) = xd2(1,:)';
192dxpdf(2:2:end,2) = xd2(2,:)';
193
194dxpdc = zeros(2*n,2);
195dxpdc(1:2:end,1) = ones(n,1);
196dxpdc(2:2:end,2) = ones(n,1);
197
198
199return;
200
201% Test of the Jacobians:
202
203n = 10;
204
205X = 10*randn(3,n);
206om = randn(3,1);
207T = [10*randn(2,1);40];
208f = 1000*rand(2,1);
209c = 1000*randn(2,1);
210k = 0.5*randn(4,1);
211
212
213[x,dxdom,dxdT,dxdf,dxdc,dxdk] = project_points(X,om,T,f,c,k);
214
215
216% Test on om: NOT OK
217
218dom = 0.000000001 * norm(om)*randn(3,1);
219om2 = om + dom;
220
221[x2] = project_points(X,om2,T,f,c,k);
222
223x_pred = x + reshape(dxdom * dom,2,n);
224
225
226norm(x2-x)/norm(x2 - x_pred)
227
228
229% Test on T: OK!!
230
231dT = 0.0001 * norm(T)*randn(3,1);
232T2 = T + dT;
233
234[x2] = project_points(X,om,T2,f,c,k);
235
236x_pred = x + reshape(dxdT * dT,2,n);
237
238
239norm(x2-x)/norm(x2 - x_pred)
240
241
242
243% Test on f: OK!!
244
245df = 0.001 * norm(f)*randn(2,1);
246f2 = f + df;
247
248[x2] = project_points(X,om,T,f2,c,k);
249
250x_pred = x + reshape(dxdf * df,2,n);
251
252
253norm(x2-x)/norm(x2 - x_pred)
254
255
256% Test on c: OK!!
257
258dc = 0.01 * norm(c)*randn(2,1);
259c2 = c + dc;
260
261[x2] = project_points(X,om,T,f,c2,k);
262
263x_pred = x + reshape(dxdc * dc,2,n);
264
265norm(x2-x)/norm(x2 - x_pred)
266
267% Test on k: OK!!
268
269dk = 0.001 * norm(4)*randn(4,1);
270k2 = k + dk;
271
272[x2] = project_points(X,om,T,f,c,k2);
273
274x_pred = x + reshape(dxdk * dk,2,n);
275
276norm(x2-x)/norm(x2 - x_pred)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/projectedGrid.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/projectedGrid.m
new file mode 100755
index 0000000..561a7d0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/projectedGrid.m
@@ -0,0 +1,24 @@
1function [XX,H] = projectedGrid ( P1, P2, P3, P4 , nx, ny);
2
3% new formalism using homographies
4
5a00 = [P1;1];
6a10 = [P2;1];
7a11 = [P3;1];
8a01 = [P4;1];
9
10% Compute the planart collineation:
11
12[H] = compute_collineation (a00, a10, a11, a01);
13
14
15% Build the grid using the planar collineation:
16
17x_l = ((0:(nx-1))'*ones(1,ny))/(nx-1);
18y_l = (ones(nx,1)*(0:(ny-1)))/(ny-1);
19
20pts = [x_l(:) y_l(:) ones(nx*ny,1)]';
21
22XX = H*pts;
23
24XX = XX(1:2,:) ./ (ones(2,1)*XX(3,:));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/readras.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/readras.m
new file mode 100755
index 0000000..fc1820b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/readras.m
@@ -0,0 +1,87 @@
1function [X, map] = readras(filename, ys, ye, xs, xe);
2%READRAS Read an image file in sun raster format.
3% READRAS('imagefile.ras') reads a "sun.raster" image file.
4% [X, map] = READRAS('imagefile.ras') returns both the image and a
5% color map, so that
6% [X, map] = readras('imagefile.ras');
7% image(X)
8% colormap(map)
9% axis('equal')
10% will display the result with the proper colors.
11% NOTE: readras cannot deal with complicated color maps.
12% In fact, Matlab doesn't quite allow to work with colormaps
13% with more than 64 entries.
14%
15
16%%
17%% (C) Thomas K. Leung 3/30/93.
18%% California Institute of Technology.
19%% Modified by Andrea Mennucci to deal with color images
20%%
21
22% PC and UNIX version of readras - Jean-Yves Bouguet - Dec. 1998
23
24dot = max(find(filename == '.'));
25suffix = filename(dot+1:dot+3);
26
27if(strcmp(suffix, 'ras')) % raster file format %
28 fp = fopen(filename, 'rb');
29 if(fp<0) error(['Cannot open ' filename '.']), end
30
31 %Read and crack the 32-byte header
32 fseek(fp, 4, -1);
33
34 width = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
35
36 height = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
37
38 depth = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
39
40 length = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
41
42 type = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
43
44 maptype = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
45
46 maplen = 2^24 * fread(fp, 1, 'uchar') + 2^16 * fread(fp, 1, 'uchar') + 2^8 * fread(fp, 1, 'uchar') + fread(fp, 1, 'uchar');
47
48 maplen = maplen / 3;
49
50 if maptype == 2 % RMT_RAW
51 map = fread(fp, [maplen, 3], 'uchar')/255;
52% if maplen<64, map=[map',zeros(3,64-maplen)]';maplen=64; end;
53 elseif maptype == 1 % RMT_EQUAL_RGB
54 map(:,1) = fread(fp, [maplen], 'uchar');
55 map(:,2) = fread(fp, [maplen], 'uchar');
56 map(:,3) = fread(fp, [maplen], 'uchar');
57 %maxmap = max(max(map));
58 map = map/255;
59 if maplen<64, map=[map',zeros(3,64-maplen)]'; maplen=64; end;
60 else % RMT_NONE
61 map = [];
62 end
63% if maplen>64,
64% map=[map',zeros(3,256-maplen)]';
65% end;
66
67 % Read the image
68
69 if rem(width,2) == 1
70 Xt = fread(fp, [width+1, height], 'uchar');
71 X = Xt(1:width, :)';
72 else
73 Xt = fread(fp, [width, height], 'uchar');
74 X = Xt';
75 end
76 X = X + 1;
77 fclose(fp);
78else
79 error('Image file name must end in either ''ras'' or ''rast''.');
80end
81
82
83if nargin == 5
84
85 X = X(ys:ye, xs:xe);
86
87end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/recomp_corner_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/recomp_corner_calib.m
new file mode 100755
index 0000000..e0af501
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/recomp_corner_calib.m
@@ -0,0 +1,96 @@
1% Re-select te corners after calibration
2
3check_active_images;
4
5if ~exist(['y_' num2str(ind_active(1))]),
6 fprintf(1,'Need to calibrate once before before recomputing image corners. Maybe need to load Calib_Results.mat file.\n');
7 return;
8end;
9
10if ~exist(['I_' num2str(ind_active(1))]),
11 ima_read_calib;
12 if no_image_file,
13 disp('Cannot extract corners without images');
14 return;
15 end;
16end;
17
18fprintf(1,'\nRe-extraction of the grid corners on the images (after first calibration)\n');
19
20disp('Window size for corner finder (wintx and winty):');
21wintx = input('wintx ([] = 5) = ');
22if isempty(wintx), wintx = 5; end;
23wintx = round(wintx);
24winty = input('winty ([] = 5) = ');
25if isempty(winty), winty = 5; end;
26winty = round(winty);
27
28fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);
29
30ima_numbers = input('Number(s) of image(s) to process ([] = all images) = ');
31
32if isempty(ima_numbers),
33 ima_proc = 1:n_ima;
34else
35 ima_proc = ima_numbers;
36end;
37
38q_auto = input('Use the projection of 3D grid or manual click ([]=auto, other=manual): ');
39
40fprintf(1,'Processing image ');
41
42for kk = ima_proc;
43
44 if active_images(kk),
45
46 fprintf(1,'%d...',kk);
47
48 if isempty(q_auto),
49
50 eval(['I = I_' num2str(kk) ';']);
51
52 eval(['y = y_' num2str(kk) ';']);
53
54 xc = cornerfinder(y+1,I,winty,wintx); % the four corners
55
56 eval(['wintx_' num2str(kk) ' = wintx;']);
57 eval(['winty_' num2str(kk) ' = winty;']);
58
59 eval(['x_' num2str(kk) '= xc - 1;']);
60
61 else
62
63 fprintf(1,'\n');
64
65 click_ima_calib;
66
67 end;
68
69 else
70
71 if ~exist(['omc_' num2str(kk)]),
72
73 eval(['dX_' num2str(kk) ' = NaN;']);
74 eval(['dY_' num2str(kk) ' = NaN;']);
75
76 eval(['wintx_' num2str(kk) ' = NaN;']);
77 eval(['winty_' num2str(kk) ' = NaN;']);
78
79 eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);
80 eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);
81
82 eval(['n_sq_x_' num2str(kk) ' = NaN;']);
83 eval(['n_sq_y_' num2str(kk) ' = NaN;']);
84
85 end;
86
87 end;
88
89
90end;
91
92% Recompute the error:
93
94comp_error_calib;
95
96fprintf(1,'\ndone\n'); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rect.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rect.m
new file mode 100755
index 0000000..d8b6366
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rect.m
@@ -0,0 +1,93 @@
1function [Irec] = rect(I,R,f,c,k,KK_new);
2
3
4% Note: R is the motion of the points in space
5% So: X2 = R*X where X: coord in the old reference frame, X2: coord in the new ref frame.
6
7[nr,nc] = size(I);
8
9Irec = 255*ones(nr,nc);
10
11[mx,my] = meshgrid(1:nc, 1:nr);
12px = reshape(mx',nc*nr,1);
13py = reshape(my',nc*nr,1);
14
15rays = inv(KK_new)*[(px - 1)';(py - 1)';ones(1,length(px))];
16
17
18% Rotation: (or affine transformation):
19
20rays2 = R'*rays;
21
22
23x = [rays2(1,:)./rays2(3,:);rays2(2,:)./rays2(3,:)];
24
25% Add distortion:
26
27k1 = k(1);
28k2 = k(2);
29
30p1 = k(3);
31p2 = k(4);
32
33r_2 = sum(x.^2);
34
35delta_x = [2*p1*x(1,:).*x(2,:) + p2*(r_2 + 2*x(1,:).^2) ;
36 p1 * (r_2 + 2*x(2,:).^2)+2*p2*x(1,:).*x(2,:)];
37
38xd = (ones(2,1)*( 1 + k1 * r_2 + k2 * r_2.^2)) .* x + delta_x;
39
40
41% Reconvert in pixels:
42
43px2 = f(1)*xd(1,:)+c(1);
44py2 = f(2)*xd(2,:)+c(2);
45
46
47% Interpolate between the closest pixels:
48
49
50px_0 = floor(px2);
51px_1 = px_0 + 1;
52alpha_x = px2 - px_0;
53
54py_0 = floor(py2);
55py_1 = py_0 + 1;
56alpha_y = py2 - py_0;
57
58good_points = find((px_0 >= 0) & (px_1 <= (nc-1)) & (py_0 >= 0) & (py_1 <= (nr-1)));
59
60I_lu = I(px_0(good_points) * nr + py_0(good_points) + 1);
61I_ru = I(px_1(good_points) * nr + py_0(good_points) + 1);
62I_ld = I(px_0(good_points) * nr + py_1(good_points) + 1);
63I_rd = I(px_1(good_points) * nr + py_1(good_points) + 1);
64
65
66I_interp = (1 - alpha_y(good_points)).*((1 - alpha_x(good_points)).* I_lu + alpha_x(good_points) .* I_ru) + alpha_y(good_points) .* ((1 - alpha_x(good_points)).* I_ld + alpha_x(good_points) .* I_rd);
67
68
69Irec((px(good_points)-1)*nr + py(good_points)) = I_interp;
70
71
72
73return;
74
75
76% Convert in indices:
77
78fact = 3;
79
80[XX,YY]= meshgrid(1:nc,1:nr);
81[XXi,YYi]= meshgrid(1:1/fact:nc,1:1/fact:nr);
82
83%tic;
84Iinterp = interp2(XX,YY,I,XXi,YYi);
85%toc
86
87[nri,nci] = size(Iinterp);
88
89
90ind_col = round(fact*(f(1)*xd(1,:)+c(1)))+1;
91ind_row = round(fact*(f(2)*xd(2,:)+c(2)))+1;
92
93good_points = find((ind_col >=1)&(ind_col<=nci)&(ind_row >=1)& (ind_row <=nri));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/reproject_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/reproject_calib.m
new file mode 100755
index 0000000..86b13f5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/reproject_calib.m
@@ -0,0 +1,92 @@
1%%%%%%%%%%%%%%%%%%%% REPROJECT ON THE IMAGES %%%%%%%%%%%%%%%%%%%%%%%%
2
3if ~exist('no_image'),
4 no_image = 0;
5end;
6
7check_active_images;
8
9
10% Color code for each image:
11
12colors = 'brgkcm';
13
14% Reproject the patterns on the images, and compute the pixel errors:
15
16% Reload the images if necessary
17
18if ~exist(['omc_' num2str(ind_active(1)) ]),
19 fprintf(1,'Need to calibrate before showing image reprojection. Maybe need to load Calib_Results.mat file.\n');
20 return;
21end;
22
23if ~no_image,
24 if ~exist(['I_' num2str(ind_active(1)) ]'),
25 ima_read_calib;
26 if no_image_file,
27 fprintf(1,'WARNING: Do not show the original images\n'); %return;
28 end;
29 end;
30else
31 no_image_file = 1;
32end;
33
34
35
36ima_numbers = input('Number(s) of image(s) to show ([] = all images) = ');
37
38if isempty(ima_numbers),
39 ima_proc = 1:n_ima;
40else
41 ima_proc = ima_numbers;
42end;
43
44
45figure(5);
46for kk = ima_proc, %1:n_ima,
47 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
48 eval(['plot(ex_' num2str(kk) '(1,:),ex_' num2str(kk) '(2,:),''' colors(rem(kk-1,6)+1) '+'');']);
49 hold on;
50 end;
51end;
52hold off;
53axis('equal');
54title('Reprojection error (in pixel)');
55xlabel('x');
56ylabel('y');
57drawnow;
58
59set(5,'Name','error','NumberTitle','off');
60
61
62
63for kk = ima_proc,
64
65 if active_images(kk) & eval(['~isnan(y_' num2str(kk) '(1,1))']),
66
67 if exist(['I_' num2str(kk)]),
68 eval(['I = I_' num2str(kk) ';']);
69 else
70 I = 255*ones(ny,nx);
71 end;
72
73 figure(5+kk);
74 image(I); hold on;
75 colormap(gray(256));
76 title(['Image ' num2str(kk) ' - Image points (+) and reprojected grid points (o)']);
77 eval(['plot(x_' num2str(kk) '(1,:)+1,x_' num2str(kk) '(2,:)+1,''r+'');']);
78 eval(['plot(y_' num2str(kk) '(1,:)+1,y_' num2str(kk) '(2,:)+1,''' colors(rem(kk-1,6)+1) 'o'');']);
79 zoom on;
80 hold off;
81 drawnow;
82
83 set(5+kk,'Name',num2str(kk),'NumberTitle','off');
84
85 end;
86
87end;
88
89
90err_std = std(ex')';
91
92fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rigid_motion.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rigid_motion.m
new file mode 100755
index 0000000..473405c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rigid_motion.m
@@ -0,0 +1,66 @@
1function [Y,dYdom,dYdT] = rigid_motion(X,om,T);
2
3%rigid_motion.m
4%
5%[Y,dYdom,dYdT] = rigid_motion(X,om,T)
6%
7%Computes the rigid motion transformation Y = R*X+T, where R = rodrigues(om).
8%
9%INPUT: X: 3D structure in the world coordinate frame (3xN matrix for N points)
10% (om,T): Rigid motion parameters between world coordinate frame and camera reference frame
11% om: rotation vector (3x1 vector); T: translation vector (3x1 vector)
12%
13%OUTPUT: Y: 3D coordinates of the structure points in the camera reference frame (3xN matrix for N points)
14% dYdom: Derivative of Y with respect to om ((3N)x3 matrix)
15% dYdT: Derivative of Y with respect to T ((3N)x3 matrix)
16%
17%Definitions:
18%Let P be a point in 3D of coordinates X in the world reference frame (stored in the matrix X)
19%The coordinate vector of P in the camera reference frame is: Y = R*X + T
20%where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om);
21%
22%Important function called within that program:
23%
24%rodrigues.m: Computes the rotation matrix corresponding to a rotation vector
25
26
27
28if nargin < 3,
29 T = zeros(3,1);
30 if nargin < 2,
31 om = zeros(3,1);
32 if nargin < 1,
33 error('Need at least a 3D structure as input (in rigid_motion.m)');
34 return;
35 end;
36 end;
37end;
38
39
40[R,dRdom] = rodrigues(om);
41
42[m,n] = size(X);
43
44Y = R*X + T*ones(1,n);
45
46if nargout > 1,
47
48
49dYdR = zeros(3*n,9);
50dYdT = zeros(3*n,3);
51
52dYdR(1:3:end,1:3:end) = X';
53dYdR(2:3:end,2:3:end) = X';
54dYdR(3:3:end,3:3:end) = X';
55
56dYdT(1:3:end,1) = ones(n,1);
57dYdT(2:3:end,2) = ones(n,1);
58dYdT(3:3:end,3) = ones(n,1);
59
60dYdom = dYdR * dRdom;
61
62end;
63
64
65
66
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rodrigues.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rodrigues.m
new file mode 100755
index 0000000..9d55337
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rodrigues.m
@@ -0,0 +1,217 @@
1function [out,dout]=rodrigues(in)
2
3% RODRIGUES Transform rotation matrix into rotation vector and viceversa.
4%
5% Sintax: [OUT]=RODRIGUES(IN)
6% If IN is a 3x3 rotation matrix then OUT is the
7% corresponding 3x1 rotation vector
8% if IN is a rotation 3-vector then OUT is the
9% corresponding 3x3 rotation matrix
10%
11
12%%
13%% Copyright (c) March 1993 -- Pietro Perona
14%% California Institute of Technology
15%%
16
17%% ALL CHECKED BY JEAN-YVES BOUGUET, October 1995.
18%% FOR ALL JACOBIAN MATRICES !!! LOOK AT THE TEST AT THE END !!
19
20%% BUG when norm(om)=pi fixed -- April 6th, 1997;
21%% Jean-Yves Bouguet
22
23
24[m,n] = size(in);
25%bigeps = 10e+4*eps;
26bigeps = 10e+20*eps;
27
28if ((m==1) & (n==3)) | ((m==3) & (n==1)) %% it is a rotation vector
29 theta = norm(in);
30 if theta < eps
31 R = eye(3);
32
33 %if nargout > 1,
34
35 dRdin = [0 0 0;
36 0 0 1;
37 0 -1 0;
38 0 0 -1;
39 0 0 0;
40 1 0 0;
41 0 1 0;
42 -1 0 0;
43 0 0 0];
44
45 %end;
46
47 else
48 if n==length(in) in=in'; end; %% make it a column vec. if necess.
49
50 %m3 = [in,theta]
51
52 dm3din = [eye(3);in'/theta];
53
54 omega = in/theta;
55
56 %m2 = [omega;theta]
57
58 dm2dm3 = [eye(3)/theta -in/theta^2; zeros(1,3) 1];
59
60 alpha = cos(theta);
61 beta = sin(theta);
62 gamma = 1-cos(theta);
63 omegav=[[0 -omega(3) omega(2)];[omega(3) 0 -omega(1)];[-omega(2) omega(1) 0 ]];
64 A = omega*omega';
65
66 %m1 = [alpha;beta;gamma;omegav;A];
67
68 dm1dm2 = zeros(21,4);
69 dm1dm2(1,4) = -sin(theta);
70 dm1dm2(2,4) = cos(theta);
71 dm1dm2(3,4) = sin(theta);
72 dm1dm2(4:12,1:3) = [0 0 0 0 0 1 0 -1 0;
73 0 0 -1 0 0 0 1 0 0;
74 0 1 0 -1 0 0 0 0 0]';
75
76 w1 = omega(1);
77 w2 = omega(2);
78 w3 = omega(3);
79
80 dm1dm2(13:21,1) = [2*w1;w2;w3;w2;0;0;w3;0;0];
81 dm1dm2(13: 21,2) = [0;w1;0;w1;2*w2;w3;0;w3;0];
82 dm1dm2(13:21,3) = [0;0;w1;0;0;w2;w1;w2;2*w3];
83
84 R = eye(3)*alpha + omegav*beta + A*gamma;
85
86 dRdm1 = zeros(9,21);
87
88 dRdm1([1 5 9],1) = ones(3,1);
89 dRdm1(:,2) = omegav(:);
90 dRdm1(:,4:12) = beta*eye(9);
91 dRdm1(:,3) = A(:);
92 dRdm1(:,13:21) = gamma*eye(9);
93
94 dRdin = dRdm1 * dm1dm2 * dm2dm3 * dm3din;
95
96
97 end;
98 out = R;
99 dout = dRdin;
100
101 %% it is prob. a rot matr.
102 elseif ((m==n) & (m==3) & (norm(in' * in - eye(3)) < bigeps)...
103 & (abs(det(in)-1) < bigeps))
104 R = in;
105
106
107
108 tr = (trace(R)-1)/2;
109 dtrdR = [1 0 0 0 1 0 0 0 1]/2;
110 theta = real(acos(tr));
111
112
113 if sin(theta) >= 1e-5,
114
115 dthetadtr = -1/sqrt(1-tr^2);
116
117 dthetadR = dthetadtr * dtrdR;
118 % var1 = [vth;theta];
119 vth = 1/(2*sin(theta));
120 dvthdtheta = -vth*cos(theta)/sin(theta);
121 dvar1dtheta = [dvthdtheta;1];
122
123 dvar1dR = dvar1dtheta * dthetadR;
124
125
126 om1 = [R(3,2)-R(2,3), R(1,3)-R(3,1), R(2,1)-R(1,2)]';
127
128 dom1dR = [0 0 0 0 0 1 0 -1 0;
129 0 0 -1 0 0 0 1 0 0;
130 0 1 0 -1 0 0 0 0 0];
131
132 % var = [om1;vth;theta];
133 dvardR = [dom1dR;dvar1dR];
134
135 % var2 = [om;theta];
136 om = vth*om1;
137 domdvar = [vth*eye(3) om1 zeros(3,1)];
138 dthetadvar = [0 0 0 0 1];
139 dvar2dvar = [domdvar;dthetadvar];
140
141
142 out = om*theta;
143 domegadvar2 = [theta*eye(3) om];
144
145 dout = domegadvar2 * dvar2dvar * dvardR;
146
147
148 else
149 if tr > 0; % case norm(om)=0;
150
151 out = [0 0 0]';
152
153 dout = [0 0 0 0 0 1/2 0 -1/2 0;
154 0 0 -1/2 0 0 0 1/2 0 0;
155 0 1/2 0 -1/2 0 0 0 0 0];
156 else % case norm(om)=pi; %% fixed April 6th
157
158
159 out = theta * (sqrt((diag(R)+1)/2).*[1;2*(R(1,2:3)>=0)'-1]);
160 %keyboard;
161
162 if nargout > 1,
163 fprintf(1,'WARNING!!!! Jacobian domdR undefined!!!\n');
164 dout = NaN*ones(3,9);
165 end;
166 end;
167 end;
168
169 else
170 error('Neither a rotation matrix nor a rotation vector were provided');
171 end;
172
173return;
174
175%% test of the Jacobians:
176
177%%%% TEST OF dRdom:
178om = randn(3,1);
179dom = randn(3,1)/1000000;
180
181[R1,dR1] = rodrigues(om);
182R2 = rodrigues(om+dom);
183
184R2a = R1 + reshape(dR1 * dom,3,3);
185
186gain = norm(R2 - R1)/norm(R2 - R2a)
187
188%%% TEST OF dOmdR:
189om = randn(3,1);
190R = rodrigues(om);
191dom = randn(3,1)/10000;
192dR = rodrigues(om+dom) - R;
193
194[omc,domdR] = rodrigues(R);
195[om2] = rodrigues(R+dR);
196
197om_app = omc + domdR*dR(:);
198
199gain = norm(om2 - omc)/norm(om2 - om_app)
200
201
202%%% OTHER BUG: (FIXED NOW!!!)
203
204omu = randn(3,1);
205omu = omu/norm(omu)
206om = pi*omu;
207[R,dR]= rodrigues(om);
208[om2] = rodrigues(R);
209[om om2]
210
211%%% NORMAL OPERATION
212
213om = randn(3,1);
214[R,dR]= rodrigues(om);
215[om2] = rodrigues(R);
216[om om2]
217
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rotation.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rotation.m
new file mode 100755
index 0000000..87ee2fe
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/rotation.m
@@ -0,0 +1,23 @@
1function [] = rotation(st);
2
3if nargin < 1,
4 st= 1;
5end;
6
7
8fig = gcf;
9
10ax = gca;
11
12vv = get(ax,'view');
13
14az = vv(1);
15el = vv(2);
16
17for azi = az:-abs(st):az-360,
18
19 set(ax,'view',[azi el]);
20 figure(fig);
21 drawnow;
22
23end;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/run_error_analysis.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/run_error_analysis.m
new file mode 100755
index 0000000..095e17e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/run_error_analysis.m
@@ -0,0 +1,65 @@
1%%% Program that launchs the complete
2
3for N_ima_active = 1:30,
4
5 error_analysis;
6
7end;
8
9
10
11return;
12
13
14f = [];
15f_std = [];
16
17c = [];
18c_std = [];
19
20k = [];
21k_std = [];
22
23NN = 30;
24
25for rr = 1:NN,
26
27 load(['Calib_Accuracies_' num2str(rr)]);
28
29 [m1,s1] = mean_std_robust(fc_list(1,:));
30 [m2,s2] = mean_std_robust(fc_list(2,:));
31
32 f = [f [m1;m2]];
33 f_std = [f_std [s1;s2]];
34
35 [m1,s1] = mean_std_robust(cc_list(1,:));
36 [m2,s2] = mean_std_robust(cc_list(2,:));
37
38 c = [c [m1;m2]];
39 c_std = [c_std [s1;s2]];
40
41 [m1,s1] = mean_std_robust(kc_list(1,:));
42 [m2,s2] = mean_std_robust(kc_list(2,:));
43 [m3,s3] = mean_std_robust(kc_list(3,:));
44 [m4,s4] = mean_std_robust(kc_list(4,:));
45
46 k = [k [m1;m2;m3;m4]];
47 k_std = [k_std [s1;s2;s3;s4]];
48
49end;
50
51figure(1);
52errorbar([1:NN;1:NN]',f',f_std');
53figure(2);
54errorbar([1:NN;1:NN]',c',c_std');
55figure(3);
56errorbar([1:NN;1:NN;1:NN;1:NN]',k',k_std');
57
58figure(4);
59semilogy(f_std');
60
61figure(5);
62semilogy(c_std');
63
64figure(6);
65semilogy(k_std');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveinr.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveinr.m
new file mode 100755
index 0000000..a176e39
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveinr.m
@@ -0,0 +1,46 @@
1%SAVEINR Write an INRIMAGE format file
2%
3% SAVEINR(filename, im)
4%
5% Saves the specified image array in a INRIA image format file.
6%
7% SEE ALSO: loadinr
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11% Peter Corke 1996
12
13function saveinr(fname, im)
14
15 fid = fopen(fname, 'w');
16 [r,c] = size(im');
17
18 % build the header
19 hdr = [];
20 s = sprintf('#INRIMAGE-4#{\n');
21 hdr = [hdr s];
22 s = sprintf('XDIM=%d\n',c);
23 hdr = [hdr s];
24 s = sprintf('YDIM=%d\n',r);
25 hdr = [hdr s];
26 s = sprintf('ZDIM=1\n');
27 hdr = [hdr s];
28 s = sprintf('VDIM=1\n');
29 hdr = [hdr s];
30 s = sprintf('TYPE=float\n');
31 hdr = [hdr s];
32 s = sprintf('PIXSIZE=32\n');
33 hdr = [hdr s];
34 s = sprintf('SCALE=2**0\n');
35 hdr = [hdr s];
36 s = sprintf('CPU=sun\n#');
37 hdr = [hdr s];
38
39 % make it 256 bytes long and write it
40 hdr256 = zeros(1,256);
41 hdr256(1:length(hdr)) = hdr;
42 fwrite(fid, hdr256, 'uchar');
43
44 % now the binary data
45 fwrite(fid, im', 'float32');
46 fclose(fid)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/savepgm.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/savepgm.m
new file mode 100755
index 0000000..397f028
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/savepgm.m
@@ -0,0 +1,22 @@
1%SAVEPGM Write a PGM format file
2%
3% SAVEPGM(filename, im)
4%
5% Saves the specified image array in a binary (P5) format PGM image file.
6%
7% SEE ALSO: loadpgm
8%
9% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
10
11
12% Peter Corke 1994
13
14function savepgm(fname, im)
15
16 fid = fopen(fname, 'w');
17 [r,c] = size(im');
18 fprintf(fid, 'P5\n');
19 fprintf(fid, '%d %d\n', r, c);
20 fprintf(fid, '255\n');
21 fwrite(fid, im', 'uchar');
22 fclose(fid)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveppm.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveppm.m
new file mode 100755
index 0000000..0062ee0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saveppm.m
@@ -0,0 +1,25 @@
1%SAVEPPM Write a PPM format file
2%
3% SAVEPPM(filename, r, g, b)
4%
5% Saves the specified red, green and blue planes in a binary (P6)
6% format PPM image file.
7%
8% SEE ALSO: loadppm
9%
10% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
11
12
13% Peter Corke 1994
14
15function saveppm(fname, R, G, B)
16
17 fid = fopen(fname, 'w');
18 [r,c] = size(R');
19 fprintf(fid, 'P6\n');
20 fprintf(fid, '%d %d\n', r, c);
21 fprintf(fid, '255\n');
22 im = [R(:) G(:) B(:)];
23 im = reshape(c,r);
24 fwrite(fid, im, 'uchar');
25 fclose(fid)
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saving_calib.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saving_calib.m
new file mode 100755
index 0000000..e0575e0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/saving_calib.m
@@ -0,0 +1,27 @@
1fprintf(1,'\nSaving calibration results under Calib_Results.mat\n');
2
3check_active_images;
4
5if ~exist('solution_init'), solution_init = []; end;
6
7for kk = 1:n_ima,
8 if ~exist(['dX_' num2str(kk)]), eval(['dX_' num2str(kk) '= dX;']); end;
9 if ~exist(['dY_' num2str(kk)]), eval(['dY_' num2str(kk) '= dY;']); end;
10end;
11
12if ~exist('param_list'),
13 param_list = solution;
14end;
15
16
17string_save = 'save Calib_Results param_list active_images ind_active fc kc cc ex x y solution sol_with_center solution_init wintx winty n_ima type_numbering N_slots small_calib_image first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default KK inv_KK dX dY';
18
19for kk = 1:n_ima,
20 string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' H_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
21end;
22
23%fprintf(1,'To load later click on Load\n');
24
25fprintf(1,'done\n');
26
27eval(string_save);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/script_fit_distortion.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/script_fit_distortion.m
new file mode 100755
index 0000000..c5e5430
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/script_fit_distortion.m
@@ -0,0 +1,39 @@
1
2 satis_distort = 0;
3
4 disp(['Estimated focal: ' num2str(f_g) ' pixels']);
5
6 while ~satis_distort,
7
8 k_g = input('Guess for distortion factor kc ([]=0): ');
9
10 if isempty(k_g), k_g = 0; end;
11
12 xy_corners_undist = comp_distortion2([x' - c_g(1);y'-c_g(2)]/f_g,k_g);
13
14 xu = xy_corners_undist(1,:)';
15 yu = xy_corners_undist(2,:)';
16
17 [XXu] = projectedGrid ( [xu(1);yu(1)], [xu(2);yu(2)],[xu(3);yu(3)], [xu(4);yu(4)],n_sq_x+1,n_sq_y+1); % The full grid
18
19 XX = (ones(2,1)*(1 + k_g * sum(XXu.^2))) .* XXu;
20 XX(1,:) = f_g*XX(1,:)+c_g(1);
21 XX(2,:) = f_g*XX(2,:)+c_g(2);
22
23 figure(2);
24 image(I);
25 colormap(map);
26 zoom on;
27 hold on;
28 %plot(f_g*XXu(1,:)+c_g(1),f_g*XXu(2,:)+c_g(2),'ro');
29 plot(XX(1,:),XX(2,:),'r+');
30 title('The red crosses should be on the grid corners...');
31 hold off;
32
33 satis_distort = input('Satisfied with distortion? ([]=no, other=yes) ');
34
35 satis_distort = ~isempty(satis_distort);
36
37
38 end;
39 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center.m
new file mode 100755
index 0000000..15508e5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center.m
@@ -0,0 +1,19 @@
1%%% Selection of the calibration solution with center estimation
2
3if ~exist('sol_no_center'),
4 fprintf(1,'Need to calibrate before selecting solution without center. Maybe need to load Calib_Results.mat file.\n');
5 return;
6end;
7
8solution = sol_no_center;
9
10%%% Extraction of the final intrinsic and extrinsic paramaters:
11
12extract_parameters;
13comp_error_calib;
14
15fprintf(1,'\n\nCalibration results without principal point estimation:\n\n');
16fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
17fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
18fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
19fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center3D.m
new file mode 100755
index 0000000..070d81c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_no_center3D.m
@@ -0,0 +1,20 @@
1%%% Selection of the calibration solution with center estimation
2
3solution = sol_no_center;
4
5%%% Extraction of the final intrinsic and extrinsic paramaters:
6
7extract_parameters3D;
8
9
10fprintf(1,'\n\nCalibration results without principal point estimation:\n\n');
11fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
12fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
13fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
14
15
16%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
17
18graphout_calib3D;
19
20
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center.m
new file mode 100755
index 0000000..2df9ba8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center.m
@@ -0,0 +1,19 @@
1%%% Selection of the calibration solution with center estimation
2
3if ~exist('sol_with_center'),
4 fprintf(1,'Need to calibrate before selecting solution with center. Maybe need to load Calib_Results.mat file.\n');
5 return;
6end;
7
8solution = sol_with_center;
9
10%%% Extraction of the final intrinsic and extrinsic paramaters:
11
12extract_parameters;
13comp_error_calib;
14
15fprintf(1,'\n\nCalibration results with principal point estimation:\n\n');
16fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
17fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
18fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
19fprintf(1,'Pixel error: err = [ %3.5f %3.5f]\n\n',err_std);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center3D.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center3D.m
new file mode 100755
index 0000000..eb6f4bf
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/select_sol_with_center3D.m
@@ -0,0 +1,20 @@
1%%% Selection of the calibration solution with center estimation
2
3solution = sol_with_center;
4
5%%% Extraction of the final intrinsic and extrinsic paramaters:
6
7extract_parameters3D;
8
9
10fprintf(1,'\n\nCalibration results with principal point estimation:\n\n');
11fprintf(1,'Focal Length: fc = [ %3.5f %3.5f]\n',fc);
12fprintf(1,'Principal point: cc = [ %3.5f %3.5f]\n',cc);
13fprintf(1,'Distortion: kc = [ %3.5f %3.5f %3.5f %3.5f]\n',kc);
14
15
16%%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
17
18graphout_calib3D;
19
20
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/startup.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/startup.m
new file mode 100755
index 0000000..aad0fa4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/startup.m
@@ -0,0 +1,9 @@
1% Main camera calibration toolbox:
2
3calib_gui;
4
5%calib_gui;
6
7path(pwd,path);
8
9format compact
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/test_3d.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/test_3d.m
new file mode 100755
index 0000000..9f442f4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/test_3d.m
@@ -0,0 +1,80 @@
1Rc_1 = rodrigues(omc_1);
2Rc_2 = rodrigues(omc_2);
3Rc_3 = rodrigues(omc_3);
4Rc_4 = rodrigues(omc_4);
5Rc_5 = rodrigues(omc_5);
6Rc_6 = rodrigues(omc_6);
7Rc_7 = rodrigues(omc_7);
8Rc_8 = rodrigues(omc_8);
9Rc_9 = rodrigues(omc_9);
10
11Rc_10 = rodrigues(omc_10);
12Rc_11 = rodrigues(omc_11);
13Rc_12 = rodrigues(omc_12);
14Rc_13 = rodrigues(omc_13);
15Rc_14 = rodrigues(omc_14);
16Rc_15 = rodrigues(omc_15);
17Rc_16 = rodrigues(omc_16);
18Rc_17 = rodrigues(omc_17);
19Rc_18 = rodrigues(omc_18);
20
21
22
23RR1 = Rc_1'*Rc_10; % should be rodrigues([0;pi/2;0])
24TT1 = Rc_1'*(Tc_10-Tc_1); % should be [dX*n_sq_x_1;0;0]
25
26Xr_1 = RR1 * X_10 + TT1*ones(1,length(X_10));
27
28figure(1);
29plot3(X_1(1,:),X_1(2,:),X_1(3,:),'r+'); hold on;
30plot3(Xr_1(1,:),Xr_1(2,:),Xr_1(3,:),'g+');
31hold off;
32axis('equal');
33rotate3d on;
34view(0,0);
35xlabel('x');
36ylabel('y');
37zlabel('z');
38
39aaa = [];
40
41RR1 = Rc_1'*Rc_10; % should be rodrigues([0;pi/2;0])
42TT1 = Rc_1'*(Tc_10-Tc_1); % should be [dX*n_sq_x_1;0;0]
43err = rodrigues(RR1) - [0;pi/2;0]
44aaa = [aaa 2*sin(err(2)/2)*.33*1000];
45
46RR2 = Rc_2'*Rc_11; % should be rodrigues([0;pi/2;0])
47TT2 = Rc_2'*(Tc_11-Tc_2); % should be [dX*n_sq_x_1;0;0]
48err = rodrigues(RR2) - [0;pi/2;0]
49aaa = [aaa 2*sin(err(2)/2)*.33*1000];
50
51RR3 = Rc_3'*Rc_12; % should be rodrigues([0;pi/2;0])
52TT3 = Rc_3'*(Tc_12-Tc_3); % should be [dX*n_sq_x_1;0;0]
53err = rodrigues(RR3) - [0;pi/2;0]
54aaa = [aaa 2*sin(err(2)/2)*.33*1000];
55
56RR4 = Rc_4'*Rc_13; % should be rodrigues([0;pi/2;0])
57TT4 = Rc_4'*(Tc_13-Tc_4); % should be [dX*n_sq_x_1;0;0]
58err = rodrigues(RR4) - [0;pi/2;0]
59aaa = [aaa 2*sin(err(2)/2)*.33*1000];
60
61RR5 = Rc_5'*Rc_14; % should be rodrigues([0;pi/2;0])
62TT5 = Rc_5'*(Tc_14-Tc_5); % should be [dX*n_sq_x_1;0;0]
63err = rodrigues(RR5) - [0;pi/2;0]
64aaa = [aaa 2*sin(err(2)/2)*.33*1000];
65
66RR6 = Rc_6'*Rc_15; % should be rodrigues([0;pi/2;0])
67TT6 = Rc_6'*(Tc_15-Tc_6); % should be [dX*n_sq_x_1;0;0]
68err = rodrigues(RR6) - [0;pi/2;0]
69aaa = [aaa 2*sin(err(2)/2)*.33*1000];
70
71RR7 = Rc_7'*Rc_16; % should be rodrigues([0;pi/2;0])
72TT7 = Rc_7'*(Tc_16-Tc_7); % should be [dX*n_sq_x_1;0;0]
73err = rodrigues(RR7) - [0;pi/2;0]
74aaa = [aaa 2*sin(err(2)/2)*.33*1000];
75
76RR8 = Rc_8'*Rc_17; % should be rodrigues([0;pi/2;0])
77TT8 = Rc_8'*(Tc_17-Tc_8); % should be [dX*n_sq_x_1;0;0]
78err = rodrigues(RR8) - [0;pi/2;0]
79aaa = [aaa 2*sin(err(2)/2)*.33*1000];
80
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/undistort_image.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/undistort_image.m
new file mode 100755
index 0000000..6393d78
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/undistort_image.m
@@ -0,0 +1,88 @@
1%%% INPUT THE IMAGE FILE NAME:
2
3dir;
4
5fprintf(1,'\n');
6disp('Program that undistort an image');
7disp('The intrinsic camera parameters are assumed to be known (previously computed)');
8
9fprintf(1,'\n');
10image_name = input('Image name (full name without extension): ','s');
11
12format_image2 = '0';
13
14while format_image2 == '0',
15
16 format_image2 = input('Image format: ([]=''r''=''ras'', ''b''=''bmp'', ''t''=''tif'', ''p''=''pgm'', ''j''=''jpg'') ','s');
17
18 if isempty(format_image2),
19 format_image2 = 'ras';
20 end;
21
22 if lower(format_image2(1)) == 'b',
23 format_image2 = 'bmp';
24 else
25 if lower(format_image2(1)) == 't',
26 format_image2 = 'tif';
27 else
28 if lower(format_image2(1)) == 'p',
29 format_image2 = 'pgm';
30 else
31 if lower(format_image2(1)) == 'j',
32 format_image2 = 'jpg';
33 else
34 if lower(format_image2(1)) == 'r',
35 format_image2 = 'ras';
36 else
37 disp('Invalid image format');
38 format_image2 = '0'; % Ask for format once again
39 end;
40 end;
41 end;
42 end;
43 end;
44end;
45
46ima_name = [image_name '.' format_image];
47
48
49
50%%% READ IN IMAGE:
51
52if format_image(1) == 'p',
53 I = double(pgmread(ima_name));
54else
55 if format_image(1) == 'r',
56 I = readras(ima_name);
57 else
58 I = double(imread(ima_name));
59 end;
60end;
61
62if size(I,3)>1,
63 I = I(:,:,2);
64end;
65
66
67%% SHOW THE ORIGINAL IMAGE:
68
69figure(2);
70image(I);
71colormap(gray(256));
72title('Original image (with distortion) - Stored in array I');
73drawnow;
74
75
76%% UNDISTORT THE IMAGE:
77
78fprintf(1,'Compututing the undistorted image...\n')
79
80[I2] = rect(I,eye(3),fc,cc,kc,KK);
81
82
83figure(3);
84image(I2);
85colormap(gray(256));
86title('Undistorted image - Stored in array I2');
87drawnow;
88
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/writeras.m b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/writeras.m
new file mode 100755
index 0000000..c7eb7bc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj/writeras.m
@@ -0,0 +1,105 @@
1function writeras(filename, image, map);
2%WRITERAS Write an image file in sun raster format.
3% WRITERAS('imagefile.ras', image_matrix, map) writes a
4% "sun.raster" image file.
5
6% Written by Thomas K. Leung 3/30/93.
7% @ California Institute of Technology.
8
9
10% PC and UNIX version of writeras - Jean-Yves Bouguet - Dec. 1998
11
12dot = max(find(filename == '.'));
13suffix = filename(dot+1:dot+3);
14
15if nargin < 3,
16 map = [];
17end;
18
19if(strcmp(suffix, 'ras'))
20 %Write header
21
22 fp = fopen(filename, 'wb');
23 if(fp < 0) error(['Cannot open ' filename '.']), end
24
25 [height, width] = size(image);
26 image = image - 1;
27 mapsize = size(map, 1)*size(map,2);
28 %fwrite(fp, ...
29 % [1504078485, width, height, 8, height*width, 1, 1, mapsize], ...
30 % 'long');
31
32
33 zero_str = '00000000';
34
35 % MAGIC NUMBER:
36
37
38 fwrite(fp,89,'uchar');
39 fwrite(fp,166,'uchar');
40 fwrite(fp,106,'uchar');
41 fwrite(fp,149,'uchar');
42
43 width_str = dec2hex(width);
44 width_str = [zero_str(1:8-length(width_str)) width_str];
45
46 for ii = 1:2:7,
47 fwrite(fp,hex2dec(width_str(ii:ii+1)),'uchar');
48 end;
49
50
51 height_str = dec2hex(height);
52 height_str = [zero_str(1:8-length(height_str)) height_str];
53
54 for ii = 1:2:7,
55 fwrite(fp,hex2dec(height_str(ii:ii+1)),'uchar');
56 end;
57
58 fwrite(fp,0,'uchar');
59 fwrite(fp,0,'uchar');
60 fwrite(fp,0,'uchar');
61 fwrite(fp,8,'uchar');
62
63 ll = height*width;
64 ll_str = dec2hex(ll);
65 ll_str = [zero_str(1:8-length(ll_str)) ll_str];
66
67 for ii = 1:2:7,
68 fwrite(fp,hex2dec(ll_str(ii:ii+1)),'uchar');
69 end;
70
71 fwrite(fp,0,'uchar');
72 fwrite(fp,0,'uchar');
73 fwrite(fp,0,'uchar');
74 fwrite(fp,1,'uchar');
75 fwrite(fp,0,'uchar');
76 fwrite(fp,0,'uchar');
77 fwrite(fp,0,'uchar');
78 fwrite(fp,~~mapsize,'uchar');
79
80 mapsize_str = dec2hex(mapsize);
81 mapsize_str = [zero_str(1:8-length(mapsize_str)) mapsize_str];
82
83 %keyboard;
84
85 for ii = 1:2:7,
86 fwrite(fp,hex2dec(mapsize_str(ii:ii+1)),'uchar');
87 end;
88
89
90 if mapsize ~= 0
91 map = min(255, fix(255*map));
92 fwrite(fp, map, 'uchar');
93 end
94 if rem(width,2) == 1
95 image = [image'; zeros(1, height)]';
96 top = 255 * ones(size(image));
97 fwrite(fp, min(top,image)', 'uchar');
98 else
99 top = 255 * ones(size(image));
100 fwrite(fp, min(top,image)', 'uchar');
101 end
102 fclose(fp);
103else
104 error('Image file name must end in either ''ras'' or ''rast''.');
105end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj2/TOOLBOX_calib.tar b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj2/TOOLBOX_calib.tar
new file mode 100755
index 0000000..36d5de9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/calib_bouguetj2/TOOLBOX_calib.tar
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC.m b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC.m
new file mode 100755
index 0000000..d612780
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC.m
@@ -0,0 +1,26 @@
1function [v,d] = Ncut_IC(I,nb_radius_IC);
2%
3% [v,d] = Ncut_IC(I,nb_radius_IC);
4%
5
6if nargin<2,
7 nb_radius_IC = 5;
8end
9
10I = I/max(I(:));
11
12eg_par = [16,2, 21,3]; eg_th = 0;
13
14nv = 11; reg_fac = 0.01;
15
16[ex,ey,egx,egy,eg_par,eg_th,emag,ephase] = quadedgep(I,eg_par,eg_th);
17
18
19nb_radius_IC= 10;
20sample_rate = 0.2;
21disp('setupW\n');
22[w_i,w_j] = cimgnbmap(size(I),nb_radius_IC,sample_rate);
23w = affinityic(emag,ephase,w_i,w_j);
24disp('computeNcut');
25[v,d] = ncut(w,nv,[],reg_fac);
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m.m b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m.m
new file mode 100755
index 0000000..146acf9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m.m
@@ -0,0 +1,42 @@
1function [v,d] = Ncut_IC_m(I,mask,nb_radius_IC,sig_IC);
2%
3% [v,d] = Ncut_IC_m(I,mask,nb_radius_IC,sig_IC);
4%
5
6if nargin<2,
7 mask = ones(size(I));
8end
9
10if nargin<3,
11 nb_radius_IC = 10;
12end
13
14if nargin<4,
15 sig_IC = 0.03;
16end
17
18%%% normalize the image
19I = I/max(I(:));
20
21%%% edge detecting parameter, [num_ori, sig, win_size, enlongation factor]
22eg_par = [6,2, 21,3]; eg_th = 0.01;
23
24%% number of eigenvectors+ regulization factors
25nv = 10; reg_fac = 0.0;
26
27%% compute the edge response
28[ex,ey,egx,egy,eg_par,eg_th,emag,ephase] = quadedgep(I,eg_par,eg_th);
29
30%%% setup Wij connection pattern
31sample_rate = 0.1;
32[w_i,w_j] = cimgnbmap(size(I),nb_radius_IC,sample_rate);
33
34%%% compute Wij with IC
35emag = mask.*emag;
36w = affinityic(emag,ephase,w_i,w_j,sig_IC);
37
38%show_dist_w(I,w);
39%%% running Ncut
40[v,d] = ncut(w,nv);
41
42v = reshape(v,size(I,1),size(I,2),size(v,2));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m2.m b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m2.m
new file mode 100755
index 0000000..9668b19
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/Ncut_IC_m2.m
@@ -0,0 +1,51 @@
1function [v,d] = Ncut_IC_m(I,mask,nb_radius_IC,sig_IC);
2%
3% [v,d] = Ncut_IC_m(I,mask,nb_radius_IC,sig_IC);
4%
5
6if nargin<2,
7 mask = ones(size(I));
8end
9
10if nargin<3,
11 nb_radius_IC = 10;
12end
13
14if nargin<4,
15 sig_IC = 0.03;
16end
17
18%%% normalize the image
19I = I/max(I(:));
20
21%%% edge detecting parameter, [num_ori, sig, win_size, enlongation factor]
22eg_par = [6,2, 21,3]; eg_th = 0.01;
23
24%% number of eigenvectors+ regulization factors
25nv = 10; reg_fac = 0.0;
26
27%% compute the edge response
28[nr,nc,nb] = size(I);
29emag = zeros(nr,nc);
30ephase = zeros(nr,nc);
31for j=1:nb,
32 [ex,ey,egx,egy,eg_par,eg_th,emag1,ephase1] = quadedgep(I(:,:,j),eg_par,eg_th);
33 mask = emag1>emag;
34 ephase = ephase+ mask.*ephase1;
35 emag = emag + mask.*emag1;
36end
37
38
39%%% setup Wij connection pattern
40sample_rate = 0.1;
41[w_i,w_j] = cimgnbmap(size(I),nb_radius_IC,sample_rate);
42
43%%% compute Wij with IC
44emag = mask.*emag;
45w = affinityic(emag,ephase,w_i,w_j,sig_IC);
46
47%show_dist_w(I,w);
48%%% running Ncut
49[v,d] = ncut(w,nv);
50
51v = reshape(v,size(I,1),size(I,2),size(v,2));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.c b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.c
new file mode 100755
index 0000000..e48762a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.c
@@ -0,0 +1,186 @@
1/*================================================================
2* function w = affinityic(emag,ephase,pi,pj,sigma)
3* Input:
4* emag = edge strength at each pixel
5* ephase = edge phase at each pixel
6* [pi,pj] = index pair representation for MALTAB sparse matrices
7* sigma = sigma for IC energy
8* Output:
9* w = affinity with IC at [pi,pj]
10*
11
12% test sequence
13f = synimg(10);
14[i,j] = cimgnbmap(size(f),2);
15[ex,ey,egx,egy] = quadedgep(f);
16a = affinityic(ex,ey,egx,egy,i,j)
17show_dist_w(f,a);
18
19* Jianbo Shi, Stella X. Yu, Nov 19, 2001.
20*=================================================================*/
21
22# include "mex.h"
23# include "math.h"
24
25void mexFunction(
26 int nargout,
27 mxArray *out[],
28 int nargin,
29 const mxArray *in[]
30)
31{
32 /* declare variables */
33 int nr, nc, np, total;
34 int i, j, k, ix, iy, jx, jy, ii, jj, iip1, jjp1, iip2, jjp2, step;
35 double sigma, di, dj, a, z, maxori, phase1, phase2, slope;
36 int *ir, *jc;
37 unsigned long *pi, *pj;
38 double *emag, *ephase, *w;
39
40 /* check argument */
41 if (nargin<4) {
42 mexErrMsgTxt("Four input arguments required");
43 }
44 if (nargout>1) {
45 mexErrMsgTxt("Too many output arguments");
46 }
47
48 /* get edgel information */
49 nr = mxGetM(in[0]);
50 nc = mxGetN(in[0]);
51 if ( nr*nc ==0 || nr != mxGetM(in[1]) || nc != mxGetN(in[1]) ) {
52 mexErrMsgTxt("Edge magnitude and phase shall be of the same image size");
53 }
54 emag = mxGetPr(in[0]);
55 ephase = mxGetPr(in[1]);
56 np = nr * nc;
57
58 /* get new index pair */
59 if (!mxIsUint32(in[2]) | !mxIsUint32(in[3])) {
60 mexErrMsgTxt("Index pair shall be of type UINT32");
61 }
62 if (mxGetM(in[3]) * mxGetN(in[3]) != np + 1) {
63 mexErrMsgTxt("Wrong index representation");
64 }
65 pi = mxGetData(in[2]);
66 pj = mxGetData(in[3]);
67
68 /* create output */
69 out[0] = mxCreateSparse(np,np,pj[np],mxREAL);
70 if (out[0]==NULL) {
71 mexErrMsgTxt("Not enough memory for the output matrix");
72 }
73 w = mxGetPr(out[0]);
74 ir = mxGetIr(out[0]);
75 jc = mxGetJc(out[0]);
76
77 /* find my sigma */
78 if (nargin<5) {
79 sigma = 0;
80 for (k=0; k<np; k++) {
81 if (emag[k]>sigma) { sigma = emag[k]; }
82 }
83 sigma = sigma / 10;
84 printf("sigma = %6.5f",sigma);
85 } else {
86 sigma = mxGetScalar(in[4]);
87 }
88 a = 1.0/ (sigma);
89
90 /* computation */
91 total = 0;
92 for (j=0; j<np; j++) {
93
94 jc[j] = total;
95 jx = j / nr; /* col */
96 jy = j % nr; /* row */
97
98 for (k=pj[j]; k<pj[j+1]; k++) {
99
100 i = pi[k];
101
102 if (i==j) {
103 maxori = 1;
104
105 } else {
106
107 ix = i / nr;
108 iy = i % nr;
109
110 /* scan */
111 di = (double) (iy - jy);
112 dj = (double) (ix - jx);
113
114 maxori = 0.;
115 phase1 = ephase[j];
116
117
118 /* sample in i direction */
119 if (abs(di) >= abs(dj)) {
120 slope = dj / di;
121 step = (iy>=jy) ? 1 : -1;
122
123 iip1 = jy;
124 jjp1 = jx;
125
126
127 for (ii=0;ii<abs(di);ii++){
128 iip2 = iip1 + step;
129 jjp2 = (int)(0.5 + slope*(iip2-jy) + jx);
130
131 phase2 = ephase[iip2+jjp2*nr];
132
133 if (phase1 != phase2) {
134 z = (emag[iip1+jjp1*nr] + emag[iip2+jjp2*nr]);
135 if (z > maxori){
136 maxori = z;
137 }
138 }
139
140 iip1 = iip2;
141 jjp1 = jjp2;
142 phase1 = phase2;
143 }
144
145 /* sample in j direction */
146 } else {
147 slope = di / dj;
148 step = (ix>=jx) ? 1: -1;
149
150 jjp1 = jx;
151 iip1 = jy;
152
153
154 for (jj=0;jj<abs(dj);jj++){
155 jjp2 = jjp1 + step;
156 iip2 = (int)(0.5+ slope*(jjp2-jx) + jy);
157
158 phase2 = ephase[iip2+jjp2*nr];
159
160 if (phase1 != phase2){
161 z = (emag[iip1+jjp1*nr] + emag[iip2+jjp2*nr]);
162 if (z > maxori){
163 maxori = z;
164 }
165
166 }
167
168 iip1 = iip2;
169 jjp1 = jjp2;
170 phase1 = phase2;
171 }
172 }
173
174 maxori = 0.5 * maxori*a;
175 maxori = exp(-maxori*maxori);
176 }
177 ir[total] = i;
178
179 w[total] = maxori + 0.005;
180 total = total + 1;
181
182 } /* i */
183 } /* j */
184
185 jc[np] = total;
186}
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexa64 b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexa64
new file mode 100755
index 0000000..e60b4d1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexa64
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexglx b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexglx
new file mode 100755
index 0000000..5edb5d8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/affinityic.mexglx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/anisodiff.m b/SD-VBS/common/toolbox/toolbox_basic/common/anisodiff.m
new file mode 100755
index 0000000..b576d8f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/anisodiff.m
@@ -0,0 +1,20 @@
1function [outimage] = anisodiff(inimage,iterations,K)
2% [outimage] = anisodiff(inimage,iterations,K)
3% Pietro's anisotropic diffusion routine
4
5lambda = 0.25;
6outimage = inimage; [m,n] = size(inimage);
7
8rowC = [1:m]; rowN = [1 1:m-1]; rowS = [2:m m];
9colC = [1:n]; colE = [1 1:n-1]; colW = [2:n n];
10
11for i=1:iterations,
12 deltaN = outimage(rowN,colC) - outimage(rowC,colC);
13 deltaE = outimage(rowC,colE) - outimage(rowC,colC);
14
15 fluxN = deltaN .* exp( - ((1/K) * abs(deltaN)).^2 );
16 fluxE = deltaE .* exp( - ((1/K) * abs(deltaE)).^2 );
17
18 outimage = outimage + lambda * (fluxN - fluxN(rowS,colC) + fluxE - fluxE(rowC,colW));
19end
20
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/bin.m b/SD-VBS/common/toolbox/toolbox_basic/common/bin.m
new file mode 100755
index 0000000..e2c3c90
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/bin.m
@@ -0,0 +1,39 @@
1function [i, nnbins] = bin(x, dx, x0, x1);
2%
3% [i, nbins] = bin(x, dx, x0, x1);
4%
5% Returns the vector of indices, starting from 1,
6% corresponding to the chosen bin size, dx,
7% start x0 and end x1. If x1 is omitted, x1 = max(x) - dx/2.
8% If x0 is omitted, x0 = min(x) + dx/2. If dx is omitted, the data
9% are divided into 10 classes. Note that outliers are not removed.
10%
11% Tested under MatLab 4.2, 5.0, and 5.1.
12%
13
14% 17.1.97, Oyvind.Breivik@gfi.uib.no.
15%
16% Oyvind Breivik
17% Department of Geophysics
18% University of Bergen
19% NORWAY
20
21N = 10; % Default is 10 classes
22
23if nargin < 2
24 dx = (max(x) - min(x))/N;
25end
26if nargin < 3
27 x0 = min(x) + dx/2;
28end
29if nargin < 4
30 x1 = max(x) - dx/2;
31end
32nbins = round((x1 - x0)/dx) + 1;
33i = round((x - x0)/dx) + 1;
34%in = (i >= 1) & (i <= nbins); % Indices are within range [1, nbins].
35%i = i(in);
36
37if nargout > 1
38 nnbins = nbins;
39end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.c b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.c
new file mode 100755
index 0000000..1595b68
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.c
@@ -0,0 +1,189 @@
1/*================================================================
2* function [i,j] = cimgnbmap([nr,nc], nb_r, sample_rate)
3* computes the neighbourhood index matrix of an image,
4* with each neighbourhood sampled.
5* Input:
6* [nr,nc] = image size
7* nb_r = neighbourhood radius, could be [r_i,r_j] for i,j
8* sample_rate = sampling rate, default = 1
9* Output:
10* [i,j] = each is a column vector, give indices of neighbour pairs
11* UINT32 type
12* i is of total length of valid elements, 0 for first row
13* j is of length nr * nc + 1
14*
15* See also: imgnbmap.c, id2cind.m
16*
17* Examples:
18* [i,j] = imgnbmap(10, 20); % [10,10] are assumed
19*
20* Stella X. Yu, Nov 12, 2001.
21
22% test sequence:
23nr = 15;
24nc = 15;
25nbr = 1;
26[i,j] = cimgnbmap([nr,nc], nbr);
27mask = csparse(i,j,ones(length(i),1),nr*nc);
28show_dist_w(rand(nr,nc),mask)
29
30*=================================================================*/
31
32# include "mex.h"
33# include "math.h"
34
35void mexFunction(
36 int nargout,
37 mxArray *out[],
38 int nargin,
39 const mxArray *in[]
40)
41{
42 /* declare variables */
43 int nr, nc, np, nb, total;
44 double *dim, sample_rate;
45 int r_i, r_j, a1, a2, b1, b2, self, neighbor;
46 int i, j, k, s, t, nsamp, th_rand, no_sample;
47 unsigned long *p, *qi, *qj;
48
49 /* check argument */
50 if (nargin < 2) {
51 mexErrMsgTxt("Two input arguments required");
52 }
53 if (nargout> 2) {
54 mexErrMsgTxt("Too many output arguments.");
55 }
56
57 /* get image size */
58 i = mxGetM(in[0]);
59 j = mxGetN(in[0]);
60 dim = mxGetData(in[0]);
61 nr = (int)dim[0];
62 if (j>1 || i>1) {
63 nc = (int)dim[1];
64 } else {
65 nc = nr;
66 }
67 np = nr * nc;
68
69 /* get neighbourhood size */
70 i = mxGetM(in[1]);
71 j = mxGetN(in[1]);
72 dim = mxGetData(in[1]);
73 r_i = (int)dim[0];
74 if (j>1 || i>1) {
75 r_j = (int)dim[1];
76 } else {
77 r_j = r_i;
78 }
79 if (r_i<0) { r_i = 0; }
80 if (r_j<0) { r_j = 0; }
81
82 /* get sample rate */
83 if (nargin==3) {
84 sample_rate = (mxGetM(in[2])==0) ? 1: mxGetScalar(in[2]);
85 } else {
86 sample_rate = 1;
87 }
88 /* prepare for random number generator */
89 if (sample_rate<1) {
90 srand( (unsigned)time( NULL ) );
91 th_rand = (int)ceil((double)RAND_MAX * sample_rate);
92 no_sample = 0;
93 } else {
94 sample_rate = 1;
95 th_rand = RAND_MAX;
96 no_sample = 1;
97 }
98
99 /* figure out neighbourhood size */
100
101 nb = (r_i + r_i + 1) * (r_j + r_j + 1);
102 if (nb>np) {
103 nb = np;
104 }
105 nb = (int)ceil((double)nb * sample_rate);
106
107 /* intermediate data structure */
108 p = mxCalloc(np * (nb+1), sizeof(unsigned long));
109 if (p==NULL) {
110 mexErrMsgTxt("Not enough space for my computation.");
111 }
112
113 /* computation */
114 total = 0;
115 for (j=0; j<nc; j++) {
116 for (i=0; i<nr; i++) {
117
118 self = i + j * nr;
119
120 /* put self in, otherwise the index is not ordered */
121 p[self] = p[self] + 1;
122 p[self+p[self]*np] = self;
123
124 /* j range */
125 b1 = j;
126 b2 = j + r_j;
127 if (b2>=nc) { b2 = nc-1; }
128
129 /* i range */
130 a1 = i - r_i;
131 if (a1<0) { a1 = 0; }
132 a2 = i + r_i;
133 if (a2>=nr) { a2 = nr-1; }
134
135 /* number of more samples needed */
136 nsamp = nb - p[self];
137
138 k = 0;
139 t = b1;
140 s = i + 1;
141 if (s>a2) {
142 s = a1;
143 t = t + 1;
144 }
145 while (k<nsamp && t<=b2) {
146 if (no_sample || (rand()<th_rand)) {
147 k = k + 1;
148 neighbor = s + t * nr;
149
150 p[self] = p[self] + 1;
151 p[self+p[self]*np] = neighbor;
152
153 p[neighbor] = p[neighbor] + 1;
154 p[neighbor+p[neighbor]*np] = self;
155 }
156 s = s + 1;
157 if (s>a2) {
158 s = a1;
159 t = t + 1;
160 }
161 } /* k */
162
163 total = total + p[self];
164 } /* i */
165 } /* j */
166
167 /* i, j */
168 out[0] = mxCreateNumericMatrix(total, 1, mxUINT32_CLASS, mxREAL);
169 out[1] = mxCreateNumericMatrix(np+1, 1, mxUINT32_CLASS, mxREAL);
170 qi = mxGetData(out[0]);
171 qj = mxGetData(out[1]);
172 if (out[0]==NULL || out[1]==NULL) {
173 mexErrMsgTxt("Not enough space for the output matrix.");
174 }
175
176 total = 0;
177 for (j=0; j<np; j++) {
178 qj[j] = total;
179 s = j + np;
180 for (t=0; t<p[j]; t++) {
181 qi[total] = p[s];
182 total = total + 1;
183 s = s + np;
184 }
185 }
186 qj[np] = total;
187
188 mxFree(p);
189}
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexa64 b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexa64
new file mode 100755
index 0000000..19eabe1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexa64
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexglx b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexglx
new file mode 100755
index 0000000..6f3bb32
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/cimgnbmap.mexglx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/density.m b/SD-VBS/common/toolbox/toolbox_basic/common/density.m
new file mode 100755
index 0000000..23d88cc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/density.m
@@ -0,0 +1,133 @@
1function [rrho, xxvec, yyvec] = density(x, y, dx, dy, xy0);
2% [rho, xvec, yvec] = density(x, y, dx, dy, [x0 x1 y0 y1]);
3%
4% 2-D probability density plot.
5%
6% Input: Vectors x and y of equal length. If dx and/or dy are omitted, the
7% default is 75 bins in each direction.
8%
9% If dx or dy is negative, then the variable is taken as the number of
10% bins rather than a grid resolution.
11%
12% The vector containing the limits can be padded with NaNs if only
13% certain limits are desired, e g if x0 and y1 are wanted:
14%
15% density(x, y, [.5 nan nan 45])
16%
17% Output: The density matrix RHO together with vectors XVEC and YVEC.
18% If no output arguments are specified, DENSITY will plot the density
19% function with the prescribed axes using PCOLOR.
20%
21% Requires bin.m. Tested under MatLab 4.2, 5.0, and 5.1.
22%
23% See also bin.m for further details about dx, x0, etc, and ffgrid.m.
24%
25
26% 1.9.97 Oyvind.Breivik@gfi.uib.no.
27%
28% Oyvind Breivik
29% Department of Geophysics
30% University of Bergen
31% NORWAY
32
33DX = -75; % Default grid size
34
35x = x(:);
36
37if nargin < 2
38 y = x;
39end
40
41y = y(:);
42
43xy = NaN*ones(1,4);
44
45if (nargin < 4)
46 xy0 = min(x);
47end
48
49if (nargin == 3 & length(dx) > 1)
50 xy0 = dx;
51 dx = DX;
52end
53
54if nargin < 3
55 dx = DX;
56end
57
58if (nargin == 4 & length(dy) > 1)
59 xy0 = dy;
60 dy = dx;
61end
62if nargin < 4
63 dy = dx;
64end
65
66nxy = length(xy0);
67xy(1:nxy) = xy0;
68
69if (isnan(xy(4)))
70 xy(4) = max(y);
71end
72if (isnan(xy(3)))
73 xy(3) = min(y);
74end
75if (isnan(xy(2)))
76 xy(2) = max(x);
77end
78if (isnan(xy(1)))
79 xy(1) = min(x);
80end
81x0 = xy(1); x1 = xy(2); y0 = xy(3); y1 = xy(4);
82
83if (dx < 0)
84 dx = (x1 - x0)/abs(dx);
85end
86if (dy < 0)
87 dy = (y1 - y0)/abs(dy);
88end
89
90ix = bin(x, dx, x0, x1);
91iy = bin(y, dy, y0, y1); % bin data in (x,y)-space
92
93xvec = x0:dx:x1;
94yvec = y0:dy:y1;
95
96nx = length(xvec);
97ny = length(yvec);
98
99inx = (ix >= 1) & (ix <= nx);
100iny = (iy >= 1) & (iy <= ny);
101in = (inx & iny);
102ix = ix(in); iy = iy(in);
103N = length(ix); % how many datapoints are left now?
104
105rho = zeros(length(xvec), length(yvec)) + eps;
106
107for i = 1:N
108 rho(ix(i), iy(i)) = rho(ix(i), iy(i)) + 1;
109end
110
111rho = rho/(N*dx*dy); % Density is n per dx per dy
112
113rho = rho'; % Get in shape
114
115if nargout == 0
116 pcolor(xvec, yvec, sqrt(rho)); shading interp; axis image;
117 colorbar
118 colormap jet
119 xlabel(inputname(1))
120 ylabel(inputname(2))
121 dum = size(rho');
122 str = sprintf('%d data points, grid: %dx%d', N, dum(1)-1, dum(2)-1);
123 title(str);
124end
125
126if nargout > 0
127 rrho = rho;
128end
129
130if nargout > 1
131 xxvec = xvec;
132 yyvec = yvec;
133end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/find_edge.m b/SD-VBS/common/toolbox/toolbox_basic/common/find_edge.m
new file mode 100755
index 0000000..4299c29
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/find_edge.m
@@ -0,0 +1,24 @@
1function [edgemap,mag,th] = find_edge(I,sig,mag_thld)
2%
3% [edgemap,mag,th] = find_edge(I,sig,mag_thld)
4%
5
6if nargin<2,
7 sig = 1;
8end
9
10if nargin<3,
11 mag_thld = 1/30;
12end
13
14I = I/max(I(:));
15
16ismax = 1;r = 1;
17
18[gx,gy] = grad(I,sig);
19[th,mag] = cart2pol(gy,gx);
20
21g = cat(3,gy,gx);
22edgemap = nonmaxsup(g,ismax,r);
23edgemap = edgemap.*(mag>mag_thld);
24
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/grad.m b/SD-VBS/common/toolbox/toolbox_basic/common/grad.m
new file mode 100755
index 0000000..05fce39
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/grad.m
@@ -0,0 +1,28 @@
1% gradient of an image
2% coordinates (r, c) follow matrix convention;
3% the gaussian is truncated at x = +- tail, and there are samples samples
4% inbetween, where samples = hsamples * 2 + 1
5
6function[gr,gc] = gradient(image, hsamples,cm)
7
8if nargin <3,
9 cm = 'same';
10end
11
12tail=4;
13samples = hsamples * 2 + 1;
14
15x = linspace(-tail, tail, samples);
16gauss = exp(-x.^2);
17n = gauss * ones(samples,1);
18gauss = gauss/n;
19
20gaussderiv = -x.*gauss;
21n = -gaussderiv*linspace(1,samples,samples)';
22gaussderiv = gaussderiv/n;
23
24%gr = conv2(conv2(image, gaussderiv','valid'), gauss,'valid');
25%gc = conv2(conv2(image, gaussderiv,'valid'), gauss','valid');
26
27gr = conv2(conv2(image, gaussderiv',cm), gauss,cm);
28gc = conv2(conv2(image, gaussderiv,cm), gauss',cm);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_even2.m b/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_even2.m
new file mode 100755
index 0000000..937f9bd
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_even2.m
@@ -0,0 +1,45 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz,enlong)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6if nargin<4,
7 enlong = 3;
8end
9
10enlong = 2*enlong
11
12% definine filterbank
13%num_ori=6;
14%num_scale=3;
15
16num_scale = length(filter_scales);
17
18M1=wsz; % size in pixels
19M2=M1;
20
21ori_incr=180/num_ori;
22ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
23
24FB=zeros(M1,M2,num_ori,num_scale);
25
26% elongated filter set
27counter = 1;
28
29for m=1:num_scale
30 for n=1:num_ori
31 % r=12 here is equivalent to Malik's r=3;
32 f=doog2(filter_scales(m),enlong,ori_offset+(n-1)*ori_incr,M1);
33 FB(:,:,n,m)=f;
34 end
35end
36
37FB=reshape(FB,M1,M2,num_scale*num_ori);
38total_num_filt=size(FB,3);
39
40for j=1:total_num_filt,
41 F = FB(:,:,j);
42 a = sum(sum(abs(F)));
43 FB(:,:,j) = FB(:,:,j)/a;
44end
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_odd2.m b/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_odd2.m
new file mode 100755
index 0000000..0059dca
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/make_filterbank_odd2.m
@@ -0,0 +1,46 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz,enlong)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6if nargin<4,
7 enlong = 3;
8end
9
10enlong = enlong*2;
11
12% definine filterbank
13%num_ori=6;
14%num_scale=3;
15
16num_scale = length(filter_scales);
17
18M1=wsz; % size in pixels
19M2=M1;
20
21ori_incr=180/num_ori;
22ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
23
24FB=zeros(M1,M2,num_ori,num_scale);
25
26
27% elongated filter set
28counter = 1;
29
30for m=1:num_scale
31 for n=1:num_ori
32 % r=12 here is equivalent to Malik's r=3;
33 f=doog1(filter_scales(m),enlong,ori_offset+(n-1)*ori_incr,M1);
34 FB(:,:,n,m)=f;
35 end
36end
37
38FB=reshape(FB,M1,M2,num_scale*num_ori);
39total_num_filt=size(FB,3);
40
41for j=1:total_num_filt,
42 F = FB(:,:,j);
43 a = sum(sum(abs(F)));
44 FB(:,:,j) = FB(:,:,j)/a;
45end
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/max_supress2.m b/SD-VBS/common/toolbox/toolbox_basic/common/max_supress2.m
new file mode 100755
index 0000000..05b5f11
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/max_supress2.m
@@ -0,0 +1,59 @@
1function NMS = max_supress2(data,ismax);
2%
3% NMS = max_supress(data,ismax);
4%
5% data: [nr,nc,nfilter,nscale]
6% of filter mag. map
7% ismax: 1 local max, 0 local min
8%
9
10[nr,nc,nfilter,nscale] = size(data);
11
12% set up the orthognal neighbourhood for each oriented filter
13if nfilter == 6,
14 nbr_template=[1 1 1 0 -1 -1
15 0 1 1 1 1 1];
16else
17 nbr_template=[1 0 ;
18 0 1];
19end
20
21%% for each scale, compute the dominate filter response
22canny_dir_I = zeros(nr,nc,nscale);
23
24for m = 1:nscale,
25 [max_Ori_resp_I,Ori_sca_I] = max(data(:,:,:,m),[],3);
26 canny_dir_I(:,:,m) = Ori_sca_I;
27end
28
29max_Ori_resp_small = max_Ori_resp_I(2:end-1,2:end-1);
30canny_dir = canny_dir_I(2:end-1,2:end-1);
31
32%%
33
34NMS = zeros(nr,nc,nscale);
35
36
37for m = 1:nscale,
38
39 [x,y] = meshgrid(2:nc-1,2:nr-1);
40 xid = x(:)+nbr_template(2,canny_dir(:))';
41 yid = y(:)+nbr_template(1,canny_dir(:))';
42 id1 = (xid-1)*nr+yid;
43
44 xid = x(:)-nbr_template(2,canny_dir(:))';
45 yid = y(:)-nbr_template(1,canny_dir(:))';
46 id2 = (xid-1)*nr+yid;
47 if ismax,
48 a = (max_Ori_resp_small(:)>max_Ori_resp_I(id1(:))) .* (max_Ori_resp_small(:)>max_Ori_resp_I(id2(:)));
49 NMS(2:end-1,2:end-1,m) = reshape(a,nr-2,nc-2);
50 NMS(:,:,m) = NMS(:,:,m).*max_Ori_resp_I;
51 else
52 a = (max_Ori_resp_small(:)<max_Ori_resp_I(id1(:))) .* (max_Ori_resp_small(:)<max_Ori_resp_I(id2(:)));
53 NMS(2:end-1,2:end-1,m) = reshape(a,nr-2,nc-2);
54 end
55
56end
57
58
59
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/mgrad.m b/SD-VBS/common/toolbox/toolbox_basic/common/mgrad.m
new file mode 100755
index 0000000..1d89c87
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/mgrad.m
@@ -0,0 +1,11 @@
1function [dx,dy] = mgrad(I,w)
2%
3% [dx,dy] = mgrad(I,w)
4%
5
6[nr,nc] = size(I);
7
8dx = zeros(nr,nc);dy = zeros(nr,nc);
9
10dx(:,1:nc-w) = I(:,1:nc-w) - I(:,w+1:nc);
11dy(1:nr-w,:) = I(1:nr-w,:) - I(w+1:nr,:);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.m b/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.m
new file mode 100755
index 0000000..7f964ab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.m
@@ -0,0 +1,25 @@
1%MPGREAD Read an MPEG encoded movie file.
2% [M, map] = mpgread('filename', frames) reads the specifed
3% MPEG file and translates it into the movie M, and colormap map.
4% If a vector frames is specified, then only the frames specified
5% in this vector will be placed in M. Otherwise, all frames will
6% be placed in M.
7%
8% M = mpgread('filename', frames, 'indexed')
9% Reads an MPEG file into the MATLAB 5.3+ format movie which
10% is a structure array. Each element has a cdata field
11% containing a uint8 image matrix and a colormap field
12% containing the colormap. The frames parameter can be [] to
13% indicate that all frames should be read.
14%
15% M = mpgread('filename', frames, 'truecolor')
16% Reads an MPEG file into the MATLAB 5.3+ format movie. Each
17% frame in the movie has a truecolor MxNx3 cdata field and
18% an empty colormap field.
19%
20% [R, G, B] = mpgread('filename', frames) will perform the same
21% operation as above, except that the decoded MPEG frames will
22% be placed into the matrices R, G, B, where R contains the red
23% component for each frame, G, the green component, and B, the
24% blue component.
25%
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.mexlx b/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.mexlx
new file mode 100755
index 0000000..1190192
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/mpgread.mexlx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.m b/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.m
new file mode 100755
index 0000000..b1cb773
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.m
@@ -0,0 +1,29 @@
1%MPGWRITE Write an MPEG file.
2% MPGWRITE(M, map, 'filename', options) Encodes M in MPEG
3% format using the specified colormap and writes the result to the
4% specified file. The options argument is an optional vector of
5% 8 or fewer options where each value has the following meaning:
6% 1. REPEAT:
7% An integer number of times to repeat the movie
8% (default is 1).
9% 2. P-SEARCH ALGORITHM:
10% 0 = logarithmic (fastest, default value)
11% 1 = subsample
12% 2 = exhaustive (better, but slow)
13% 3. B-SEARCH ALGORITHM:
14% 0 = simple (fastest)
15% 1 = cross2 (slightly slower, default value)
16% 2 = exhaustive (very slow)
17% 4. REFERENCE FRAME:
18% 0 = original (faster, default)
19% 1 = decoded (slower, but results in better quality)
20% 5. RANGE IN PIXELS:
21% An integer search radius. Default is 10.
22% 6. I-FRAME Q-SCALE:
23% An integer between 1 and 31. Default is 8.
24% 7. P-FRAME Q-SCALE:
25% An integer between 1 and 31. Default is 10.
26% 8. B-FRAME Q-SCALE:
27% An integer between 1 and 31. Default is 25.
28%
29
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.mexlx b/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.mexlx
new file mode 100755
index 0000000..770bad1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/mpgwrite.mexlx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut.m
new file mode 100755
index 0000000..81fb52f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut.m
@@ -0,0 +1,108 @@
1% function [v,s,na,d] = ncut(a,nv,sigma,offset)
2% Input:
3% a = affinity matrix, hermitian, could be 3D, or a cell
4% nv = number of eigenvectors v
5% sigma = refer to EIGS.M, 0 for smallest, default = 'LR'
6% offset = vector, each for an affinity matrix, offset for nondirectional repulsion
7% W = A - R = (A + offset) - (R + offset)
8% Expected value = offset in affinity value * # of neighboors
9% Output:
10% v = generalized eigenvectors of A and D
11% s = eigenvalues
12% na = normalized affinity matrix
13% d = normalization matrix 1/sqrt(rowsum(a))
14% This version now accepts multiple weight matrices
15% the format of cells are good for sparse affinity matrices
16
17% Jianbo Shi
18
19function [v,s,na,d] = ncut(a,nv,sigma,offset)
20
21is_cell = iscell(a);
22if is_cell,
23 nw = length(a);
24 [nr,nc] = size(a{1});
25else
26 [nr,nc,nw] = size(a);
27end
28
29if nargin<2 | isempty(nv),
30 nv = min(nr,6);
31end
32
33if nargin<3 | isempty(sigma),
34 sigma = 'LR';
35end
36
37if nargin<4 | isempty(offset),
38 offset = 0;
39end;
40offset=offset(:);
41j = length(offset);
42offset(j+1:nw) = offset(j);
43
44d = 0;
45na = sparse(nr,nc);
46for j=1:nw, % simultaneous partitioning with multiple weight matrices.
47 if is_cell,
48 w = a{j};
49 elseif issparse(a), % only supports 2D indexing
50 w = a;
51 else
52 w = a(:,:,j);
53 end
54 if j==nw, % to save space
55 clear a;
56 end
57
58 d = d + sum(abs(w),2) + 2*offset(j); % single equivalent D
59
60 % modify matrix a to deal with nondirectional repulsion
61 wr = real(w);
62 wr = (sum(abs(wr),2)-sum(wr,2))*0.5 + offset(j);
63 w = w + spdiags(wr,0,nr,nr);
64
65 na = na + w; % single equivalent A
66
67 % if you want the rectified individual weight matrix
68 %if is_cell,
69 % a{j} = w;
70 %else
71 % a(:,:,j) = w;
72 %end
73end
74clear w wr
75
76% normalize
77d = 1./sqrt(d+eps);
78if 1,
79 na = spmtimesd(na,d,d);
80else
81 d = spdiags(d,0,nr,nr);
82 na = d * na * d;
83end
84
85options.disp = 0;
86%options.tol = 1e-10;
87%options.maxit = 15;
88
89warning off
90[v,s] = eigs(na,nv,sigma,options);
91s = real(diag(s));
92warning on
93
94% to make sure positive eigs always come first
95% [x,y] = sort(-s);
96% s = -x;
97% v = v(:,y);
98
99% project back to get the eigenvectors for the pair (a,d)
100% a x = lambda d x
101% na y = lambda y
102% x = d^(-1/2) y
103
104if 1,
105 v = spdiags(d,0,nr,nr) * v;
106else
107 v = d * v;
108end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_b.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_b.m
new file mode 100755
index 0000000..d686981
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_b.m
@@ -0,0 +1,46 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5%
6% computes 'nv' of the normalized cut vectors 'v' from
7% matrix 'A'
8%
9% it computes the largest eigenvectors of
10% A*v = \lambda D * v; D = diag(sum(A));
11%
12% this is same as solving the smallest eigenvectors of
13% (D-A)*v = \lambda D *v;
14%
15
16%
17% Jianbo Shi
18%
19
20ds = sum(A);
21ds = ones(size(ds))./sqrt(ds);
22
23for j=1:size(A,1),
24 A(j,:) = A(j,:).*ds;
25end
26
27for j=1:size(A,2);
28 A(:,j) = A(:,j).*ds';
29end
30
31
32%disp(sprintf('computing eig values'));
33OPTIONS.tol=1e-10;
34OPTIONS.maxit=15;
35OPTIONS.disp=0;
36%tic;toc;
37
38[v,d] = eigs(A,nv,'LM',OPTIONS);
39
40d = abs(diag(d));
41
42for j=1:nv,
43 v(:,j) = v(:,j).*ds';
44end
45
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_bb.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_bb.m
new file mode 100755
index 0000000..c9b7394
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_bb.m
@@ -0,0 +1,39 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5%
6% computes 'nv' of the normalized cut vectors 'v' from
7% matrix 'A'
8%
9% it computes the largest eigenvectors of
10% A*v = \lambda D * v; D = diag(sum(A));
11%
12% this is same as solving the smallest eigenvectors of
13% (D-A)*v = \lambda D *v;
14%
15
16%
17% Jianbo Shi
18%
19
20ds = sum(A);
21ds = ones(size(ds))./sqrt(ds);
22
23D_inv_half = spdiags(ds',0,size(A,1),size(A,2));
24A = D_inv_half*A*D_inv_half;
25
26disp(sprintf('computing eig values'));
27OPTIONS.tol=1e-10;
28OPTIONS.maxit=15;
29OPTIONS.disp=0;
30%tic;toc;
31
32[v,d] = eigs(A,nv,OPTIONS);
33
34d = abs(diag(d));
35
36for j=1:nv,
37 v(:,j) = v(:,j).*ds';
38end
39
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_e.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_e.m
new file mode 100755
index 0000000..e06c8a6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_e.m
@@ -0,0 +1,36 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5% computes 'nv' of the normalized cut vectors 'v' from
6% matrix 'A'
7%
8
9%
10% Jianbo Shi
11%
12
13ds = sum(A);
14D = diag(ds);
15
16ds = ones(size(ds))./sqrt(ds);
17
18B = D-A;
19
20for j=1:size(A,1),
21 B(j,:) = B(j,:).*ds;
22end
23
24for j=1:size(A,2);
25 B(:,j) = B(:,j).*ds';
26end
27
28disp(sprintf('computing eig values'));
29tic;[v,d] = eigs(B,nv,'sm');toc;
30
31d = abs(diag(d));
32
33for j=1:nv,
34 v(:,j) = v(:,j).*ds';
35end
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_neg.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_neg.m
new file mode 100755
index 0000000..89a1caa
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_neg.m
@@ -0,0 +1,45 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5%
6% computes 'nv' of the normalized cut vectors 'v' from
7% matrix 'A'
8%
9% it computes the largest eigenvectors of
10% A*v = \lambda D * v; D = diag(sum(A));
11%
12% this is same as solving the smallest eigenvectors of
13% (D-A)*v = \lambda D *v;
14%
15
16%
17% Jianbo Shi
18%
19
20ds = sum(abs(A));
21ds = ones(size(ds))./sqrt(ds);
22
23for j=1:size(A,1),
24 A(j,:) = A(j,:).*ds;
25end
26
27for j=1:size(A,2);
28 A(:,j) = A(:,j).*ds';
29end
30
31
32%disp(sprintf('computing eig values'));
33OPTIONS.tol=1e-10;
34OPTIONS.maxit=15;
35OPTIONS.disp=0;
36%tic;toc;
37
38[v,d] = eigs(A,nv,OPTIONS);
39
40d = abs(diag(d));
41
42for j=1:nv,
43 v(:,j) = v(:,j).*ds';
44end
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_sparse.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_sparse.m
new file mode 100755
index 0000000..dc6d076
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_sparse.m
@@ -0,0 +1,45 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5% Assume A is sparse,
6%
7% computes 'nv' of the normalized cut vectors 'v' from
8% matrix 'A'
9%
10% it computes the largest eigenvectors of
11% A*v = \lambda D * v; D = diag(sum(A));
12%
13% this is same as solving the smallest eigenvectors of
14% (D-A)*v = \lambda D *v;
15%
16
17%
18% Jianbo Shi
19%
20
21ds = sum(abs(A));
22ds = 1./sqrt(ds);
23
24[id_i,id_j,W] = find(A);
25A = sparse(id_i,id_j,ds(id_i)'.*ds(id_j)'.*(W));
26
27%disp(sprintf('computing eig values'));
28SIGMA = 'LM';
29%OPTIONS.issym = 0;
30OPTIONs.isreal = 1;
31OPTIONS.tol=1e-12;
32OPTIONS.maxit=25;
33OPTIONS.disp=0;
34%tic;toc;
35
36tic
37[v,d] = eigs(A,nv,SIGMA,OPTIONS);
38%,OPTIONS);
39toc
40d = abs(diag(d));
41
42for j=1:nv,
43 v(:,j) = v(:,j).*ds';
44end
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncut_tmp.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_tmp.m
new file mode 100755
index 0000000..b623ee4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncut_tmp.m
@@ -0,0 +1,45 @@
1function [v,d] = ncut(A,nv)
2%
3% [v,d] = ncut(A,nv)
4%
5%
6% computes 'nv' of the normalized cut vectors 'v' from
7% matrix 'A'
8%
9% it computes the largest eigenvectors of
10% A*v = \lambda D * v; D = diag(sum(A));
11%
12% this is same as solving the smallest eigenvectors of
13% (D-A)*v = \lambda D *v;
14%
15
16%
17% Jianbo Shi
18%
19
20ds = sum(A);
21ds = ones(size(ds))./sqrt(ds);
22
23for j=1:size(A,1),
24 A(j,:) = A(j,:).*ds;
25end
26
27for j=1:size(A,2);
28 A(:,j) = A(:,j).*ds';
29end
30
31
32%disp(sprintf('computing eig values'));
33OPTIONS.tol=1e-10;
34OPTIONS.maxit=15;
35OPTIONS.disp=0;
36%tic;toc;
37
38[v,d] = eigs(A,nv,OPTIONS);
39
40d = abs(diag(d));
41
42for j=1:nv,
43 v(:,j) = v(:,j).*ds';
44end
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/ncutd.m b/SD-VBS/common/toolbox/toolbox_basic/common/ncutd.m
new file mode 100755
index 0000000..cd5e8a4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/ncutd.m
@@ -0,0 +1,108 @@
1% function [v,s,na,d] = ncutd(a,nv,beta,sigma,offset)
2% Input:
3% a = (attraction + i*repulsion), both nonnegative but could be asymmetrical
4% nv = number of eigenvectors v
5% beta = weighting between undirected graph and directed graph
6% beta = 1, undirected; beta = 0, directed. Default = 0.5
7% sigma = refer to EIGS.M, 0 for smallest, default = 'LR'
8% offset = vector, each for an affinity matrix,
9% per_edge offset for nondirectional attraction and repulsion
10% Output:
11% v = generalized eigenvectors of A and D
12% s = eigenvalues
13% na = normalized affinity matrix
14% d = normalization matrix 1/sqrt(rowsum(a))
15% This version now accepts multiple weight matrices
16% the format of cells are good for sparse affinity matrices
17
18% Stella X. Yu, 2001.
19
20function [v,s,na,d] = ncutd(a,nv,beta,sigma,offset)
21
22is_cell = iscell(a);
23if is_cell,
24 nw = length(a);
25 [nr,nc] = size(a{1});
26else
27 [nr,nc,nw] = size(a);
28end
29
30if nargin<2 | isempty(nv),
31 nv = min(nr,6);
32end
33
34if nargin<3 | isempty(beta),
35 beta = 0.5;
36end
37beta = beta *2;
38
39if nargin<4 | isempty(sigma),
40 sigma = 'LR';
41end
42
43if nargin<5 | isempty(offset),
44 offset = 0;
45end;
46offset=offset(:);
47j = length(offset);
48offset(j+1:nw) = offset(j);
49
50% modify per-edge offset delta to 2 D_{\delta} = offset to D_R
51offset = offset * (2*nc);
52
53z = zeros(nr,nw);
54na = 0;
55for j=1:nw, % simultaneous partitioning with multiple weight matrices.
56 if is_cell,
57 w = a{j};
58 elseif issparse(a), % only supports 2D indexing
59 w = a;
60 else
61 w = a(:,:,j);
62 end
63
64 wr = real(w); % attraction
65 wi = imag(w); % repulsion
66
67 % if wr has negative numbers, treat as repulsion
68 % while negative numbers in wi is ignored
69 aa = wr.*(wr>0);
70 rr = wi.*(wi>0)-wr.*(wr<0);
71
72 % decomposition
73 au = aa + aa';
74 ad = aa - aa';
75 ru = rr + rr';
76 rd = rr - rr';
77
78 % construct equivalent matrices
79 x = sum(ru,2);
80 wr = au - ru + diag(x);
81 wi = ad + rd;
82 x = x + sum(au,2);
83
84 % re-organize, add in offset and beta
85 z(:,j) = x + 2 * offset;
86 na = na + ( beta * (wr + offset) + sqrt(-1)* (2-beta) * wi );
87
88end
89z = sum(z,2); % diag(z) = single equivalent D
90
91% normalize
92d = repmat(1./sqrt(z+eps),1,nc);
93na = d.*na;
94na = na.*d';
95
96options.disp = 0;
97%options.tol = 1e-10;
98%options.maxit = 15;
99
100[v,s] = eigs(na,nv,sigma,options);
101s = real(diag(s));
102
103% project back to get the eigenvectors for the pair (a,d)
104% a x = lambda d x
105% na y = lambda y
106% x = d^(-1/2) y
107
108v = v .* d(:,ones(nv,1));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/nonmaxsup.m b/SD-VBS/common/toolbox/toolbox_basic/common/nonmaxsup.m
new file mode 100755
index 0000000..d12301c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/nonmaxsup.m
@@ -0,0 +1,81 @@
1% function f = nonmaxsup(g,ismax,r) return extrema boolean map.
2% Input: g = image, gradient image pair [x,y], or [x,y,g] in 3D matrix
3% ismax (=1)/0 is for non maximum/minimum suppression
4% r (=1) is the neighbourhood radius.
5% Output:
6% f = thinned extrema boolean map, where
7% d (||gradient||) / d gradient = 0
8
9% Stella X. Yu, 2000.
10
11function f = nonmaxsup(g,ismax,r)
12
13if nargin<2,
14 ismax = 1;
15end
16
17if nargin<3,
18 r = 1;
19end
20
21i = size(g,3);
22if i==3,
23 x = g(:,:,1);
24 y = g(:,:,2);
25 g = g(:,:,3);
26elseif i==2,
27 x = g(:,:,1);
28 y = g(:,:,2);
29 g = x.*x + y.*y;
30else
31 [x,y] = gradient(g);
32end
33
34% label angles into 4 directions
35a = angle(x - sqrt(-1).*y); % [-pi,pi)
36s = ceil((abs(a)+pi/8)./(pi/4));
37s(find(s==5)) = 1;
38s(find(isnan(s))) = 1;
39
40% augment the image
41[m,n] = size(g);
42newm = m + r + r;
43i = [g(:,1);g(:,end);g(1,:)';g(end,:)']; % image boundary
44if ismax,
45 v = min(i) - 1;
46else
47 v = max(i) + 1;
48end
49i = zeros(newm,r) + v;
50j = zeros(r,n) + v;
51newg = [i, [j; g; j;], i];
52
53% k = index as the interior of the new image
54i = [r+1:newm-r]'+ r*newm;
55j = [0:n-1].*newm;
56k = i(:,ones(1,n)) + j(ones(1,m),:);
57k = k(:);
58
59% unit displacement vectors along gradient directions
60d = [newm,newm-1,-1,-1-newm]'; % for 4 directions
61d = d(s(:));
62
63% non maximum suppression
64f = ones(m*n,1);
65g = g(:);
66newd = 0;
67
68if ismax,
69 for i=1:r,
70 newd = newd + d;
71 f = f & (g>newg(k+newd)) & (g>newg(k-newd));
72 end
73else
74 for i=1:r,
75 newd = newd + d;
76 f = f & (g<newg(k+newd)) & (g<newg(k-newd));
77 end
78end
79
80f = reshape(f,[m,n]);
81
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/pair_dist.m b/SD-VBS/common/toolbox/toolbox_basic/common/pair_dist.m
new file mode 100755
index 0000000..3ea970a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/pair_dist.m
@@ -0,0 +1,14 @@
1function W = pari_hist_dist_fast(data)
2%
3% W = pari_hist_dist(data)
4%
5% data: num_im by num_feature
6% W : num_im by num_im hist diff
7%
8
9[num_im,num_feature] = size(data);
10mag = sum(data.*data,2);
11
12W = mag(:,ones(1,num_im)) - 2*data*data';
13mag = mag';
14W = W+mag(ones(num_im,1),:);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/quadedgep.m b/SD-VBS/common/toolbox/toolbox_basic/common/quadedgep.m
new file mode 100755
index 0000000..eda33f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/quadedgep.m
@@ -0,0 +1,106 @@
1% function [x,y,gx,gy,par,threshold,mag,mage,g,FIe,FIo,mago] = quadedgep(I,par,threshold);
2% Input:
3% I = image
4% par = vector for 4 parameters
5% [number of filter orientations, number of scales, filter size, elongation]
6% To use default values, put 0.
7% threshold = threshold on edge strength
8% Output:
9% [x,y,gx,gy] = locations and gradients of an ordered list of edgels
10% x,y could be horizontal or vertical or 45 between pixel sites
11% but it is guaranteed that there [floor(y) + (floor(x)-1)*nr]
12% is ordered and unique. In other words, each edgel has a unique pixel id.
13% par = actual par used
14% threshold = actual threshold used
15% mag = edge magnitude
16% mage = phase map
17% g = gradient map at each pixel
18% [FIe,FIo] = odd and even filter outputs
19% mago = odd filter output of optimum orientation
20
21% Stella X. Yu, 2001
22
23function [x,y,gx,gy,par,threshold,mag,mage,g,FIe,FIo,mago] = quadedgep(I,par,threshold);
24
25if nargin<3 | isempty(threshold),
26 threshold = 0.2;
27end
28
29[r,c] = size(I);
30def_par = [8,1,20,3];
31
32% take care of parameters, any missing value is substituted by a default value
33if nargin<2 | isempty(par),
34 par = def_par;
35end
36par(end+1:4)=0;
37par = par(:);
38j = (par>0);
39have_value = [ j, 1-j ];
40j = 1; n_filter = have_value(j,:) * [par(j); def_par(j)];
41j = 2; n_scale = have_value(j,:) * [par(j); def_par(j)];
42j = 3; winsz = have_value(j,:) * [par(j); def_par(j)];
43j = 4; enlong = have_value(j,:) * [par(j); def_par(j)];
44
45% always make filter size an odd number so that the results will not be skewed
46j = winsz/2;
47if not(j > fix(j) + 0.1),
48 winsz = winsz + 1;
49end
50
51% filter the image with quadrature filters
52FBo = make_filterbank_odd2(n_filter,n_scale,winsz,enlong);
53FBe = make_filterbank_even2(n_filter,n_scale,winsz,enlong);
54n = ceil(winsz/2);
55f = [fliplr(I(:,2:n+1)), I, fliplr(I(:,c-n:c-1))];
56f = [flipud(f(2:n+1,:)); f; flipud(f(r-n:r-1,:))];
57FIo = fft_filt_2(f,FBo,1);
58FIo = FIo(n+[1:r],n+[1:c],:);
59FIe = fft_filt_2(f,FBe,1);
60FIe = FIe(n+[1:r],n+[1:c],:);
61
62% compute the orientation energy and recover a smooth edge map
63% pick up the maximum energy across scale and orientation
64% even filter's output: as it is the second derivative, zero cross localize the edge
65% odd filter's output: orientation
66mag = sqrt(sum(FIo.^2,3)+sum(FIe.^2,3));
67mag_a = sqrt(FIo.^2+FIe.^2);
68[tmp,max_id] = max(mag_a,[],3);
69base_size = r * c;
70id = [1:base_size]';
71mage = reshape(FIe(id+(max_id(:)-1)*base_size),[r,c]);
72mage = (mage>0) - (mage<0);
73
74ori_incr=pi/n_filter; % to convert jshi's coords to conventional image xy
75ori_offset=ori_incr/2;
76theta = ori_offset+([1:n_filter]-1)*ori_incr; % orientation detectors
77% [gx,gy] are image gradient in image xy coords, winner take all
78mago = reshape(FIo(id+(max_id(:)-1)*base_size),[r,c]);
79ori = theta(max_id);
80ori = ori .* (mago>0) + (ori + pi).*(mago<0);
81gy = mag .* cos(ori);
82gx = -mag .* sin(ori);
83g = cat(3,gx,gy);
84
85% phase map: edges are where the phase changes
86mag_th = max(mag(:)) * threshold;
87eg = (mag>mag_th);
88h = eg & [(mage(2:r,:) ~= mage(1:r-1,:)); zeros(1,c)];
89v = eg & [(mage(:,2:c) ~= mage(:,1:c-1)), zeros(r,1)];
90[y,x] = find(h | v);
91k = y + (x-1) * r;
92h = h(k);
93v = v(k);
94y = y + h * 0.5; % i
95x = x + v * 0.5; % j
96t = h + v * r;
97gx = g(k) + g(k+t);
98k = k + (r * c);
99gy = g(k) + g(k+t);
100
101% display
102if 1,
103%figure; showmask(I,mage<0);
104figure(2); clf;showim(I,1); hold on; quiver(x,y,gx,gy);
105%figure; showim(-I,1); hold on; quiver(i,j,ex,ey);
106end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/readpcm.m b/SD-VBS/common/toolbox/toolbox_basic/common/readpcm.m
new file mode 100755
index 0000000..ca736da
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/readpcm.m
@@ -0,0 +1,12 @@
1function I = readpcm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d\n',2);
6I = fscanf(fid,'%c',A(2)*A(1));
7I = I';
8I = str2num(I);
9I = reshape(I,A(2),A(1))';
10
11
12fclose(fid); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/readpdm.m b/SD-VBS/common/toolbox/toolbox_basic/common/readpdm.m
new file mode 100755
index 0000000..9a1068e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/readpdm.m
@@ -0,0 +1,8 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%d',[A(1),A(2)]);
7
8fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/readpfm.m b/SD-VBS/common/toolbox/toolbox_basic/common/readpfm.m
new file mode 100755
index 0000000..48ecd78
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/readpfm.m
@@ -0,0 +1,10 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%f',[A(1),A(2)]);
7
8%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
9
10fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/renormalize.m b/SD-VBS/common/toolbox/toolbox_basic/common/renormalize.m
new file mode 100755
index 0000000..5d84724
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/renormalize.m
@@ -0,0 +1,32 @@
1function W2 = renormalize(W,nstep)
2%
3% keep renormalizing until W is almost double
4% stocastic
5%
6
7if nargin<2,
8 nstep = 5;
9end
10
11n_node = size(W,1);
12
13for j=1:nstep,
14 fprintf(',');
15 % normalize row
16 D = sum(W,2);
17 D = 1./(D+eps);
18 W = W.*D(:,ones(1,n_node));
19
20 % normlize column
21 D = sum(W,1);
22 D = 1./(D+eps);
23 W = W.*D(ones(n_node,1),:);
24end
25fprintf('\n');
26
27 D = sum(W,2);
28 D = 1./(D+eps);
29 W2 = W.*D(:,ones(1,n_node));
30
31
32
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/show_edge.m b/SD-VBS/common/toolbox/toolbox_basic/common/show_edge.m
new file mode 100755
index 0000000..63b2f98
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/show_edge.m
@@ -0,0 +1,11 @@
1function [id_i,id_j,ids] = show_edge(I,MI,thI);
2%
3% show_edge(I,MI,thI);
4%
5
6[id_i,id_j,tmp] = find(MI);
7ids = sub2ind(size(I),id_i,id_j);
8clf;im(I);colormap(gray);hold on;
9quiver(id_j,id_i,-sin(thI(ids)),cos(thI(ids)),0.5);hold off;
10
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.c b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.c
new file mode 100755
index 0000000..a98dc0a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.c
@@ -0,0 +1,141 @@
1/*================================================================
2* spmtimesd.c
3* This routine computes a sparse matrix times a diagonal matrix
4* whose diagonal entries are stored in a full vector.
5*
6* Examples:
7* spmtimesd(m,d,[]) = diag(d) * m,
8* spmtimesd(m,[],d) = m * diag(d)
9* spmtimesd(m,d1,d2) = diag(d1) * m * diag(d2)
10* m could be complex, but d is assumed real
11*
12* Stella X. Yu's first MEX function, Nov 9, 2001.
13
14% test sequence:
15
16m = 1000;
17n = 2000;
18a=sparse(rand(m,n));
19d1 = rand(m,1);
20d2 = rand(n,1);
21tic; b=spmtimesd(a,d1,d2); toc
22tic; bb = spdiags(d1,0,m,m) * a * spdiags(d2,0,n,n); toc
23e = (bb-b);
24max(abs(e(:)))
25
26*=================================================================*/
27
28# include "mex.h"
29
30void mexFunction(
31 int nargout,
32 mxArray *out[],
33 int nargin,
34 const mxArray *in[]
35)
36{
37 /* declare variables */
38 int i, j, k, m, n, nzmax, cmplx, xm, yn;
39 int *pir, *pjc, *qir, *qjc;
40 double *x, *y, *pr, *pi, *qr, *qi;
41
42 /* check argument */
43 if (nargin != 3) {
44 mexErrMsgTxt("Three input arguments required");
45 }
46 if (nargout>1) {
47 mexErrMsgTxt("Too many output arguments.");
48 }
49 if (!(mxIsSparse(in[0]))) {
50 mexErrMsgTxt("Input argument #1 must be of type sparse");
51 }
52 if ( mxIsSparse(in[1]) || mxIsSparse(in[2]) ) {
53 mexErrMsgTxt("Input argument #2 & #3 must be of type full");
54 }
55
56 /* computation starts */
57 m = mxGetM(in[0]);
58 n = mxGetN(in[0]);
59 pr = mxGetPr(in[0]);
60 pi = mxGetPi(in[0]);
61 pir = mxGetIr(in[0]);
62 pjc = mxGetJc(in[0]);
63
64 i = mxGetM(in[1]);
65 j = mxGetN(in[1]);
66 xm = ((i>j)? i: j);
67
68 i = mxGetM(in[2]);
69 j = mxGetN(in[2]);
70 yn = ((i>j)? i: j);
71
72 if ( xm>0 && xm != m) {
73 mexErrMsgTxt("Row multiplication dimension mismatch.");
74 }
75 if ( yn>0 && yn != n) {
76 mexErrMsgTxt("Column multiplication dimension mismatch.");
77 }
78
79
80 nzmax = mxGetNzmax(in[0]);
81 cmplx = (pi==NULL ? 0 : 1);
82 out[0] = mxCreateSparse(m,n,nzmax,cmplx);
83 if (out[0]==NULL) {
84 mexErrMsgTxt("Not enough space for the output matrix.");
85 }
86
87 qr = mxGetPr(out[0]);
88 qi = mxGetPi(out[0]);
89 qir = mxGetIr(out[0]);
90 qjc = mxGetJc(out[0]);
91
92 /* left multiplication */
93 x = mxGetPr(in[1]);
94 if (yn==0) {
95 for (j=0; j<n; j++) {
96 qjc[j] = pjc[j];
97 for (k=pjc[j]; k<pjc[j+1]; k++) {
98 i = pir[k];
99 qir[k] = i;
100 qr[k] = x[i] * pr[k];
101 if (cmplx) {
102 qi[k] = x[i] * pi[k];
103 }
104 }
105 }
106 qjc[n] = k;
107 return;
108 }
109
110 /* right multiplication */
111 y = mxGetPr(in[2]);
112 if (xm==0) {
113 for (j=0; j<n; j++) {
114 qjc[j] = pjc[j];
115 for (k=pjc[j]; k<pjc[j+1]; k++) {
116 qir[k] = pir[k];
117 qr[k] = pr[k] * y[j];
118 if (cmplx) {
119 qi[k] = qi[k] * y[j];
120 }
121 }
122 }
123 qjc[n] = k;
124 return;
125 }
126
127 /* both sides */
128 for (j=0; j<n; j++) {
129 qjc[j] = pjc[j];
130 for (k=pjc[j]; k<pjc[j+1]; k++) {
131 i = pir[k];
132 qir[k]= i;
133 qr[k] = x[i] * pr[k] * y[j];
134 if (cmplx) {
135 qi[k] = x[i] * qi[k] * y[j];
136 }
137 }
138 qjc[n] = k;
139 }
140
141}
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexa64 b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexa64
new file mode 100755
index 0000000..15fa9d2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexa64
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexglx b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexglx
new file mode 100755
index 0000000..7478fb0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/spmtimesd.mexglx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/tmp.tex b/SD-VBS/common/toolbox/toolbox_basic/common/tmp.tex
new file mode 100755
index 0000000..0458ef3
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/tmp.tex
@@ -0,0 +1,16 @@
1Hi Prof. Geiger,
2
3 My name is Jianbo Shi. I am a graduate student working
4with Jitendra Malik at UC Berkeley. My current research interest is
5on the topic of grouping and perceptual organization. I have read
6many of your works in this area.
7
8 I will be giving a talk at NECI and David Sarnoff Lab on Dec. 8
9and 9 on ``Normalized cuts and its application to motion segmentation''.
10I am wondering if I could visit you and your lab on Dec. 10. I would
11very much like the opportunity to talk to you on varies topics related
12to the problem of grouping. Let me know if that is possible.
13
14 -thanks!
15
16 -Jianbo
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/vmquant.m b/SD-VBS/common/toolbox/toolbox_basic/common/vmquant.m
new file mode 100755
index 0000000..ab4eb28
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/vmquant.m
@@ -0,0 +1,112 @@
1function [im, map] = vmquant(arg1,arg2,arg3,arg4,arg5,arg6,arg7)
2%VMQUANT Variance Minimization Color Quantization.
3% [X, MAP] = VMQUANT(R,G,B,K,[Qr Qg Qb],DITHER,Qe) or
4% VMQUANT(RGB,K,[Qr Qg Qb],DITHER,Qe), where RGB is a 3-D array,
5% converts an arbitrary image comprised of RGB triples into an
6% indexed image X with color map MAP. K specifies the number
7% of desired entries in the target color map, and [Qr Qg Qb]
8% specifies the number of quantization bits to assign each color
9% axis during color interpolation. DITHER is a string ('dither' or
10% 'nodither') that indicates whether or not to perform error propagation
11% dither on the output image. Qe specifies the number of bits of
12% quantization used in the error calculations.
13%
14% K is optional and defaults to 256.
15% [Qr Qg Qb] is optional and defaults to [5 5 5].
16% DITHER is optional and defaults to 'nodither'.
17% Qe is optional and defaults to 8.
18%
19% See also: RGB2IND, RGB2GRAY, DITHER, IND2RGB, CMUNIQUE, IMAPPROX.
20
21% This is the wrapper function for the MEX file VMQUANTC.C
22
23% Joseph M. Winograd 6-93
24% Copyright (c) 1993 by The MathWorks, Inc.
25% $Revision: 5.3 $ $Date: 1996/08/22 22:09:03 $
26
27% Reference: Xiaolin Wu, "Efficient Statistical Computation for
28% Optimal Color Quantization," Graphics Gems II, (ed. James
29% Arvo). Academic Press: Boston. 1991.
30
31if nargin < 1,
32 error('Not enough input arguments.');
33end
34
35threeD = (ndims(arg1)==3); % Determine if input includes a 3-D array
36
37if threeD,
38 error( nargchk( 1, 5, nargin ) );
39
40 % NOTE: If you change defaults, change them also
41 % in VMQUANTC.C and recompile the MEX function.
42 if nargin < 5
43 arg5 = 8; % DEFAULT_QE = 8
44 end
45
46 if nargin < 4
47 arg4 = 'n'; % DEFAULT_DITHER = 0
48 end
49
50 if nargin < 3
51 arg3 = [5 5 5]; % DEFAULT_Q = [5 5 5]
52 end
53
54 if nargin < 2
55 arg2 = 256; % DEFAULT_K = 256
56 end
57
58 rout = arg1(:,:,1);
59 g = arg1(:,:,2);
60 b = arg1(:,:,3);
61
62 if strcmp(lower(arg4(1)),'d')
63 dith = 1;
64 else
65 dith = 0;
66 end
67
68 arg7 = arg5;
69 arg5 = arg3;
70 arg4 = arg2;
71
72else
73 error( nargchk( 3, 7, nargin ) );
74
75 if nargin < 7
76 arg7 = 8; % DEFAULT_QE = 8
77 end
78
79 if nargin < 6
80 arg6 = 'n'; % DEFAULT_DITHER = 0
81 end
82
83 if nargin < 5
84 arg5 = [5 5 5]; % DEFAULT_Q = [5 5 5]
85 end
86
87 if nargin < 4
88 arg4 = 256; % DEFAULT_K = 256
89 end
90
91 rout = arg1;
92 g = arg2;
93 b = arg3;
94
95 if strcmp(lower(arg6(1)),'d')
96 dith = 1;
97 else
98 dith = 0;
99 end
100
101end
102
103if (~isa(rout,'uint8'))
104 rout = uint8(round(255*rout));
105end
106if (~isa(g,'uint8'))
107 g = uint8(round(255*g));
108end
109if (~isa(b,'uint8'))
110 b = uint8(round(255*b));
111end
112[im,map] = vmquantc( rout, g, b, arg4, arg5, dith, arg7 );
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexhp7 b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexhp7
new file mode 100755
index 0000000..c0e35c4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexhp7
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexlx b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexlx
new file mode 100755
index 0000000..f79c1d3
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexlx
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexsol b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexsol
new file mode 100755
index 0000000..f711a98
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/vmquantc.mexsol
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/writepdm.m b/SD-VBS/common/toolbox/toolbox_basic/common/writepdm.m
new file mode 100755
index 0000000..a8cba11
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/writepdm.m
@@ -0,0 +1,11 @@
1function writepfm(name,I)
2%
3% writepfm(name,I)
4%
5 [nr,nc] = size(I);
6
7 fid = fopen(name, 'w');
8 fprintf(fid, '%d %d\n', nr,nc);
9 fprintf(fid,'%d ',I');
10 fclose(fid);
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/common/writepfm.m b/SD-VBS/common/toolbox/toolbox_basic/common/writepfm.m
new file mode 100755
index 0000000..ee25fdc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/common/writepfm.m
@@ -0,0 +1,11 @@
1function writepfm(name,I)
2%
3% writepfm(name,I)
4%
5 [nr,nc] = size(I);
6
7 fid = fopen(name, 'w');
8 fprintf(fid, '%d %d\n', nr,nc);
9 fprintf(fid,'%f ',I');
10 fclose(fid);
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/disp_image.m b/SD-VBS/common/toolbox/toolbox_basic/disp/disp_image.m
new file mode 100755
index 0000000..4745d8d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/disp_image.m
@@ -0,0 +1,19 @@
1function disp_image(img,sze,index,mask)
2
3%figure(2)
4subplot(sze(1),sze(2),index);
5
6if (size(mask) ~= size(mask)),
7 error(['size of image is ',int2str(size(mask)),' size of mask is ',...
8 int2str(size(mask))]);
9end
10
11img = img-min(min(img));
12I = 0*(img.*(~mask)) + img.*mask;
13I = img.*mask;
14colormap(gray)
15imagesc(I);
16%axis('off')
17axis('equal');
18axis('square');
19drawnow;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box.m b/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box.m
new file mode 100755
index 0000000..556afdc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box.m
@@ -0,0 +1,9 @@
1function draw_box(left,right,top,down)
2
3plot([left,right],[top,top]);
4hold on
5plot([left,right],[down,down]);
6hold on
7plot([left,left],[top,down]);
8hold on
9plot([right,right],[top,down]); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box2.m b/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box2.m
new file mode 100755
index 0000000..adec284
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/draw_box2.m
@@ -0,0 +1,17 @@
1function draw_box(center,w_h,j)
2
3
4center_x = center(1);
5center_y = center(2);
6
7%plot(center_x,center_y,'r*');
8%text(center_x,center_y,int2str(j));
9
10l_x = center_x-w_h(1);
11r_x = center_x+w_h(1);
12u_y = center_y-w_h(2);
13l_y = center_y+w_h(2);
14
15plot([l_x,r_x,r_x,l_x,l_x],[u_y,u_y,l_y,l_y,u_y],'c');
16
17
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/im.m b/SD-VBS/common/toolbox/toolbox_basic/disp/im.m
new file mode 100755
index 0000000..a707916
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/im.m
@@ -0,0 +1,8 @@
1function im(I)
2
3imagesc(I);drawnow;
4pixval on
5title(inputname(1))
6%colormap(gray)
7%colorbar
8axis('image')
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/ims.m b/SD-VBS/common/toolbox/toolbox_basic/disp/ims.m
new file mode 100755
index 0000000..2fb5f25
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/ims.m
@@ -0,0 +1,3 @@
1function ims(I,nr,nc)
2
3im(reshape(I,nr,nc)); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/montage2.m b/SD-VBS/common/toolbox/toolbox_basic/disp/montage2.m
new file mode 100755
index 0000000..fb04b0b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/montage2.m
@@ -0,0 +1,17 @@
1function montage2(FI)
2% montage2(FI)
3% display 3D stack of images in a montage
4
5[N1,N2,N3]=size(FI);
6Q=zeros(N1,N2,1,N3);
7for n=1:N3
8 Q(:,:,1,n)=FI(:,:,n);
9end
10
11a=min(Q(:));
12b=max(Q(:));
13
14Q=Q-a;
15Q=Q/(b-a);
16
17montage(Q); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/showmask.m b/SD-VBS/common/toolbox/toolbox_basic/disp/showmask.m
new file mode 100755
index 0000000..f301638
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/showmask.m
@@ -0,0 +1,20 @@
1function showmask(V,M,display_flag);
2% showmask(V,M);
3%
4% M is a nonneg. mask
5
6V=V-min(V(:));
7V=V/max(V(:));
8V=.25+0.75*V; %brighten things up a bit
9
10M=M-min(M(:));
11M=M/max(M(:));
12
13H=0.0+zeros(size(V));
14S=M;
15RGB=hsv2rgb(H,S,V);
16
17%if nargin>2
18 image(RGB)
19 axis('image')
20%end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/disp/showmaskb.m b/SD-VBS/common/toolbox/toolbox_basic/disp/showmaskb.m
new file mode 100755
index 0000000..1f67ba2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/disp/showmaskb.m
@@ -0,0 +1,20 @@
1function RGB = showmask(V,M,M2,display_flag);
2% showmask(V,M);
3%
4% M is a nonneg. mask
5
6V=V-min(V(:));
7V=V/max(V(:));
8V=.25+0.75*V; %brighten things up a bit
9
10M=M-min(M(:));
11M=M/max(M(:));
12
13H=0.6*M2+0*M;
14S=min(1,M2+M);
15RGB=hsv2rgb(H,S,V);
16
17%if nargin>2
18 image(RGB)
19 axis('image')
20%end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w.m b/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w.m
new file mode 100755
index 0000000..372b4b6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w.m
@@ -0,0 +1,25 @@
1function W = construct_w(centers,Ds,img_center,indexes,frames)
2%
3% function W = construct_w(centers,Ds,img_center,indexes,frames)
4% optional: frames
5%
6
7
8points = length(indexes);
9if (nargin == 4),
10 frames = 0.5*size(centers,2);
11end
12
13W = zeros(2*frames,points);
14
15center_x = img_center(1);
16center_y = img_center(2);
17
18for j=1:frames,
19 % x is centers(:,2*j-1)
20 % y is centers(:,2*j)
21 % d is Ds(:,2*j-1)
22 W(j,:) = (centers(indexes,2*j-1) -center_x)'./Ds(indexes,2*j-1)';
23 W(j+frames,:) = (centers(indexes,2*j) -center_y)'./Ds(indexes,2*j-1)';
24 % W(j+2*frames,:) = ones(1,points)./Ds(indexes,2*j-1)';
25end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w2.m b/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w2.m
new file mode 100755
index 0000000..b2939b7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/construct_w2.m
@@ -0,0 +1,25 @@
1function W = construct_w2(centers,Ds,img_center,indexes,frames)
2%
3% function W = construct_w2(centers,Ds,img_center,indexes,frames)
4% optional: frames
5%
6
7
8points = length(indexes);
9if (nargin == 4),
10 frames = 0.5*size(centers,2);
11end
12
13W = zeros(3*frames,points);
14
15center_x = img_center(1);
16center_y = img_center(2);
17
18for j=1:frames,
19 % x is centers(:,2*j-1)
20 % y is centers(:,2*j)
21 % d is Ds(:,2*j-1)
22 W(j,:) = (centers(indexes,2*j-1) -center_x)'./Ds(indexes,2*j-1)';
23 W(j+frames,:) = (centers(indexes,2*j) -center_y)'./Ds(indexes,2*j-1)';
24 W(j+2*frames,:) = ones(1,points)./Ds(indexes,2*j-1)';
25end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m
new file mode 100755
index 0000000..635c29a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factor.m
@@ -0,0 +1,50 @@
1%
2% Usage:
3%
4% [R,t,S] = factor(W)
5%
6% Function to factor a matrix of input data (W) into the camera
7% rotation matrix (R), translation (t), and the shape matrix (S).
8% Three-dimensional version. Failure of normalization results in
9% empty R and S.
10
11function [R,t,S] = factor(W)
12
13pts = size(W,2);
14t = W*ones(pts,1)/pts;
15W = W - t*ones(1,pts);
16
17% Use SVD to factor W.
18 [a,b,c] = svd(W,0);
19
20smallb = b(1:3,1:3); % Since W is rank 3, b has only three meaningful values
21sqrtb = sqrt(smallb);
22Rhat = a(:,1:3) * sqrtb;
23Shat = sqrtb * c(:,1:3)';
24
25G = findG(Rhat);
26
27if size(G,1) == 0,
28R = [];
29S = [];
30else
31 R = Rhat*G;
32 S = inv(G)*Shat;
33
34 % rotation matrix that aligns the reference frame with the first camera
35 F = size(R,1)/2;
36 R1 = R(1,:);
37 R1 = R1/norm(R1);
38 R2 = R(F+1,:);
39 R2 = R2/norm(R2);
40 R3 = cross(R1,R2);
41 R3 = R3/norm(R3);
42 P = [R1; R2; R3];
43 P = P';
44
45 R = R*P;
46 S = inv(P)*S;
47end
48
49
50
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test.m b/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test.m
new file mode 100755
index 0000000..12ceb95
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test.m
@@ -0,0 +1,52 @@
1%
2% Usage:
3%
4% [R,t,S] = factor(W)
5%
6% Function to factor a matrix of input data (W) into the camera
7% rotation matrix (R), translation (t), and the shape matrix (S).
8% Three-dimensional version. Failure of normalization results in
9% empty R and S.
10
11function [R,t,S,C,b] = factor(W)
12
13pts = size(W,2);
14t = W*ones(pts,1)/pts;
15W = W - t*ones(1,pts);
16
17% Use SVD to factor W.
18 [a,b,c] = svd(W,0);
19
20figure(3);plot(diag(b))
21
22smallb = b(1:3,1:3); % Since W is rank 3, b has only three meaningful values
23sqrtb = sqrt(smallb);
24Rhat = a(:,1:3) * sqrtb;
25Shat = sqrtb * c(:,1:3)';
26
27[G,C] = findg1(Rhat);
28
29if size(G,1) == 0,
30R = [];
31S = [];
32else
33 R = Rhat*G;
34 S = inv(G)*Shat;
35
36 % rotation matrix that aligns the reference frame with the first camera
37 F = size(R,1)/2;
38 R1 = R(1,:);
39 R1 = R1/norm(R1);
40 R2 = R(F+1,:);
41 R2 = R2/norm(R2);
42 R3 = cross(R1,R2);
43 R3 = R3/norm(R3);
44 P = [R1; R2; R3];
45 P = P';
46
47 R = R*P;
48 S = inv(P)*S;
49end
50
51
52
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test2.m b/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test2.m
new file mode 100755
index 0000000..3520122
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factor_test2.m
@@ -0,0 +1,52 @@
1%
2% Usage:
3%
4% [R,t,S] = factor(W)
5%
6% Function to factor a matrix of input data (W) into the camera
7% rotation matrix (R), translation (t), and the shape matrix (S).
8% Three-dimensional version. Failure of normalization results in
9% empty R and S.
10
11function [R,t,S,C,b] = factor(W)
12
13pts = size(W,2);
14t = W*ones(pts,1)/pts;
15W = W - t*ones(1,pts);
16
17% Use SVD to factor W.
18 [a,b,c] = svd(W,0);
19
20figure(3);plot(diag(b))
21
22smallb = b(1:3,1:3); % Since W is rank 3, b has only three meaningful values
23sqrtb = sqrt(smallb);
24Rhat = a(:,1:3) * sqrtb;
25Shat = sqrtb * c(:,1:3)';
26
27[G,C] = findg2(Rhat);
28
29if size(G,1) == 0,
30R = [];
31S = [];
32else
33 R = Rhat*G;
34 S = inv(G)*Shat;
35
36 % rotation matrix that aligns the reference frame with the first camera
37 F = size(R,1)/2;
38 R1 = R(1,:);
39 R1 = R1/norm(R1);
40 R2 = R(F+1,:);
41 R2 = R2/norm(R2);
42 R3 = cross(R1,R2);
43 R3 = R3/norm(R3);
44 P = [R1; R2; R3];
45 P = P';
46
47 R = R*P;
48 S = inv(P)*S;
49end
50
51
52
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/factorizaion.tar b/SD-VBS/common/toolbox/toolbox_basic/fact/factorizaion.tar
new file mode 100755
index 0000000..133cdff
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/factorizaion.tar
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/findG.m b/SD-VBS/common/toolbox/toolbox_basic/fact/findG.m
new file mode 100755
index 0000000..9a6bd73
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/findG.m
@@ -0,0 +1,48 @@
1function G = find3G(Rhat)
2
3% number of frames
4F = size(Rhat,1)/2;
5
6% Build matrix Q such that Q * v = [1,...,1,0,...,0] where v is a six
7% element vector containg all six distinct elements of the Matrix C
8
9clear Q
10for f = 1:F,
11 g = f + F;
12 h = g + F;
13 Q(f,:) = zt(Rhat(f,:), Rhat(f,:));
14 Q(g,:) = zt(Rhat(g,:), Rhat(g,:));
15 Q(h,:) = zt(Rhat(f,:), Rhat(g,:));
16end
17
18% Solve for v
19rhs = [ones(2*F,1); zeros(F,1)];
20v = Q \ rhs;
21
22% C is a symmetric 3x3 matrix such that C = G * transpose(G)
23C(1,1) = v(1);
24C(1,2) = v(2);
25C(1,3) = v(3);
26C(2,2) = v(4);
27C(2,3) = v(5);
28C(3,3) = v(6);
29C(2,1) = C(1,2);
30C(3,1) = C(1,3);
31C(3,2) = C(2,3);
32
33e = eig(C);
34disp(e)
35
36if (any(e<= 0)),
37 G = [];
38else
39 G = sqrtm(C);
40end
41
42%neg = 0;
43%if e(1) <= 0, neg = 1; end
44%if e(2) <= 0, neg = 1; end
45%if e(3) <= 0, neg = 1; end
46%if neg == 1, G = [];
47%else G = sqrtm(C);
48%end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/findg1.m b/SD-VBS/common/toolbox/toolbox_basic/fact/findg1.m
new file mode 100755
index 0000000..f14ecc6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/findg1.m
@@ -0,0 +1,49 @@
1function [G,C] = find3G(Rhat)
2
3% number of frames
4F = size(Rhat,1)/2;
5
6% Build matrix Q such that Q * v = [1,...,1,0,...,0] where v is a six
7% element vector containg all six distinct elements of the Matrix C
8
9clear Q
10for f = 1:F,
11 g = f + F;
12 h = g + F;
13 Q(f,:) = zt(Rhat(f,:), Rhat(f,:));
14 Q(g,:) = zt(Rhat(g,:), Rhat(g,:));
15 Q(h,:) = zt(Rhat(f,:), Rhat(g,:));
16end
17
18% Solve for v
19rhs = [ones(2*F,1); zeros(F,1)];
20v = Q \ rhs;
21
22% C is a symmetric 3x3 matrix such that C = G * transpose(G)
23C(1,1) = v(1);
24C(1,2) = v(2);
25C(1,3) = v(3);
26C(2,2) = v(4);
27C(2,3) = v(5);
28C(3,3) = v(6);
29C(2,1) = C(1,2);
30C(3,1) = C(1,3);
31C(3,2) = C(2,3);
32
33e = eig(C);
34disp(e)
35
36if (any(e<= 0)),
37 C = C -2*min(e)*eye(3);
38 G = sqrtm(C);
39else
40 G = sqrtm(C);
41end
42
43%neg = 0;
44%if e(1) <= 0, neg = 1; end
45%if e(2) <= 0, neg = 1; end
46%if e(3) <= 0, neg = 1; end
47%if neg == 1, G = [];
48%else G = sqrtm(C);
49%end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m b/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m
new file mode 100755
index 0000000..5a84b86
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m
@@ -0,0 +1,56 @@
1function [G,C] = find3G(Rhat)
2
3% number of frames
4F = size(Rhat,1)/3;
5
6% Build matrix Q such that Q * v = [1,...,1,0,...,0] where v is a six
7% element vector containg all six distinct elements of the Matrix C
8
9clear Q
10for f = 1:F,
11 g = f + F;
12 h = g + F;
13 j = h + F;
14 k = j + F;
15 l = k + F;
16 Q(f,:) = zt(Rhat(f,:), Rhat(f,:));
17 Q(g,:) = zt(Rhat(g,:), Rhat(g,:));
18 Q(h,:) = zt(Rhat(h,:), Rhat(h,:));
19 Q(j,:) = zt(Rhat(f,:), Rhat(g,:));
20 Q(k,:) = zt(Rhat(f,:), Rhat(h,:));
21 Q(l,:) = zt(Rhat(g,:), Rhat(h,:));
22end
23
24% Solve for v
25rhs = [ones(3*F,1); zeros(3*F,1)];
26v = Q \ rhs;
27
28% C is a symmetric 3x3 matrix such that C = G * transpose(G)
29C(1,1) = v(1);
30C(1,2) = v(2);
31C(1,3) = v(3);
32C(2,2) = v(4);
33C(2,3) = v(5);
34C(3,3) = v(6);
35C(2,1) = C(1,2);
36C(3,1) = C(1,3);
37C(3,2) = C(2,3);
38
39e = eig(C);
40disp(e)
41
42
43if (any(e<= 0)),
44 C = C -2*min(e)*eye(3);
45 G = sqrtm(C);
46else
47 G = sqrtm(C);
48end
49
50%neg = 0;
51%if e(1) <= 0, neg = 1; end
52%if e(2) <= 0, neg = 1; end
53%if e(3) <= 0, neg = 1; end
54%if neg == 1, G = [];
55%else G = sqrtm(C);
56%end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/hotel.mat b/SD-VBS/common/toolbox/toolbox_basic/fact/hotel.mat
new file mode 100755
index 0000000..61ea6c8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/hotel.mat
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/show_3dpoints.m b/SD-VBS/common/toolbox/toolbox_basic/fact/show_3dpoints.m
new file mode 100755
index 0000000..b6edfd5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/show_3dpoints.m
@@ -0,0 +1,22 @@
1function show_3dpoints(S)
2
3
4for j=1:size(S,2),
5 x = S(1,j);
6 y = S(2,j);
7 z = S(3,j);
8 plot3(x,y,z,'*');
9 hold on;
10 plot3([x,0],[y,0],[z,0],'r');
11% plot3([x,x],[y,y],[z,0],'r');
12% plot3([x,0],[y,y],[z,z],'r'); plot3([x,x],[y,0],[z,z],'r');
13 text(x,y,z,int2str(j))
14% plot3(x,y,0,'co');
15end
16
17grid on
18xlabel('x');
19ylabel('y');
20zlabel('z');
21
22hold off \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/show_S.m b/SD-VBS/common/toolbox/toolbox_basic/fact/show_S.m
new file mode 100755
index 0000000..5828696
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/show_S.m
@@ -0,0 +1,17 @@
1function show_S(S,fig)
2
3if (nargin == 1),
4 figure(1);
5else
6 figure(fig);
7end
8
9num_points = size(S,2);
10
11subplot(1,2,1); plot(S(1,:),S(3,:),'cx'); axis('equal');axis('square');hold on
12subplot(1,2,2); plot(S(2,:),S(3,:),'cx'); axis('equal');axis('square');hold on
13
14for j=1:num_points,
15 subplot(1,2,1);text(S(1,j),S(3,j),int2str(j));hold off
16 subplot(1,2,2);text(S(2,j),S(3,j),int2str(j));hold off
17end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/show_t.m b/SD-VBS/common/toolbox/toolbox_basic/fact/show_t.m
new file mode 100755
index 0000000..b475c76
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/show_t.m
@@ -0,0 +1,10 @@
1function show_t(t)
2
3frames = 0.5*length(t);
4
5ts = reshape(t,frames,2);
6
7plot(ts(:,1),ts(:,2));
8hold on
9plot(ts(:,1),ts(:,2),'rx');
10hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/show_t3.m b/SD-VBS/common/toolbox/toolbox_basic/fact/show_t3.m
new file mode 100755
index 0000000..2766061
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/show_t3.m
@@ -0,0 +1,10 @@
1function show_t(t)
2
3frames = length(t)/3;
4
5ts = reshape(t,frames,3);
6
7plot3(ts(:,1),ts(:,2),ts(:,3));
8hold on
9plot3(ts(:,1),ts(:,2),ts(:,3),'rx');
10hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/zt.m b/SD-VBS/common/toolbox/toolbox_basic/fact/zt.m
new file mode 100755
index 0000000..3f88d21
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/zt.m
@@ -0,0 +1,6 @@
1% the z' operator described in the paper (returns a row vector)
2
3function v = zt(a, b)
4
5v = [ a(1)*b(1), a(1)*b(2)+a(2)*b(1), a(1)*b(3)+a(3)*b(1), ...
6 a(2)*b(2), a(2)*b(3)+a(3)*b(2), a(3)*b(3) ];
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/91048.jpg b/SD-VBS/common/toolbox/toolbox_basic/filter/91048.jpg
new file mode 100755
index 0000000..6b2313b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/91048.jpg
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/bar2d.m b/SD-VBS/common/toolbox/toolbox_basic/filter/bar2d.m
new file mode 100755
index 0000000..76fa819
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/bar2d.m
@@ -0,0 +1,16 @@
1function kernel = bar2d(sigx,sigy,siz,angle)
2
3X = -siz:.1:siz;
4G = exp(-0.5*X.^2/sigx^2);
5
6DGG = (1/sigy^2) * ((X/sigy).^2-1) .* exp(- (X/sigy).^2/2);
7%DGG = (X.^2/(sqrt(2*pi)*sigy^5) - 1/(sqrt(2*pi)*sigy^2)) .* ...
8% exp(-0.5*X.^2/sigy^2);
9
10K = G'*DGG;
11K = rotate_J(angle,K);
12
13K = imresize(K,0.1);
14K = K-mean(mean(K));
15
16kernel = K; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/barrot.m b/SD-VBS/common/toolbox/toolbox_basic/filter/barrot.m
new file mode 100755
index 0000000..bd7676e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/barrot.m
@@ -0,0 +1,22 @@
1img1 = gifread('color010.gif');
2img1 = img1(220:350,1:200);
3img2 = gifread('color-avg.gif');
4img2 = img2(220:350,1:200);
5
6sigx = 3;
7sigy = 3;
8siz = 8;
9angles = 0:19:179;
10
11[Imag1,Iangle1] = brute_force_angle(img1,sigx,sigy,siz,angles);
12[Imag2,Iangle2] = brute_force_angle(img2,sigx,sigy,siz,angles);
13
14tresh = max(max(Imag1))*0.1
15D = angle_diff(Imag1,Iangle1,Imag2,Iangle2,tresh);
16subplot(2,2,1); imagesc(Iangle1*180/pi); colorbar;
17subplot(2,2,2); imagesc(Iangle2*180/pi); colorbar;
18subplot(2,2,3); imagesc(D*180/pi); colorbar;
19subplot(2,2,4); imagesc(Imag1); colorbar;
20colormap(jet)
21
22
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/bars.m b/SD-VBS/common/toolbox/toolbox_basic/filter/bars.m
new file mode 100755
index 0000000..77eccea
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/bars.m
@@ -0,0 +1,39 @@
1function [filt] = bars(X,Y,ks);
2%FIL1 the first filter to use has the following specifications:
3%
4% real part: 2nd derivative of gaussian along Y
5% normal gaussian along X
6% This filter is elongated along the X direction
7% imag part: hilbert transform of the real part
8%
9% [filt] = fil1(X,Y,ks);
10% X,Y : index matrix obtained by meshgrid
11% ks : kernel size
12% filt : the output kernel
13%
14
15%%
16%% (c) Thomas Leung
17%% California Institute of Technology
18%% Feb 27, 1994.
19%%
20
21if(nargin == 2)
22 ks = 17;
23end
24
25sigmay = 2.4 * ks / 17;
26sigmax = 3 * sigmay;
27
28fxr = exp(-(X/sigmax).^2/2);
29fyr = (1/sigmay^2) * ((Y/sigmay).^2-1) .* exp(- (Y/sigmay).^2/2);
30nrm = 1/(sigmax*sigmay*2*pi);
31
32% real part of filter
33fr = nrm * fxr .* fyr;
34
35% imag part of filter
36filt = hilbert(fr);
37
38
39return;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/clip_image.m b/SD-VBS/common/toolbox/toolbox_basic/filter/clip_image.m
new file mode 100755
index 0000000..bf7b50c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/clip_image.m
@@ -0,0 +1,6 @@
1function J = clip_image(I,w)
2
3[size_y,size_x] = size(I);
4
5J = I(w+1:size_y-w,w+1:size_x-w);
6
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_J_simple.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_J_simple.m
new file mode 100755
index 0000000..e790601
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_J_simple.m
@@ -0,0 +1,50 @@
1function J = compute_J(I,A,D,base)
2%% function J = compute_J(I,A,D)
3%
4
5if nargin == 3,
6 base = -1;
7end
8
9[size_y,size_x] = size(I);
10[center_x,center_y] = find_center(size_x,size_y);
11
12add_x = round(size_x*0.45);
13add_y = round(size_y*0.45);
14big_I = base*ones(size_y+2*add_y,size_x+2*add_x);
15
16big_I(add_y+1:add_y+size_y,add_x+1:add_x+size_x) = I;
17
18center_x = add_x+ center_x;
19center_y = add_y+ center_y;
20[size_y,size_x] = size(big_I);
21
22%a = angle * pi/180;
23%A = [cos(a),-sin(a);sin(a),cos(a)];
24
25[XX,YY] = meshgrid(1:size_x,1:size_y);
26
27x = reshape(XX,size_x*size_y,1);
28y = reshape(YY,size_x*size_y,1);
29index(:,1) = x-center_x;
30
31%index(:,2) = (size_y+1) - y;
32index(:,2) = y-center_y;
33
34position_new = A*index';
35position_new(1,:) = position_new(1,:)+D(1)+center_x;
36position_new(2,:) = position_new(2,:)+D(2)+center_y;
37%position_new(2,:) = (size_y+1) - position_new(2,:);
38
39position_new_x = reshape(position_new(1,:),size_y,size_x);
40position_new_y = reshape(position_new(2,:),size_y,size_x);
41
42J = m_interp4(big_I,position_new_x,position_new_y);
43
44
45[size_y,size_x] = size(I);
46J = J(add_y+1:add_y+size_y,add_x+1:add_x+size_x);
47
48
49
50
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_angle.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_angle.m
new file mode 100755
index 0000000..7a995af
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_angle.m
@@ -0,0 +1,18 @@
1function [angle,mag,c2,c3] = compute_angle(I)
2
3[g,ga,gb,gc] = compute_g2(I,0);
4[h,ha,hb,hc,hd] = compute_h2(I,0);
5
6c2 = 0.5*(ga.^2 - gc.^2) + 0.46875*(ha.^2 - hd.^2) +...
7 0.28125*(hb.^2 - hc.^2) + 0.1875*(ha.*hc - hb.*hd);
8
9c3 = -ga.*gb - gb.*gc - 0.9375*(hc.*hd + ha.*hb) -...
10 1.6875*hb.*hc - 0.1875*ha.*hd;
11
12[angle,mag] = cart2pol(-c2,-c3);
13
14%angle = angle/2+pi/2;
15%angle = (angle>pi).*(angle-2*pi) + (angle<=pi).*angle;
16
17angle = angle/2;
18mag = sqrt(mag); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_filter_fft.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_filter_fft.m
new file mode 100755
index 0000000..359c6ba
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_filter_fft.m
@@ -0,0 +1,84 @@
1function [filter_output,filters] = compute_filter_fft(I,sig,r,sz,num_ori);
2%
3%
4%
5
6ori_incr=180/num_ori;
7ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
8
9as = ori_offset:ori_incr:180+ori_offset-ori_incr;
10
11filter_output = [];
12filters = [];
13
14wsz = 2*round(sz(end)) + 1;
15M1 = wsz;M2 = wsz;
16
17%%%%% prepare FFT of image %%%%%%%%%%%%%
18
19[N1,N2]=size(I);
20tmp=zeros(size(I)+[M1-1 M2-1]);
21tmp(1:N1,1:N2)=I;
22IF=fft2(tmp);
23
24
25%%%%%%%%%% filtering stage %%%%%%%%%%%
26if size(sig,2)== 1,
27
28 for j = 1:length(as),
29 fprintf('.');
30 angle = as(j);
31
32 g = mdoog2(sig,r,angle,round(sz));
33
34 g = g - mean(reshape(g,prod(size(g)),1));
35
36 g = g/sum(sum(abs(g)));
37
38 filters(:,:,j) = g;
39
40 gF = fft2(g,N1+M1-1,N2+M2-1);
41 IgF = IF.*gF;
42 Ig = real(ifft2(IgF));
43 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
44
45 %c = conv2(I,g,'valid');
46
47 filter_output(:,:,j) = Ig;
48 end
49else
50
51 % there are multiple scales
52 sigs = sig;
53 szs = sz;
54 for k = 1:size(sigs,2),
55 sig = sigs(k);
56 sz = szs(end);
57 fprintf('%d',k);
58 for j = 1:length(as),
59 fprintf('.');
60 angle = as(j);
61
62 g = mdoog2(sig,r,angle,round(sz));
63 g = g - mean(reshape(g,prod(size(g)),1));
64 g = g/sum(sum(abs(g)));
65
66 gF = fft2(g,N1+M1-1,N2+M2-1);
67 IgF = IF.*gF;
68 Ig = real(ifft2(IgF));
69 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
70
71 %c = conv2(I,g,'valid');
72 %c = conv2(I,g,'same');
73
74 filter_output(:,:,j,k) = Ig;
75 filters(:,:,j,k) = g;
76 end
77
78
79 end
80
81end
82
83fprintf('\n');
84
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_g2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_g2.m
new file mode 100755
index 0000000..ac27d00
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_g2.m
@@ -0,0 +1,23 @@
1function [g,ga,gb,gc] = compute_g2(I,angle)
2
3if (nargin == 1),
4 angle = 0;
5end
6
7f1 = [0.0094 0.1148 0.3964 -0.0601 -0.9213 -0.0601 0.3964 0.1148 0.0094];
8f2 = [0.0008 0.0176 0.166 0.6383 1.0 0.6383 0.166 0.0176 0.0008];
9f3 = [-0.0028 -0.048 -0.302 -0.5806 0 0.5806 0.302 0.048 0.0028];
10
11%ga = conv2(conv2(I,f2,'same'),f1','same');
12%gb = conv2(conv2(I,f3,'same'),f3','same');
13%gc = conv2(conv2(I,f1,'same'),f2','same');
14
15ga = conv2(conv2(I,f1,'same'),f2','same');
16gb = conv2(conv2(I,f3,'same'),f3','same');
17gc = conv2(conv2(I,f2,'same'),f1','same');
18
19ka = cos(angle)^2;
20kb = -2*cos(angle)*sin(angle);
21kc = sin(angle)^2;
22
23g = ka*ga + kb*gb + kc*gc;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_h2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_h2.m
new file mode 100755
index 0000000..e4cdcfb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_h2.m
@@ -0,0 +1,27 @@
1function [h,ha,hb,hc,hd] = compute_h2(I,angle)
2
3if (nargin == 1),
4 angle = 0;
5end
6
7f1 = [0.0098 0.0618 -0.0998 -0.7551 0 0.7551 0.0998 -0.0618 -0.0098];
8f2 = [ 0.0008 0.0176 0.166 0.6383 1 0.6383 0.166 0.0176 0.0008];
9f3 = -[-0.002 -0.0354 -0.2225 -0.4277 0 0.4277 0.2225 0.0354 0.002];
10f4 = [0.0048 0.0566 0.1695 -0.1889 -0.7349 -0.1889 0.1695 0.0566 0.0048];
11
12%ha = conv2(conv2(I,f2,'same'),f1','same');
13%hb = conv2(conv2(I,f3,'same'),f4','same');
14%hc = conv2(conv2(I,f4,'same'),f3','same');
15%hd = conv2(conv2(I,f1,'same'),f2','same');
16
17ha = conv2(conv2(I,f1,'same'),f2','same');
18hb = conv2(conv2(I,f4,'same'),f3','same');
19hc = conv2(conv2(I,f3,'same'),f4','same');
20hd = conv2(conv2(I,f2,'same'),f1','same');
21
22ka = cos(angle)^3;
23kb = -3*cos(angle)^2*sin(angle);
24kc = 3*cos(angle)*sin(angle)^2;
25kd = -sin(angle)^3;
26
27h = ka*ha + kb*hb + kc*hc + kd*hd;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/compute_ofilter_fft.m b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_ofilter_fft.m
new file mode 100755
index 0000000..41989ed
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/compute_ofilter_fft.m
@@ -0,0 +1,88 @@
1function [filter_output,filters] = compute_odd_filter_fft(I,sig,r,sz,num_ori);
2%
3% computes the filter response of I to the set of odd symmetric filters
4%
5% sig = scale(sigma) for the filters
6% r = enlongation factor
7% sz = the radius of the filters
8% num_ori = number of orientations
9%
10
11ori_incr=180/num_ori;
12ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
13
14as = ori_offset:ori_incr:180+ori_offset-ori_incr;
15
16filter_output = zeros(size(I,1),size(I,2),num_ori,length(sig));
17filters = [];
18
19wsz = 2*round(sz(end)) + 1;
20M1 = wsz;M2 = wsz;
21
22%%%%% prepare FFT of image %%%%%%%%%%%%%
23
24[N1,N2]=size(I);
25tmp=zeros(size(I)+[M1-1 M2-1]);
26tmp(1:N1,1:N2)=I;
27IF=fft2(tmp);
28
29
30%%%%%%%%%% filtering stage %%%%%%%%%%%
31if size(sig,2)== 1,
32
33 for j = 1:length(as),
34 fprintf('.');
35 angle = as(j);
36
37 g = mk_odd_filter(sig,r,angle,round(sz));
38
39 g = g - mean(reshape(g,prod(size(g)),1));
40
41 g = g/sum(sum(abs(g)));
42
43 filters(:,:,j,1) = g;
44
45 gF = fft2(g,N1+M1-1,N2+M2-1);
46 IgF = IF.*gF;
47 Ig = real(ifft2(IgF));
48 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
49
50 %c = conv2(I,g,'valid');
51
52 filter_output(:,:,j,1) = Ig;
53 end
54else
55
56 % there are multiple scales
57 sigs = sig;
58 szs = sz;
59 for k = 1:size(sigs,2),
60 sig = sigs(k);
61 sz = szs(end);
62 fprintf('%d',k);
63
64 for j = 1:length(as),
65 fprintf('.');
66 angle = as(j);
67
68 g = mk_odd_filter(sig,r,angle,round(sz));
69 g = g - mean(reshape(g,prod(size(g)),1));
70 g = g/sum(sum(abs(g)));
71
72 gF = fft2(g,N1+M1-1,N2+M2-1);
73 IgF = IF.*gF;
74 Ig = real(ifft2(IgF));
75 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
76
77 %c = conv2(I,g,'valid');
78 %c = conv2(I,g,'same');
79
80 filter_output(:,:,j,k) = Ig;
81 filters(:,:,j,k) = g;
82 end
83 end
84
85end
86
87fprintf('\n');
88
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/dgauss.m b/SD-VBS/common/toolbox/toolbox_basic/filter/dgauss.m
new file mode 100755
index 0000000..207e781
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/dgauss.m
@@ -0,0 +1,16 @@
1function dg = dgauss(sig)
2% first derivative of N(sig)
3% cutoff after 1% of max
4
5 i = 1;
6 max = 0;
7 dgi = max;
8 dg = [dgi];
9 while dgi >= 0.01*max
10 dgi = i / (sqrt(2*pi) * sig^3) * exp(-0.5*i^2/sig^2);
11 dg = [dgi dg -dgi];
12 i = i + 1;
13 if dgi > max
14 max = dgi;
15 end
16 end; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/dog1.m b/SD-VBS/common/toolbox/toolbox_basic/filter/dog1.m
new file mode 100755
index 0000000..e9f64e6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/dog1.m
@@ -0,0 +1,28 @@
1function G=dog1(sig,N);
2% G=dog1(sig,N);
3
4% by Serge Belongie
5
6no_pts=N; % no. of points in x,y grid
7
8[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
9
10sigi=0.71*sig;
11sigo=1.14*sig;
12Ci=diag([sigi,sigi]);
13Co=diag([sigo,sigo]);
14
15X=[x(:) y(:)];
16
17Ga=gaussian(X,[0 0]',Ci);
18Ga=reshape(Ga,N,N);
19Gb=gaussian(X,[0 0]',Co);
20Gb=reshape(Gb,N,N);
21
22a=1;
23b=-1;
24
25G = a*Ga + b*Gb;
26
27G=G-mean(G(:));
28
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/dog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/dog2.m
new file mode 100755
index 0000000..8446198
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/dog2.m
@@ -0,0 +1,31 @@
1function G=dog2(sig,N);
2% G=dog2(sig,N);
3
4% by Serge Belongie
5
6no_pts=N; % no. of points in x,y grid
7
8[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
9
10sigi=0.62*sig;
11sigo=1.6*sig;
12C=diag([sig,sig]);
13Ci=diag([sigi,sigi]);
14Co=diag([sigo,sigo]);
15
16X=[x(:) y(:)];
17
18Ga=gaussian(X,[0 0]',Ci);
19Ga=reshape(Ga,N,N);
20Gb=gaussian(X,[0 0]',C);
21Gb=reshape(Gb,N,N);
22Gc=gaussian(X,[0 0]',Co);
23Gc=reshape(Gc,N,N);
24
25a=-1;
26b=2;
27c=-1;
28
29G = a*Ga + b*Gb + c*Gc;
30
31G=G-mean(G(:));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/doog1.m b/SD-VBS/common/toolbox/toolbox_basic/filter/doog1.m
new file mode 100755
index 0000000..dd8e87b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/doog1.m
@@ -0,0 +1,32 @@
1function H=doog1(sig,r,th,N);
2% H=doog1(sig,r,th,N);
3
4
5% by Serge Belongie
6
7no_pts=N; % no. of points in x,y grid
8
9[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
10
11phi=pi*th/180;
12sigy=sig;
13sigx=r*sig;
14R=[cos(phi) -sin(phi); sin(phi) cos(phi)];
15C=R*diag([sigx,sigy])*R';
16
17X=[x(:) y(:)];
18
19Gb=gaussian(X,[0 0]',C);
20Gb=reshape(Gb,N,N);
21
22m=R*[0 sig]';
23
24a=1;
25b=-1;
26
27% make odd-symmetric filter
28Ga=gaussian(X,m/2,C);
29Ga=reshape(Ga,N,N);
30Gb=rot90(Ga,2);
31H=a*Ga+b*Gb;
32
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/doog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/doog2.m
new file mode 100755
index 0000000..a0511cb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/doog2.m
@@ -0,0 +1,38 @@
1function G=doog2(sig,r,th,N);
2% G=doog2(sig,r,th,N);
3% Make difference of offset gaussians kernel
4% theta is in degrees
5% (see Malik & Perona, J. Opt. Soc. Amer., 1990)
6%
7% Example:
8% >> imagesc(doog2(1,12,0,64,1))
9% >> colormap(gray)
10
11% by Serge Belongie
12
13no_pts=N; % no. of points in x,y grid
14
15[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
16
17phi=pi*th/180;
18sigy=sig;
19sigx=r*sig;
20R=[cos(phi) -sin(phi); sin(phi) cos(phi)];
21C=R*diag([sigx,sigy])*R';
22
23X=[x(:) y(:)];
24
25Gb=gaussian(X,[0 0]',C);
26Gb=reshape(Gb,N,N);
27
28m=R*[0 sig]';
29Ga=gaussian(X,m,C);
30Ga=reshape(Ga,N,N);
31Gc=rot90(Ga,2);
32
33a=-1;
34b=2;
35c=-1;
36
37G = a*Ga + b*Gb + c*Gc;
38
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt.m b/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt.m
new file mode 100755
index 0000000..25fa5f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt.m
@@ -0,0 +1,82 @@
1% script for fft-based filtering
2
3% set up filterbank
4make_filterbank
5
6% prepare FFT of image for filtering
7[N1,N2]=size(V);
8I=zeros(size(V)+[M1-1 M2-1]);
9I(1:N1,1:N2)=V;
10IF=fft2(I);
11FI=zeros(N1,N2,total_num_filt);
12
13% apply filters
14for n=1:total_num_filt
15 disp(n)
16 f=rot90(FB(:,:,n),2);
17 fF=fft2(f,N1+M1-1,N2+M2-1);
18 IfF=IF.*fF;
19 If=real(ifft2(IfF));
20 If=If(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
21 FI(:,:,n)=If;
22% im(If)
23% drawnow
24end
25
26%%%% end of filtering part; the remainder is for reconstruction & analysis
27break
28
29
30% use pseudoinverse to reconstruct image from filter projections
31fbv=reshape(FB,M1*M2,total_num_filt)';
32fbi=pinv(fbv);
33
34% find principal components
35T=reshape(FI,N1*N2,total_num_filt)';
36C=T*T';
37[U,S,junk]=svd(C);
38s=diag(S);
39
40% synthesize using some eigenvectors
41synth=fbi*U;
42k=ceil(sqrt(total_num_filt));
43for n=1:total_num_filt
44 subplot(k,k,n)
45 im(reshape(synth(:,n),M1,M2));
46 title(num2str(s(n)))
47 drawnow
48end
49
50% synthesize at a point by clicking on coordinates
51figure(1)
52im(V)
53[x,y]=ginput(1);
54x=round(x);
55y=round(y);
56u=squeeze(FI(y,x,:));
57synth=fbi*u;
58synth=reshape(synth,M1,M2);
59figure(2)
60subplot(1,2,1)
61im(V)
62axis([x-M2/2 x+M2/2 y-M1/2 y+M1/2])
63subplot(1,2,2)
64im(synth)
65title(num2str(max(synth(:))));
66
67figure(3)
68plot(u,'o-')
69
70% show pseudoinverse filterbank
71if 0
72k=ceil(sqrt(total_num_filt));
73for n=1:total_num_filt
74 subplot(k,k,n)
75 im(reshape(fbi(:,n),M1,M2));
76 axis('off')
77 drawnow
78end
79end
80
81
82
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt_2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt_2.m
new file mode 100755
index 0000000..9c84e96
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/fft_filt_2.m
@@ -0,0 +1,29 @@
1function FI=fft_filt_2(V,FB,sf);
2% FI=fft_filt_2(V,FB,sf);
3% fft-based filtering
4% requires image to be called "V"
5% and filters to be in FB
6% sf is the subsampling factor
7%
8% FI is the result
9
10[M1,M2,N3]=size(FB);
11% prepare FFT of image for filtering
12[N1,N2]=size(V);
13I=zeros(size(V)+[M1-1 M2-1]);
14I(1:N1,1:N2)=V;
15N1s=length(1:sf:N1);
16N2s=length(1:sf:N2);
17IF=fft2(I);
18FI=zeros(N1s,N2s,N3);
19
20% apply filters
21for n=1:N3;
22 f=rot90(FB(:,:,n),2);
23 fF=fft2(f,N1+M1-1,N2+M2-1);
24 IfF=IF.*fF;
25 If=real(ifft2(IfF));
26 If=If(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
27 FI(:,:,n)=If(1:sf:N1,1:sf:N2);
28end
29
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/filter_bank_jshi.tar b/SD-VBS/common/toolbox/toolbox_basic/filter/filter_bank_jshi.tar
new file mode 100755
index 0000000..b43b49c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/filter_bank_jshi.tar
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/gauss.m b/SD-VBS/common/toolbox/toolbox_basic/filter/gauss.m
new file mode 100755
index 0000000..f0403ed
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/gauss.m
@@ -0,0 +1,16 @@
1function dg = gauss(sig)
2% first derivative of N(sig)
3% cutoff after 1% of max
4
5 i = 1;
6 max = 0;
7 dgi = max;
8 dg = [1/ (sqrt(2*pi) * sig) ];
9 while dgi >= 0.01*max
10 dgi = 1/ (sqrt(2*pi) * sig) * exp(-0.5*i^2/sig^2);
11 dg = [dgi dg dgi];
12 i = i + 1;
13 if dgi > max
14 max = dgi;
15 end
16 end; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/gaussian.m b/SD-VBS/common/toolbox/toolbox_basic/filter/gaussian.m
new file mode 100755
index 0000000..509b129
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/gaussian.m
@@ -0,0 +1,31 @@
1function p=gaussian(x,m,C);
2% p=gaussian(x,m,C);
3%
4% Evaluate the multi-variate density with mean vector m and covariance
5% matrix C for the input vector x.
6%
7% p=gaussian(X,m,C);
8%
9% Vectorized version: Here X is a matrix of column vectors, and p is
10% a vector of probabilities for each vector.
11
12d=length(m);
13
14if size(x,1)~=d
15 x=x';
16end
17N=size(x,2);
18
19detC = det(C);
20if rcond(C)<eps
21% fprintf(1,'Covariance matrix close to singular. (gaussian.m)\n');
22 p = zeros(N,1);
23else
24 m=m(:);
25 M=m*ones(1,N);
26 denom=(2*pi)^(d/2)*sqrt(abs(detC));
27 mahal=sum(((x-M)'*inv(C)).*(x-M)',2); % Chris Bregler's trick
28 numer=exp(-0.5*mahal);
29 p=numer/denom;
30end
31
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff2.m
new file mode 100755
index 0000000..31f3ac5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff2.m
@@ -0,0 +1,43 @@
1function [diffI,corr,mag,theta] = get_diff2(I,J,w)
2% car: I
3% background: J
4
5% half window size
6if (nargin == 2)
7 w = 1;
8end
9
10[gIx,gIy] = grad2(I,w);
11[gJx,gJy] = grad2(J,w);
12gx = gIx;
13gy = gIy;
14
15% normalize
16sI= sqrt(gIx.*gIx+gIy.*gIy);
17sJ= sqrt(gJx.*gJx+gJy.*gJy);
18gIx = gIx./sI;
19gIy = gIy./sI;
20gJx = gJx./sJ;
21gJy = gJy./sJ;
22
23theta = cart2pol(gIy,gIx);
24corr = gIx.*gJx + gIy.*gJy;
25
26%[gx,gy]= grad((I-J),w);mag = sqrt(gx.*gx+gy.*gy);
27%mag = sI;
28
29
30mag = sqrt((cos(theta).^2).*gy.^2 + (sin(theta).^2).*gx.^2 +...
31 2*cos(theta).*sin(theta).*gx.*gy);
32
33% want to look at the grad. mag greater than 10, and corr less than 0.9
34threshold = max(3.5,0.1*max(max(mag(5:size(mag,1)-5,5:size(mag,2)-5))))
35diffI = (abs(corr)<0.85).*(mag>threshold);
36
37
38
39
40
41
42
43
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff_free.m b/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff_free.m
new file mode 100755
index 0000000..f020fab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/get_diff_free.m
@@ -0,0 +1,8 @@
1function [diff,corr,mag,angle] = get_diff_free(I,J)
2
3[angle,mag,c2,c3] = compute_angle(I);
4[angleJ,magJ] = compute_angle(J);
5
6corr = cos(angle).*cos(angleJ) + sin(angle).*sin(angleJ);
7threshold = 0.075*max(max(mag(5:size(mag,1)-5,5:size(mag,2)-5)));
8diff = (abs(corr)<0.9).*(mag>threshold); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/grad1.m b/SD-VBS/common/toolbox/toolbox_basic/filter/grad1.m
new file mode 100755
index 0000000..eca34db
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/grad1.m
@@ -0,0 +1,11 @@
1function [gx,gy] = grad2(I,ratio)
2%
3%
4
5kern = dgauss(ratio);kern = kern/sum(abs(kern));
6gkern = gauss(ratio);gkern = gkern/sum(abs(kern));
7
8gx = conv2(I,kern,'same');
9gx = conv2(gx,gkern','same');
10
11gy = conv2(conv2(I,kern','same'),gkern,'same');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/grad2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/grad2.m
new file mode 100755
index 0000000..ea4ec0e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/grad2.m
@@ -0,0 +1,11 @@
1function [gx,gy] = grad2(I,ratio)
2%
3%
4
5ddgauss = gradient(dgauss(ratio));ddgauss = ddgauss/sum(abs(ddgauss));
6gkern = gauss(ratio); gkern = gkern/sum(abs(gkern));
7
8gx = conv2(I,ddgauss,'same');
9gx = conv2(gx,gkern','same');
10
11gy = conv2(conv2(I,ddgauss','same'),gkern,'same');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/m_interp4.m b/SD-VBS/common/toolbox/toolbox_basic/filter/m_interp4.m
new file mode 100755
index 0000000..314f140
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/m_interp4.m
@@ -0,0 +1,49 @@
1function [F,mask] = m_interp4(z,s,t)
2%INTERP4 2-D bilinear data interpolation.
3% ZI = INTERP4(Z,XI,YI) assumes X = 1:N and Y = 1:M, where
4% [M,N] = SIZE(Z).
5%
6% Copyright (c) 1984-93 by The MathWorks, Inc.
7% Clay M. Thompson 4-26-91, revised 7-3-91, 3-22-93 by CMT.
8%
9% modified to
10
11
12[nrows,ncols] = size(z);
13
14
15if any(size(z)<[3 3]), error('Z must be at least 3-by-3.'); end
16if size(s)~=size(t), error('XI and YI must be the same size.'); end
17
18% Check for out of range values of s and set to 1
19sout = find((s<1)|(s>ncols));
20if length(sout)>0, s(sout) = ones(size(sout)); end
21
22% Check for out of range values of t and set to 1
23tout = find((t<1)|(t>nrows));
24if length(tout)>0, t(tout) = ones(size(tout)); end
25
26% Matrix element indexing
27ndx = floor(t)+floor(s-1)*nrows;
28
29% Compute intepolation parameters, check for boundary value.
30d = find(s==ncols);
31s(:) = (s - floor(s));
32if length(d)>0, s(d) = s(d)+1; ndx(d) = ndx(d)-nrows; end
33
34% Compute intepolation parameters, check for boundary value.
35d = find(t==nrows);
36t(:) = (t - floor(t));
37if length(d)>0, t(d) = t(d)+1; ndx(d) = ndx(d)-1; end
38d = [];
39
40% Now interpolate, reuse u and v to save memory.
41F = ( z(ndx).*(1-t) + z(ndx+1).*t ).*(1-s) + ...
42 ( z(ndx+nrows).*(1-t) + z(ndx+(nrows+1)).*t ).*s;
43
44mask = ones(size(z));
45
46% Now set out of range values to zeros.
47if length(sout)>0, F(sout) = zeros(size(sout));mask(sout)=zeros(size(sout));end
48if length(tout)>0, F(tout) = zeros(size(tout));mask(tout)=zeros(size(tout));end
49
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank.m b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank.m
new file mode 100755
index 0000000..2ff15d2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank.m
@@ -0,0 +1,63 @@
1function FB = make_filterbank(num_ori,num_scale,wsz)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6
7% definine filterbank
8%num_ori=6;
9%num_scale=3;
10
11M1=wsz; % size in pixels
12M2=M1;
13
14ori_incr=180/num_ori;
15ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
16
17FBdoog1=zeros(M1,M2,num_scale,num_ori);
18FBdoog2=zeros(M1,M2,num_scale,num_ori);
19FBdog1=zeros(M1,M2,num_scale);
20FBdog2=zeros(M1,M2,num_scale);
21
22% elongated filter set
23counter = 1;
24filter_scale = 1.0;
25filter_scale_step = sqrt(2);
26
27for m=1:num_scale
28 f=dog1(filter_scale,M1);
29 FBdog1(:,:,m)=f;
30 f=dog2(filter_scale,M1);
31 FBdog2(:,:,m)=f;
32 counter=counter+1;
33 for n=1:num_ori
34 % r=12 here is equivalent to Malik's r=3;
35 f=doog2(filter_scale,6,ori_offset+(n-1)*ori_incr,M1);
36 FBdoog2(:,:,m,n)=f;
37 f=doog1(filter_scale,6,ori_offset+(n-1)*ori_incr,M1);
38 FBdoog1(:,:,m,n)=f;
39 end
40 filter_scale = filter_scale * filter_scale_step;
41end
42
43FB=cat(3,3*FBdog1,4.15*FBdog2,2*reshape(FBdoog1,M1,M2,num_scale*num_ori),2*reshape(FBdoog2,M1,M2,num_scale*num_ori));
44total_num_filt=size(FB,3);
45
46nb = size(FB,3);
47for j=1:nb,
48 F = FB(:,:,j);
49 a = sum(sum(abs(F)));
50 FB(:,:,j) = FB(:,:,j)/a;
51end
52
53
54if 0
55k=ceil(sqrt(total_num_filt));
56for n=1:total_num_filt
57 subplot(k,k,n)
58 im(FB(:,:,n));
59 axis('off')
60 drawnow
61end
62end
63
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_23.m b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_23.m
new file mode 100755
index 0000000..f9fcaa9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_23.m
@@ -0,0 +1,40 @@
1function [FB,M1,M2,N3]=make_filterbank_23;
2% multi-scale even and odd filters
3
4M1=31; % size in pixels
5M2=M1;
6num_ori=6;
7num_scales=3;
8num_phases=2;
9N3=num_ori*num_scales*num_phases;
10FB=zeros(M1,M2,N3);
11
12counter=1;
13
14for m=1:num_scales
15 for n=1:num_ori
16 [F1,F2]=quadpair(sqrt(2)^m,3,180*(n-1)/num_ori,M1);
17 FB(:,:,counter)=F1;
18 counter=counter+1;
19 FB(:,:,counter)=F2;
20 counter=counter+1;
21 end
22end
23
24FB=cat(3,FB,dog2(1,M1),dog2(sqrt(2),M1),dog2(2,M1),dog2(2*sqrt(2),M1));
25
26N3=size(FB,3);
27
28% stuff for visualizing spectra of filters:
29if 0
30FBF=zeros(size(FB));
31
32for n=1:36
33 FBF(:,:,n)=abs(fftshift(fft2(FB(:,:,n))));
34end
35
36montage2(FBF)
37
38im(sum(FBF,3))
39
40end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_even.m b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_even.m
new file mode 100755
index 0000000..8c8d802
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_even.m
@@ -0,0 +1,40 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6
7% definine filterbank
8%num_ori=6;
9%num_scale=3;
10
11num_scale = length(filter_scales);
12
13M1=wsz; % size in pixels
14M2=M1;
15
16ori_incr=180/num_ori;
17ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
18
19FB=zeros(M1,M2,num_ori,num_scale);
20
21% elongated filter set
22counter = 1;
23
24for m=1:num_scale
25 for n=1:num_ori
26 % r=12 here is equivalent to Malik's r=3;
27 f=doog2(filter_scales(m),6,ori_offset+(n-1)*ori_incr,M1);
28 FB(:,:,n,m)=f;
29 end
30end
31
32FB=reshape(FB,M1,M2,num_scale*num_ori);
33total_num_filt=size(FB,3);
34
35for j=1:total_num_filt,
36 F = FB(:,:,j);
37 a = sum(sum(abs(F)));
38 FB(:,:,j) = FB(:,:,j)/a;
39end
40
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_odd.m b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_odd.m
new file mode 100755
index 0000000..8103598
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/make_filterbank_odd.m
@@ -0,0 +1,41 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6
7% definine filterbank
8%num_ori=6;
9%num_scale=3;
10
11num_scale = length(filter_scales);
12
13M1=wsz; % size in pixels
14M2=M1;
15
16ori_incr=180/num_ori;
17ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
18
19FB=zeros(M1,M2,num_ori,num_scale);
20
21
22% elongated filter set
23counter = 1;
24
25for m=1:num_scale
26 for n=1:num_ori
27 % r=12 here is equivalent to Malik's r=3;
28 f=doog1(filter_scales(m),6,ori_offset+(n-1)*ori_incr,M1);
29 FB(:,:,n,m)=f;
30 end
31end
32
33FB=reshape(FB,M1,M2,num_scale*num_ori);
34total_num_filt=size(FB,3);
35
36for j=1:total_num_filt,
37 F = FB(:,:,j);
38 a = sum(sum(abs(F)));
39 FB(:,:,j) = FB(:,:,j)/a;
40end
41
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mdoog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mdoog2.m
new file mode 100755
index 0000000..25bc2f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mdoog2.m
@@ -0,0 +1,36 @@
1function G=doog2(sig,r,th,N);
2% [G,H]=doog2(sig,r,th,N);
3% Make difference of offset gaussians kernel
4% theta is in degrees
5% (see Malik & Perona, J. Opt. Soc. Amer., 1990)
6%
7
8
9[x,y]=meshgrid(-N:N,-N:N);
10
11a=-1;
12b=2;
13c=-1;
14
15ya=sig;
16yc=-ya;
17yb=0;
18sigy=sig;
19sigx=r*sig;
20
21Ga=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-ya)/sigy).^2));
22Gb=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yb)/sigy).^2));
23Gc=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yc)/sigy).^2));
24
25Go = a*Ga + b*Gb + c*Gc;
26%Ho = imag(hilbert(Go));
27G = Go;
28
29G = mimrotate(Go,th,'bilinear','crop');
30
31G = G-mean(reshape(G,prod(size(G)),1));
32
33G = G/sum(sum(abs(G)));
34
35
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mimrotate.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mimrotate.m
new file mode 100755
index 0000000..7dd31a2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mimrotate.m
@@ -0,0 +1,119 @@
1function bout = imrotate(arg1,arg2,arg3,arg4)
2%IMROTATE Rotate image.
3% B = IMROTATE(A,ANGLE,'method') rotates the image A by ANGLE
4% degrees. The image returned B will, in general, be larger
5% than A. Invalid values on the periphery are set to one
6% for indexed images or zero for all other image types. Possible
7% interpolation methods are 'nearest','bilinear' or 'bicubic'.
8% 'bilinear' is the default for intensity images, otherwise
9% 'nearest' is used if no method is given.
10%
11% B = IMROTATE(A,ANGLE,'crop') or IMROTATE(A,ANGLE,'method','crop')
12% crops B to be the same size as A.
13%
14% Without output arguments, IMROTATE(...) displays the rotated
15% image in the current axis.
16%
17% See also IMRESIZE, IMCROP, ROT90.
18
19% Clay M. Thompson 8-4-92
20% Copyright (c) 1992 by The MathWorks, Inc.
21% $Revision: 1.14 $ $Date: 1993/09/01 21:27:38 $
22
23if nargin<2, error('Requires at least two input parameters.'); end
24if nargin<3,
25 if isgray(arg1), caseid = 'bil'; else caseid = 'nea'; end
26 docrop = 0;
27elseif nargin==3,
28 if isstr(arg3),
29 method = [lower(arg3),' ']; % Protect against short method
30 caseid = method(1:3);
31 if caseid(1)=='c', % Crop string
32 if isgray(arg1), caseid = 'bil'; else caseid = 'nea'; end
33 docrop = 1;
34 else
35 docrop = 0;
36 end
37 else
38 error('''METHOD'' must be a string of at least three characters.');
39 end
40else
41 if isstr(arg3),
42 method = [lower(arg3),' ']; % Protect against short method
43 caseid = method(1:3);
44 else
45 error('''METHOD'' must be a string of at least three characters.');
46 end
47 docrop = 1;
48end
49
50% Catch and speed up 90 degree rotations
51if rem(arg2,90)==0 & nargin<4,
52 phi = rem(arg2,360);
53 if phi==90,
54 b = rot90(arg1);
55 elseif phi==180,
56 b = rot90(arg1,2);
57 elseif phi==270,
58 b = rot90(arg1,-1);
59 else
60 b = arg1;
61 end
62 if nargout==0, imshow(b), else bout = b; end
63 return
64end
65
66phi = arg2*pi/180; % Convert to radians
67
68% Rotation matrix
69T = [cos(phi) -sin(phi); sin(phi) cos(phi)];
70
71% Coordinates from center of A
72[m,n] = size(arg1);
73if ~docrop, % Determine limits for rotated image
74 siz = ceil(max(abs([(n-1)/2 -(m-1)/2;(n-1)/2 (m-1)/2]*T))/2)*2;
75 uu = -siz(1):siz(1); vv = -siz(2):siz(2);
76else % Cropped image
77 uu = (1:n)-(n+1)/2; vv = (1:m)-(m+1)/2;
78end
79nu = length(uu); nv = length(vv);
80
81blk = bestblk([nv nu]);
82nblks = floor([nv nu]./blk); nrem = [nv nu] - nblks.*blk;
83mblocks = nblks(1); nblocks = nblks(2);
84mb = blk(1); nb = blk(2);
85
86rows = 1:blk(1); b = zeros(nv,nu);
87for i=0:mblocks,
88 if i==mblocks, rows = (1:nrem(1)); end
89 for j=0:nblocks,
90 if j==0, cols = 1:blk(2); elseif j==nblocks, cols=(1:nrem(2)); end
91 if ~isempty(rows) & ~isempty(cols)
92 [u,v] = meshgrid(uu(j*nb+cols),vv(i*mb+rows));
93 % Rotate points
94 uv = [u(:) v(:)]*T'; % Rotate points
95 u(:) = uv(:,1)+(n+1)/2; v(:) = uv(:,2)+(m+1)/2;
96 if caseid(1)=='n', % Nearest neighbor interpolation
97 b(i*mb+rows,j*nb+cols) = interp6(arg1,u,v);
98 elseif all(caseid=='bil'), % Bilinear interpolation
99 b(i*mb+rows,j*nb+cols) = interp2(arg1,u,v,'linear');
100 elseif all(caseid=='bic'), % Bicubic interpolation
101 b(i*mb+rows,j*nb+cols) = interp5(arg1,u,v);
102 else
103 error(['Unknown interpolation method: ',method]);
104 end
105 end
106 end
107end
108
109d = find(isnan(b));
110if length(d)>0,
111 if isind(arg1), b(d) = ones(size(d)); else b(d) = zeros(size(d)); end
112end
113
114if nargout==0,
115 imshow(b), return
116end
117bout = b;
118
119
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mk_odd_filter.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mk_odd_filter.m
new file mode 100755
index 0000000..43ec7d7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mk_odd_filter.m
@@ -0,0 +1,36 @@
1function G=doog2(sig,r,th,N);
2% [G,H]=doog2(sig,r,th,N);
3% Make difference of offset gaussians kernel
4% theta is in degrees
5% (see Malik & Perona, J. Opt. Soc. Amer., 1990)
6%
7
8
9[x,y]=meshgrid(-N:N,-N:N);
10
11a=-1;
12b=2;
13c=-1;
14
15ya=sig;
16yc=-ya;
17yb=0;
18sigy=sig;
19sigx=r*sig;
20
21Ga=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-ya)/sigy).^2));
22Gb=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yb)/sigy).^2));
23Gc=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yc)/sigy).^2));
24
25Go = a*Ga + b*Gb + c*Gc;
26Ho = imag(hilbert(Go));
27%G = Ho;
28
29G = mimrotate(Ho,th,'bilinear','crop');
30
31G = G-mean(reshape(G,prod(size(G)),1));
32
33G = G/sum(sum(abs(G)));
34
35
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog1.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog1.m
new file mode 100755
index 0000000..f1225cc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog1.m
@@ -0,0 +1,20 @@
1function dog1 = mkdog1(sigma_base,size_w)
2%
3% function dog1 = mkdog1(sigma_base,size_w)
4%
5%
6
7%scale_base = 1;
8scale_base = 3;
9
10a = scale_base;
11c = -1*scale_base;
12
13sigma_a = 0.71*sigma_base;
14sigma_c = 1.14*sigma_base;
15
16dog1 = a*mkg(0,0,sigma_a,sigma_a,size_w) +...
17 c*mkg(0,0,sigma_c,sigma_c,size_w);
18
19dog1 = dog1-mean(reshape(dog1,prod(size(dog1)),1));
20dog1 = dog1/sum(sum(abs(dog1)));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog2.m
new file mode 100755
index 0000000..a78824a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdog2.m
@@ -0,0 +1,22 @@
1function dog2 = mkdog2(sigma_base,size_w)
2%
3% function dog2 = mkdog2(sigma_base,size_w)
4%
5%
6
7%scale_base = 1.224;
8scale_base = 4.15;
9
10a = scale_base;
11b = -2*scale_base;
12c = scale_base;
13
14sigma_a = 0.62*sigma_base;
15sigma_b = sigma_base;
16sigma_c = 1.6*sigma_base;
17
18dog2 = a*mkg(0,0,sigma_a,sigma_a,size_w) +...
19 b*mkg(0,0,sigma_b,sigma_b,size_w) +...
20 c*mkg(0,0,sigma_c,sigma_c,size_w);
21
22%dog2 = 255*5.1745*dog2; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoog2.m
new file mode 100755
index 0000000..5db2877
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoog2.m
@@ -0,0 +1,30 @@
1function doog2 = mkdoog2(sigma_w,r,theta,size_w)
2%
3% function doog2 = mkdoog2(sigma_w,r,theta,size_w)
4%
5%
6
7%scale_base = 2.8814;
8scale_base = 2;
9
10a = -1*scale_base;
11b = 2*scale_base;
12c = -1*scale_base;
13
14sigma_x = r*sigma_w;
15sigma_y = sigma_w;
16
17ya = sigma_w;
18yc = -sigma_w;
19yb = 0;
20
21doog2 = a*mkg(0,ya,sigma_x,sigma_y,size_w) +...
22 b*mkg(0,yb,sigma_x,sigma_y,size_w) +...
23 c*mkg(0,yc,sigma_x,sigma_y,size_w);
24
25%doog2 = 255*5.1745*doog2;
26
27
28
29
30
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoogs.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoogs.m
new file mode 100755
index 0000000..e5796bc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mkdoogs.m
@@ -0,0 +1,15 @@
1function [doogs,index] = mkdoogs(sigma_w,r,theta,theta_to,size_w)
2% function doogs = mkdoogs(sigma_w,r,theta,theta_to,size_w)
3%
4
5doogs = [];
6
7angle_start = theta*pi/180;
8angle_end = theta_to*pi/180;
9step = pi/180;
10
11index = 1;
12for k=angle_start:step:angle_end,
13 doogs = [doogs,mkdoog2(sigma_w,r,k,size_w)];
14 index = index +1;
15end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/mkg.m b/SD-VBS/common/toolbox/toolbox_basic/filter/mkg.m
new file mode 100755
index 0000000..1fb1f7e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/mkg.m
@@ -0,0 +1,9 @@
1function g= mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
2%
3% function G = mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
4%
5
6size_wh = round(0.5*size_w);
7[x,y] = meshgrid([-size_wh:1:size_wh],[-size_wh:1:size_wh]);
8g = 1/(2*pi*sigma_x*sigma_y)*(exp(-( ((x-xo)/sigma_x).^2 + ((y-yo)/sigma_y).^2)));
9
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/quadpair.m b/SD-VBS/common/toolbox/toolbox_basic/filter/quadpair.m
new file mode 100755
index 0000000..96c2a22
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/quadpair.m
@@ -0,0 +1,20 @@
1function [F1,F2]=quadpair(sig,lam,th,N);
2% [F1,F2]=quadpair(sig,lam,th,N);
3%
4% For Thomas' ECCV98 filters, use sig=sqrt(2), lam=4.
5
6%N=31;
7[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
8
9
10F1=(4*(y.^2)/(sig^4)-2/(sig^2)).*exp(-(y.^2)/(sig^2)-(x.^2)/(lam^2*sig^2));
11F2=imag(hilbert(F1));
12
13F1=imrotate(F1,th,'bil','crop');
14F2=imrotate(F2,th,'bil','crop');
15
16F1=F1-mean(F1(:));
17F2=F2-mean(F2(:));
18
19F1=F1/norm(F1(:),1);
20F2=F2/norm(F2(:),1); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/smooth.m b/SD-VBS/common/toolbox/toolbox_basic/filter/smooth.m
new file mode 100755
index 0000000..5ef7579
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/smooth.m
@@ -0,0 +1,24 @@
1% smooth an image
2% coordinates (r, c) follow matrix convention;
3% the gaussian is truncated at x = +- tail, and there are samples samples
4% inbetween, where samples = hsamples * 2 + 1
5
6function g = smooth(image, hsamples)
7
8tail=4;
9samples = hsamples * 2 + 1;
10
11x = linspace(-tail, tail, samples);
12gauss = exp(-x.^2);
13%s = sum(gauss)/length(x);gauss = gauss-s;
14gauss = gauss/sum(abs(gauss));
15
16n = gauss * ones(samples,1);
17gauss = gauss/n;
18
19
20g = conv2(conv2(image, gauss,'same'), gauss','same');
21%g = conv2(conv2(image, gauss,'valid'), gauss','valid');
22
23
24
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/softkmean.m b/SD-VBS/common/toolbox/toolbox_basic/filter/softkmean.m
new file mode 100755
index 0000000..b9b4feb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/softkmean.m
@@ -0,0 +1,56 @@
1function [cluster,var,mix,membership,lG] = softkmeans(data,k,cluster0)
2
3[n,D] = size(data);
4var = 1.0;
5var0 = ones(k,1)*var; minvar = 0.0001;
6mix0 = ones(k,1)/k; minmix = 0.0001;
7
8k = size(var0,1);
9[n,D] = size(data);
10
11lGG = [];
12ma = -1e20;
13in = 0;
14
15if (nargin == 2),
16 max_data = max(data);
17 min_data = min(data);
18 %step = (max_data-min_data)/(k+1);
19 %cluster0 = [1:k]'*step+min_data;
20 mag = ones(k,1)*(max_data-min_data);
21 base = ones(k,1)*min_data;
22 cluster0 = rand(k,D).*mag + base;
23end
24
25%cluster0
26for t = 1:3,
27 %rndindx = round(rand(1,k)*(n-3))+2;
28 %cluster0 = (data(rndindx,:)+data(rndindx+1,:)+data(rndindx-1,:))/2;
29 [cluster,var,mix,membership,lG] = softmeans(cluster0,var0,minvar,mix0,minmix,data);
30 eval(sprintf('mix_var_cluster_%d = [mix,var,cluster];',t));
31 eval(sprintf('lG_%d = lG;',t));
32 if ma<lG(size(lG,2)),
33 ma = lG(size(lG,2));
34 in = t;
35 end
36
37end
38
39eval(sprintf('mix_var_cluster = mix_var_cluster_%d;',in));
40eval(sprintf('lG = lG_%d;',in));
41mix = mix_var_cluster(:,1);
42var = mix_var_cluster(:,2);
43cluster = mix_var_cluster(:,3:size(mix_var_cluster,2))
44
45
46[tmp,vecs2cluster] = max(membership');
47vecs2cluster = vecs2cluster';
48cluster_iCV = inv(var);
49
50
51
52
53
54
55
56
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans.m b/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans.m
new file mode 100755
index 0000000..b7e5068
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans.m
@@ -0,0 +1,46 @@
1function [cluster,var,mix,membership,lG] = softmeans(cluster0,var0,minvar,mix0,minmix,data)
2
3[k,D] = size(cluster0);
4[n,D] = size(data);
5cluster_p = cluster0; var_p = var0; mix_p = mix0;
6old_lg = -inf; lG = [];
7
8for iter = 1:30, % max.iterations
9 % E-Step + comp. incomplete likelihood
10
11 H = zeros(n,k);
12 for j = 1:k,
13 Hj = (data-(ones(n,1)*cluster_p(j,:))).^2;
14 if D > 1, Hj = sum(Hj')'; end
15 H(:,j) = exp(Hj /(-2*var_p(j)))/(sqrt(var_p(j))^D);
16 end
17 H = H.*(ones(n,1)*mix_p');
18 new_lg = sum(log(sum(H')/(sqrt(2*pi)^D)));
19 lG = [lG, new_lg];
20 if new_lg == old_lg, break; end; old_lg = new_lg;
21 H = H./(sum(H')'*ones(1,k)); % normalize
22
23 % M-Step:
24
25 if minmix > 0,
26 mix_p = sum(H); mix_p = mix_p/sum(mix_p); mix_p = mix_p';
27 for j = 1:k, if mix_p(j)<minmix, mix_p(j) = minmix; end; end;
28 end
29 cluster_p = (H./(ones(n,1)*sum(H)))'*data;
30 if minvar > 0,
31 for j = 1:k,
32 varj = (data-(ones(n,1)*cluster_p(j,:))).^2;
33 if D > 1, varj = sum(varj')'; end
34 var_p(j) = sum(H(:,j).*varj)/(D*sum(H(:,j)));
35 if var_p(j)<minvar, var_p(j) = minvar; end;
36 end;
37 end
38
39% cluster_p = cluster_p./(sqrt(sum(cluster_p'.^2)')*ones(1,D));
40end
41
42cluster = cluster_p;
43var = var_p;
44mix = mix_p;
45membership = H;
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans2.m b/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans2.m
new file mode 100755
index 0000000..8fd194e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter/softmeans2.m
@@ -0,0 +1,39 @@
1function [cluster,var,mix,membership,lG] = softmeans2(var0,minvar,mix0,minmix,data,cluster0,iter)
2
3if (~exist('iter')),
4 iter = 3;
5end
6
7k = size(var0,1);
8[n,D] = size(data);
9
10lGG = [];
11ma = -1e20;
12in = 0;
13
14if (nargin == 5),
15 max_data = max(data);
16 min_data = min(data);
17 step = (max_data-min_data)/(k+1);
18 cluster0 = [1:k]'*step+min_data;
19end
20cluster0
21for t = 1:iter,
22 %rndindx = round(rand(1,k)*(n-3))+2;
23 %cluster0 = (data(rndindx,:)+data(rndindx+1,:)+data(rndindx-1,:))/2;
24 [cluster,var,mix,membership,lG] = softmeans(cluster0,var0,minvar,mix0,minmix,data);
25 eval(sprintf('mix_var_cluster_%d = [mix,var,cluster];',t));
26 eval(sprintf('lG_%d = lG;',t));
27 if ma<lG(size(lG,2)),
28 ma = lG(size(lG,2));
29 in = t;
30 end
31
32end
33
34eval(sprintf('mix_var_cluster = mix_var_cluster_%d;',in));
35eval(sprintf('lG = lG_%d;',in));
36mix = mix_var_cluster(:,1);
37var = mix_var_cluster(:,2);
38cluster = mix_var_cluster(:,3:size(mix_var_cluster,2))
39
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filterQuad.zip b/SD-VBS/common/toolbox/toolbox_basic/filterQuad.zip
new file mode 100755
index 0000000..00e6141
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filterQuad.zip
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/1d_cut.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/1d_cut.m
new file mode 100755
index 0000000..46f865b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/1d_cut.m
@@ -0,0 +1,16 @@
1function [x,map] = idcut(data,cmap,nbin)
2%
3%
4%
5
6lc = size(cmap,1);
7
8data = data - min(data);
9data = 1+ ((lc-1)*data/max(data));
10
11r = cmap(data,1);
12g = cmap(data,2);
13b = cmap(data,3);
14
15[x,map] = vmquant(r,g,b,nbin);
16
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Bfilter.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Bfilter.m
new file mode 100755
index 0000000..ee086f0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Bfilter.m
@@ -0,0 +1,11 @@
1function output = Bfilter(img,H)
2%
3% function output = Bfilter(img,H)
4%
5
6sze = size(img);
7
8Y = fft(reshape(img,1,sze(1)*sze(2)));
9C = Y.*conj(H);
10c = real(ifft(C));
11output = reshape(c,sze(1),sze(2));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/BfilterS.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/BfilterS.m
new file mode 100755
index 0000000..4eb4fd6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/BfilterS.m
@@ -0,0 +1,17 @@
1function output = Bfilters(img,H,w)
2%
3% function output = Bfilter(img,H,w)
4%
5
6sze = size(img);
7w_h = round(0.5*(w-1));
8
9Y = fft(reshape(img,1,sze(1)*sze(2)));
10C = Y.*conj(H);
11c = real(ifft(C));
12o = reshape(c,sze(1),sze(2));
13
14output(1:w_h(1),1:w_h(2)) = o(sze(1)-w_h(1)+1:sze(1),sze(2)-w_h(2)+1:sze(2));
15output(1:w_h(1),w_h(2)+1:sze(2)) = o(sze(1)-w_h(1)+1:sze(1),1:sze(2)-w_h(2));
16output(w_h(1)+1:sze(1),w_h(2)+1:sze(2)) = o(1:sze(1)-w_h(1),1:sze(2)-w_h(2));
17output(w_h(1)+1:sze(1),1:w_h(2)) = o(1:sze(1)-w_h(1),sze(2)-w_h(2)+1:sze(2));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Ncut.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Ncut.m
new file mode 100755
index 0000000..30c9b33
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/Ncut.m
@@ -0,0 +1,14 @@
1function [v,d] = ncut(A,nv)
2
3ds = sum(A);
4ds = ones(size(ds))./sqrt(ds);
5
6D1 = ds'*ones(1,length(ds));
7A = D1'.*A.*D1;
8
9disp(sprintf('computing eig values'));
10tic;[v,d] = eigs(A,nv);toc;
11
12d = abs(diag(d));
13
14v = D1(:,1:size(v,2)).*v;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/apply_image.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/apply_image.m
new file mode 100755
index 0000000..0791aa4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/apply_image.m
@@ -0,0 +1,38 @@
1function [aout1,aout2,aout3,aout4] = apply_image(gx,gy,wc)
2%
3% aout = apply_image(gx,gy,wc)
4%
5%
6
7[nr,nc] =size(gx);
8
9w = 2*wc+1;
10
11aout1 = ones(nr,nc);
12aout2 = zeros(nr,nc);
13aout3 = aout2;
14aout4 = aout2;
15
16%mask = smooth(ones(w,w),w);
17%sig = w;
18%[x,y] = meshgrid(-wc:wc,-wc:wc);
19%mask = exp(-(x.*x)/sig).*exp(-(y.*y)/sig);
20%mask = mask/sum(sum(mask));
21
22
23tmp = ones(w,w);
24for j=wc+1:w:nr-wc-1,
25 for k=wc+1:w:nc-wc-1,
26 tgx = get_win(gx,[k,j],[wc,wc]);
27 tgy = get_win(gy,[k,j],[wc,wc]);
28 %mag = sum(sum(sqrt((mask.*tgx).^2+(mask.*tgy).^2)));
29 mag = sum(sum(sqrt(tgx.^2 + tgy.^2)))/prod(size(tgy));
30
31 M = is_step(tgx,tgy);
32
33 aout1(j-wc:j+wc,k-wc:k+wc) = M(1)*tmp;
34 aout2(j-wc:j+wc,k-wc:k+wc) = M(2)*tmp;
35 aout3(j-wc:j+wc,k-wc:k+wc) = M(3)*tmp;
36 aout4(j-wc:j+wc,k-wc:k+wc) = mag*tmp;
37 end
38end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/back_proj.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/back_proj.m
new file mode 100755
index 0000000..47ac865
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/back_proj.m
@@ -0,0 +1,10 @@
1function BI = back_proj(PFt,vec)
2
3BI = [];
4
5sz1 = sqrt(size(PFt,1));
6
7for j=1:size(vec,2)
8 tmp = PFt*vec(:,j);
9 BI(:,:,j) = reshape(tmp,sz1,sz1);
10end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer.m
new file mode 100755
index 0000000..b4560c5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer.m
@@ -0,0 +1,9 @@
1function v = backproj_outer(fvs,u,hb)
2%
3% given the eigenvecs of the hist.bin. features
4% computes the back projection on the eigenvects
5%
6
7[nv,np] = size(fvs);
8
9for j=1: \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank.m
new file mode 100755
index 0000000..5e3eac9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank.m
@@ -0,0 +1,33 @@
1function v = backproj_outer_chank(fvs,u,d,chank_size)
2%
3% given the eigenvecs of the hist.bin. features
4% computes the back projection on the eigenvects
5%
6
7[nv,np] = size(fvs);
8[nbins,nv] = size(u);
9
10n_chanks = ceil(np/chank_size);
11
12v = ones(np,nv);
13
14for j=1:n_chanks,
15 fprintf('<');
16
17 cm = sprintf('load st_%d',j);
18 eval(cm);
19 fprintf(sprintf('%d',n_chanks-j));
20
21 v((j-1)*chank_size+1:min(np,j*chank_size),:) = fh'*u;
22 fprintf('>');
23end
24
25fprintf('\n');
26
27s = 1./sqrt(d);
28
29for j=1:nv,
30 v(:,j) = v(:,j)*s(j);
31end
32
33
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank2.m
new file mode 100755
index 0000000..084c150
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/backproj_outer_chank2.m
@@ -0,0 +1,36 @@
1function v = backproj_outer_chank(fvs,u,d,chank_size)
2%
3% given the eigenvecs of the hist.bin. features
4% computes the back projection on the eigenvects
5%
6
7[nv,np] = size(fvs);
8[nbins,nv] = size(u);
9
10n_chanks = ceil(np/chank_size);
11
12v = ones(np,nv);
13
14for j=1:n_chanks,
15 fprintf('<');
16
17 cm = sprintf('load st_%d',j);
18 eval(cm);
19 fprintf(sprintf('%d',n_chanks-j));
20
21 ms = mean(fh');
22 fh = fh - ms'*ones(1,size(fh,2));
23
24 v((j-1)*chank_size+1:min(np,j*chank_size),:) = fh'*u;
25 fprintf('>');
26end
27
28fprintf('\n');
29
30s = 1./sqrt(d);
31
32for j=1:nv,
33 v(:,j) = v(:,j)*s(j);
34end
35
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize.m
new file mode 100755
index 0000000..d166cd5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize.m
@@ -0,0 +1,15 @@
1function [binv,bins] = binize(data,sig,bin_min,bin_max,num_bin)
2%
3% given an input data, and sigma which describes the uncertainty
4% of the data, along with information on the bins,
5% return the soft-hist on data
6%
7
8ndata = length(data);
9
10bins = linspace(bin_min,bin_max,num_bin+1);
11binv = zeros(num_bin,ndata);
12
13for j=1:num_bin,
14 binv(j,:) = erf((bins(j+1)-data)/sig) - erf((bins(j)-data)/sig);
15end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize_old.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize_old.m
new file mode 100755
index 0000000..d56d263
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binize_old.m
@@ -0,0 +1,34 @@
1function [binv,bins] = binize(data,sig,bin_min,bin_max,num_bin)
2%
3% given an input data, and sigma which describes the uncertainty
4% of the data, along with information on the bins,
5% return the soft-hist on data
6%
7
8ndata = length(data);
9
10if 0,
11bins = linspace(bin_min,bin_max,num_bin);
12binv = zeros(num_bin,ndata);
13
14Largev = 1000;
15
16bins = [-Largev,bins];
17
18for j=1:num_bin,
19 binv(j,:) = erf((bins(j+1)-data)/sig) - erf((bins(j)-data)/sig);
20end
21
22binv(num_bin,:) = binv(num_bin,:) + erf((Largev-data)/sig) - erf((bins(end)-data)/sig);
23bins = bins(2:end);
24else
25
26bins = linspace(bin_min,bin_max,num_bin+1);
27binv = zeros(num_bin,ndata);
28
29
30for j=1:num_bin,
31 binv(j,:) = erf((bins(j+1)-data)/sig) - erf((bins(j)-data)/sig);
32end
33
34end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binomialfield.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binomialfield.m
new file mode 100755
index 0000000..d83d96d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/binomialfield.m
@@ -0,0 +1,75 @@
1function [x,y,success] = BinomialField(n,sx,sy,ir,numtri);
2%BF_HardCore Generates a hard core binomial field
3% [x,y,success] = BinomialField(n,sx,sy,ir);
4% n : # points (default 100)
5% sx : size in x (default 100)
6% sy : size in y (default 100)
7% ir : inhibition radius (default 0)
8% numtri : number of trials (default 200)
9% x : x coordinates
10% y : y coordinates
11% success: whether success or not, useful when producing hard core model
12
13%%
14%% (C) Thomas K. Leung
15%% University of California at Berkeley
16%% April 26, 1995.
17%% leungt@cajal.cs.berkeley.edu
18%%
19
20%%
21%% Generate n points first and then reject those closer to the
22%% previous points than ir
23%%
24
25if nargin < 1
26 n = 100;
27 sx = 100;
28 sy = 100;
29 ir = 0;
30 numtri = 200;
31elseif (nargin == 1 | nargin == 2)
32 sx = 100;
33 sy = 100;
34 ir = 0;
35 numtri = 200;
36elseif (nargin == 3)
37 ir = 0;
38 numtri = 200;
39elseif (nargin == 4)
40 numtri = 200;
41end
42
43x = zeros(1,n);
44y = zeros(1,n);
45
46rand('seed',sum(100*clock));
47x(1) = rand(1) * sx;
48y(1) = rand(1) * sy;
49
50success = 1;
51
52I = 2;
53trial = 0;
54while (I <= n & trial < numtri)
55 found = 0;
56 trial = 0;
57 while (~found & trial < numtri);
58 tx = rand(1) * sx;
59 ty = rand(1) * sy;
60 D = (x(1:(I-1)) - tx).^2 + (y(1:(I-1)) - ty).^2;
61 if sum(D > (ir^2)) == (I-1)
62 found = 1;
63 x(I) = tx;
64 y(I) = ty;
65 end
66 trial = trial + 1;
67 end
68 I = I + 1;
69end
70
71if trial >= numtri
72 fprintf(1,'Failed to generate a point in %d trials\n',numtri);
73 success = 0;
74end
75
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize.m
new file mode 100755
index 0000000..b03616f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize.m
@@ -0,0 +1,9 @@
1function t1a = colize(t1,I1);
2
3t1a = t1;
4
5t1a = reshape(t1a,size(t1,1)*size(t1,2),1,size(t1,3));
6t1a = squeeze(t1a);
7t1a = t1a';
8
9%I1a = 2*I1(:)';I1a = I1a-mean(I1a(:));t1a = [I1a;t1a];
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_hist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_hist.m
new file mode 100755
index 0000000..9c7b68e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_hist.m
@@ -0,0 +1,29 @@
1function fh = colize_hist(fv,hb)
2% (hb = sigs,bin_mins,bin_maxs,nbins)
3%
4% fv = [nfeature x npoints];
5% fh = [nfeatures*nbins x npoints];
6%
7% take a feature matrix, and turn it into histogram bin feature matrix
8%
9%
10
11[nf,np] = size(fv);
12
13nbins = [0,hb.nbins];
14disp(sprintf('need matrix of %d x %d ',sum(nbins),np));
15
16fh = zeros(sum(nbins),np);
17
18for k=1:nf,
19 bin_min = hb.bmins(k);
20 bin_max = hb.bmaxs(k);
21 nbin = nbins(k+1);
22 sig = hb.sigs(k);
23 fprintf('.');
24 b = binize(fv(k,:),sig,bin_min,bin_max,nbin);
25 fh(sum(nbins(1:k))+1:sum(nbins(1:k+1)),:) = b;
26
27end
28
29fprintf('\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_s.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_s.m
new file mode 100755
index 0000000..61c81ca
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_s.m
@@ -0,0 +1,47 @@
1function fhs = colize_histnb_s(fh,Is,nw,hw)
2%
3% fhs = colize_histneigh(fh,fvs,nw)
4%
5%
6
7[tnbins,np] = size(fh);
8
9[nr,nc] = size(Is);
10
11st_sz = 2*hw + 1;
12
13nr_chank = floor(nr/st_sz);
14nc_chank = floor(nc/st_sz);
15
16fhs = zeros(size(fh,1),nr_chank*nc_chank);
17
18idx = 0;
19for k=1+hw:st_sz:nc-hw,
20
21 fprintf('.');
22 sk = max(1,k-nw);
23 ek = min(nc,k+nw);
24
25
26 % for each column,
27 for j=1+hw:st_sz:nr-hw,
28 sj = max(1,j-nw);
29 ej = min(nr,j+nw);
30
31 id = j+(k-1)*nr;
32 idx = idx+1;
33 for li=sj:ej,
34 for lj=sk:ek,
35 idn = li+(lj-1)*nr;
36
37 fhs(:,idx) = fhs(:,idx) + fh(:,idn);
38
39 end
40 end
41 end
42end
43
44fprintf('\n');
45
46
47 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_sf.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_sf.m
new file mode 100755
index 0000000..d0d60f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histnb_sf.m
@@ -0,0 +1,52 @@
1function fhs = colize_histnb_s(fvs,Is,hb,nw,hw)
2%
3% fhs = colize_histneigh(fvs,Is,hb,nw,hw)
4%
5%
6
7[nf,np] = size(fvs);
8
9[nr,nc] = size(Is);
10
11st_sz = 2*hw + 1;
12
13nr_chank = floor(nr/st_sz);
14nc_chank = floor(nc/st_sz);
15
16tnbins = prod(hb.nbins(1:nf));
17disp(sprintf('allocat memory for %d x %d',tnbins,nr_chank*nc_chank));
18
19fhs = zeros(tnbins,nr_chank*nc_chank);
20
21idx = 0;
22for k=1+hw:st_sz:nc-hw,
23
24 fprintf(',');
25 sk = max(1,k-nw);
26 ek = min(nc,k+nw);
27
28
29 % for each column,
30 for j=1+hw:st_sz:nr-hw,
31 sj = max(1,j-nw);
32 ej = min(nr,j+nw);
33
34 id = j+(k-1)*nr;
35 idx = idx+1;
36
37 %% find idx for the neighboring points
38 lis = [sj:ej]'*ones(1,ek-sk+1);
39 ljs = ones(ej-sj+1,1)*[sk:ek];
40 idns = lis+(ljs-1)*nr;
41
42 fh = colize_joint_hist(fvs(:,idns(:)),hb);
43
44 fhs(:,idx) = sum(fh')';
45
46 end
47end
48
49fprintf('\n');
50
51
52 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histneighb.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histneighb.m
new file mode 100755
index 0000000..6189cab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_histneighb.m
@@ -0,0 +1,37 @@
1function fhs = colize_histneigh(fh,Is,nw)
2%
3% fhs = colize_histneigh(fh,fvs,nw)
4%
5%
6
7[tnbins,np] = size(fh);
8
9[nr,nc] = size(Is);
10
11fhs = zeros(size(fh));
12
13for j=1:nr,
14 fprintf('.');
15 sj = max(1,j-nw);
16 ej = min(nr,j+nw);
17
18 % for each column,
19 for k=1:nc,
20 sk = max(1,k-nw);
21 ek = min(nc,k+nw);
22
23 id = j+(k-1)*nr;
24
25 for li=sj:ej,
26 for lj=sk:ek,
27 idn = li+(lj-1)*nr;
28
29 fhs(:,id) = fhs(:,id) + fh(:,idn);
30 end
31 end
32 end
33end
34fprintf('\n');
35
36
37 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_joint_hist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_joint_hist.m
new file mode 100755
index 0000000..e7844d8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_joint_hist.m
@@ -0,0 +1,41 @@
1function fh = colize_joint_hist(fv,hb)
2% (hb = sigs,bin_mins,bin_maxs,nbins)
3%
4% take which histogram value and turn it into histogram bin
5%
6
7
8 [nf,np] = size(fv);
9
10 nbins = [0,hb.nbins];
11 %disp(sprintf('need matrix of %d x %d ',prod(hb.nbins),np));
12
13 fh = zeros(hb.nbins(1),hb.nbins(2),np);
14
15 k=1;
16 bin_min = hb.bmins(k);
17 bin_max = hb.bmaxs(k);
18 nbin = nbins(k+1);
19 sig = hb.sigs(k);
20 %fprintf('.');
21
22 b1 = binize(fv(k,:),sig,bin_min,bin_max,nbin);
23 k=2;
24 bin_min = hb.bmins(k);
25 bin_max = hb.bmaxs(k);
26 nbin = nbins(k+1);
27 sig = hb.sigs(k);
28 %fprintf('.');
29
30 b2 = binize(fv(k,:),sig,bin_min,bin_max,nbin);
31
32
33 for k=1:hb.nbins(1),
34 for j=1:hb.nbins(2),
35 fh(k,j,:) = b1(k,:).*b2(j,:);
36 end
37 end
38
39%fprintf('\n');
40
41fh = reshape(fh,hb.nbins(1)*hb.nbins(2),np);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_test.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_test.m
new file mode 100755
index 0000000..a9135cc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/colize_test.m
@@ -0,0 +1,19 @@
1function t1a = colize(t1,I1);
2
3if 1,
4t1a = t1;
5%t1a = 1.2*half_sigmoid(t1,0.3,0.1);;
6t1a = reshape(t1a,size(t1,1)*size(t1,2),1,size(t1,3));
7t1a = squeeze(t1a);
8t1a = t1a';
9
10%I1a = I1(:)';I1a = I1a-mean(I1a(:));t1a = [I1a;t1a];
11
12else
13 mask = t1>=0;
14 t1a = abs(t1);
15 t1a = 0.5-t1a;
16 t1a = reshape(t1a,size(t1,1)*size(t1,2),1,size(t1,3));
17 t1a = squeeze(t1a);
18 t1a = t1a';
19end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compact.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compact.m
new file mode 100755
index 0000000..9863e0f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compact.m
@@ -0,0 +1,36 @@
1function I = compact(img,ws)
2
3
4%ws = 2*hws+1;
5
6[sy,sx] = size(img);
7
8rem_x = rem(sx,ws);
9rem_y = rem(sy,ws);
10
11fix_x = ceil(sx/ws);
12fix_y = ceil(sy/ws);
13
14fprintf('nr = %d, nc = %d\n',fix_y,fix_x);
15
16%startx= 1 + floor(rem_x*0.5)+hws;
17%starty= 1 + floor(rem_y*0.5)+hws;
18
19I = zeros(fix_y,fix_x);
20
21yid = 0;
22for j=1:ws:sy,
23 xid = 0;
24 yid = yid +1;
25 fprintf('.');
26 for k=1:ws:sx,
27 xid = xid+1;
28 %I(yid,xid) = median(median(img(j-hws:j+hws,k-hws:k+hws)));
29 %I(yid,xid) = sum(sum(img(j-hws:j+hws,k-hws:k+hws)));
30 v = img(j:min(sy,j+ws-1),k:min(sx,k+ws-1));
31 %I(yid,xid) = median(reshape(v,prod(size(v)),1));
32 I(yid,xid) = median(median(v));
33 end
34end
35fprintf('\n');
36 \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_J.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_J.m
new file mode 100755
index 0000000..99b8b69
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_J.m
@@ -0,0 +1,31 @@
1function J = compute_J(A,I,size_x,size_y,D)
2%% function J = compute_J(A,I,size_x,size_y,D)
3%
4
5[center_x,center_y] = find_center(size_x,size_y);
6
7tmp = ones(size_y,1)*[1:size_x];
8index(:,1) = reshape(tmp,size_x*size_y,1)-center_x*ones(size_x*size_y,1);
9index(:,2) = reshape(tmp',size_x*size_y,1)-center_y*ones(size_x*size_y,1);
10
11position_new = A*index'+ [D(1),0;0,D(2)]*ones(2,size_x*size_y);
12position_new = round(position_new +...
13 [center_x,0;0,center_y]*ones(2,size_x*size_y));
14% we have to deal with out of boundary ones
15%
16bad_ones(1,:) = position_new(1,:)<1 | position_new(1,:)>size_x;
17bad_ones(2,:) = position_new(2,:)<1 | position_new(2,:)>size_y;
18bad = max([bad_ones(1,:);bad_ones(2,:)]);
19good = ~bad;
20% if new index is out of boundary, then set it to (0,0)
21position_new(1,:) = position_new(1,:).*good;
22position_new(2,:) = position_new(2,:).*good;
23
24new_index = size_y*(position_new(1,:)-ones(1,size_x*size_y))+...
25 position_new(2,:);
26new_index = max([new_index;ones(1,size_x*size_y)]);
27J = I(new_index);
28% set the "out of boundary" to zero.
29J = J.*good;
30J = reshape(J',size_y,size_x);
31
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_Lf.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_Lf.m
new file mode 100755
index 0000000..7cda523
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_Lf.m
@@ -0,0 +1,35 @@
1function dists = compute_Lf(F,cts,wz,nr,nc)
2
3gap = 2*wz(1)+1;
4hw = wz(1);
5
6nr = nr+1;
7nc = nc+1;
8
9dists = zeros(size(cts,1),nr*nc);
10for ctj = 1:size(cts,1),
11 t1 = cutout(F,cts(ctj,:),wz);
12
13 rid = 1;
14 fprintf('>');
15
16 for ri = hw+1:gap:size(F,1)-hw,
17 %fprintf('[%d]',ri);
18 cid = 1;
19 for ci = hw+1:gap:size(F,2)-hw,
20 %fprintf('(%d)',ci);
21 t2 = cutout(F,[ci,ri],wz);
22
23 dist = abs(mean(t1(:))-mean(t2(:)));
24
25 dists(ctj,rid+cid*nr) = max(dist,dists(ctj,rid+cid*nr));
26
27 cid = cid+1;
28 end
29 rid = rid+1;
30 end
31
32 %fprintf('\n');
33
34end
35
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_corr.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_corr.m
new file mode 100755
index 0000000..92f9da4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_corr.m
@@ -0,0 +1,10 @@
1function a = compute_corr(f,g)
2%
3% compute the circular correlation of f and g
4% at points around zero
5%
6%
7
8ff = interp(f,4);
9gg = interp(g,4);
10
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff.m
new file mode 100755
index 0000000..72bfe54
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff.m
@@ -0,0 +1,36 @@
1function B = compute_diff(Ja,Jfa,hw,hnb);
2%
3% B = compute_diff(Ja,Jfa,hw,hnb)
4%
5%
6
7figure(1);%imagesc(Ja);axis('image');
8cs = round(ginput(1));
9
10B = zeros(2*hnb+1,2*hnb+1);
11
12scales = [1:5];filter_ids = [1:7];
13Jc = get_win(Ja,cs,[hw,hw]);
14Jfc= get_win5(Jfa,cs,[hw,hw]);
15H2c = hist2d(Jc,Jfc,scales,filter_ids);
16
17figure(2);imagesc(Ja);axis('image');colormap(gray);
18hold on; plot(cs(1),cs(2),'g*');
19
20
21for ii=-hnb:hnb,
22 for jj=-hnb:hnb,
23 J1 = get_win(Ja,cs+4*[jj,ii],[hw,hw]);
24 Jf1= get_win5(Jfa,cs+4*[jj,ii],[hw,hw]);
25 figure(2);plot(cs(1)+4*jj,cs(2)+4*ii,'ro');drawnow;
26 %figure(3);imagesc(J1);drawnow;
27
28 H2 = hist2d(J1,Jf1,scales,filter_ids);
29 d = hist_diff(H2/prod(size(Jc)),H2c/prod(size(Jc)));
30 disp(sprintf('d=%f',d));
31 B(ii+hnb+1,jj+hnb+1) = d;
32
33 end
34end
35
36figure(2);hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch.m
new file mode 100755
index 0000000..260b93a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch.m
@@ -0,0 +1,34 @@
1function a = compute_diff_patch(gx1,gy1,gx2,gy2,I1,I2)
2%
3% a = compute_diff_patch(gx1,gy1,gx2,gy2,I1,I2)
4%
5%
6
7%ws = size(gx1);
8%mask = smooth(ones(ws),2*max(ws));
9%mask = mask/sum(sum(mask));
10
11%mag1= sum(sum(sqrt((mask.*gx1).^2 + (mask.*gy1).^2)));
12%mag2= sum(sum(sqrt((mask.*gx2).^2 + (mask.*gy2).^2)));
13
14mag1= sum(sum(sqrt((gx1).^2 + (gy1).^2)));
15mag2= sum(sum(sqrt((gx2).^2 + (gy2).^2)));
16
17P_tx1 = sigmoid(mag1,400,80);
18P_tx2 = sigmoid(mag2,400,80);
19
20diff_I = mean(reshape(I1,prod(size(I1)),1))-...
21 mean(reshape(I2,prod(size(I2)),1));
22diff_I = abs(diff_I);
23
24s_g1 = [sum(sum(abs(gx1))),sum(sum(abs(gy1)))];
25s_g2 = [sum(sum(abs(gx2))),sum(sum(abs(gy2)))];
26
27s_g1 = s_g1/(norm(s_g1));
28s_g2 = s_g2/(norm(s_g2));
29
30a = (1-P_tx1)*(1-P_tx2)*exp(-diff_I/0.1) +...
31 P_tx1*P_tx2*(dot(s_g1,s_g2));
32
33
34
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch2.m
new file mode 100755
index 0000000..9d2b528
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_diff_patch2.m
@@ -0,0 +1,45 @@
1function [a,phi1,phi2] = compute_diff_patch(gx1,gy1,gx2,gy2,I1,I2)
2%
3% a = compute_diff_patch(gx1,gy1,gx2,gy2,I1,I2)
4%
5%
6
7%ws = size(gx1);
8%mask = smooth(ones(ws),2*max(ws));
9%mask = mask/sum(sum(mask));
10
11%mag1= sum(sum(sqrt((mask.*gx1).^2 + (mask.*gy1).^2)));
12%mag2= sum(sum(sqrt((mask.*gx2).^2 + (mask.*gy2).^2)));
13
14mag1= sum(sum(sqrt((gx1).^2 + (gy1).^2)))/prod(size(gx1));
15mag2= sum(sum(sqrt((gx2).^2 + (gy2).^2)))/prod(size(gx1));
16
17P_tx1 = sigmoid(mag1,2,0.5);
18P_tx2 = sigmoid(mag2,2,0.5);
19
20diff_I = mean(reshape(I1,prod(size(I1)),1))-...
21 mean(reshape(I2,prod(size(I2)),1));
22diff_I = abs(diff_I);
23
24[l1,l2,phi1] = mwis(gx1,gy1);
25[k1,k2,phi2] = mwis(gx2,gy2);
26
27ratio1 = min([l1,l2])/max([l1,l2]);
28ratio2 = min([k1,k2])/max([k1,k2]);
29
30r1 = 1-sigmoid(ratio1,0.35,0.05);
31r2 = 1-sigmoid(ratio2,0.35,0.05);
32
33s1 = [cos(phi1),sin(phi1)];
34s2 = [cos(phi2),sin(phi2)];
35
36angle = acos(abs(dot(s1,s2)))*180/pi;
37
38a1 = (1-P_tx1*P_tx2)*exp(-diff_I/0.1);
39a2 = P_tx1*P_tx2*(r1*r2*(90-angle)/90);
40a3 = P_tx1*P_tx2*((1-r1*r2)*(1-sigmoid(abs(r1-r2),0.3,0.04)));
41
42a = a1+a2+a3;
43
44
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter.m
new file mode 100755
index 0000000..04e78e1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter.m
@@ -0,0 +1,84 @@
1function [filter_output,filters] = compute_filter(I,sig,r,sz);
2%
3%
4%
5
6ori_incr=180/num_ori;
7ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
8
9as = ori_offset:ori_incr:180+ori_offset-ori_incr;
10
11filter_output = [];
12filters = [];
13
14wsz = 2*round(sz) + 1;
15M1 = wsz(1);M2 = wsz(2);
16
17%%%%% prepare FFT of image %%%%%%%%%%%%%
18
19[N1,N2]=size(I);
20tmp=zeros(size(I)+[M1-1 M2-1]);
21tmp(1:N1,1:N2)=I;
22IF=fft2(tmp);
23
24
25%%%%%%%%%% filtering stage %%%%%%%%%%%
26if size(sig,2)== 1,
27
28 for j = 1:length(as),
29 fprintf('.');
30 angle = as(j);
31
32 g = mdoog2(sig,r,angle,round(sz));
33
34 g = g - mean(reshape(g,prod(size(g)),1));
35
36 g = g/sum(sum(abs(g)));
37
38 filters(:,:,j) = g;
39
40 gF = fft2(g,N1+M1-1,N2+M2-1);
41 IgF = If.*gF;
42 Ig = real(ifft2(IgF));
43 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
44
45 %c = conv2(I,g,'valid');
46
47 filter_output(:,:,j) = Ig;
48 end
49else
50
51 % there are multiple scales
52 sigs = sig;
53 szs = sz;
54 for k = 1:size(sigs,2),
55 sig = sigs(k);
56 sz = szs(k);
57 fprintf('%d',k);
58 for j = 1:length(as),
59 fprintf('.');
60 angle = as(j);
61
62 g = mdoog2(sig,r,angle,round(sz));
63 g = g - mean(reshape(g,prod(size(g)),1));
64 g = g/sum(sum(abs(g)));
65
66 gF = fft2(g,N1+M1-1,N2+M2-1);
67 IgF = If.*gF;
68 Ig = real(ifft2(IgF));
69 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
70
71 %c = conv2(I,g,'valid');
72 %c = conv2(I,g,'same');
73
74 filter_output(:,:,j,k) = Ig;
75 filters(:,:,j,k) = g;
76 end
77
78
79 end
80
81end
82
83fprintf('\n');
84
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter_fft.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter_fft.m
new file mode 100755
index 0000000..359c6ba
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/compute_filter_fft.m
@@ -0,0 +1,84 @@
1function [filter_output,filters] = compute_filter_fft(I,sig,r,sz,num_ori);
2%
3%
4%
5
6ori_incr=180/num_ori;
7ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
8
9as = ori_offset:ori_incr:180+ori_offset-ori_incr;
10
11filter_output = [];
12filters = [];
13
14wsz = 2*round(sz(end)) + 1;
15M1 = wsz;M2 = wsz;
16
17%%%%% prepare FFT of image %%%%%%%%%%%%%
18
19[N1,N2]=size(I);
20tmp=zeros(size(I)+[M1-1 M2-1]);
21tmp(1:N1,1:N2)=I;
22IF=fft2(tmp);
23
24
25%%%%%%%%%% filtering stage %%%%%%%%%%%
26if size(sig,2)== 1,
27
28 for j = 1:length(as),
29 fprintf('.');
30 angle = as(j);
31
32 g = mdoog2(sig,r,angle,round(sz));
33
34 g = g - mean(reshape(g,prod(size(g)),1));
35
36 g = g/sum(sum(abs(g)));
37
38 filters(:,:,j) = g;
39
40 gF = fft2(g,N1+M1-1,N2+M2-1);
41 IgF = IF.*gF;
42 Ig = real(ifft2(IgF));
43 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
44
45 %c = conv2(I,g,'valid');
46
47 filter_output(:,:,j) = Ig;
48 end
49else
50
51 % there are multiple scales
52 sigs = sig;
53 szs = sz;
54 for k = 1:size(sigs,2),
55 sig = sigs(k);
56 sz = szs(end);
57 fprintf('%d',k);
58 for j = 1:length(as),
59 fprintf('.');
60 angle = as(j);
61
62 g = mdoog2(sig,r,angle,round(sz));
63 g = g - mean(reshape(g,prod(size(g)),1));
64 g = g/sum(sum(abs(g)));
65
66 gF = fft2(g,N1+M1-1,N2+M2-1);
67 IgF = IF.*gF;
68 Ig = real(ifft2(IgF));
69 Ig = Ig(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1);
70
71 %c = conv2(I,g,'valid');
72 %c = conv2(I,g,'same');
73
74 filter_output(:,:,j,k) = Ig;
75 filters(:,:,j,k) = g;
76 end
77
78
79 end
80
81end
82
83fprintf('\n');
84
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/conv_trim.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/conv_trim.m
new file mode 100755
index 0000000..30d16a9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/conv_trim.m
@@ -0,0 +1,6 @@
1% trims an array to remove meaningless pixels after a convolution with
2% an r * c window
3
4function[B] = conv_trim(A, r, c)
5
6B = A(r+1:size(A,1)-r, c+1:size(A,2)-c);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/corr_hist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/corr_hist.m
new file mode 100755
index 0000000..c538dc1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/corr_hist.m
@@ -0,0 +1,9 @@
1function alpha = corr_hist(hists)
2
3[y,x,v] = find(hists);
4mx = sum(x.*v)/sum(v);
5my = sum(y.*v)/sum(v);
6
7top = sum( (x-mx).*(y-my).*v);
8bottom = sqrt(sum( ((x-mx).^2).*v))*sqrt(sum( ((y-my).^2).*v));
9alpha = top/bottom;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/crop_im_fil.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/crop_im_fil.m
new file mode 100755
index 0000000..5472171
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/crop_im_fil.m
@@ -0,0 +1,11 @@
1function [J,f,rect] = crop_im_fil(Ja,Jfa,fig_id)
2%
3%
4
5figure(fig_id);
6imagesc(Ja);axis('image');
7
8[J,rect] = imcrop;rect = round(rect);
9J = Ja(rect(2):rect(2)+rect(4),rect(1):rect(1)+rect(3));
10f = Jfa(rect(2):rect(2)+rect(4),rect(1):rect(1)+rect(3),:,:);
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutoff.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutoff.m
new file mode 100755
index 0000000..58c6b94
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutoff.m
@@ -0,0 +1,13 @@
1function I = cutoff(I,wc)
2%
3%
4
5nr = size(I,1);
6nc = size(I,2);
7
8if ndims(I) == 3,
9I = I(wc+1:nr-wc,wc+1:nc-wc,:,:);
10else
11I = I(wc+1:nr-wc,wc+1:nc-wc,:,:);
12end
13
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutout.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutout.m
new file mode 100755
index 0000000..b80f27b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/cutout.m
@@ -0,0 +1,3 @@
1function a = cutout(I,ct,wz);
2
3a = I(ct(2)-wz(2):ct(2)+wz(2),ct(1)-wz(1):ct(1)+wz(1),:);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_Imask.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_Imask.m
new file mode 100755
index 0000000..dbd7fdb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_Imask.m
@@ -0,0 +1,20 @@
1function Imasks = disp_Imask(Is,nr,nc,hw,masks)
2%
3% Imasks = disp_Imask(Is,nr,nc,hw,masks)
4%
5
6%hw = 2; %nr = 43;nc=68;
7gap = 2*hw+1;
8
9x = [1:nc*gap];
10y = [1:nr*gap];
11
12xs = (x-hw-1)/gap + 1;ys = (y-hw-1)/gap + 1;
13
14for gid=1:size(masks,3),
15 tmp = interp2(reshape(masks(:,:,gid),nr,nc),xs,ys');
16
17 Imasks(:,:,gid) = (tmp>0.52).* ((Is).^0.8);
18 subplot(3,3,gid);
19 im(Imasks(:,:,gid));
20end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_diff.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_diff.m
new file mode 100755
index 0000000..090c273
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_diff.m
@@ -0,0 +1,37 @@
1function disp_diff(H1,H2)
2%
3% disp_diff(H1,H2)
4%
5
6ns = size(H1,3);
7nf = size(H1,4);
8
9H1 = H1/49;
10H2 = H2/49;
11
12
13sI= [1,0,1];sI = exp(-sI);
14sI = sI/sum(sI);
15
16for j = 1:ns,
17 for k = 1:nf,
18 h1 = H1(:,:,j,k);
19 h2 = H2(:,:,j,k);
20
21 subplot(ns,nf,(j-1)*nf+k);
22 h1s = conv2(conv2(h1,sI','same'),sI,'same');
23 h2s = conv2(conv2(h2,sI','same'),sI,'same');
24
25 [is,js] = find( (h1>0) | (h2>0));
26 ids = (js-1)*size(h1,1) + is;
27
28 hdiff = abs(h1s-h2s).*((h1>0) | (h2>0));
29
30 xdiff = ((h1(ids)-h2(ids)).*(h1(ids)-h2(ids)))./(h1(ids)+h2(ids));
31
32 xdiffs = ((h1s(ids)-h2s(ids)).*(h1s(ids)-h2s(ids)))./(h1s(ids)+h2s(ids));
33 imagesc(hdiff);colorbar;axis('off');
34% title(sprintf('%3.3f, %3.3f',sum(sum(hdiff))/49,sum(sum(abs(h1-h2)))/49));drawnow;
35 title(sprintf('%3.3f, %3.3f',sum(xdiff),sum(xdiffs)));drawnow
36 end
37end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult.m
new file mode 100755
index 0000000..e07556a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult.m
@@ -0,0 +1,435 @@
1%fn = '134035';
2%fn = '130040';
3%fn = '334074';
4fn = '130065';
5
6%basedir = 'plaatje_data/olddata/';
7% basedir = 'data/'; nr = 49;nc =30;
8
9basedir = 'plaatje_data/';
10
11fname = sprintf('%s%s_eigvec.pfm',basedir,fn);
12eigv = readpfm(fname);
13fname = sprintf('%s%s_eigval.pfm',basedir,fn);
14eigval = readpfm(fname);
15
16fname = sprintf('%s%s_ncutvec.pfm',basedir,fn);
17ncutv = readpfm(fname);
18fname = sprintf('%s%s_ncutval.pfm',basedir,fn);
19ncutval = readpfm(fname);
20
21%fname = sprintf('images/130039.pgm');
22fname = sprintf('images/%s.pgm',fn);
23I = readpgm(fname);
24cutsz = 20; I = cutoff(I,cutsz);
25figure(3);im(I);colormap(gray);
26
27new = 0;
28
29if ~new,
30
31 %nr = 49;nc = 30;
32 nr = 30;nc = 49;
33
34%nr = 68;nc = 43;
35%nc = 68;nr = 43;
36
37else
38
39 fn1 = fn;
40 fn = 'test';
41 fname = sprintf('plaatje_data/%s_gcs.pfm',fn);
42 gcs = readpfm(fname);
43
44 fname = sprintf('plaatje_data/%s_gce.pfm',fn);
45 gce = readpfm(fname);
46
47 fname = sprintf('plaatje_data/%s_grs.pfm',fn);
48 grs = readpfm(fname);
49
50 fname = sprintf('plaatje_data/%s_gre.pfm',fn);
51 gre = readpfm(fname);
52
53 nr = max(gre(:))+1;
54 nc = max(gce(:))+1;
55
56 fn = fn1;
57
58end
59
60figure(6);
61for j=1:8,
62 subplot(3,3,j);
63 im(reshape(ncutv(:,j+1),nr,nc));colorbar
64 title(num2str(ncutval(j+1,1)));
65end
66%cm = sprintf('print -dps ncut_%s',fn);disp(cm);eval(cm);
67subplot(3,3,9);im(I);axis('off');
68
69figure(7);clf
70for j=1:12,
71 subplot(3,4,j);
72 im(reshape(eigv(:,j),nr,nc));colorbar;%axis('off');
73 title(sprintf('%3.4e',eigval(j,1)));
74end
75%cm = sprintf('print -dps eig_%s',fn);disp(cm);eval(cm);
76
77%%%%%%%%%%%
78
79ev = eigval(:,1);
80figure(5);hold off;clf;subplot(1,2,1);
81%semilogy((ev(1:end-1) - ev(2:end))./ev(1:end-1),'x-');grid on;
82plot((ev(1:end-1) - ev(2:end))./ev(1:end-1),'x-');grid on;
83%semilogy(0.01*ones(size(ev(2:end-1))),'r-');semilogy(0.005*ones(size(ev(2:end-1))),'r-');semilogy(0.0025*ones(size(ev(2:end-1))),'r-');grid on;hold off;
84subplot(1,2,2);
85%semilogy(ev(1:end-1)-ev(2:end),'p-');grid on;
86semilogy((ev(1:end-1) - ev(2:end))/ev(1),'x-');grid on;
87
88
89if 0,
90
91fname = sprintf('plaatje_data/ncutval_%s.pfm',fn);
92nval = readpfm(fname);
93fname = sprintf('plaatje_data/ncutvec_%s.pfm',fn);
94nv = readpfm(fname);
95
96figure(2);
97nvv = size(nv,2);
98for j=1:min(5,nvv-1),
99 subplot(1,min(5,nvv-1),j);
100 ims(nv(:,j+1),nr,nc);
101end
102
103
104%figure(5);
105%subplot(2,2,1);plot(eigval(:,1),'x-');
106
107
108if 0,
109
110fname = 130039;
111for j=0:20,
112 cm = sprintf('!cp plaatje_data/%d_%d.pfm plaatje_data/test_%d.pfm ',fname,j,j);
113 disp(cm);eval(cm);
114end
115
116%%%%%%%%
117fnout = 'test';fn_t = '334003';
118cm = sprintf('!cp plaatje_data/%s_eigval.pfm %s_eigval.pfm',fnout,fn_t);
119disp(cm);eval(cm);
120cm = sprintf('!cp plaatje_data/%s_eigvec.pfm %s_eigvec.pfm',fnout,fn_t);
121disp(cm);eval(cm);
122cm = sprintf('!cp plaatje_data/%s_ncutvec.pfm %s_ncutvec.pfm',fnout,fn_t);
123disp(cm);eval(cm);
124cm = sprintf('!cp plaatje_data/%s_ncutval.pfm %s_ncutval.pfm',fnout,fn_t);
125disp(cm);eval(cm);
126
127
128
129
130end
131
132disp_flag = 0;
133if disp_flag,
134 [I1,bnr,bnc] = proj_back_id(ncutv(:,2),gcs,gce,grs,gre);
135 imvs(I,I1>0.002,bnr,bnc);
136end
137
138if 0,
139
140 nv = 3;
141 A = eigv(:,1:nv)*eigv(:,1:nv)';
142 [v,d] = ncut(abs(A),min(nv,5));
143
144 figure(3);
145 for j=1:min(nv,5),
146 subplot(2,2,j);
147 ims(v(:,j),nr,nc);
148 end
149
150end
151
152%%%%%%%%
153
154figure(4);%im(I);colorbar;
155hw = 3;st_sz = 2*hw+1;
156ct = round(ginput(1));
157ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
158ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
159
160idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
161
162figure(5);im(abs(reshape(A(idx,:),nr,nc)));%colorbar;
163
164
165
166 %%%%%
167
168 fname = 'test2';
169 fn = sprintf('plaatje_data/ncut_%s.pfm',fname);
170 ncutv1 = readpfm(fn);
171 nr = 30; nc=49;
172
173 figure(1);
174 for j=1:min(4,size(ncutv1,2)),
175 subplot(2,2,j);
176 ims(ncutv1(:,j+1),nr,nc);
177 end
178
179
180
181%%%%%%%%%%
182
183 id = 0;
184 fn = sprintf('plaatje_data/test_Aa%d.pfm',id);
185 disp(sprintf('A = readpfm(%s);',fn));
186 A = readpfm(fn);
187
188 cm = sprintf('[v%d,d%d] = eigs(A,12);',id,id);
189 disp(cm);eval(cm);
190
191 writepfm('test_eigv0.pfm',v0);
192 writepfm('test_eigva0.pfm',diag(d0));
193
194
195
196
197vs = zeros(size(v1,1),size(v1,2),6);
198ds = zeros(length(d1),6);
199
200for j=0:5,
201 cm = sprintf('vs(:,:,%d) = v%d;',j+1,j);
202 disp(cm);eval(cm);
203 cm = sprintf('d = diag(d%d);',j);
204 disp(cm);eval(cm);
205 cm = sprintf('ds(:,%d) = d(:);',j+1);
206 disp(cm);eval(cm);
207
208
209end
210
211%save evsum vs ds
212
213figure(1);nr = 49;nc=30;evid = 3;
214for j=1:12,subplot(3,4,j);ims(vs(:,j,evid),nr,nc);end
215
216I = readpgm('images/334039.pgm');I = cutoff(I,20);
217
218As = zeros(6,nr*nc);
219
220figure(3);%im(I);colormap(gray);
221hw = 3;st_sz = 2*hw+1;
222ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
223idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
224
225figure(5);
226
227figure(4);nvs = [6,9,12,12,12,12];
228for evid = 1:5,As(evid,:) = squeeze(vs(idx,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))';end
229for evid =1:5,subplot(2,3,evid);im(abs(reshape(As(evid,:),nr,nc)));colorbar;end
230subplot(2,3,6);ims(sum(abs(As)),nr,nc);colorbar
231
232%%%%%%%%%
233
234%%%%%% eig of the As over all scales %%
235
236A = zeros(nr*nc,nr*nc);
237
238for evid=1:5, disp(evid);
239 A = A + abs(squeeze(vs(:,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))');
240end
241
242[v,d] = eigs(A,12);
243figure(1); for j=1:12, subplot(3,4,j);ims(v(:,j),nr,nc);end
244
245[vn,dn] = ncut_b(A,12);
246figure(3); for j=1:12, subplot(3,4,j);ims(-vn(:,j),nr,nc);end
247
248nv = 6;
249A = abs(eigv(:,1:nv)*eigv(:,1:nv)');
250[v,d] = ncut_b(A,nv+1);
251figure(1);
252nv = 4;
253for j=1:nv,subplot(2,nv,j);ims(v(:,j+1),nr,nc);title(sprintf('%3.3e',d(j+1)));end
254
255for j=1:nv,subplot(2,nv,j+nv);ims(eigv(:,j),nr,nc);title(sprintf('%3.3e',eigval(j,1)));end
256
257%%%%%%%%%%%%%
258
259while 1,
260figure(3);%im(I);colormap(gray);
261hw = 3;st_sz = 2*hw+1;
262ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
263idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
264
265figure(1);
266ims(exp(-(A(idx,:))/(0.02^2)),nr,nc);colorbar
267end
268
269
270
271%%%%%%%%%%%%%%
272
273figure(3);
274hw = 3;st_sz = 2*hw+1;
275np = 20;
276ct = round(ginput(np));
277ct_chank =[];
278ct_chank(:,1) = round((ct(:,1)-hw-1)/st_sz) + 1;
279ct_chank(:,2) = round((ct(:,2)-hw-1)/st_sz) + 1;
280idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
281
282%As = readpfm_id('plaatje_data/130040_AX.pfm',idx,2924);
283As = readpfm_idf('plaatje_data/tmp/134035_AX3.pfm',idx,nr*nc);
284
285%save dist_data2 As idx ct_chank ct hw nr nc eigv eigval
286
287%load dist_data1a
288
289set(gcf,'DefaultLineLinewidth',5);
290
291minA = min(min(As));
292figure(1);clf; hold off;
293set(gcf,'DefaultLineLinewidth',2);
294for id = 1:np,
295subplot(4,5,id);
296%image(2.8e-2*((-minA)+reshape(As(id,:),nr,nc)));axis('image');axis('off');hold on
297ims(-As(id,:),nr,nc);axis('off');hold on
298plot(ct_chank(id,1)+1,ct_chank(id,2)+1,'rx');hold off;
299end
300
301figure(1);clf;hold off;
302nvv = 6
303set(gcf,'DefaultLineLinewidth',1);
304for id=1:np,
305 At = abs(eigv(idx(id),1:nvv)*eigv(:,1:nvv)');
306 subplot(4,5,id);
307 %image(2.5e4*reshape(At,nr,nc));axis('image');axis('off');hold on
308 ims(At,nr,nc);axis('off');hold on;
309 plot(ct_chank(id,1)+1,ct_chank(id,2)+1,'rx');hold off;
310end
311
312
313print_flag =0;
314if print_flag,
315 fn = '130040';
316
317 figure(4);clf;
318 colormap(gray);
319 set(gcf,'DefaultLineLinewidth',7);
320
321 for id =1:np,
322 %image(2.8e-2*((-minA)+reshape(As(id,:),nr,nc)));axis('image');axis('off');hold on
323 ims(-As(id,:),nr,nc);axis('off');
324 hold on;plot(ct_chank(id,1)+1,ct_chank(id,2)+1,'rp');hold off;
325 cm = sprintf('print -deps dist_x1_%s_%d',fn,id);
326 disp(cm);eval(cm);
327 end
328
329 nvv = 5;
330 set(gcf,'DefaultLineLinewidth',7);
331 figure(4);colormap(gray);
332 for id=1:np,
333 At = abs(eigv(idx(id),1:nvv)*eigv(:,1:nvv)');
334 %image(1.5e4*reshape(At,nr,nc));axis('image');axis('off');%hold on
335 ims(At,nr,nc);axis('off');%hold on;
336 %plot(ct_chank(id,1)+1,ct_chank(id,2)+1,'rp');hold off;
337 cm = sprintf('print -deps dist_d_%s_%d',fn,id);
338 disp(cm);eval(cm);
339 end
340
341 % print eigvects
342 for j=1:size(eigv,2),
343 ims(eigv(:,j),nr,nc);axis('off');
344 cm = sprintf('print -deps eigv_%s_%d',fn,j);
345 disp(cm);eval(cm);
346 end
347
348 for j=1:size(ncutv,2),
349 ims(ncutv(:,j),nr,nc);axis('off');
350 cm = sprintf('print -deps ncutv_%s_%d',fn,j);
351 disp(cm);eval(cm);
352 end
353
354
355end
356
357basedir ='plaatje_data/newdata/';
358fname = sprintf('%s%s_eigvec.pfm',basedir,fn);
359eigv = readpfm(fname);
360
361ix = 1;
362figure(5);colormap(gray);clf
363for j=1:7,
364 for k=[2,3,4,6,9,12];
365 subplot(7,6,ix);
366 At = abs(eigv(idx(j),1:k)*eigv(:,1:k)');
367 ims(At,nr,nc);axis('off');%colorbar;
368 if (k==2),
369 hold on; plot(ct_chank(j,1),ct_chank(j,2),'rp');hold off;
370 title(num2str(j));
371 end
372 ix = ix+1;
373 end
374end
375
376figure(4);clf;colormap(gray);
377set(gcf,'DefaultLineLinewidth',7);
378for j=1:20,
379 for k=[2,3,4,6,9,12];
380
381 At = abs(eigv(idx(j),1:k)*eigv(:,1:k)');
382 ims(At,nr,nc);axis('off');%colorbar;
383 if (k==2),
384 hold on; plot(ct_chank(j,1),ct_chank(j,2),'rp');hold off;
385 end
386
387 cm = sprintf('print -deps dist_scale_65_%d_%d',j,k);
388 disp(cm);eval(cm);
389
390 end
391end
392
393base_dir = 'plaatje_data/';
394
395% cts are the centers,
396
397wz = [hw,hw];
398gap = 2*hw+1;
399dist = zeros(size(cts,1),(nr+1)*(nc+1));
400
401for j=1:1:24,
402 fn = sprintf('%s134035_%d.pfm',base_dir,j);
403 disp(fn);
404 F = readpfm(fn);
405
406 dists = compute_Lf(F,cts,wz,nr,nc);
407 dist = max(dists,dist);
408
409end
410
411
412figure(4);clf;colormap(gray);
413set(gcf,'DefaultLineLinewidth',7);
414
415ids = [8,1,12,5,10,15];
416
417for j=1:6,
418
419 d = reshape(dist(j,:),nr+1,nc+1);
420 d = d(1:end-1,2:end);
421 im(-d);axis('off'); hold on;
422 plot(ct_chank(ids(j),1),ct_chank(ids(j),2),'p');
423 hold off
424
425 cm = sprintf('print -deps dist_lf_65_%d',j);
426 disp(cm);eval(cm);
427
428 pause;
429end
430
431
432
433end
434
435
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult2.m
new file mode 100755
index 0000000..46239ef
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresult2.m
@@ -0,0 +1,215 @@
1fn = '130042';
2
3fname = sprintf('data/%s_eigvec.pfm',fn);
4eigv = readpfm(fname);
5fname = sprintf('data/%s_eigval.pfm',fn);
6eigval = readpfm(fname);
7
8fname = sprintf('data/%s_ncutvec.pfm',fn);
9ncutv = readpfm(fname);
10fname = sprintf('data/%s_ncutval.pfm',fn);
11ncutval = readpfm(fname);
12
13%fname = sprintf('images/130038.pgm');
14fname = sprintf('images/%s.pgm',fn);
15I = readpgm(fname);
16cutsz = 20; I = cutoff(I,cutsz);
17figure(3);im(I);colormap(gray);
18
19new = 0;
20
21if new,
22 fn1 = fn;
23 fn = 'test';
24 fname = sprintf('data/%s_gcs.pfm',fn);
25 gcs = readpfm(fname);
26
27 fname = sprintf('data/%s_gce.pfm',fn);
28 gce = readpfm(fname);
29
30 fname = sprintf('data/%s_grs.pfm',fn);
31 grs = readpfm(fname);
32
33 fname = sprintf('data/%s_gre.pfm',fn);
34 gre = readpfm(fname);
35
36 nr = max(gre(:))+1;
37 nc = max(gce(:))+1;
38
39 fn = fn1;
40
41else
42 %nr = 49;nc = 30;
43 nr = 30;nc = 49;
44
45end
46
47figure(6);
48for j=1:8,
49 subplot(3,3,j);
50 im(reshape(ncutv(:,j+1),nr,nc));colorbar
51 title(num2str(ncutval(j+1,1)));
52end
53%cm = sprintf('print -dps ncut_%s',fn);disp(cm);eval(cm);
54subplot(3,3,9);im(I);axis('off');
55
56figure(7);clf
57for j=1:9,
58 subplot(3,3,j);
59 im(reshape(eigv(:,j),nr,nc));colorbar;%axis('off');
60 title(sprintf('%3.4e',eigval(j,1)));
61end
62%cm = sprintf('print -dps eig_%s',fn);disp(cm);eval(cm);
63
64
65
66if 0,
67
68fname = 130042;
69for j=0:30,
70 cm = sprintf('!cp plaatje_data/%d_%d.pfm data/%d_%d.pfm ',fname,j,fname,j);
71 disp(cm);eval(cm);
72end
73
74%%%%%%%%
75fnout = '130042';fn_t = '130042';
76cm = sprintf('!cp data/%s_eigval.pfm %s_eigval.pfm',fnout,fn_t);
77disp(cm);eval(cm);
78cm = sprintf('!cp data/%s_eigvec.pfm %s_eigvec.pfm',fnout,fn_t);
79disp(cm);eval(cm);
80cm = sprintf('!cp data/%s_ncutvec.pfm %s_ncutvec.pfm',fnout,fn_t);
81disp(cm);eval(cm);
82cm = sprintf('!cp data/%s_ncutval.pfm %s_ncutval.pfm',fnout,fn_t);
83disp(cm);eval(cm);
84
85
86
87
88end
89
90disp_flag = 0;
91if disp_flag,
92 [I1,bnr,bnc] = proj_back_id(ncutv(:,2),gcs,gce,grs,gre);
93 imvs(I,I1>0.002,bnr,bnc);
94end
95
96if 0,
97
98 nv = 3;
99 A = eigv(:,1:nv)*eigv(:,1:nv)';
100 [v,d] = ncut(abs(A),min(nv,5));
101
102 figure(3);
103 for j=1:min(nv,5),
104 subplot(2,2,j);
105 ims(v(:,j),nr,nc);
106 end
107
108
109%%%%%%%%
110
111figure(4);%im(I);colorbar;
112hw = 3;st_sz = 2*hw+1;
113ct = round(ginput(1));
114ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
115ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
116
117idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
118
119figure(5);im(abs(reshape(A(idx,:),nr,nc)));%colorbar;
120
121
122
123 %%%%%
124
125 fname = 'test2';
126 fn = sprintf('data/ncut_%s.pfm',fname);
127 ncutv1 = readpfm(fn);
128 nr = 30; nc=49;
129
130 figure(1);
131 for j=1:min(4,size(ncutv1,2)),
132 subplot(2,2,j);
133 ims(ncutv1(:,j+1),nr,nc);
134 end
135
136
137
138%%%%%%%%%%
139
140 id = 0;
141 fn = sprintf('data/test_Aa%d.pfm',id);
142 disp(sprintf('A = readpfm(%s);',fn));
143 A = readpfm(fn);
144
145 cm = sprintf('[v%d,d%d] = eigs(A,12);',id,id);
146 disp(cm);eval(cm);
147
148 writepfm('test_eigv0.pfm',v0);
149 writepfm('test_eigva0.pfm',diag(d0));
150
151
152
153
154vs = zeros(size(v1,1),size(v1,2),6);
155ds = zeros(length(d1),6);
156
157for j=0:5,
158 cm = sprintf('vs(:,:,%d) = v%d;',j+1,j);
159 disp(cm);eval(cm);
160 cm = sprintf('d = diag(d%d);',j);
161 disp(cm);eval(cm);
162 cm = sprintf('ds(:,%d) = d(:);',j+1);
163 disp(cm);eval(cm);
164
165
166end
167
168%save evsum vs ds
169
170figure(1);nr = 49;nc=30;evid = 3;
171for j=1:12,subplot(3,4,j);ims(vs(:,j,evid),nr,nc);end
172
173I = readpgm('images/334039.pgm');I = cutoff(I,20);
174
175As = zeros(6,nr*nc);
176
177figure(3);%im(I);colormap(gray);
178hw = 3;st_sz = 2*hw+1;
179ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
180idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
181
182figure(5);
183
184figure(4);nvs = [6,9,12,12,12,12];
185for evid = 1:5,As(evid,:) = squeeze(vs(idx,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))';end
186for evid =1:5,subplot(2,3,evid);im(abs(reshape(As(evid,:),nr,nc)));colorbar;end
187subplot(2,3,6);ims(sum(abs(As)),nr,nc);colorbar
188
189%%%%%%%%%
190
191%%%%%% eig of the As over all scales %%
192
193A = zeros(nr*nc,nr*nc);
194
195for evid=1:5, disp(evid);
196 A = A + abs(squeeze(vs(:,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))');
197end
198
199[v,d] = eigs(A,12);
200figure(1); for j=1:12, subplot(3,4,j);ims(v(:,j),nr,nc);end
201
202[vn,dn] = ncut_b(A,12);
203figure(3); for j=1:12, subplot(3,4,j);ims(-vn(:,j),nr,nc);end
204
205nv = 6;
206A = abs(eigv(:,1:nv)*eigv(:,1:nv)');
207[v,d] = ncut_b(A,nv+1);
208figure(1);
209for j=1:nv,subplot(2,nv,j);ims(v(:,j+1),nr,nc);title(sprintf('%3.3e',d(j+1)));end
210
211for j=1:nv,subplot(2,nv,j+nv);ims(eigv(:,j),nr,nc);title(sprintf('%3.3e',eigval(j,1)));end
212
213
214
215end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresulthome.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresulthome.m
new file mode 100755
index 0000000..208b86a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_evresulthome.m
@@ -0,0 +1,237 @@
1fn = '334003';
2
3fname = sprintf('%s_eigvec.pfm',fn);
4disp(sprintf('reading %s',fname));
5eigv = readpfm(fname);
6fname = sprintf('%s_eigval.pfm',fn);
7eigval = readpfm(fname);
8
9fname = sprintf('%s_ncutvec.pfm',fn);
10ncutv = readpfm(fname);
11fname = sprintf('%s_ncutval.pfm',fn);
12ncutval = readpfm(fname);
13
14%fname = sprintf('images/130038.pgm');
15fname = sprintf('images/%s.pgm',fn);
16I = readpgm(fname);
17cutsz = 20; I = cutoff(I,cutsz);
18figure(3);im(I);colormap(gray);
19
20new = 0;
21
22if new,
23 fn1 = fn;
24 fn = 'test';
25 fname = sprintf('%s_gcs.pfm',fn);
26 gcs = readpfm(fname);
27
28 fname = sprintf('%s_gce.pfm',fn);
29 gce = readpfm(fname);
30
31 fname = sprintf('%s_grs.pfm',fn);
32 grs = readpfm(fname);
33
34 fname = sprintf('%s_gre.pfm',fn);
35 gre = readpfm(fname);
36
37 nr = max(gre(:))+1;
38 nc = max(gce(:))+1;
39
40 fn = fn1;
41
42else
43 nr = 49;nc = 30;
44 %nr = 30;nc = 49;
45
46end
47
48figure(6);
49for j=1:8,
50 subplot(3,3,j);
51 im(reshape(ncutv(:,j+1),nr,nc));colorbar
52 title(num2str(ncutval(j+1,1)));
53end
54%cm = sprintf('print -dps ncut_%s',fn);disp(cm);eval(cm);
55%subplot(3,3,9);im(I);axis('off');
56
57figure(7);clf
58for j=1:9,
59 subplot(3,3,j);
60 im(reshape(eigv(:,j),nr,nc));colorbar;%axis('off');
61 title(sprintf('%3.4e',eigval(j,1)));
62end
63%cm = sprintf('print -dps eig_%s',fn);disp(cm);eval(cm);
64
65
66
67if 0,
68
69fname = 130042;
70for j=0:30,
71 cm = sprintf('!cp plaatje_data/%d_%d.pfm data/%d_%d.pfm ',fname,j,fname,j);
72 disp(cm);eval(cm);
73end
74
75%%%%%%%%
76fnout = '130042';fn_t = '130042';
77cm = sprintf('!cp data/%s_eigval.pfm %s_eigval.pfm',fnout,fn_t);
78disp(cm);eval(cm);
79cm = sprintf('!cp data/%s_eigvec.pfm %s_eigvec.pfm',fnout,fn_t);
80disp(cm);eval(cm);
81cm = sprintf('!cp data/%s_ncutvec.pfm %s_ncutvec.pfm',fnout,fn_t);
82disp(cm);eval(cm);
83cm = sprintf('!cp data/%s_ncutval.pfm %s_ncutval.pfm',fnout,fn_t);
84disp(cm);eval(cm);
85
86
87
88
89end
90
91disp_flag = 0;
92if disp_flag,
93 [I1,bnr,bnc] = proj_back_id(ncutv(:,2),gcs,gce,grs,gre);
94 imvs(I,I1>0.002,bnr,bnc);
95end
96
97if 0,
98
99 nv = 3;
100 A = eigv(:,1:nv)*eigv(:,1:nv)';
101 [v,d] = ncut(abs(A),min(nv,5));
102
103 figure(3);
104 for j=1:min(nv,5),
105 subplot(2,2,j);
106 ims(v(:,j),nr,nc);
107 end
108
109
110%%%%%%%%
111
112figure(4);%im(I);colorbar;
113hw = 3;st_sz = 2*hw+1;
114ct = round(ginput(1));
115ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
116ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
117
118idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
119
120figure(5);im(abs(reshape(A(idx,:),nr,nc)));%colorbar;
121
122
123
124 %%%%%
125
126 fname = 'test2';
127 fn = sprintf('data/ncut_%s.pfm',fname);
128 ncutv1 = readpfm(fn);
129 nr = 30; nc=49;
130
131 figure(1);
132 for j=1:min(4,size(ncutv1,2)),
133 subplot(2,2,j);
134 ims(ncutv1(:,j+1),nr,nc);
135 end
136
137
138
139%%%%%%%%%%
140
141 id = 0;
142 fn = sprintf('test_Aa%d.pfm',id);
143 disp(sprintf('A = readpfm(%s);',fn));
144 A = readpfm(fn);
145
146 cm = sprintf('[v%d,d%d] = eigs(A,12);',id,id);
147 disp(cm);eval(cm);
148
149 writepfm('test_eigv0.pfm',v0);
150 writepfm('test_eigva0.pfm',diag(d0));
151
152
153
154
155vs = zeros(size(v1,1),size(v1,2),6);
156ds = zeros(length(d1),6);
157
158for j=0:5,
159 cm = sprintf('vs(:,:,%d) = v%d;',j+1,j);
160 disp(cm);eval(cm);
161 cm = sprintf('d = diag(d%d);',j);
162 disp(cm);eval(cm);
163 cm = sprintf('ds(:,%d) = d(:);',j+1);
164 disp(cm);eval(cm);
165
166
167end
168
169%save evsum vs ds
170
171figure(1);nr = 49;nc=30;evid = 3;
172for j=1:12,subplot(3,4,j);ims(vs(:,j,evid),nr,nc);end
173
174I = readpgm('images/334039.pgm');I = cutoff(I,20);
175
176As = zeros(6,nr*nc);
177
178figure(3);%im(I);colormap(gray);
179hw = 3;st_sz = 2*hw+1;
180ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
181idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
182
183figure(5);
184
185figure(4);nvs = [6,9,12,12,12,12];
186for evid = 1:5,As(evid,:) = squeeze(vs(idx,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))';end
187for evid =1:5,subplot(2,3,evid);im(abs(reshape(As(evid,:),nr,nc)));colorbar;end
188subplot(2,3,6);ims(sum(abs(As)),nr,nc);colorbar
189
190%%%%%%%%%
191
192%%%%%% eig of the As over all scales %%
193
194A = zeros(nr*nc,nr*nc);
195
196for evid=1:5, disp(evid);
197 A = A + abs(squeeze(vs(:,1:nvs(evid),evid))*squeeze(vs(:,1:nvs(evid),evid))');
198end
199
200[v,d] = eigs(A,12);
201figure(1); for j=1:12, subplot(3,4,j);ims(v(:,j),nr,nc);end
202
203[vn,dn] = ncut_b(A,12);
204figure(3); for j=1:12, subplot(3,4,j);ims(-vn(:,j),nr,nc);end
205
206nv = 6;
207A = abs(eigv(:,1:nv)*eigv(:,1:nv)');
208[v,d] = ncut_b(A,nv+1);
209figure(1);
210for j=1:nv,subplot(2,nv,j);ims(v(:,j+1),nr,nc);title(sprintf('%3.3e',d(j+1)));end
211
212for j=1:nv,subplot(2,nv,j+nv);ims(eigv(:,j),nr,nc);title(sprintf('%3.3e',eigval(j,1)));end
213
214%%%%%%%%%%%%%%%%%
215
216while 1,
217figure(3);%im(I);colormap(gray);
218hw = 3;st_sz = 2*hw+1;
219ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
220idx = (ct_chank(:,1)-1)*nr + ct_chank(:,2);
221
222figure(1);
223ims(exp(-(A(idx,:))/(0.03^2)),nr,nc);colorbar
224end
225
226disp_evresulthome;
227close(3);close(7);close(6);
228A = euclid_dist(ncutv(:,2:6));
229A = exp(-A/(0.05^2));
230
231[v,d] = eigs(A,9);
232
233figure(2);
234for j=1:9,subplot(3,3,j);ims(v(:,j),nr,nc);colorbar;end
235
236
237end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_groups.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_groups.m
new file mode 100755
index 0000000..d087218
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_groups.m
@@ -0,0 +1,13 @@
1function disp_groups(groups,ids,nr,nc);
2
3np = ids(end);
4
5baseid =1;
6for j=1:length(ids),
7 mask = zeros(np,1);
8 mask(groups(baseid:ids(j))) = 1+mask(groups(baseid:ids(j)));
9
10 subplot(3,3,j);
11 ims(mask,nr,nc);
12 baseid = 1+ids(j);
13end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_hist2d.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_hist2d.m
new file mode 100755
index 0000000..4313234
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/disp_hist2d.m
@@ -0,0 +1,15 @@
1function H2 = disp_hist2d(J,Jf,scales,filter_ids)
2
3ns = length(scales);
4nf = length(filter_ids);
5
6H2 = [];
7for j=1:ns,
8 for k=1:nf,
9 subplot(ns,nf,(j-1)*nf+k);
10 H2d = hist_I_f(J,Jf(:,:,filter_ids(k),scales(j)));
11 imagesc(H2d);axis('image');axis('off');drawnow;
12 H2(:,:,j,k) = H2d;
13 end
14end
15
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair.m
new file mode 100755
index 0000000..1c7b2cf
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair.m
@@ -0,0 +1,28 @@
1function d = dist_pair(idx,fv,hb)
2% (hb=sigs,bin_mins,bin_maxs,nbins)
3%
4%
5% computes the pairwise distance between
6% a point and everyone else using histogram binized feature
7%
8
9
10[nf,np] = size(fv);
11
12d = zeros(1,np);
13nbins = [0,hb.nbins];
14
15
16for j=1:nf,
17 bin_min = hb.bmins(j);
18 bin_max = hb.bmaxs(j);
19 nbin = nbins(j+1);
20 sig = hb.sigs(j);
21 fprintf(sprintf('|%d',j));
22 b = binize(fv(j,:),sig,bin_min,bin_max,nbin);
23
24 a = binize(fv(j,idx),sig,bin_min,bin_max,nbin);
25
26 d = d + a'*b;
27end
28fprintf('\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair_chank.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair_chank.m
new file mode 100755
index 0000000..96a0d60
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/dist_pair_chank.m
@@ -0,0 +1,25 @@
1function d = dist_pair_chank(a,fvs,chank_size)
2% (hb=sigs,bin_mins,bin_maxs,nbins)
3%
4%
5% computes the pairwise distance between
6% a point and everyone else using histogram binized feature
7%
8
9
10[nf,np] = size(fvs);
11
12n_chanks = ceil(np/chank_size);
13
14d = [];
15for j=1:n_chanks,
16 fprintf('<');
17
18 cm = sprintf('load st_%d',j);
19 eval(cm);
20 fprintf(sprintf('%d',n_chanks-j));
21
22 d = [d,a*fh];
23end
24
25fprintf('\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/doog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/doog2.m
new file mode 100755
index 0000000..3ec22c1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/doog2.m
@@ -0,0 +1,43 @@
1function [G]=doog2(sig,r,th,N);
2% [G,H]=doog2(sig,r,th,N);
3% Make difference of offset gaussians kernel
4% theta is in degrees
5% (see Malik & Perona, J. Opt. Soc. Amer., 1990)
6%
7% Example:
8% >> imagesc(-doog2(.5,4,15,32))
9% >> colormap(gray)
10
11% by Serge Belongie
12
13no_pts=N; % no. of points in x,y grid
14pad_pts=no_pts*sqrt(2); % pad grid dimensions for up to a 45 degree rotation
15siz=6; % range of x,y grid
16
17[x,y]=meshgrid(linspace(-siz,siz,pad_pts),linspace(-siz,siz,pad_pts));
18
19a=-1;
20b=2;
21c=-1;
22
23ya=sig;
24yc=-ya;
25yb=0;
26sigy=sig;
27sigx=r*sig;
28
29Ga=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-ya)/sigy).^2));
30Gb=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yb)/sigy).^2));
31Gc=(1/(2*pi*sigx*sigy))*exp(-(((x-0)/sigx).^2+((y-yc)/sigy).^2));
32
33Go = a*Ga + b*Gb + c*Gc;
34%Ho = imag(hilbert(Go));
35G = Go;
36
37G = mimrotate(Go,th,'bilinear','crop');
38G = imcrop(G,[(pad_pts-no_pts)/2, (pad_pts-no_pts)/2, no_pts, no_pts]);
39
40%H = imrotate(Ho,th,'bilinear','crop');
41%H = imcrop(H,[(pad_pts-no_pts)/2, (pad_pts-no_pts)/2, no_pts, no_pts]);
42
43
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp.m
new file mode 100755
index 0000000..5209088
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp.m
@@ -0,0 +1,15 @@
1function [v,d] = eig_decomp(A)
2
3ds = sum(A);
4ds = ones(size(ds))./sqrt(ds);
5D1 = ds'*ones(1,length(ds));
6A = D1'.*A.*D1;
7
8disp(sprintf('computing eig values'));
9tic;[v,d] = eig(A);toc;
10
11d = abs(diag(d));
12[tmp,idx] = sort(-d);
13d = d(idx);
14v = v(:,idx);
15v = D1.*v;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp_v5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp_v5.m
new file mode 100755
index 0000000..e0fab2c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_decomp_v5.m
@@ -0,0 +1,13 @@
1function [v,d] = eig_decomp_v5(A,nv)
2
3ds = sum(A);
4ds = ones(size(ds))./sqrt(ds);
5D1 = ds'*ones(1,length(ds));
6A = D1'.*A.*D1;
7
8disp(sprintf('computing eig values'));
9tic;[v,d] = eigs(A,nv);toc;
10
11d = abs(diag(d));
12
13v = D1(:,1:size(v,2)).*v;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_proj.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_proj.m
new file mode 100755
index 0000000..78d5296
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eig_proj.m
@@ -0,0 +1,12 @@
1function v = eig_proj(u,data)
2
3% fd = feature dimension, nv = num. of eigvectors
4[fd,nv] = size(u);
5
6[fd2,nd] = size(data);
7
8if (fd ~= fd2),
9 error(sprintf('size don't match'));
10else
11 v = data'*u;
12end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eigs_decomp.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eigs_decomp.m
new file mode 100755
index 0000000..7763124
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/eigs_decomp.m
@@ -0,0 +1,39 @@
1function [v,d,D,Ipara] = eigs_decomp(fn,num_eigs)
2%
3% function [v,d,D,Ipara] = eigs_decomp(fn,num_eigs)
4%
5
6%fn = '2.ppm';
7fn = 'images/130049.pgm';
8
9
10% spatial gaussian parameter
11xscale = 3;
12
13% half size of the neighbourhood
14xnb = 6;
15
16% setting the the HSV gaussian parameter:[h s v]
17Iscale = [0.008,0.01,0.01];
18
19Input_para = [xscale,xnb,Iscale];
20
21% compute the lower half the association matrix
22[A,D,Ipara] = compute_A_ppm(fn,Input_para);
23
24B = A+A';
25clear A;
26
27% eigen decompostion
28options.tol = 1e-7;
29num_eig_v = 4;
30fprintf('doing eigs ...\n');
31[v,d] = eigs(B,num_eig_v,options);
32
33d = diag(d);
34
35% to display the final result
36
37%nr = Ipara(1);nc = Ipara(2);
38%k = 1;imagesc(reshape(v(:,k).*D,nc,nr)');colorbar
39
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/euclid_dist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/euclid_dist.m
new file mode 100755
index 0000000..cbf0734
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/euclid_dist.m
@@ -0,0 +1,22 @@
1function [A,mag] = euclid_dist(v)
2
3
4
5A = 2*v*v';
6
7nv = size(v,2);
8if (nv>1)
9 mag = sum((v.*v)')';
10else
11 mag = v.*v;
12end
13
14np = length(mag);
15
16for j=1:np,
17 A(:,j) = mag-A(:,j);
18end
19
20for j=1:np,
21 A(j,:) = mag' + A(j,:);
22end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_all_files.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_all_files.m
new file mode 100755
index 0000000..c1752e5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_all_files.m
@@ -0,0 +1,29 @@
1sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
2
3load filenames;
4
5nfiles = size(filename,1);
6
7for j = 48:nfiles,
8 fname = ['images/',filename(j,:)];
9 fname
10 I = readpgm(fname);
11
12 text_des = compute_filter(I,sigs,r,szs);
13
14 data_name = sprintf('filter_%s.mat',filename(j,:));
15 cm = sprintf('save %s ',data_name);
16
17 disp(cm);
18 eval(cm);
19 clear;
20
21 sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
22
23 load filenames;
24
25 nfiles = size(filename,1);
26
27
28end
29
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_output.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_output.m
new file mode 100755
index 0000000..a489c6e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/filter_output.m
@@ -0,0 +1,38 @@
1function If = filter_output(I,sigs,szs,flag);
2%
3% compute filter output for all orientation and scale,
4%
5
6%% flag = 1 if compute oriented filter output
7if (~exist('flag')),
8 flag = 1;
9end
10
11
12If = [];
13
14for j = 1:length(sigs),
15 sig = sigs(j);
16 sz = 2*round(4*sig)+1;
17
18 g = mkdog1(sig,sz);
19 fprintf('[');
20 fprintf('.');
21 If(:,:,1,j) = conv2(I,g,'same');
22
23 angles = [0:30:150];
24 r = 3;
25
26 if flag,
27 for k = 1:length(angles),
28 fprintf('.');
29 g = mdoog2(sig,r,angles(k),szs(j));
30 If(:,:,k+1,j) = conv2(I,g,'same');
31 end
32 end
33
34 fprintf(']');
35
36end
37
38fprintf('\n'); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_bst_cut.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_bst_cut.m
new file mode 100755
index 0000000..c85cc2b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_bst_cut.m
@@ -0,0 +1,24 @@
1function [cut_threshold,max_asso] = find_bst_cut(fn_base,para,threshold,Gmask)
2
3basedir = 'plaatje_data/';
4%basedir = './';
5
6fn = sprintf('%sbst_cut.tex',basedir);
7write_command(fn,fn_base,para);
8
9fn= sprintf('%sthreshold_%s.pfm',basedir,fn_base);
10writepfm(fn,threshold(:));
11
12fn= sprintf('%sGmask_%s.pfm',basedir,fn_base);
13writepfm(fn,Gmask(:));
14
15cd plaatje_data
16!./find_bestcut
17cd /home/barad-dur/vision/malik/jshi/proj/grouping/texture
18
19fn = sprintf('%sbst_asso_%s.pfm',basedir,fn_base);
20results = readpfm(fn);
21asso = results(1,:);
22[max_asso,id] = max(asso);
23cut_threshold = threshold(id);
24
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_center.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_center.m
new file mode 100755
index 0000000..b5a127a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_center.m
@@ -0,0 +1,4 @@
1function [center_x,center_y] = find_center(size_x,size_y);
2
3center_x = 0.5*(size_x -1)+1;
4center_y = 0.5*(size_y -1)+1;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_cutpoint.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_cutpoint.m
new file mode 100755
index 0000000..5cab956
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/find_cutpoint.m
@@ -0,0 +1,13 @@
1function [cutpoints,x] = find_cutpoint(data,cmap,nbin)
2%
3% [cutpoints,x] = find_cutpoint(data,cmap,nbin)
4%
5%
6
7x = id_cut(data,cmap,nbin);
8
9cutpoints = zeros(1,nbin);
10
11for j=1:nbin,
12 cutpoints(j) = max(data(x<=j));
13end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/gen_filters.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/gen_filters.m
new file mode 100755
index 0000000..65e3c3a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/gen_filters.m
@@ -0,0 +1,47 @@
1function filters = gen_filters(sig,r,sz);
2
3
4as = 0:30:150;
5
6filters = [];
7
8if size(sig,2)== 1,
9
10 for j = 1:length(as),
11 fprintf('.');
12 angle = as(j);
13
14 g = mdoog2(sig,r,angle,round(sz));
15
16 g = g - mean(reshape(g,prod(size(g)),1));
17
18 g = g/sum(sum(abs(g)));
19
20 filters(:,:,j) = g;
21 end
22else
23
24 % there are multiple scales
25 sigs = sig;
26 szs = sz;
27 for k = 1:size(sigs,2),
28 sig = sigs(k);
29 sz = szs(length(szs)-1);
30 fprintf('%d',k);
31 for j = 1:length(as),
32 fprintf('.');
33 angle = as(j);
34
35 g = mdoog2(sig,r,angle,round(sz));
36 g = g - mean(reshape(g,prod(size(g)),1));
37 g = g/sum(sum(abs(g)));
38
39 filters(:,:,j,k) = g;
40 end
41
42
43 end
44
45end
46
47fprintf('\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist.m
new file mode 100755
index 0000000..b05d680
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist.m
@@ -0,0 +1,9 @@
1function cumhists = get_cumhist(hists)
2%
3%
4% cumhists = get_cumhist(hists)
5%
6
7cumhists.inten = cumsum(hists.inten)/sum(hists.inten);
8cumhists.text = cumsum(hists.text,1)./(ones(size(hists.text,1),1)*sum(hists.text,1));
9cumhists.mag = cumsum(hists.mag)/sum(hists.mag); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist_inten.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist_inten.m
new file mode 100755
index 0000000..911b4e6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_cumhist_inten.m
@@ -0,0 +1,7 @@
1function CH_inten = get_cumhist(hists)
2%
3%
4% cumhists = get_cumhist(hists)
5%
6
7CH_inten = cumsum(hists)/sum(hists);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist.m
new file mode 100755
index 0000000..d480a3a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist.m
@@ -0,0 +1,24 @@
1function [hists,bins] = get_hists(J,Jbar)
2%
3%
4% produce histogram output of the image J and its
5% filter outputs Jbar
6%
7
8maxval = 60;
9bin = [1:4:maxval+1];
10
11w = size(J);
12
13
14[hists.inten,bins.inten] = hist(reshape(J,prod(w),1),[1:26:256]);
15
16for j=1:size(Jbar,3),
17 hists.text(:,j) = hist(reshape(abs(Jbar(:,:,j)),prod(w),1),bin);
18end
19
20bins.text = bin;
21
22[hists.mag,bins.mag] = hist(reshape(sum(abs(Jbar),3),prod(w),1),[1:10:161]);
23
24
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist_inten.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist_inten.m
new file mode 100755
index 0000000..c8357c6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_hist_inten.m
@@ -0,0 +1,15 @@
1function [Hinten,Hbins] = get_hists_inten(J,nbin)
2%
3%
4% produce histogram output of the image J and its
5% filter outputs Jbar
6%
7
8
9w = size(J);
10
11[Hinten,Hbins] = hist(reshape(J,prod(w),1),linspace(1,256,nbin));
12
13
14
15
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win.m
new file mode 100755
index 0000000..411a694
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win.m
@@ -0,0 +1,10 @@
1function J = get_win(I,center,wc)
2%
3% J = get_win(I,center,wc)
4%
5% center: [x,y]
6
7
8
9J = I(center(2)-wc(2):center(2)+wc(2),...
10 center(1)-wc(1):center(1)+wc(1));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win5.m
new file mode 100755
index 0000000..e8404e5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/get_win5.m
@@ -0,0 +1,11 @@
1function J = get_win5(I,center,wc)
2%
3% J = get_win5(I,center,wc)
4%
5% center: [x,y]
6
7
8
9J = I(center(2)-wc(2):center(2)+wc(2),...
10 center(1)-wc(1):center(1)+wc(1),:,:);
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/grad.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/grad.m
new file mode 100755
index 0000000..6da0fbf
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/grad.m
@@ -0,0 +1,24 @@
1% gradient of an image
2% coordinates (r, c) follow matrix convention;
3% the gaussian is truncated at x = +- tail, and there are samples samples
4% inbetween, where samples = hsamples * 2 + 1
5
6function[gr,gc] = gradient(image, hsamples)
7
8tail=4;
9samples = hsamples * 2 + 1;
10
11x = linspace(-tail, tail, samples);
12gauss = exp(-x.^2);
13n = gauss * ones(samples,1);
14gauss = gauss/n;
15
16gaussderiv = -x.*gauss;
17n = -gaussderiv*linspace(1,samples,samples)';
18gaussderiv = gaussderiv/n;
19
20gr = conv2(conv2(image, gaussderiv','valid'), gauss,'valid');
21gc = conv2(conv2(image, gaussderiv,'valid'), gauss','valid');
22
23%gr = conv_trim(gr, hsamples, hsamples);
24%gc = conv_trim(gc, hsamples, hsamples);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/half_sigmoid.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/half_sigmoid.m
new file mode 100755
index 0000000..c187b6c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/half_sigmoid.m
@@ -0,0 +1,17 @@
1function a = half_sigmoid(x,offset,sig)
2%
3% a = half_sigmoid(x,offset,sig)
4%
5% a = ones(size(x))./(1+exp(-(x-offset)/sig));
6%
7% keep the sign of a
8
9sign_x = sign(x);
10x = abs(x);
11
12a = ones(size(x))./(1+exp(-(x-offset)/sig));
13
14off = 1/(1+exp(-(0-offset)/sig));
15
16a = sign_x.*(a-off);
17
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist2d.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist2d.m
new file mode 100755
index 0000000..3f4db0c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist2d.m
@@ -0,0 +1,13 @@
1function H2 = hist2d(J,Jf,scales,filter_ids)
2
3ns = length(scales);
4nf = length(filter_ids);
5
6H2 = [];
7for j=1:ns,
8 for k=1:nf,
9 H2d = hist_I_f(J,Jf(:,:,filter_ids(k),scales(j)));
10 H2(:,:,j,k) = H2d;
11 end
12end
13
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_I_f.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_I_f.m
new file mode 100755
index 0000000..a993661
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_I_f.m
@@ -0,0 +1,22 @@
1function h2d = hist_I_f(I,If,binI,binf)
2
3if (nargin == 2),
4 binI = [0:13:260];
5 binf = [-30:2.5*2:30];
6end
7
8%%% make 2d histogram bin
9h2d = [];
10
11for j = 2:length(binf),
12
13 [id_i,id_j] = find((If>binf(j-1)) & (If<=binf(j)));
14 if (length(id_i) >0),
15 h = hist(I(id_i+(id_j-1)*size(I,1)),binI);
16 else
17 h = zeros(size(binI));
18 end
19
20 h2d = [h2d,h'];
21end
22
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_diff.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_diff.m
new file mode 100755
index 0000000..6976c8f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_diff.m
@@ -0,0 +1,30 @@
1function hdiff = hist_diff(H1,H2)
2%
3% hdiff = hist_diff(H1,H2)
4%
5
6ns = size(H1,3);
7nf = size(H1,4);
8
9sI= [1,0,1];sI = exp(-sI);
10sI = sI/sum(sI);
11
12hdiff = 0;
13for j = 1:ns,
14 for k = 1:nf,
15 h1 = H1(:,:,j,k);
16 h2 = H2(:,:,j,k);
17
18 h1s = conv2(conv2(h1,sI','same'),sI,'same');
19 h2s = conv2(conv2(h2,sI','same'),sI,'same');
20
21 [is,js] = find( (h1>0) | (h2>0));
22 ids = (js-1)*size(h1,1) + is;
23
24 xdiffs = ((h1s(ids)-h2s(ids)).*(h1s(ids)-h2s(ids)))./(h1s(ids)+h2s(ids));
25 hdiff = hdiff + sum(xdiffs);
26
27 end
28end
29
30hdiff = hdiff/(ns*nf);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_f.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_f.m
new file mode 100755
index 0000000..93f50a9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_f.m
@@ -0,0 +1,28 @@
1function h2d = hist_f(Ifs,f1,s1,f2,s2)
2
3
4binf = [-30:2.5*2:30];
5
6
7%%% make 2d histogram bin
8
9If1 = Ifs(:,:,f1,s1);
10If2 = Ifs(:,:,f2,s2);
11h2d = [];
12
13binf(1) = -100;
14binf(length(binf)) = 100;
15
16for j = 2:length(binf),
17
18 [id_i,id_j] = find((If1>binf(j-1)) & (If1<=binf(j)));
19 if (length(id_i) >0),
20
21 h = hist(If2(id_i+(id_j-1)*size(If2,1)),binf);
22 else
23 h = zeros(size(binf));
24 end
25
26
27 h2d = [h2d,h'];
28end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_in_chank.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_in_chank.m
new file mode 100755
index 0000000..74661b2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_in_chank.m
@@ -0,0 +1,33 @@
1function covfh = hist_inner_chank(fv,chank_size,nbin)
2% fh = hist_inner_chank(fv,hb,chank_file)
3%
4% (hb = bin_mins,bin_maxs,nbins)
5%
6% take which histogram value and turn it into histogram bin
7% compute the inner product of the histogram bin features
8%
9
10[nf,np] = size(fv);
11
12tbins = nf*nbin;
13disp(sprintf('need matrix of %d x %d ',tbins,tbins));
14
15covfh = zeros(tbins,tbins);
16
17n_chanks = ceil(np/chank_size);
18for j=1:n_chanks,
19 fprintf('<');
20
21 cm = sprintf('load st_%d',j);
22 eval(cm);
23 fprintf(sprintf('%d',n_chanks-j));
24
25 %ms = mean(fh');
26 %fh = fh- ms'*ones(1,size(fh,2));
27
28 covfh = covfh + fh*fh';
29 fprintf('>');
30end
31
32fprintf('\n');
33
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_inner.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_inner.m
new file mode 100755
index 0000000..6fd02b7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hist_inner.m
@@ -0,0 +1,40 @@
1function fh = hist_inner(fv,hb)
2% (hb = bin_mins,bin_maxs,nbins)
3%
4% take which histogram value and turn it into histogram bin
5% compute the inner product of the histogram bin features
6%
7
8[nf,np] = size(fv);
9
10nbins = [0,hb.nbins];
11
12disp(sprintf('need matrix of %d x %d ',sum(nbins),sum(nbins)));
13
14fh = zeros(sum(nbins),sum(nbins));
15
16for j=1:nf,
17 bin_min = hb.bmins(j);
18 bin_max = hb.bmaxs(j);
19 nbin = nbins(j+1);
20 sig = hb.sigs(j);
21 fprintf('|');
22 b0 = binize(fv(j,:),sig,bin_min,bin_max,nbin);
23
24 fh(sum(nbins(1:j))+1:sum(nbins(1:j+1)),sum(nbins(1:j))+1:sum(nbins(1:j+1))) = b0*b0';
25
26 for k=j+1:nf,
27 bin_min = hb.bmins(k);
28 bin_max = hb.bmaxs(k);
29 nbin = nbins(k+1);
30 sig = hb.sigs(k);
31 fprintf('.');
32 b = binize(fv(k,:),sig,bin_min,bin_max,nbin);
33 tmp = b0*b';
34
35 fh(sum(nbins(1:j))+1:sum(nbins(1:j+1)),sum(nbins(1:k))+1:sum(nbins(1:k+1))) = tmp;
36 fh(sum(nbins(1:k))+1:sum(nbins(1:k+1)),sum(nbins(1:j))+1:sum(nbins(1:j+1))) = tmp';
37 end
38end
39
40fprintf('\n');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/histbin_fv_chank.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/histbin_fv_chank.m
new file mode 100755
index 0000000..8cf2a35
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/histbin_fv_chank.m
@@ -0,0 +1,14 @@
1function histbin_fv_chank(fvs,hb,chank_size,fname_base)
2
3[nv,np] = size(fvs);
4
5k =1;
6for j=1:chank_size:np,
7 disp(sprintf('|%d',j));
8 fh = colize_hist(fvs(:,j:min(j+chank_size-1,np)),hb);
9 fname = sprintf('%s_%d.mat',fname_base,k);
10 cm = sprintf('save %s fh hb;',fname);
11 disp(cm);
12 eval(cm);
13 k = k+1;
14end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hsv2clrs.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hsv2clrs.m
new file mode 100755
index 0000000..cfbb8b0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/hsv2clrs.m
@@ -0,0 +1,25 @@
1function [x,y,z] = hsv2clrs(h,s,v)
2%
3% function [x,y,z] = hsv2clrs(h,s,v)
4% if h is 3D matrix, output in 3D x
5%
6
7if (size(h,3) == 3),
8 s = h(:,:,2);
9 v = h(:,:,3);
10 h = h(:,:,1);
11
12 z = v;
13 xx = s.*v.*cos(2*pi*h);
14 y = s.*v.*sin(2*pi*h);
15
16 x(:,:,1) = xx;
17 x(:,:,2) = y;
18 x(:,:,3) = z;
19else
20
21 z = v;
22 x = s.*v.*cos(2*pi*h);
23 y = s.*v.*sin(2*pi*h);
24end
25
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/id_cut.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/id_cut.m
new file mode 100755
index 0000000..daf8f2b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/id_cut.m
@@ -0,0 +1,14 @@
1function [x,map] = idcut(data,cmap,nbin)
2%
3%
4%
5
6lc = size(cmap,1);
7
8data = data - min(data);
9data = 1+ ((lc-1)*data/max(data));
10
11r = cmap(data,1);g = cmap(data,2);b = cmap(data,3);
12
13[x,map] = vmquant(r,g,b,nbin);
14
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im.m
new file mode 100755
index 0000000..6450120
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im.m
@@ -0,0 +1,3 @@
1function im(I)
2
3imagesc(I);axis('image');drawnow; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im3.m
new file mode 100755
index 0000000..b49e690
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im3.m
@@ -0,0 +1,3 @@
1function im3(d)
2
3imagesc(reshape(d,size(d,1),size(d,2)*size(d,3)));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im5.m
new file mode 100755
index 0000000..7f1b16d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im5.m
@@ -0,0 +1,16 @@
1function im5(data,nr,nc,mag)
2
3if nargin == 4,
4for j=1:size(data,3),
5 subplot(nr,nc,j);
6 imagesc(data(:,:,j)./mag);axis('image');axis('off');colorbar;drawnow;
7
8% image(150*data(:,:,j));axis('image');axis('off');colorbar;drawnow;
9end
10
11else
12for j=1:size(data,3),
13 subplot(nr,nc,j);
14 imagesc(data(:,:,j));axis('image');axis('off');colorbar;drawnow;
15end
16end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im_vect.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im_vect.m
new file mode 100755
index 0000000..d0a5b30
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/im_vect.m
@@ -0,0 +1,20 @@
1function a = im_vect(loca,v,scale);
2
3if ~exist('scale'),
4 scale = 50;
5end
6
7y = loca(1,:);
8x = loca(2,:);
9
10x = x - min(x);
11y = y - min(y);
12
13max_x = max(x);max_y = max(y);
14min_scale = min(max_x,max_y);
15
16x = scale*x/min_scale;
17y = scale*y/min_scale;
18
19
20a = sparse(y+1,x+1,v);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imrotate.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imrotate.m
new file mode 100755
index 0000000..167fd02
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imrotate.m
@@ -0,0 +1,119 @@
1function bout = imrotate(arg1,arg2,arg3,arg4)
2%IMROTATE Rotate image.
3% B = IMROTATE(A,ANGLE,'method') rotates the image A by ANGLE
4% degrees. The image returned B will, in general, be larger
5% than A. Invalid values on the periphery are set to one
6% for indexed images or zero for all other image types. Possible
7% interpolation methods are 'nearest','bilinear' or 'bicubic'.
8% 'bilinear' is the default for intensity images, otherwise
9% 'nearest' is used if no method is given.
10%
11% B = IMROTATE(A,ANGLE,'crop') or IMROTATE(A,ANGLE,'method','crop')
12% crops B to be the same size as A.
13%
14% Without output arguments, IMROTATE(...) displays the rotated
15% image in the current axis.
16%
17% See also IMRESIZE, IMCROP, ROT90.
18
19% Clay M. Thompson 8-4-92
20% Copyright (c) 1992 by The MathWorks, Inc.
21% $Revision: 1.14 $ $Date: 1993/09/01 21:27:38 $
22
23if nargin<2, error('Requires at least two input parameters.'); end
24if nargin<3,
25 if isgray(arg1), caseid = 'bil'; else caseid = 'nea'; end
26 docrop = 0;
27elseif nargin==3,
28 if isstr(arg3),
29 method = [lower(arg3),' ']; % Protect against short method
30 caseid = method(1:3);
31 if caseid(1)=='c', % Crop string
32 if isgray(arg1), caseid = 'bil'; else caseid = 'nea'; end
33 docrop = 1;
34 else
35 docrop = 0;
36 end
37 else
38 error('''METHOD'' must be a string of at least three characters.');
39 end
40else
41 if isstr(arg3),
42 method = [lower(arg3),' ']; % Protect against short method
43 caseid = method(1:3);
44 else
45 error('''METHOD'' must be a string of at least three characters.');
46 end
47 docrop = 1;
48end
49
50% Catch and speed up 90 degree rotations
51if rem(arg2,90)==0 & nargin<4,
52 phi = rem(arg2,360);
53 if phi==90,
54 b = rot90(arg1);
55 elseif phi==180,
56 b = rot90(arg1,2);
57 elseif phi==270,
58 b = rot90(arg1,-1);
59 else
60 b = arg1;
61 end
62 if nargout==0, imshow(b), else bout = b; end
63 return
64end
65
66phi = arg2*pi/180; % Convert to radians
67
68% Rotation matrix
69T = [cos(phi) -sin(phi); sin(phi) cos(phi)];
70
71% Coordinates from center of A
72[m,n] = size(arg1);
73if ~docrop, % Determine limits for rotated image
74 siz = ceil(max(abs([(n-1)/2 -(m-1)/2;(n-1)/2 (m-1)/2]*T))/2)*2;
75 uu = -siz(1):siz(1); vv = -siz(2):siz(2);
76else % Cropped image
77 uu = (1:n)-(n+1)/2; vv = (1:m)-(m+1)/2;
78end
79nu = length(uu); nv = length(vv);
80
81blk = bestblk([nv nu]);
82nblks = floor([nv nu]./blk); nrem = [nv nu] - nblks.*blk;
83mblocks = nblks(1); nblocks = nblks(2);
84mb = blk(1); nb = blk(2);
85
86rows = 1:blk(1); b = zeros(nv,nu);
87for i=0:mblocks,
88 if i==mblocks, rows = (1:nrem(1)); end
89 for j=0:nblocks,
90 if j==0, cols = 1:blk(2); elseif j==nblocks, cols=(1:nrem(2)); end
91 if ~isempty(rows) & ~isempty(cols)
92 [u,v] = meshgrid(uu(j*nb+cols),vv(i*mb+rows));
93 % Rotate points
94 uv = [u(:) v(:)]*T'; % Rotate points
95 u(:) = uv(:,1)+(n+1)/2; v(:) = uv(:,2)+(m+1)/2;
96 if caseid(1)=='n', % Nearest neighbor interpolation
97 b(i*mb+rows,j*nb+cols) = interp6(arg1,u,v);
98 elseif all(caseid=='bil'), % Bilinear interpolation
99 b(i*mb+rows,j*nb+cols) = interp4(arg1,u,v);
100 elseif all(caseid=='bic'), % Bicubic interpolation
101 b(i*mb+rows,j*nb+cols) = interp5(arg1,u,v);
102 else
103 error(['Unknown interpolation method: ',method]);
104 end
105 end
106 end
107end
108
109d = find(isnan(b));
110if length(d)>0,
111 if isind(arg1), b(d) = ones(size(d)); else b(d) = zeros(size(d)); end
112end
113
114if nargout==0,
115 imshow(b), return
116end
117bout = b;
118
119
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ims.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ims.m
new file mode 100755
index 0000000..2fb5f25
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ims.m
@@ -0,0 +1,3 @@
1function ims(I,nr,nc)
2
3im(reshape(I,nr,nc)); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imvs.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imvs.m
new file mode 100755
index 0000000..21dde73
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/imvs.m
@@ -0,0 +1,4 @@
1function imvs(I,v,nr,nc)
2
3v = reshape(v,nr,nc);
4im(I(1:size(v,1),1:size(v,2)).*v); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/is_step.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/is_step.m
new file mode 100755
index 0000000..4903778
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/is_step.m
@@ -0,0 +1,33 @@
1function P_step = is_step(gx,gy)
2%
3% P_step = is_step(gx,gy)
4%
5% determine wheter gx,gy(which is first
6% order filter output) is a response
7% to a step function
8%
9
10M = zeros(2,2);
11M(1,1) = sum(sum(gx.*gx));
12M(2,2) = sum(sum(gy.*gy));
13M(1,2) = sum(sum(gx.*gy));
14M(2,1) = M(1,2);
15
16[v,d] = eig(M);
17d = diag(d);
18
19% make the first eig_value to be the smaller one
20if (d(2)< d(1)),
21 tmp = d(1);d(1) = d(2);d(2) = tmp;
22 tmp = v(:,1); v(:,1) = v(:,2); v(:,2) = tmp;
23end
24
25ratio = d(1)/d(2);
26threshold = 0;
27gx_ratio = sum(sum(gx.*(gx>threshold)))/(sum(sum(abs(gx).*(abs(gx)>threshold))));
28gx_ratio = max(gx_ratio,1-gx_ratio);
29
30gy_ratio = sum(sum(gy.*(gy>threshold)))/(sum(sum(abs(gy).*(abs(gy)>threshold))));
31gy_ratio = max(gy_ratio,1-gy_ratio);
32
33P_step = [ratio,gx_ratio,gy_ratio];
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ks_2d.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ks_2d.m
new file mode 100755
index 0000000..cfac005
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ks_2d.m
@@ -0,0 +1,20 @@
1function [na,nb,nc,nd] = ks_2d(cum_filter)
2
3[nb_filters,nb_bins] = size(cum_filter);
4
5T = 1;
6
7for j = [1:nb_filters],
8 for l = [1:nb_bins],
9 nc(j,l) = sum(cum_filter(1:j,l));
10 nd(j,l) = j*T - nc(j,l);
11
12 if (j~= nb_filters),
13 nb(j,l) = sum(cum_filter(j+1:nb_filters,l));
14 na(j,l) = (nb_filters-j)*T-nb(j,l);
15 else
16 nb(j,l) = 0;
17 na(j,l) = 0;
18 end
19 end
20end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/load_result.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/load_result.m
new file mode 100755
index 0000000..0ff328c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/load_result.m
@@ -0,0 +1,39 @@
1
2fnameI = '130056';
3
4cm = sprintf('load filter_%s.pgm.mat',fnameI);
5disp(cm);
6eval(cm);
7
8text_des= reshape(text_des,size(text_des,1),size(text_des,2),size(text_des,3)*size(text_des,4));
9
10for j=1:size(text_des,3),
11 text_des(:,:,j) = abs(text_des(:,:,j)).*(text_des(:,:,j) <0);
12end
13
14%text_des = abs(text_des);
15
16
17 %%%% cutoff margins,
18margin = 6+10;
19
20Iw = cutoff(I,margin);
21
22
23T1 = cutoff(text_des,margin);
24
25%%%%% reduce resolution
26
27
28
29T1 = reduce_all(T1);
30T1 = reduce_all(T1);
31
32im5(T1,5,6);
33
34cm = sprintf('writepnm5(''%s_f.pnm'',%s)',fnameI,'T1/70');
35
36% disp(cm);eval(cm);
37
38nr = size(T1,1);
39nc = size(T1,2);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/m_interp4.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/m_interp4.m
new file mode 100755
index 0000000..314f140
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/m_interp4.m
@@ -0,0 +1,49 @@
1function [F,mask] = m_interp4(z,s,t)
2%INTERP4 2-D bilinear data interpolation.
3% ZI = INTERP4(Z,XI,YI) assumes X = 1:N and Y = 1:M, where
4% [M,N] = SIZE(Z).
5%
6% Copyright (c) 1984-93 by The MathWorks, Inc.
7% Clay M. Thompson 4-26-91, revised 7-3-91, 3-22-93 by CMT.
8%
9% modified to
10
11
12[nrows,ncols] = size(z);
13
14
15if any(size(z)<[3 3]), error('Z must be at least 3-by-3.'); end
16if size(s)~=size(t), error('XI and YI must be the same size.'); end
17
18% Check for out of range values of s and set to 1
19sout = find((s<1)|(s>ncols));
20if length(sout)>0, s(sout) = ones(size(sout)); end
21
22% Check for out of range values of t and set to 1
23tout = find((t<1)|(t>nrows));
24if length(tout)>0, t(tout) = ones(size(tout)); end
25
26% Matrix element indexing
27ndx = floor(t)+floor(s-1)*nrows;
28
29% Compute intepolation parameters, check for boundary value.
30d = find(s==ncols);
31s(:) = (s - floor(s));
32if length(d)>0, s(d) = s(d)+1; ndx(d) = ndx(d)-nrows; end
33
34% Compute intepolation parameters, check for boundary value.
35d = find(t==nrows);
36t(:) = (t - floor(t));
37if length(d)>0, t(d) = t(d)+1; ndx(d) = ndx(d)-1; end
38d = [];
39
40% Now interpolate, reuse u and v to save memory.
41F = ( z(ndx).*(1-t) + z(ndx+1).*t ).*(1-s) + ...
42 ( z(ndx+nrows).*(1-t) + z(ndx+(nrows+1)).*t ).*s;
43
44mask = ones(size(z));
45
46% Now set out of range values to zeros.
47if length(sout)>0, F(sout) = zeros(size(sout));mask(sout)=zeros(size(sout));end
48if length(tout)>0, F(tout) = zeros(size(tout));mask(tout)=zeros(size(tout));end
49
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/make_masks.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/make_masks.m
new file mode 100755
index 0000000..d2c8ba7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/make_masks.m
@@ -0,0 +1,12 @@
1function masks = make_masks(groups,ids,nr,nc);
2
3np = ids(end);
4
5baseid =1;
6for j=1:length(ids),
7 mask = zeros(np,1);
8 mask(groups(baseid:ids(j))) = 1+mask(groups(baseid:ids(j)));
9 baseid = 1+ids(j);
10
11 masks(:,:,j) = mask;
12end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/makefilter.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/makefilter.m
new file mode 100755
index 0000000..a768269
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/makefilter.m
@@ -0,0 +1,14 @@
1function H = make_filter(txture,sze,noise)
2% function H = make_filter(txture,sze)
3%
4%
5
6x = zeros(sze);
7tx_sze = size(txture);
8
9x(1:tx_sze(1),1:tx_sze(2)) = txture;
10x = reshape(x,1,sze(1)*sze(2));
11X = fft(x);
12figure(3);plot(abs(X).^2);
13
14H = X./(abs(X).^2+noise);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t1.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t1.m
new file mode 100755
index 0000000..256e609
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t1.m
@@ -0,0 +1,22 @@
1function [H,h] = make_filter(txture,sze,noise)
2% function H = make_filter(txture,sze)
3%
4%
5
6tx_sze = size(txture);
7x = reshape(txture,1,tx_sze(1)*tx_sze(2));
8X = fft(x);
9H = X./(abs(X).^2+noise);
10h = reshape(real(ifft(H)),tx_sze(1),tx_sze(2));
11
12
13x = zeros(sze);
14x(1:tx_sze(1),1:tx_sze(2)) = h;
15figure(1);imagesc(x);drawnow;
16x = reshape(x,1,sze(1)*sze(2));
17H = fft(x);
18
19h = reshape(real(ifft(H)),sze(1),sze(2));
20figure(2);imagesc(h);
21
22figure(3); mesh(h); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t2.m
new file mode 100755
index 0000000..c84482d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_t2.m
@@ -0,0 +1,21 @@
1function [H,h] = make_filter(txture,sze,noise)
2% function H = make_filter(txture,sze)
3%
4%
5
6x = zeros(sze);
7tx_sze = size(txture);
8
9[center_x,center_y] = find_center(sze(2),sze(1));
10tx_sze_h = round(0.5*tx_sze);
11
12x(center_y-tx_sze_h(1):center_y-tx_sze_h(1)+tx_sze(1)-1,...
13 center_x-tx_sze_h(2):center_x-tx_sze_h(2)+tx_sze(2)-1) = txture;
14figure(1);imagesc(x);drawnow;
15x = reshape(x,1,sze(1)*sze(2));
16X = fft(x);
17H = X./(abs(X).^2+noise);
18h = reshape(real(ifft(H)),sze(1),sze(2));
19figure(2);imagesc(h);
20
21figure(3); mesh(h); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_test.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_test.m
new file mode 100755
index 0000000..e8d0ad8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkf_test.m
@@ -0,0 +1,43 @@
1function [H,h] = make_filter(txture,sze,n_c,a,b,c)
2% function H = make_filter(txture,sze)
3%
4%
5
6x = zeros(sze);
7tx_sze = size(txture);
8
9x(1:tx_sze(1),1:tx_sze(2)) = txture;
10%figure(1);imagesc(x);drawnow;
11x = reshape(x,1,sze(1)*sze(2));
12X = fft(x);
13power = abs(X).^2;
14
15figure(3);plot(power);
16len = length(X);
17
18t = [1:0.5*(length(X)-1),0.5*(length(X)-1):-1:1];
19
20top = max(power);
21if (c == -1),
22 c = top*5.0e-1
23end
24if (n_c == -1),
25 n_c = top*1.0e-1
26end
27
28nois = n_c +c*(exp(-a*(t.^b)));
29if (rem(len,2) == 1),
30 noise = [c+n_c,nois];
31else
32 noise = [c+n_c,nois,c+n_c];
33end
34
35figure(3);hold on;plot(noise,'r');
36hold off
37H = X./(abs(X).^2+noise);
38h = reshape(real(ifft(H)),sze(1),sze(2));
39figure(2);imagesc(h);
40
41figure(4);plot(abs(H).^2,'c')
42%figure(3); mesh(h);
43
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkg.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkg.m
new file mode 100755
index 0000000..1fb1f7e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkg.m
@@ -0,0 +1,9 @@
1function g= mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
2%
3% function G = mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
4%
5
6size_wh = round(0.5*size_w);
7[x,y] = meshgrid([-size_wh:1:size_wh],[-size_wh:1:size_wh]);
8g = 1/(2*pi*sigma_x*sigma_y)*(exp(-( ((x-xo)/sigma_x).^2 + ((y-yo)/sigma_y).^2)));
9
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkgaussian.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkgaussian.m
new file mode 100755
index 0000000..1213757
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkgaussian.m
@@ -0,0 +1,11 @@
1function G = mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
2%
3% function G = mkgaussian(xo,yo,sigma_x,sigma_y,size_w)
4%
5
6size_wh = round(0.5*size_w);
7
8[x,y] = meshgrid([-size_wh:1:size_wh],[-size_wh:1:size_wh]);
9
10G = 0.5/(sigma_x*sigma_y)*(exp(-( ((x-xo)/sigma_x).^2 + ((y-yo)/sigma).^2)));
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkmulfilter.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkmulfilter.m
new file mode 100755
index 0000000..fe501b5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkmulfilter.m
@@ -0,0 +1,52 @@
1function H = make_multi_filter(templates,num_templates,sze,u,noise)
2% function H = make_filter(templates,num_templates,sze,u,noise)
3% templates are column vectors of template
4% sze is the size of the filter
5% u is a vector of specified value
6%
7%
8
9templates_size_x = size(templates,2)/num_templates;
10templates_size_y = size(templates,1);
11
12alpha = 1/num_templates;
13
14X = zeros(num_templates,sze(1)*sze(2));
15Spectrums = zeros(num_templates,sze(1)*sze(2));
16
17
18for k =1:num_templates,
19 tmp = zeros(sze);
20 tmp(1:templates_size_y,1:templates_size_x) =...
21 templates(:,(k-1)*templates_size_x+1:k*templates_size_x);
22 x(k,:) = reshape(tmp,1,sze(1)*sze(2));
23 X(k,:) = fft(x(k,:));
24 Spectrums(k,:) = conj(X(k,:)).*X(k,:);
25end
26
27if num_templates > 1
28 sum_Spect = sum(Spectrums)*alpha;
29else
30 sum_Spect = Spectrums;
31end
32
33for row = 1:num_templates,
34 for column = 1:num_templates,
35
36 A(row,column) = sum( ((conj(X(row,:)).*X(column,:))./...
37 (sum_Spect + noise))')/(sze(1)*sze(2));
38 end
39end
40
41
42epsilon = inv(A)*u;
43
44top = epsilon(1)*X(1,:);
45for k = 2:num_templates,
46 top = top + epsilon(k)*X(k,:);
47end
48
49H = top./(sum_Spect + noise);
50
51
52
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkpoog2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkpoog2.m
new file mode 100755
index 0000000..4bd0366
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mkpoog2.m
@@ -0,0 +1,29 @@
1function doog2 = mkdoog2(sigma_w,r,theta,size_w)
2%
3% function doog2 = mkdoog2(sigma_w,r,theta,size_w)
4%
5%
6
7%scale_base = 2.8814;
8scale_base = 2;
9
10a = -1*scale_base;
11b = 2*scale_base;
12c = -1*scale_base;
13
14sigma_x = r*sigma_w;
15sigma_y = sigma_w;
16
17ya = sigma_w;
18yc = -sigma_w;
19yb = 0;
20
21doog2 = a*mkg(0,ya,sigma_x,sigma_y,size_w) +...
22 b*mkg(0,yb,sigma_x,sigma_y,size_w) +...
23 c*mkg(0,yc,sigma_x,sigma_y,size_w);
24
25figure(3);colormap(hsv);
26subplot(1,3,1);mesh(a*mkg(0,ya,sigma_x,sigma_y,size_w));
27subplot(1,3,2);mesh(b*mkg(0,yb,sigma_x,sigma_y,size_w));
28subplot(1,3,3);mesh(c*mkg(0,yc,sigma_x,sigma_y,size_w));
29%doog2 = 255*5.1745*doog2;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn.m
new file mode 100755
index 0000000..15f947b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn.m
@@ -0,0 +1,10 @@
1function sgn = makesgn(sigma,sigma_x,sze)
2
3
4size_wh = round(0.5*sze);
5[x,y] = meshgrid([-size_wh:1:size_wh],[-size_wh:1:size_wh]);
6steps = 1/(1+2*sigma_x);
7
8fx = -1*(x<=-sigma_x) + (x>=sigma_x) + steps*((x+sigma_x).*(x>-sigma_x).*(x<sigma_x));
9
10sgn = fx.*(exp(- (y.*y)/(2*sigma))); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn2.m
new file mode 100755
index 0000000..857360b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mksgn2.m
@@ -0,0 +1,9 @@
1function sgn = makesgn(sigma,sigma_x,sze)
2
3
4size_wh = round(0.5*sze);
5[x,y] = meshgrid([-size_wh(2):1:size_wh(2)],[-size_wh(1):1:size_wh(1)]);
6steps = 1/(1+sigma_x);
7
8fx = steps*((x+sigma_x).*(x>-sigma_x).*(x<1)) + steps*(sigma_x-x).*(x<sigma_x).*(x>=1);
9sgn = fx.*(exp(- (y.*y)/(2*sigma))); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm.m
new file mode 100755
index 0000000..cf68a01
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm.m
@@ -0,0 +1,11 @@
1function I = read_pfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2)
6I = fscanf(fid,'%f',[A(1),A(2)]);
7
8
9I = I';
10size(I);
11fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm2.m
new file mode 100755
index 0000000..c01b25b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mreadpfm2.m
@@ -0,0 +1,9 @@
1function I = read_pfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2)
6I = fscanf(fid,'%f',[A(1),A(2)]);
7
8
9fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis.m
new file mode 100755
index 0000000..95de8f6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis.m
@@ -0,0 +1,16 @@
1function [l1,l2,phi] = mwis(gx,gy)
2%
3% [l1,l2,phi] = mwis(gx,gy)
4%
5%
6
7sgx = sum(sum(gx.*gx));
8sgxy = sum(sum(gx.*gy));
9sgy = sum(sum(gy.*gy));
10
11tr = sgx + sgy;
12v1 = 0.5*sqrt(tr*tr - 4*(sgx*sgy-sgxy*sgxy));
13l1 = real(0.5*tr+v1);
14l2 = real(0.5*tr-v1);
15
16phi= 0.5*atan2(2*sgxy,sgx-sgy);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis_image.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis_image.m
new file mode 100755
index 0000000..c8e8b66
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/mwis_image.m
@@ -0,0 +1,25 @@
1function [l1,l2,phi] = mwis_image(gx,gy,hs)
2%
3% [l1,l2,phi] = mwis_image(gx,gy)
4%
5%
6
7if (~exist('hs')),
8 hs = 10;
9end
10
11
12sgx = gx.*gx;
13sgxy = gx.*gy;
14sgy = gy.*gy;
15
16ssgx = smooth(sgx,hs);
17ssgxy = smooth(sgxy,hs);
18ssgy = smooth(sgy,hs);
19
20tr = ssgx + ssgy;
21v1 = 0.5*sqrt(tr.*tr - 4*(ssgx.*ssgy-ssgxy.*ssgxy));
22l1 = real(0.5*tr+v1);
23l2 = real(0.5*tr-v1);
24
25phi= 0.5*atan2(2*sgxy,sgx-sgy);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/myinterp.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/myinterp.m
new file mode 100755
index 0000000..6d8f055
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/myinterp.m
@@ -0,0 +1,18 @@
1function y = myinterp(d,rate)
2%
3
4
5if (size(d,1)>1),
6 d = [d;d(1)];
7else
8 d = [d,d(1)];
9end
10
11lgn = length(d);
12
13x = 1:lgn;
14xx = linspace(1,lgn,rate*lgn);
15
16y = interp1(x,d,xx,'linear');
17
18y = y(1:(length(y)-1));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ncut_b.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ncut_b.m
new file mode 100755
index 0000000..c9eee35
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/ncut_b.m
@@ -0,0 +1,25 @@
1function [v,d] = ncut(A,nv)
2
3ds = sum(A);
4ds = ones(size(ds))./sqrt(ds);
5
6for j=1:size(A,1),
7 A(j,:) = A(j,:).*ds;
8end
9
10for j=1:size(A,2);
11 A(:,j) = A(:,j).*ds';
12end
13
14%D1 = ds'*ones(1,length(ds));
15%A = D1'.*A.*D1;
16
17disp(sprintf('computing eig values'));
18tic;[v,d] = eigs(A,nv);toc;
19
20d = abs(diag(d));
21
22for j=1:nv,
23 v(:,j) = v(:,j).*ds';
24end
25%v = D1(:,1:size(v,2)).*v;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/new_compute_J.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/new_compute_J.m
new file mode 100755
index 0000000..f4e376a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/new_compute_J.m
@@ -0,0 +1,32 @@
1function [JJ,mask] = compute_J(A,D,I,center,window_size_h)
2%% function J = compute_J(A,D,I,center,window_size_h)
3%
4
5[size_y,size_x] = size(I);
6
7center_x = center(1);
8center_y = center(2);
9
10XX = meshgrid(1:size_x,1:size_y);
11YY = meshgrid(1:size_y,1:size_x)';
12x = reshape(XX,size_x*size_y,1);
13y = reshape(YY,size_x*size_y,1);
14index(:,1) = x-center_x;
15index(:,2) = y-center_y;
16
17position_new = A*index'+ [D(1),0;0,D(2)]*ones(2,size_x*size_y);
18position_new(1,:) = position_new(1,:)+center_x;
19position_new(2,:) = position_new(2,:)+center_y;
20
21position_new_x = reshape(position_new(1,:),size_y,size_x);
22position_new_y = reshape(position_new(2,:),size_y,size_x);
23
24[J,mask]= m_interp4(I,position_new_x,position_new_y);
25
26JJ = J(center(2)-window_size_h(2):center(2)+window_size_h(2),...
27 center(1)-window_size_h(1):center(1)+window_size_h(1));
28mask = mask(center(2)-window_size_h(2):center(2)+window_size_h(2),...
29 center(1)-window_size_h(1):center(1)+window_size_h(1));
30
31
32
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist.m
new file mode 100755
index 0000000..f8dbd32
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist.m
@@ -0,0 +1,45 @@
1function A = apply_image(gx,gy,I,wc)
2%
3% aout = apply_image(gx,gy,wc)
4%
5%
6
7[nr,nc] =size(gx);
8
9w = 2*wc+1;
10
11s1 = floor(nr/w);
12s2 = floor(nc/w);
13
14A = zeros(s1*s2,s1*s2);
15
16yid = 0;
17for j=wc+1:w:nr-wc-1,
18 yid = yid+1;
19 xid = 0;
20 for k=wc+1:w:nc-wc-1,
21 xid = xid + 1;
22 c1 = [k,j];
23
24 yyid = 0;
25 fprintf('.');
26 for jj=wc+1:w:nr-wc-1,
27 yyid = yyid+1;
28 xxid = 0;
29 for kk=wc+1:w:nc-wc-1,
30 xxid = xxid + 1;
31
32 c2 = [kk,jj];
33
34 a = compute_diff_patch(get_win(gx,c1,[wc,wc]),...
35 get_win(gy,c1,[wc,wc]),...
36 get_win(gx,c2,[wc,wc]),...
37 get_win(gy,c2,[wc,wc]),...
38 get_win(I,c1,[wc,wc]),...
39 get_win(I,c2,[wc,wc]));
40
41 A(yid+(xid-1)*s1,yyid+(xxid-1)*s1) = a;
42 end
43 end
44 end
45end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist2.m
new file mode 100755
index 0000000..dc31469
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist2.m
@@ -0,0 +1,46 @@
1function A = apply_image(gx,gy,I,wc)
2%
3% aout = apply_image(gx,gy,wc)
4%
5%
6
7[nr,nc] =size(gx);
8
9w = 2*wc+1;
10
11lws = 4;
12
13s1 = floor(nr/w);
14s2 = floor(nc/w);
15
16A = zeros(s1*s2,s1*s2);
17
18for j=1:s1,
19 for k=1:s2,
20 c1 = [(wc+1)+(k-1)*w,(wc+1)+(j-1)*w];
21 fprintf('.');
22
23 for jj=j-lws:j+lws,
24 for kk=k-lws:k+lws,
25
26 c2 = [(wc+1)+(kk-1)*w,(wc+1)+(jj-1)*w];
27 if ( (jj>0) & (kk>0) & (jj <= s1) & (kk <= s2))
28 a = compute_diff_patch(get_win(gx,c1,[wc,wc]),...
29 get_win(gy,c1,[wc,wc]),...
30 get_win(gx,c2,[wc,wc]),...
31 get_win(gy,c2,[wc,wc]),...
32 get_win(I,c1,[wc,wc]),...
33 get_win(I,c2,[wc,wc]));
34
35 dx = abs(k-kk);dy = abs(j-jj);
36 sp_diff = exp(-sqrt(dx.^2+dy.^2)/4);
37 A(j+(k-1)*s1,jj+(kk-1)*s1) = a*sp_diff;
38
39 end
40
41 end
42 end
43 end
44end
45
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text.m
new file mode 100755
index 0000000..5cdb201
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text.m
@@ -0,0 +1,70 @@
1function A = apply_image(I,bars,wc)
2%
3% aout = apply_image(gx,gy,wc)
4%
5%
6
7[nr,nc] =size(I);
8
9w = 2*wc+1;
10
11lws = 4;
12
13gap = 10;
14
15s1 = floor((nr-w)/gap);
16s2 = floor((nc-w)/gap);
17
18A = zeros(s1*s2,s1*s2);
19
20sigma.text = 0.20;
21sigma.mag = 0.20;
22sigma.inten = 0.15;
23
24for j=1:s1,
25 for k=1:s2,
26
27
28 c1 = [(wc+1)+(k-1)*gap,(wc+1)+(j-1)*gap];
29 fprintf('.');
30 for jj=j-lws:j+lws,
31 for kk=k-lws:k+lws,
32
33 c2 = [(wc+1)+(kk-1)*gap,(wc+1)+(jj-1)*gap];
34 if ( (jj>0) & (kk>0) & (jj <= s1) & (kk <= s2)),
35
36 J1 = get_win(I,c1,[wc,wc]);
37 J2 = get_win(I,c2,[wc,wc]);
38
39 Jbars1 = get_win5(bars,c1,[wc,wc]);
40 Jbars2 = get_win5(bars,c2,[wc,wc]);
41
42
43 hists1 = get_hist(J1,Jbars1);
44 hists2 = get_hist(J2,Jbars2);
45
46 cumhists1 = get_cumhist(hists1);
47 cumhists2 = get_cumhist(hists2);
48
49
50 diff.inten = max(abs(cumhists1.inten-cumhists2.inten));
51 diff.mag = max(abs(cumhists1.mag-cumhists2.mag));
52 diff.text = max(max(abs(cumhists1.text-cumhists2.text)));
53
54 diffs = max([diff.inten/sigma.inten,...
55 diff.mag/sigma.mag,...
56 diff.text/sigma.text]);
57
58 dx = abs(k-kk);dy = abs(j-jj);
59 sp_diff = sqrt(dx.^2+dy.^2)/4;
60
61 A(j+(k-1)*s1,jj+(kk-1)*s1) = exp(-diffs-sp_diff);
62
63 end
64
65 end
66 end
67 end
68end
69
70
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text2.m
new file mode 100755
index 0000000..5c6e0d4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text2.m
@@ -0,0 +1,58 @@
1function A = apply_image(I,bars,wc)
2%
3% aout = apply_image(gx,gy,wc)
4%
5%
6
7[nr,nc] =size(I);
8
9w = 2*wc+1;
10
11lws = 4;
12
13gap = 10;
14
15mag = sum(bars,3);
16
17s1 = floor((nr-w)/gap)
18s2 = floor((nc-w)/gap)
19
20A = zeros(s1*s2,s1*s2);
21
22sigma.text = 0.20;
23sigma.mag = 0.20;
24sigma.inten = 0.15;
25
26for j=1:s1,
27 for k=1:s2,
28
29
30 c1 = [(wc+1)+(k-1)*gap,(wc+1)+(j-1)*gap];
31 fprintf('.');
32 for jj=j-lws:j+lws,
33 for kk=k-lws:k+lws,
34
35 c2 = [(wc+1)+(kk-1)*gap,(wc+1)+(jj-1)*gap];
36 if ( (jj>0) & (kk>0) & (jj <= s1) & (kk <= s2)),
37
38 ces = [c1,c2]-wc;
39 cum = compute_dist_hist(I,mag,bars,[ces,w]);
40
41 diffs = max([cum(1)/sigma.inten,...
42 cum(2)/sigma.mag,...
43 cum(3)/sigma.text]);
44
45 dx = abs(k-kk);dy = abs(j-jj);
46 sp_diff = sqrt(dx.^2+dy.^2)/4;
47
48 A(j+(k-1)*s1,jj+(kk-1)*s1) = exp(-diffs-sp_diff);
49
50 end
51
52 end
53 end
54
55 end
56end
57
58
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text3.m
new file mode 100755
index 0000000..a7ff408
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text3.m
@@ -0,0 +1,84 @@
1function [A,D] = pair_dist_text3(Cum,cumhists)
2%
3% A = pair_dist_text3(Cum,cumhists);
4%
5%
6
7s1 = Cum(2);
8s2 = Cum(1);
9
10st = Cum(3) + Cum(4) + 1;
11ed = size(cumhists,1);
12
13cumhists = cumhists(st:ed,:);
14
15np = size(cumhists,2);
16
17sigma.text = 0.20;
18sigma.mag = 0.20;
19sigma.inten = 0.15;
20
21lws = 4;
22
23
24k = sqrt(2)/2;
25M = 8*6;
26N = k*sqrt(M);
27
28r1 = 0.001;
29r2 = 0.001;
30
31c = N/(1+ (sqrt(1-0.5*(r1*r1+r2*r2)))*(0.25-0.75/N));
32
33D = zeros(1,s1*s2);
34
35nn = 1;
36for j =1:s1,
37 for k=1:s2,
38
39 id = j*s2+k;
40
41 cum_filter1 = reshape(cumhists(:,id),8,6)';
42 [na1,nb1,nc1,nd1] = ks_2d(cum_filter1);
43
44
45 fprintf('.');
46 for jj=j-lws:j+lws,
47 for kk=k-lws:k+lws,
48
49 if ( (jj>0) & (kk>0) & (jj <= s1) & (kk <= s2)),
50
51 idn = jj*s2+k;
52
53 cum_filter2 = reshape(cumhists(:,idn),8,6)';
54 [na2,nb2,nc2,nd2] = ks_2d(cum_filter2);
55
56
57 diffa = abs(na2-na1);diffb =abs(nb2-nb1);
58 diffc = abs(nc2-nc1);diffd = abs(nd2-nd1);
59 maxs(1) = max(max(diffa));maxs(2) = max(max(diffb));
60 maxs(3) = max(max(diffc));maxs(4) = max(max(diffd));
61
62
63 maxs = maxs/6;
64
65 d = min(1,signif(c*max(maxs)));
66
67 ids(nn) = id;
68 idns(nn) = idn;
69 B(nn) = d;
70
71 D(id) = D(id) + d;
72 D(idn) = D(idn) + d;
73
74 nn = nn+1;
75
76 end
77
78 end
79 end
80
81 end
82end
83
84A = sparse(ids,idns,b);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text4.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text4.m
new file mode 100755
index 0000000..83f3d49
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pair_dist_text4.m
@@ -0,0 +1,81 @@
1function [A] = pair_dist_text4(Iw,Cresult,cso)
2%
3% A = pair_dist_text3(Cum,cumhists);
4%
5%
6
7%s1 = Cum(2);s2 = Cum(1);
8
9figure(1);hold on;plot(cso(1),cso(2),'bo');
10
11ws = [10,10];
12
13lws = 3;
14gap = 7;
15
16J1 = get_win(Iw,round(cso),ws);
17Jbar1 = abs(get_win5(Cresult,round(cso),ws));
18hists1 = get_hist(J1,Jbar1);
19cumhists1 = get_cumhist(hists1);
20[na1,nb1,nc1,nd1] = ks_2d(cumhists1.text');
21
22figure(4);colormap(gray);
23imagesc(reshape(abs(Jbar1),size(Jbar1,1),size(Jbar1,2)*size(Jbar1,3)));
24colorbar;axis('image');drawnow;
25
26figure(2);
27subplot(2,5,1);imagesc(J1);%colormap(gray)
28subplot(2,5,2);imagesc(hists1.text');title('hist_1');colorbar;
29subplot(2,5,3);imagesc(cumhists1.text');title('cumhist_1');colorbar;
30subplot(2,5,4);imagesc(nc1);title('nc_1');colorbar
31subplot(2,5,5);imagesc(nb1);title('nb_1');colorbar
32drawnow;
33
34k = sqrt(2)/2;M = prod(size(cumhists1.text));
35N = k*sqrt(M);
36r1 = 0.001;r2 = 0.001;
37con = N/(1+ (sqrt(1-0.5*(r1*r1+r2*r2)))*(0.25-0.75/N));
38
39jid = 1;
40for jj=cso(2)-lws*gap:gap:cso(2)+lws*gap,
41 kid = 1;
42 for kk=cso(1)-lws*gap:gap:cso(1)+lws*gap,
43
44 figure(1);hold on; plot(kk,jj,'r*');drawnow;
45
46 J2 = get_win(Iw,round([kk,jj]),ws);
47 Jbar2 = get_win5(Cresult,round([kk,jj]),ws);
48
49 hists2 = get_hist(J2,Jbar2);
50 cumhists2 = get_cumhist(hists2);
51 [na2,nb2,nc2,nd2] = ks_2d(cumhists2.text');
52
53 figure(2);
54 subplot(2,5,6);imagesc(J2);%colormap(gray)
55 subplot(2,5,7);imagesc(hists2.text');title('hist_2');colorbar
56 subplot(2,5,8);imagesc(cumhists2.text');title('cumhist_2');colorbar
57
58 diffa = abs(na2-na1);diffb =abs(nb2-nb1);
59 diffc = abs(nc2-nc1);diffd = abs(nd2-nd1);
60
61 maxs(1) = max(max(diffa));maxs(2) = max(max(diffb));
62 maxs(3) = max(max(diffc));maxs(4) = max(max(diffd));
63
64 maxs = maxs/6;for j=1:4, sig(j) = signif(con*maxs(j)); end
65
66 subplot(2,5,9);imagesc(diffc);title('diff_{nc}');colorbar
67 subplot(2,5,10);imagesc(diffb);title('diff_{nb} ');colorbar
68
69 disp(sprintf('max diff is %f\n',min(sig)));
70
71 A(jid,kid) = min(1,min(sig));
72
73 %disp('press return to continue');
74 pause(3);
75
76 kid = kid+1;
77 end
78 jid = jid+1;
79end
80
81figure(1);hold off;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/patch_cat.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/patch_cat.m
new file mode 100755
index 0000000..0bf22c3
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/patch_cat.m
@@ -0,0 +1,9 @@
1function T = patch_cat(dotfilter,text_des)
2
3T(:,:,2:7,:) = text_des;
4clear text_des;
5
6for k=1:size(T,4),
7 T(:,:,1,k) = dotfilter(:,:,1,k);
8end
9
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pgmread.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pgmread.m
new file mode 100755
index 0000000..620408a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/pgmread.m
@@ -0,0 +1,15 @@
1function img = pgmread(filename,size)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7fid = fopen(filename,'r');
8
9for j=1:4,
10 a = fgetl(fid);
11end
12
13img = fscanf(fid,'%d',size);
14img = img';
15
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poisson.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poisson.m
new file mode 100755
index 0000000..99d49b6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poisson.m
@@ -0,0 +1,44 @@
1function [x] = Poisson(lambda);
2%Poisson generates a random variable with a Poisson
3% distribution
4% Pr(x = n) = lambda^n exp(-lambda)/n
5%
6% [x] = Poisson(lambda);
7% lambda: the parameter for the Poisson distribution
8% (default is 1)
9% x : the output number
10%
11
12%%
13%% (C) Thomas K. Leung
14%% University of California at Berkeley
15%% Apr 25, 1995.
16%%
17
18%%% Notice that in this implementation, we are comparing log(Z) with
19%%% T. In fact, we can compare T = exp(-lambda) with Z, which will
20%%% save us from computing a large number of log's. However, when
21%%% lambda is bigger than 709, exp(-lambda) = 0, which causes problem.
22
23if nargin == 0
24 lambda = 1;
25end
26
27if lambda < 0
28 lambda = 1;
29end
30
31P = 0;
32N = 0;
33T = -lambda;
34
35rand('seed',sum(100*clock));
36
37while P >= T
38 Z = rand(1);
39 P = P + log(Z);
40 N = N + 1;
41end
42
43x = N;
44
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poissonfield.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poissonfield.m
new file mode 100755
index 0000000..8051867
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/poissonfield.m
@@ -0,0 +1,53 @@
1function [x,y,success] = PoissonField(int,sx,sy,ir);
2%BF_HardCore Generates a hard core Poisson field
3% [x,y] = Poisson_HC(int,ir,sx,sy);
4% int: intensity of the field. (default is 1)
5% ir : inhibition radius (default is 1)
6% sx : size in x (default 100)
7% sy : size in y (default 100)
8% x : x coordinates
9% y : y coordinates
10%
11
12%%
13%% (C) Thomas K. Leung
14%% University of California at Berkeley
15%% April 26, 1995.
16%% leungt@cajal.cs.berkeley.edu
17%%
18
19%%
20%% Generate each point in sequence and reject it if it's too close to
21%% previous ones.
22%%
23
24if nargin <= 0
25 int = 1;
26 sx = 100;
27 sy = 100;
28 ir = 0;
29elseif nargin <= 1
30 sx = 100;
31 sy = 100;
32 ir = 0;
33elseif nargin <= 2
34 sy = 100;
35 ir = 0;
36elseif nargin <= 3
37 ir = 0;
38end
39
40%%
41%% Notice that the average number of a poisson process is the
42%% parameter lambda. This is consistent with our definition of the
43%% intensity here. Intensity is the mean number of points inside each
44%% unit area. Therefore, in a window of sx by sy, we should get
45%% int*sx*sy number of points on average which is the mean number of
46%% arrivals in a Poisson Process
47%%
48
49[n] = poisson(int * sx * sy);
50
51[x,y,success] = binomialfield(n,sx,sy,ir);
52
53
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back.m
new file mode 100755
index 0000000..069fe61
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back.m
@@ -0,0 +1,24 @@
1function mask = proj_back(I,hw,mask_s)
2%
3% mask = proj_back(I,hw,mask_s)
4%
5%
6
7
8[nr,nc] = size(I2);
9
10hw = 3;
11st_sz = 2*hw + 1;
12
13nr_chank = floor(nr/st_sz);
14nc_chank = floor(nc/st_sz);
15
16[x,y] = meshgrid(1:nc,1:nr);
17
18ct_chank_x = round((x-hw-1)/st_sz) + 1;
19ct_chank_y = round((y-hw-1)/st_sz) + 1;
20
21idx = (ct_chank_x - 1)*nr_chank + ct_chank_y;
22
23mask = full(sparse(y,x,mask_s(idx(:))));
24
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back_id.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back_id.m
new file mode 100755
index 0000000..9db322e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/proj_back_id.m
@@ -0,0 +1,19 @@
1function [vbig,bnr,bnc] = proj_back_id(v,gcs,gce,grs,gre)
2%
3% vbig = proj_back_id(v,gcs,gce,grs,gre)
4%
5
6nr = max(gre)+1;
7nc = max(gce)+1;
8
9sw = 3;
10gap = 2*sw+1;
11
12bnc = nc*gap;
13bnr = nr*gap;
14
15[x,y] = meshgrid(1:bnc,1:bnr);
16
17idx = grs(y(:))+1+gcs(x(:))*nr;
18
19vbig = full(sparse(y(:),x(:),v(idx)));
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/quant.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/quant.m
new file mode 100755
index 0000000..c2dfae6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/quant.m
@@ -0,0 +1,20 @@
1function [x,map] = quant(d1,d2,d3,nbin,ws)
2
3if (~exist('ws')),
4 ws = [1,1,1];
5end
6
7d1 = d1-min(d1);
8d2 = d2-min(d2);
9d3 = d3-min(d3);
10
11d1 = d1/max(d1);
12d2 = d2/max(d2);
13d3 = d3/max(d3);
14
15d1 = d1*ws(1);
16d2 = d2*ws(2);
17d3 = d3*ws(3);
18
19
20[x,map] = vmquant(d1,d2,d3,nbin);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpdm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpdm.m
new file mode 100755
index 0000000..9a1068e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpdm.m
@@ -0,0 +1,8 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%d',[A(1),A(2)]);
7
8fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm.m
new file mode 100755
index 0000000..48ecd78
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm.m
@@ -0,0 +1,10 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%f',[A(1),A(2)]);
7
8%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
9
10fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_id.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_id.m
new file mode 100755
index 0000000..5f5c4f7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_id.m
@@ -0,0 +1,21 @@
1function Is = readpfm(filename,ids,nodes)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6
7Is = zeros(length(ids),nodes);
8
9ix = 1;
10for j=1:max(ids),
11 I = fscanf(fid,'%f',nodes);
12 if (find(ids==j)),
13 Is(ix,:) = I(:)';
14 ix = ix+1;
15 fprintf('.');
16 end
17end
18
19%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
20
21fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_idf.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_idf.m
new file mode 100755
index 0000000..d7916e7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpfm_idf.m
@@ -0,0 +1,29 @@
1function Is = readpfm(filename,ids,nodes)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6
7Is = zeros(length(ids),nodes);
8
9idt = sort(ids);
10
11idh = 1;
12
13ix = 1;
14for j=1:length(ids),
15
16 gap = idt(j) - idh;
17 fprintf('%d',gap);
18
19 I = fscanf(fid,'%f',nodes*gap);
20 I = fscanf(fid,'%f',nodes);
21
22 Is(find(ids==idt(j)),:) = I(:)';
23 fprintf('.');
24
25 idh = idt(j)+1;
26end
27
28
29fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpgm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpgm.m
new file mode 100755
index 0000000..a5fd7f2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpgm.m
@@ -0,0 +1,26 @@
1function img = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7
8fid = fopen(filename,'r');
9fscanf(fid, 'P5\n');
10cmt = '#';
11while findstr(cmt, '#'),
12 cmt = fgets(fid);
13 if length(findstr(cmt, '#')) ~= 1,
14 YX = sscanf(cmt, '%d %d');
15 y = YX(1); x = YX(2);
16 end
17end
18
19fgets(fid);
20
21%img = fscanf(fid,'%d',size);
22%img = img';
23
24img = fread(fid,[y,x],'uint8');
25img = img';
26fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpnm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpnm.m
new file mode 100755
index 0000000..ab78c2c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readpnm.m
@@ -0,0 +1,21 @@
1function I = readpnm(name)
2
3 fid = fopen(name, 'r');
4 fscanf(fid, 'P5\n');
5 cmt = '#';
6 while findstr(cmt, '#') == 1
7 cmt = fgets(fid);
8 if findstr(cmt, '#') ~= 1
9 YX = sscanf(cmt, '%d %d %d');
10 y = YX(1); x = YX(2); nb = YX(3);
11 end
12 end
13 fgets(fid);
14 packed = fscanf(fid,'%f',[nb*y*x]);
15
16 for j = 1:nb,
17 I(:,:,j) = reshape(packed(j:nb:nb*y*x),y,x)';
18 end
19
20 fclose(fid);
21
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readppm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readppm.m
new file mode 100755
index 0000000..300f597
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/readppm.m
@@ -0,0 +1,19 @@
1function [r, g, b] = readppm(name)
2
3 fid = fopen(name, 'r');
4 fscanf(fid, 'P6\n');
5 cmt = '#';
6 while findstr(cmt, '#') == 1
7 cmt = fgets(fid);
8 if findstr(cmt, '#') ~= 1
9 YX = sscanf(cmt, '%d %d');
10 y = YX(1); x = YX(2);
11 end
12 end
13 fgets(fid);
14 packed = fread(fid,[3*y,x],'uint8')';
15 r = packed(:,1:3:3*y);
16 g = packed(:,2:3:3*y);
17 b = packed(:,3:3:3*y);
18 fclose(fid);
19
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/record.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/record.m
new file mode 100755
index 0000000..9626038
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/record.m
@@ -0,0 +1,6 @@
1load patch1;
2doog2 = mkdoog2(2,10,0,80);
3dog2 = rotate_J(90,doog2);
4
5H = mkf_test(dog2,size(patch1),-1,0.00001,2,-1);
6o = BfilterS(patch1,H,size(dog));figure(4);colormap(gray);imagesc(o.*(o>0)); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/recursive_cut_tc.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/recursive_cut_tc.m
new file mode 100755
index 0000000..a8c9362
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/recursive_cut_tc.m
@@ -0,0 +1,140 @@
1%function [groups,ids] = recursive_cut(ncutv,fn_base)
2%
3%
4% function [groups,ids] = recursive_cut(ncutv,threshold,spthresh)
5%
6%
7
8ncutv= ncutv_o(:,1:4);
9
10fn_base = fn;
11%fn_base = '130040';
12
13nvv = size(ncutv_o,2);
14nbin = 24;
15
16ids = [];
17groups = [];
18labels = [];
19
20load cmaps
21cmap = cmapg;
22
23j = 1;
24done = 0;
25np = size(ncutv,1);
26nv = size(ncutv,2);
27
28%%%%%% find the cut for the first ncut vector
29ev_id = 2;
30para = [nvv ev_id nr nc 100];
31Gmask = ones(nr,nc);
32%threshold = find_cutpoint(ncutv(:,ev_id),cmapg,nbin);threshold = threshold(1:end-1);
33threshold = linspace(min(ncutv(:,ev_id)),max(ncutv(:,ev_id)),nbin);
34[cut_threshold,max_asso] = find_bst_cut(fn_base,para,threshold,Gmask);
35disp(max_asso);
36
37id1 = find(ncutv(:,ev_id)<=cut_threshold);
38id2 = find(ncutv(:,ev_id)>cut_threshold);
39
40groups = [groups,id1(:)'];
41ids = [ids,length(id1)];
42
43groups = [groups,id2(:)'];
44ids = [ids,length(groups)];
45
46
47for j=3:nv,
48 fprintf('j = %d\n',j);
49 % expand the current level,
50 new_groups = [];
51 new_ids = [];
52
53
54 figure(4);ims(ncutv(:,j),nr,nc);title(num2str(j));
55
56 figure(1);clf
57 disp_groups(groups,ids,nr,nc);
58 drawnow;
59
60 %figure(3);
61 % for each leaves,
62 mx = max(ncutv(:,j))-min(ncutv(:,j));
63 %mx = std(ncutv(:,j));
64
65 base_id =1;
66 for k=1:length(ids),
67 old_groups = groups(base_id:ids(k));
68
69 v = ncutv(old_groups,j);
70 change_v = max(v)-min(v);
71 %change_v = std(v);
72 n1 = sum(v>(min(v)+0.85*change_v));%n1 = n1/length(old_groups);
73 n2 = sum(v<=(min(v)+0.15*change_v));%n2 = n2/length(old_groups);
74 disp(sprintf('n1 = %f, n2 = %f',n1,n2));
75
76 figure(2);
77 Gmask = zeros(np,1);
78 Gmask(old_groups) = Gmask(old_groups)+1;
79 drawnow;
80 ims(ncutv(:,j).*Gmask,nr,nc);
81
82 disp(sprintf('!!!!!!!!!!!!!RATIO= %f',change_v/mx))
83
84 %pause;
85
86 if (((change_v/mx)>0.5) & (n1>10) &(n2>10)),
87
88 ev_id = j;
89
90 %threshold = find_cutpoint(ncutv(old_groups,ev_id),cmapg,nbin);threshold = threshold(1:end-1);
91 threshold = linspace(min(ncutv(:,ev_id)),max(ncutv(:,ev_id)),nbin);
92 para = [nvv ev_id nr nc 100];
93 [cut_threshold,max_asso] = find_bst_cut(fn_base,para,threshold,Gmask);
94
95 disp(max_asso);
96
97 if (max_asso>1.2),
98 id1 = find(ncutv(old_groups,ev_id)<=cut_threshold);
99 id2 = find(ncutv(old_groups,ev_id)>cut_threshold);
100
101 figure(5);
102 subplot(1,2,1);maskt= zeros(np,1);maskt(old_groups(id1))=1+maskt(old_groups(id1));ims(maskt,nr,nc);
103 subplot(1,2,2);maskt= zeros(np,1);maskt(old_groups(id2))=1+maskt(old_groups(id2));ims(maskt,nr,nc);
104
105 new_groups = [new_groups,old_groups(id1)];
106 new_ids = [new_ids,length(new_groups)];
107
108
109 new_groups = [new_groups,old_groups(id2)];
110 new_ids = [new_ids,length(new_groups)];
111 else
112 fprintf(' keep ');
113 new_groups = [new_groups,old_groups];
114 new_ids = [new_ids,length(new_groups)];
115 end
116
117 else
118 fprintf(' keep ');
119 new_groups = [new_groups,old_groups];
120 new_ids = [new_ids,length(new_groups)];
121 end
122 fprintf('\n');
123 base_id = ids(k) + 1;
124 end
125
126
127
128 groups = new_groups;
129 ids = new_ids;
130
131 figure(1);disp_groups(groups,ids,nr,nc);
132
133 fprintf('press return\n');
134 pause;
135 j= j+1;
136end
137
138fprintf('total group = %d \n',length(ids));
139
140
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/reduce_all.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/reduce_all.m
new file mode 100755
index 0000000..d7d31f8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/reduce_all.m
@@ -0,0 +1,8 @@
1function b = reduce_all(a)
2
3numband = size(a,3);
4
5for j=1:numband,
6
7 b(:,:,j) = reduce(a(:,:,j));
8end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/rotate_J.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/rotate_J.m
new file mode 100755
index 0000000..12f29b6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/rotate_J.m
@@ -0,0 +1,30 @@
1function J = compute_J(angle,I)
2%% function J = compute_J(angle,I)
3%
4
5[size_y,size_x] = size(I);
6
7[center_x,center_y] = find_center(size_x,size_y);
8
9a = angle * pi/180;
10A = [cos(a),-sin(a);sin(a),cos(a)];
11
12[XX,YY] = meshgrid(1:size_x,1:size_y);
13
14x = reshape(XX,size_x*size_y,1);
15y = reshape(YY,size_x*size_y,1);
16index(:,1) = x-center_x;
17index(:,2) = y-center_y;
18
19position_new = A*index';
20position_new(1,:) = position_new(1,:)+center_x;
21position_new(2,:) = position_new(2,:)+center_y;
22
23position_new_x = reshape(position_new(1,:),size_y,size_x);
24position_new_y = reshape(position_new(2,:),size_y,size_x);
25
26J = m_interp4(I,position_new_x,position_new_y);
27
28
29
30
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/session.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/session.m
new file mode 100755
index 0000000..70fabbf
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/session.m
@@ -0,0 +1,4 @@
1t = rj(1:50,19:50); tt = interp4(t,1);
2sgn = mksgn2(182,2,[91,9]);
3H = mkf_test(sgn,size(tt),1,0.01,2,300);
4o = BfilterS(tt,H,size(sgn));figure(1);imagesc(o.*(o>0));axis('equal');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_cumhist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_cumhist.m
new file mode 100755
index 0000000..fe82e64
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_cumhist.m
@@ -0,0 +1,28 @@
1function show_hist(cumhists,bins,fig_id,hold_flag,ct)
2%%
3% show_hist(cumhists,bins,fig_id,ct)
4%
5%
6
7 if (~exist('ct')),
8 ct = 'b-o';
9 end
10
11 figure(fig_id);
12
13 subplot(3,3,1);plot(bins.inten,cumhists.inten,ct);
14
15 if (hold_flag == 1), hold on;else hold off; end
16
17 for j=1:size(cumhists.text,2),
18 subplot(3,3,1+j);
19 plot(bins.text,cumhists.text(:,j),ct);
20 if (hold_flag == 1), hold on;else hold off; end
21 end
22
23 subplot(3,3,8);
24 plot(bins.mag,cumhists.mag,ct);
25 if (hold_flag == 1), hold on;else hold off; end
26
27
28
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_hist.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_hist.m
new file mode 100755
index 0000000..efaf899
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/show_hist.m
@@ -0,0 +1,23 @@
1function show_hist(hists,bins,fig_id)
2%%
3% show_hist(hists,bins,fig_id)
4%
5%
6
7 figure(fig_id);
8
9 subplot(3,3,1);bar(bins.inten,hists.inten);
10
11 %maxval = max(max(max(abs(Jbar))));
12
13 for j=1:size(hists.text,2),
14 subplot(3,3,1+j);% hist(reshape(abs(Jbar(:,:,j)),prod(w),1),[1:10:maxval+1]);
15 bar(bins.text,hists.text(:,j));
16 end
17
18 subplot(3,3,8);%hist(reshape(sum(abs(Jbar),3),prod(w),1),[1:10:161]);
19 bar(bins.mag,hists.mag);
20
21
22
23
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm.m
new file mode 100755
index 0000000..1833062
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm.m
@@ -0,0 +1,45 @@
1function [T,A,M2,TAM]=showsmm(L1,L2,phi,maxM);
2% [T,A,M]=showsmm(L1,L2,phi,maxM);
3
4if (~exist('maxM')),
5% needs to know upper bound on M for given window function in smm
6maxM=0.18; % temporary
7end
8
9
10A=1-L2./(L1+eps);
11T=2*(phi+pi/2)/(2*pi);
12M=L1+L2;
13M2=min(M/maxM,1); % keep it from exceeding 1
14%M2 = sigmoid(M,maxM,30);
15
16matlab5on = 1;
17
18if matlab5on == 1,
19 TAM=hsv2rgb(T,A,M2);
20
21 figure(3);
22 image(TAM);
23 axis('tightequal');
24else
25 H = [reshape(T,prod(size(T)),1),...
26 reshape(A,prod(size(A)),1),...
27 reshape(M2,prod(size(M2)),1)];
28 M = hsv2rgb(H);
29 [Ic,map] =vmquant(M(:,1),M(:,2),M(:,3),256);
30
31 image(reshape(Ic,size(T,1),size(T,2)));colormap(map);
32end
33
34if 0
35 plot3(A(:).*M(:).*cos(2*pi*T(:)),A(:).*M(:).*sin(2*pi*T(:)),M(:),'.','markersize',15)
36 axis([-1 1 -1 1 0 1])
37 [x,y,z] = cylinder(ones(1,5));
38 x=x.*z;
39 y=y.*z;
40 hold on
41 h=mesh(x,y,z);
42 set(h,'edgecolor',[.2 .2 .2]);
43 hidden off
44 hold off
45end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm_v5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm_v5.m
new file mode 100755
index 0000000..937303d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/showsmm_v5.m
@@ -0,0 +1,34 @@
1function [T,A,M2,TAM]=showsmm(L1,L2,phi,maxM);
2% [T,A,M]=showsmm(L1,L2,phi,maxM);
3
4if (~exist('maxM')),
5% needs to know upper bound on M for given window function in smm
6maxM=0.18; % temporary
7end
8
9
10A=1-L2./(L1+eps);
11T=2*(phi+pi/2)/(2*pi);
12M=L1+L2;
13M2=min(M/maxM,1); % keep it from exceeding 1
14%M2 = sigmoid(M,maxM,30);
15
16 TAM=hsv2rgb(T,A,M2);
17
18 figure(3);
19 image(TAM);
20 axis('tightequal');
21
22
23if 0
24 plot3(A(:).*M(:).*cos(2*pi*T(:)),A(:).*M(:).*sin(2*pi*T(:)),M(:),'.','markersize',15)
25 axis([-1 1 -1 1 0 1])
26 [x,y,z] = cylinder(ones(1,5));
27 x=x.*z;
28 y=y.*z;
29 hold on
30 h=mesh(x,y,z);
31 set(h,'edgecolor',[.2 .2 .2]);
32 hidden off
33 hold off
34end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/sigmoid.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/sigmoid.m
new file mode 100755
index 0000000..996f7fe
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/sigmoid.m
@@ -0,0 +1,10 @@
1function a = sigmoid(x,offset,sig)
2%
3% a = sigmoid(x,offset,sig)
4%
5% a = ones(size(x))./(1+exp(-(x-offset)/sig));
6%
7
8
9a = ones(size(x))./(1+exp(-(x-offset)/sig));
10
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif.m
new file mode 100755
index 0000000..f49eefc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif.m
@@ -0,0 +1,22 @@
1function a = signif(b)
2
3js = [1:101];
4
5
6if 0,
7d = (-ones(size(js))).^(js-1);
8d1 = exp(-2*(js.*js)*b*b);
9
10a = 2*sum(d.*d1);
11
12end
13
14d1 = exp(-2*(js.*js)*b*b);
15d2 = 4*(js.*js)*b*b - 1;
16
17a = 2*sum(d1.*d2);
18
19if (b<0.03),a = 1;end
20
21
22
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif_N.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif_N.m
new file mode 100755
index 0000000..82dc914
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/signif_N.m
@@ -0,0 +1,10 @@
1function a = signif_N(b,N)
2%
3%
4%
5
6Ne = sqrt(N*0.5);
7
8cof = Ne + 0.155 + 0.24/Ne;
9
10a= signif(cof*b);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/smooth.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/smooth.m
new file mode 100755
index 0000000..919b53a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/smooth.m
@@ -0,0 +1,20 @@
1% smooth an image
2% coordinates (r, c) follow matrix convention;
3% the gaussian is truncated at x = +- tail, and there are samples samples
4% inbetween, where samples = hsamples * 2 + 1
5
6function g = smooth(image, hsamples)
7
8tail=4;
9samples = hsamples * 2 + 1;
10
11x = linspace(-tail, tail, samples);
12gauss = exp(-x.^2);
13n = gauss * ones(samples,1);
14gauss = gauss/n;
15
16
17g = conv2(conv2(image, gauss), gauss');
18
19g = conv_trim(g, hsamples, hsamples);
20
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/startup.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/startup.m
new file mode 100755
index 0000000..8d38803
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/startup.m
@@ -0,0 +1,9 @@
1%path(path,'/usr/sww/matlab-4.2c/toolbox/images');
2home_dir = '/home/barad-dur/vision/malik/jshi/';
3path(path,[home_dir,'matlab/toolbox/io'])
4path(path,[home_dir,'matlab/pyramid']);
5path(path,[home_dir,'matlab/toolbox/filter'])
6path(path,[home_dir,'matlab/toolbox/disp'])
7path(path,[home_dir,'matlab/vision/vision94/tracking/'])
8path(path,[home_dir,'proj/grouping/laso']);
9path(path,[home_dir,'proj/grouping/eig']);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarp.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarp.m
new file mode 100755
index 0000000..60a4530
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarp.m
@@ -0,0 +1,9 @@
1function J = swarp(I)
2
3[nr,nc] = size(I);
4
5center_x = round(0.5*nc);
6center_y = round(0.5*nr);
7
8J = [I(center_y:nr,center_x:nc),I(center_y:nr,1:center_x-1);...
9 I(1:center_y-1,center_x:nc),I(1:center_y-1,1:center_x-1)]; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarpback.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarpback.m
new file mode 100755
index 0000000..513bc25
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/swarpback.m
@@ -0,0 +1,12 @@
1function J = swarpback(I);
2
3[nr,nc] = size(I);
4
5center_x = round(0.5*nc);
6center_y = round(0.5*nr);
7
8cx= center_x -1;
9cy= center_y -1;
10
11J = [I(nr-cy+1:nr,nc-cx+1:nc),I(nr-cy+1:nr,1:(nc-center_x+1));...
12 I(1:(nr-center_y+1),nc-cx+1:nc),I(1:(nr-center_y+1),1:(nc-center_x+1))]; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test.m
new file mode 100755
index 0000000..12470eb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test.m
@@ -0,0 +1,110 @@
1
2fn = '130065'; nr = 30;nc = 49;
3%nr = 49;nc = 30;
4%nc = 68;nr = 43;
5%nr =49;nc = 30;
6
7basedir = 'plaatje_data/newdata/';
8if 1,
9fname = sprintf('%s%s_eigvec.pfm',basedir,fn);
10eigv = readpfm(fname);
11fname = sprintf('%s%s_eigval.pfm',basedir,fn);
12eigval = readpfm(fname);
13
14fname = sprintf('%s%s_ncutvec.pfm',basedir,fn);
15ncutv = readpfm(fname);
16fname = sprintf('%s%s_ncutval.pfm',basedir,fn);
17ncutval = readpfm(fname);
18else
19fname = sprintf('%sncutvec_%s.pfm',basedir,fn);
20ncutv = readpfm(fname);
21fname = sprintf('%sncutval_%s.pfm',basedir,fn);
22ncutval = readpfm(fname);
23end
24
25
26fname = sprintf('images/%s.pgm',fn);
27I = readpgm(fname);
28cutsz = 20; I = cutoff(I,cutsz);
29figure(3);im(I);colormap(gray);
30
31figure(6);
32for j=1:min(8,size(ncutv,2)-1),
33 subplot(3,3,j);
34 im(reshape(ncutv(:,j+1),nr,nc));colorbar
35 title(num2str(ncutval(j+1,1)));
36end
37%cm = sprintf('print -dps ncut_%s',fn);disp(cm);eval(cm);
38subplot(3,3,9);im(I);axis('off');
39
40ev = eigval(:,1);
41figure(5);hold off;clf;subplot(1,2,1);
42%semilogy((ev(1:end-1) - ev(2:end))./ev(1:end-1),'x-');grid on;
43plot((ev(1:end-1) - ev(2:end))./ev(1:end-1),'x-');grid on;
44%semilogy(0.01*ones(size(ev(2:end-1))),'r-');semilogy(0.005*ones(size(ev(2:end-1))),'r-');semilogy(0.0025*ones(size(ev(2:end-1))),'r-');grid on;hold off;
45subplot(1,2,2);
46%semilogy(ev(1:end-1)-ev(2:end),'p-');grid on;
47semilogy((ev(1:end-1) - ev(2:end))/ev(1),'x-');grid on;
48
49
50ncutv_o = ncutv;
51
52recursive_cut_tc;
53
54%[groups,ids] = recursive_cut(ncutv(:,1:4),fn);
55
56masks = make_masks(groups,ids,nr,nc);
57
58cm = sprintf('save masks_%s masks ncutv_o groups ids nr nc',fn);
59disp(cm);
60
61eval(cm);
62
63
64%%%%%%%%%%%%%%%%%%
65fn = '130040';
66cm = sprintf('load masks_%s',fn);
67disp(cm);
68eval(cm);
69
70fn = '130040';
71fname= sprintf('images/%s.pgm',fn);
72I = readpgm(fname);cutsz = 20; I = cutoff(I,cutsz);
73figure(3);im(I);colormap(gray);
74hw = 2; %nr = 43;nc=68;
75gap = 2*hw+1;
76%nr = 30;nc=49;
77Is = I(1:nr*gap,1:nc*gap);
78figure(3);im(Is);axis('off');
79
80%cm = sprintf('print -deps I_%s',fn);disp(cm);eval(cm);
81
82
83
84%masks = make_masks(groups,ids,nr,nc);
85figure(2);disp_groups(groups,ids,nr,nc);
86
87figure(1);
88Imasks = disp_Imask(Is,nr,nc,hw,masks);
89
90for j=1:length(ids),
91 figure(4);colormap(gray);clf
92 im(Imasks(:,:,j));axis('off');
93 cm = sprintf('print -deps result_cut_%s_%d',fn,j);
94 disp(cm);eval(cm);
95
96 %print -deps result_cut_134011_1
97end
98
99
100if 0,
101
102%load st_134013
103
104fn = '134013_t';
105
106I_max = 250;
107tex_max = 40;
108
109writeout_feature(I1,T1,fn,I_max,tex_max);
110end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test1.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test1.m
new file mode 100755
index 0000000..691b63e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test1.m
@@ -0,0 +1,175 @@
1
2fnameI = '130068';
3
4cm = sprintf('load filter_%s.pgm.mat',fnameI);
5disp(cm);
6eval(cm);
7
8text_des = abs(text_des);
9
10
11 %%%% cutoff margins,
12margin = 6+10;
13
14Iw = cutoff(I,margin);
15
16T1= reshape(text_des,size(text_des,1),size(text_des,2),size(text_des,3)*size(text_des,4));
17T1 = cutoff(T1,margin);
18
19%%%%% reduce resolution
20
21
22
23T1 = reduce_all(T1);
24T1 = reduce_all(T1);
25
26im5(T1,5,6);
27
28cm = sprintf('writepnm5(''%s_f.pnm'',%s)',fnameI,'T1/70');
29
30% disp(cm);eval(cm);
31
32nr = size(T1,1);
33nc = size(T1,2);
34
35% D = mreadpfm('D_134011_f.pnm.pfm');
36
37% figure(3);imagesc(reshape(D,nc,nr)');axis('image');colorbar
38
39if 0,
40figure(7);
41subplot(3,1,1);hist(reshape(I1,prod(size(I1)),1),binI);
42subplot(3,1,2);hist(reshape(I2,prod(size(I2)),1),binI);
43subplot(3,1,3);hist(reshape(I3,prod(size(I3)),1),binI);
44
45
46If1 = filter_output(I1,sigs,szs);
47If2 = filter_output(I2,sigs,szs);
48If3 = filter_output(I3,sigs,szs);
49
50I1a = cutoff(I1,5); If1 = cutoff(If1,5);
51I2a = cutoff(I2,5); If2 = cutoff(If2,5);
52I3a = cutoff(I3,5); If3 = cutoff(If3,5);
53
54
55
56figure(4);
57bint = [-0.15:0.02:0.15];
58id = 4;
59
60If = If1;
61for j=1:5,
62 subplot(5,2,2*(j-1)+1);
63 hist(reshape(If(:,:,id,j)./s1,prod(size(If(:,:,id,j))),1),bint);
64end
65
66If = If2;
67for j=1:5,
68 subplot(5,2,2*j);
69 hist(reshape(If(:,:,id,j)./s2,prod(size(If(:,:,id,j))),1),bint);
70end
71
72
73%%% make 2d histogram bin
74figure(5);
75idmax = 5;
76filt_id = 4;
77
78for id=1:idmax,
79
80 subplot(idmax,3,(id-1)*3+1);
81 h2d1 = hist_I_f(I1a,If1(:,:,filt_id,id),binI,bintex);
82 imagesc(h2d1);axis('image')
83 subplot(idmax,3,(id-1)*3+2);
84 h2d2 = hist_I_f(I2a,If2(:,:,filt_id,id),binI,bintex);
85 imagesc(h2d2);axis('image')
86
87 subplot(idmax,3,id*3);
88 imagesc(h2d2/sum(sum(h2d2)) + h2d1/sum(sum(h2d1)));axis('image')
89 colorbar
90end
91
92%%%%%%%%%%%%%%%%%%%%% three types %%%%%%%%
93figure(4);
94idmax = 5;
95filt_id = 2;
96
97width = 4;
98
99for id=1:idmax,
100
101 subplot(idmax,width,(id-1)*width+1);
102 h2d1 = hist_I_f(I1a,If1(:,:,filt_id,id),binI,bintex);
103 h2d1 = h2d1/sum(sum(h2d1));
104 imagesc(h2d1);axis('image');
105
106 subplot(idmax,width,(id-1)*width+2);
107 h2d2 = hist_I_f(I2a,If2(:,:,filt_id,id),binI,bintex);
108 h2d2 = h2d2/sum(sum(h2d2));
109 imagesc(h2d2);axis('image')
110
111 subplot(idmax,width,(id-1)*width+3);
112 h2d3 = hist_I_f(I3a,If3(:,:,filt_id,id),binI,bintex);
113 h2d3 = h2d3/sum(sum(h2d3));
114 imagesc(h2d3);axis('image')
115
116 subplot(idmax,width,id*width);
117 imagesc(h2d1+h2d2+h2d3);axis('image')
118 colorbar
119end
120
121
122%%%%%%%%%%%% smaller window %%%%
123hw = round(4*sigs(1));
124
125figure(5);%imagesc(I1a);axis('image');
126cs = round(ginput(1));
127
128J = get_win(I1a,cs,[hw,hw]);figure(7);imagesc(J);axis('image');
129
130Jf = get_win5(If1,cs,[hw,hw]);
131scales = 1:5; nscales = length(scales);
132filters = 1:7; nfilters = length(filters);
133
134figure(8);
135for j=1:nscales,
136 for k=1:nfilters,
137 subplot(nscales,nfilters,(j-1)*nfilters+k);
138 h2d = hist_I_f(J,Jf(:,:,(j-1)*7+k));h2d = h2d/sum(sum(h2d));
139 imagesc(h2d);axis('image');colorbar;axis('off');
140 end
141end
142
143
144if 0,
145
146 figure(3);
147 cs = ginput(1);
148
149 ws = [15,15];
150 J = get_win(I,cs,ws);
151 figure(6);imagesc(J);axis('image');
152
153 t1 = get_win5(text_des,cs,ws);
154
155 t1p = abs(t1);
156 %t1p = abs(t1);
157 %t1p = t1.*(t1>0);
158
159 figure(2);im5(t1p,5,6);
160
161 t1p = reshape(t1p,size(t1p,1)*size(t1p,2),size(t1p,3))';
162
163 t1pm = mean(t1p')';
164 t1ps = t1p- t1pm*ones(1,size(t1p,2));
165
166 B = t1ps*t1ps';
167 [v,d] = eig(B);d = diag(d);
168 figure(4);plot(d,'x-');
169
170 figure(5);
171 subplot(2,2,1);vid = 30;plot(reshape(v(:,vid),6,5),'x-');
172
173end
174
175end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test2.m
new file mode 100755
index 0000000..c70446a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test2.m
@@ -0,0 +1,220 @@
1
2%fnameI = '130056';
3%fnameI = '134013';
4fnameI = '134007';
5
6%%%% flags %%%%%%%%%
7read_image = 1;
8
9margin = 10+6;
10sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];
11r =3;
12szs = round(3*r*sigs);
13
14
15
16%%% image read %%%
17if read_image,
18 cm = sprintf('I = readpgm(''images/%s.pgm'');',fnameI);
19 disp(cm);
20 eval(cm);
21
22 Iw = cutoff(I,margin);
23 figure(1);imagesc(Iw);axis('image');
24end
25
26%%%% image crop %%%
27figure(1);J = imcrop;
28figure(2);imagesc(J);axis('image');drawnow;
29
30Jf = filter_output(J,sigs,szs);
31margin = 5;
32Ja = cutoff(J,margin);Jfa = cutoff(Jf,margin);
33figure(2);imagesc(Ja);axis('image');
34
35figure(3);
36imagesc(Jfa(:,:,1,3));axis('image');drawnow;
37
38Jfb = reshape(Jfa,size(Jfa,1),size(Jfa,2),size(Jfa,3)*size(Jfa,4));
39mag = sum(abs(Jfb),3);
40
41%%%%%% Joint hist. %%%%%%%%%
42
43filter_id = 1;
44scale = 1;
45h2d = hist_I_f(Ja,Jfa(:,:,filter_id,scale));
46
47figure(4);
48imagesc(h2d/sum(sum(h2d)));axis('image');colorbar;colormap(hot);
49
50
51%%%%%%%%%% Jointe hist of cropped area %%%%%
52%%% block 1
53fig_id = 1;
54[J3,f3,rect] = crop_im_fil(Ja,Jfa,fig_id);
55
56filter_id = 1;scale = 1;H1 = hist_I_f(J1,f1(:,:,filter_id,scale));
57
58
59%%% block 2
60fig_id = 1;
61[J2,f2,rect] = crop_im_fil(Ja,Jfa,fig_id);
62
63filter_id = 1;scale = 1;H2 = hist_I_f(J2,f2(:,:,filter_id,scale));
64
65
66%%%%% disp result %%%%%
67
68scales = [1:5];
69filter_ids = [1:7];
70
71figure(6);disp_hist2d(J2,f2,scales,filter_ids);
72
73figure(4);disp_hist2d(J1,f1,scales,filter_ids);
74
75%%%%%%%%%%%%%%%%%
76%%%%%%%%%%%%%%%%% smaller window
77hw = round(4*sigs(1));
78
79figure(2);%imagesc(Ja);axis('image');
80cs = round(ginput(1));
81
82J1 = get_win(Ja,cs,[hw,hw]);Jf1 = get_win5(Jfa,cs,[hw,hw]);
83figure(4);imagesc(J1);axis('image');drawnow;
84scales = [1:5];filter_ids = [1:7];
85figure(9);H2 = disp_hist2d(J1,Jf1,scales,filter_ids);
86
87figure(6); disp_diff(H2,H2o);
88
89
90%%%%%% difference in the neighbourhood %%
91hw = round(4*sigs(1));
92hnb = 3;
93
94B = compute_diff(Ja,Jfa,hw,hnb);
95
96
97%%%%%%%%%%
98
99if 0,
100
101figure(4);
102bint = [-0.15:0.02:0.15];
103id = 4;
104
105If = If1;
106for j=1:5,
107 subplot(5,2,2*(j-1)+1);
108 hist(reshape(If(:,:,id,j)./s1,prod(size(If(:,:,id,j))),1),bint);
109end
110
111If = If2;
112for j=1:5,
113 subplot(5,2,2*j);
114 hist(reshape(If(:,:,id,j)./s2,prod(size(If(:,:,id,j))),1),bint);
115end
116
117
118%%% make 2d histogram bin
119figure(5);
120idmax = 5;
121filt_id = 4;
122
123for id=1:idmax,
124
125 subplot(idmax,3,(id-1)*3+1);
126 h2d1 = hist_I_f(I1a,If1(:,:,filt_id,id),binI,bintex);
127 imagesc(h2d1);axis('image')
128 subplot(idmax,3,(id-1)*3+2);
129 h2d2 = hist_I_f(I2a,If2(:,:,filt_id,id),binI,bintex);
130 imagesc(h2d2);axis('image')
131
132 subplot(idmax,3,id*3);
133 imagesc(h2d2/sum(sum(h2d2)) + h2d1/sum(sum(h2d1)));axis('image')
134 colorbar
135end
136
137%%%%%%%%%%%%%%%%%%%%% three types %%%%%%%%
138figure(4);
139idmax = 5;
140filt_id = 2;
141
142width = 4;
143
144for id=1:idmax,
145
146 subplot(idmax,width,(id-1)*width+1);
147 h2d1 = hist_I_f(I1a,If1(:,:,filt_id,id),binI,bintex);
148 h2d1 = h2d1/sum(sum(h2d1));
149 imagesc(h2d1);axis('image');
150
151 subplot(idmax,width,(id-1)*width+2);
152 h2d2 = hist_I_f(I2a,If2(:,:,filt_id,id),binI,bintex);
153 h2d2 = h2d2/sum(sum(h2d2));
154 imagesc(h2d2);axis('image')
155
156 subplot(idmax,width,(id-1)*width+3);
157 h2d3 = hist_I_f(I3a,If3(:,:,filt_id,id),binI,bintex);
158 h2d3 = h2d3/sum(sum(h2d3));
159 imagesc(h2d3);axis('image')
160
161 subplot(idmax,width,id*width);
162 imagesc(h2d1+h2d2+h2d3);axis('image')
163 colorbar
164end
165
166
167%%%%%%%%%%%% smaller window %%%%
168hw = round(4*sigs(1));
169
170figure(5);%imagesc(I1a);axis('image');
171cs = round(ginput(1));
172
173J = get_win(I1a,cs,[hw,hw]);figure(7);imagesc(J);axis('image');
174
175Jf = get_win5(If1,cs,[hw,hw]);
176scales = 1:5; nscales = length(scales);
177filters = 1:7; nfilters = length(filters);
178
179figure(8);
180for j=1:nscales,
181 for k=1:nfilters,
182 subplot(nscales,nfilters,(j-1)*nfilters+k);
183 h2d = hist_I_f(J,Jf(:,:,(j-1)*7+k));h2d = h2d/sum(sum(h2d));
184 imagesc(h2d);axis('image');colorbar;axis('off');
185 end
186end
187
188
189if 0,
190
191 figure(3);
192 cs = ginput(1);
193
194 ws = [15,15];
195 J = get_win(I,cs,ws);
196 figure(6);imagesc(J);axis('image');
197
198 t1 = get_win5(text_des,cs,ws);
199
200 t1p = abs(t1);
201 %t1p = abs(t1);
202 %t1p = t1.*(t1>0);
203
204 figure(2);im5(t1p,5,6);
205
206 t1p = reshape(t1p,size(t1p,1)*size(t1p,2),size(t1p,3))';
207
208 t1pm = mean(t1p')';
209 t1ps = t1p- t1pm*ones(1,size(t1p,2));
210
211 B = t1ps*t1ps';
212 [v,d] = eig(B);d = diag(d);
213 figure(4);plot(d,'x-');
214
215 figure(5);
216 subplot(2,2,1);vid = 30;plot(reshape(v(:,vid),6,5),'x-');
217
218end
219
220end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test3.m
new file mode 100755
index 0000000..040ed3d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test3.m
@@ -0,0 +1,4 @@
1fn = 'lightsmall.ppm';
2nr = Ipara(1);nc = Ipara(2);
3
4k = 1;imagesc(reshape(v(:,k).*D,nc,nr)');colorbar \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_best_cut.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_best_cut.m
new file mode 100755
index 0000000..e04c6ff
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_best_cut.m
@@ -0,0 +1,12 @@
1
2fn_base = '134035';
3ev_id = 4;
4para = [12 ev_id nr nc 100];
5Gmask = ones(nr,nc);
6threshold = find_cutpoint(ncutv(:,ev_id),cmapg,12);
7threshold = threshold(1:end-1);
8
9cut_threshold = find_bst_cut(fn_base,para,threshold,Gmask);
10
11figure(8);ims(ncutv(:,ev_id)<cut_threshold,nr,nc);
12
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex.m
new file mode 100755
index 0000000..fc420c7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex.m
@@ -0,0 +1,361 @@
1
2setup_flag = 0;
3cut_window_flag = 0;
4run_flag = 0;
5other_flag = 0;
6test_flag = 1;
7
8
9%%%%%%%%%%%%%%%%%
10if setup_flag == 1,
11I = readpgm('images/134035.pgm');
12
13sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
14%[text_des,TIw] = compute_filter(I,sigs,r,szs);
15load filter_134035
16
17text_des = cutoff(text_des,szs(1));
18
19I_max = 255;
20tex_max = 75;
21
22TIw = cutoff(I,szs(1));
23figure(1);im(TIw);
24
25fts = gen_filters(sigs,r,szs);
26Ft = reshape(fts,size(fts,1)*size(fts,2),size(fts,3)*size(fts,4));
27Ft = Ft';
28PFt1 = pinv(Ft);
29
30temp1 = zeros(2*szs(end-1)+1,2*szs(end-1)+1);
31temp1(szs(end-1)+1,szs(end-1)+1) = 1;
32Ft2 = [Ft;temp1(:)'];
33PFt2 = pinv(Ft2);
34
35
36end
37
38%%%%%%%%%%
39
40if cut_window_flag == 1,
41wz = [30,30];
42
43figure(1);
44ct0 = round(ginput(1))
45
46t0 = cutout(text_des,ct0,wz)/tex_max;
47I0 = cutout(TIw,ct0,wz)/I_max;
48
49figure(3);im(I0);colorbar
50
51figure(1);
52ct1 = round(ginput(1))
53
54t1 = cutout(text_des,ct1,wz)/tex_max;
55I1 = cutout(TIw,ct1,wz)/I_max;
56
57figure(3);im(I1);colorbar
58
59%%%%%%%%%%
60ts = cat(2,t0,t1);
61Is = [I0,I1];
62
63figure(3);
64subplot(2,1,1);im(Is);
65subplot(2,1,2);im(ts(:,:,15));
66
67end
68
69%%%%%%
70
71if run_flag == 1,
72
73neigs = 15;
74
75fv1 = colize(t1,I1);
76cov1 = fv1*fv1';
77
78[u1,s1] = eigs(cov1,neigs); s1= diag(s1);
79figure(4);plot(s1,'p-');
80
81fv0 = colize(t0,I0);
82cov0 = fv0*fv0';
83
84[u0,s0] = eigs(cov0,neigs); s0 = diag(s0);
85figure(4);hold on; plot(s0,'rp-');
86
87fvs = colize(ts,Is);
88covs = fvs*fvs';
89
90[us,ss] = eigs(covs,neigs); ss = diag(ss);
91figure(4);plot(ss,'mo-');
92hold off
93
94figure(5);
95subplot(2,2,1);
96im(cov0);colorbar;
97subplot(2,2,2);
98im(cov1);colorbar;
99subplot(2,2,3);
100im(covs);colorbar;
101
102%%%%%%%%%%%%%%%%%
103
104ivss = ones(size(ss))./sqrt(ss);
105ivs0 = ones(size(s0))./sqrt(s0);
106ivs1 = ones(size(s1))./sqrt(s1);
107
108
109nv = 10;
110v1 = fv1'*u1(:,1:nv)*diag(ivs1(1:nv));
111v0 = fv0'*u0(:,1:nv)*diag(ivs0(1:nv));
112vs = fvs'*us(:,1:nv)*diag(ivss(1:nv));
113
114
115%v1s = v1(1:50:3721,:);
116vss = vs(1:10:7442,:);
117
118if nv == 1,
119 mag = vss';
120else
121 mag = sum(vss'.*vss');
122end
123
124tmp1 = vss*vss';
125figure(5);im(abs(tmp1));
126
127if 0,
128magx = mag'*ones(1,length(mag));
129magy = ones(length(mag),1)*mag;
130tmp2 = tmp1./(magx+magy);
131figure(5);subplot(1,2,2);im(abs(tmp2));colorbar;axis('off');
132end
133
134
135end
136
137%%%%%%%%%%%%%%%%%%%
138if other_flag == 1,
139
140%tmp1 = PFt*us(:,1);
141%im(reshape(tmp1,sqrt(length(tmp1)),sqrt(length(tmp1))));
142PFt = PFt1;
143
144
145BI0 = back_proj(PFt,u0);
146BI1 = back_proj(PFt,u1);
147BIs = back_proj(PFt,us);
148
149figure(7);im5(BI0(:,:,1:9),3,3);
150figure(8);im5(BI1(:,:,1:9),3,3);
151figure(9);im5(BIs(:,:,1:9),3,3);
152
153
154%%%%%%%%%%
155figure(12);
156im(Is);
157
158figure(13);
159clf
160 x1 = vs(1:3721,2);
161 y1 = vs(1:3721,3);
162 subplot(1,2,1);
163 plot(x1,y1,'.')
164 axis('image');hold on;
165 subplot(1,2,2);
166 x2 = vs(3722:end,2);
167 y2 = vs(3722:end,3);
168 plot(x2,y2,'.')
169 axis('image');hold on;
170
171
172figure(11);
173 subplot(1,2,1);hist0 = im_vect([y1,x1]',ones(size(y1)));
174 im(hist0);axis('xy');
175 subplot(1,2,2);hist1 = im_vect([y2,x2]',ones(size(y1)));
176 im(hist1);axis('xy');
177
178end
179
180if test_flag == 1,
181figure(12);
182 ct = round(ginput(1));
183 idx = (ct(1)-1)*size(Is,1) + ct(2);
184
185 cl = 'r';
186 figure(13);subplot(1,2,1);
187 plot(vs(idx,2),vs(idx,3),[cl,'o']);
188 subplot(1,2,2);plot(vs(idx,2),vs(idx,3),[cl,'o']);
189
190 tmp = vs(idx,1:2)*vs(:,1:2)';tmp = reshape(tmp,size(Is,1),size(Is,2));
191 figure(14);subplot(3,2,1);
192 im(abs(tmp));colorbar
193 subplot(3,2,2); im((Is+0.5).*(abs(tmp)>0.2*max(max(abs(tmp)))));
194
195 tmp = vs(idx,1:3)*vs(:,1:3)';tmp = reshape(tmp,size(Is,1),size(Is,2));
196 subplot(3,2,3);
197 im(abs(tmp));colorbar;
198 subplot(3,2,4); im((Is+0.5).*(abs(tmp)>0.2*max(max(abs(tmp)))));
199
200 tmp = vs(idx,1:5)*vs(:,1:5)';
201 tmp = reshape(tmp,size(Is,1),size(Is,2));
202 subplot(3,2,5);
203 im(abs(tmp));colorbar
204 subplot(3,2,6); im((Is+0.5).*(abs(tmp)>0.2*max(max(abs(tmp)))));
205
206end
207
208
209%%%%%%%%%%
210test_tmp = 0;
211if test_tmp,
212x = -10:0.02:20;
213sig = 4;
214d = exp(-(x.^2)/sig);
215figure(2);plot(x,d);
216
217ers = [];
218for j=0:0.5:10,
219 d1 = exp(-(x-j).^2/sig);
220 hold on
221 plot(x,d1,'r');
222 ers = [ers,sum((d1-d).^2)];
223end
224hold off;
225
226figure(1);plot(ers(end)-ers);
227
228
229
230
231
232
233end
234
235%%%%%%%%%%%%%%%%%%%
236
237
238fvs = colize(ts,Is);
239
240nf = 24;np = 0.5*7442;
241hb.sigs = 0.02*ones(1,nf);
242hb.bmins= -0.6*ones(1,nf);
243hb.bmaxs= 0.6*ones(1,nf);
244hb.nbins= 20*ones(1,nf);
245
246%fh = colize_hist(fvs(1:nf,1:10:end),hb);
247
248fh2 = hist_inner(fvs(1:nf,1:np),hb);
249
250[u,d] = eigs(fh2,60); d = diag(d);
251
252%%%%%%%%%%%%
253figure(12);
254 ct = round(ginput(1));
255 idx = (ct(:,1)-1)*size(Is,1) + ct(:,2);
256
257dist = dist_pair(idx,fvs(1:nf,:),hb);
258figure(4);
259im(reshape(dist,size(Is,1),size(Is,2)));colorbar
260
261
262%%%%%%%%%
263figure(12);
264 ct = round(ginput(1));
265 idx = (ct(:,1)-1)*size(Is,1) + ct(:,2);
266
267a = colize_hist(fvs(1:nf,idx'),hb);
268
269figure(5);
270cl = 'brgm';
271for j=1:length(idx);
272 plot(a(:,j),cl(j));
273 hold on;
274end
275hold off
276
277%%%%%%%%%%%
278
279%% use chanked feature vectors
280
281chank_size = 1000;
282fname = 'st';
283histbin_fv_chank(fvs(1:nf,:),hb,chank_size,fname);
284
285
286covfh2 = hist_in_chank(fvs(1:nf,:),chank_size,hb.nbins(1));
287[u2,d2] = eigs(covfh2,60); d2 = diag(d2);
288
289figure(4);
290semilogy(d,'p-');
291
292figure(3);imagesc(u);
293
294back_v = backproj_outer_chank(fvs,u,d,chank_size);
295
296back_v2 = backproj_outer_chank2(fvs,u,d,chank_size);
297
298
299%%%%%%%%%%
300figure(2);
301for j = 1:16,
302 subplot(4,4,j);
303 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));
304 axis('off');title(num2str(j));
305end
306
307binv = linspace(-0.6,0.6,20);
308
309figure(4);
310for j=1:16,
311 subplot(4,4,j);
312 imagesc(reshape(u(:,j),20,24));title(num2str(j));drawnow;
313end
314
315
316figure(6);
317for j=1:16,
318 subplot(4,4,j);
319 plot(binv,(reshape(u(:,j),20,24)));title(num2str(j));drawnow;
320end
321
322
323%%%%%%%%%%
324figure(12);
325 ct = round(ginput(1));
326 idx = (ct(:,1)-1)*size(Is,1) + ct(:,2);
327
328figure(5);
329for j = 1:7*2,
330 subplot(7,2,j);
331 nvv = 2*j;
332 dist = back_v(idx,1:nvv)*back_v(:,1:nvv)';
333 im(reshape(abs(dist).^2,size(Is,1),size(Is,2)));colorbar
334 axis('off');title(num2str(nvv));
335end
336
337
338a = colize_hist(fvs(1:nf,idx'),hb)';
339
340dist_raw = dist_pair_chank(a,fvs,chank_size);
341figure(3);im(reshape(dist_raw.^2,size(Is,1),size(Is,2)));
342
343
344
345%%%%%%%%%%%%%%
346figure(12);
347 ct_t3 = round(ginput(5));
348 idx_t3 = (ct_t3(:,1)-1)*size(Is,1) + ct_t3(:,2);
349
350a1 = colize_hist(fvs(1:nf,idx_t1'),hb)';
351a2 = colize_hist(fvs(1:nf,idx_t2'),hb)';
352a3 = colize_hist(fvs(1:nf,idx_t3'),hb)';
353
354
355%%%%%%%%%%%
356figure(1);
357for j=1:9,
358 subplot(3,3,j);
359 hist(back_v(:,j))
360end
361
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex2.m
new file mode 100755
index 0000000..9e1d3e7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex2.m
@@ -0,0 +1,136 @@
1
2%%%%%%%%% test histogram on gray levels %%%%%%%%%%%%%
3
4%load st
5%fvs = colize(Is,Is);
6
7nf = 1;np = 7442;nbins = 10;
8
9hb.sigs = 0.02*ones(1,nf);
10hb.bmins= 0*ones(1,nf);
11hb.bmaxs= 1*ones(1,nf);
12hb.nbins= nbins*ones(1,nf);
13
14fh = colize_hist(fvs(1:nf,1:np),hb);
15
16fh_inner = fh*fh';
17
18nv = nbins-1;
19
20[u,d] = eigs(fh_inner,nv); d = diag(d);
21
22figure(6);
23for j=1:nv,
24 subplot(4,4,j);
25 plot(u(:,j));
26 title(num2str(j));
27end
28
29s = 1./sqrt(d);
30
31back_v = (fh'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
32
33figure(7);
34for j=1:nv,
35 subplot(4,4,j);
36 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
37 title(num2str(j));
38end
39
40figure(1);
41plot(d,'p-');
42figure(2);
43im(u);
44
45
46%%%%%%%%% try the joint x-I histogram bin %%%%%%%%%%%%%
47
48x = [1:size(Is,1)]'*ones(1,size(Is,2));
49x = reshape(x,size(Is,1),size(Is,2));
50
51joint_f(:,:,1) = x;
52joint_f(:,:,2) = Is;
53
54fvs = colize(joint_f,Is);
55
56nf = 2;np = 7442;nbins = [5,10];
57
58hb.sigs = [4,0.02].*ones(1,nf);
59hb.bmins= [1,0].*ones(1,nf);
60hb.bmaxs= [size(Is,1),1].*ones(1,nf);
61hb.nbins= nbins.*ones(1,nf);
62
63fh = colize_joint_hist(fvs,hb);
64fh = reshape(fh,50,np);
65
66fh_inner = fh*fh';
67
68nv = 30;
69
70[u,d] = eigs(fh_inner,nv); d = diag(d);
71
72figure(3);
73for j=1:min(16,nv),
74 subplot(4,4,j);
75 im(reshape(u(:,j),5,10));axis('off');
76 title(num2str(j));
77end
78
79s = 1./sqrt(d);
80
81back_v = (fh'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
82
83figure(4);
84for j=1:min(16,nv),
85 subplot(4,4,j);
86 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
87 title(num2str(j));
88end
89
90
91%%%%%%%%
92
93
94joint_f = [];
95
96joint_f(:,:,1) = Is;
97joint_f(:,:,2) = ts(:,:,1);
98
99fvs = colize(joint_f,Is);
100
101nf = 2;np = 7442;nbins = [10,10];
102
103hb.sigs = [0.02,0.02].*ones(1,nf);
104hb.bmins= [0,-0.6].*ones(1,nf);
105hb.bmaxs= [1,0.6].*ones(1,nf);
106hb.nbins= nbins.*ones(1,nf);
107
108fh = colize_joint_hist(fvs,hb);
109
110fh = reshape(fh,size(fh,1)*size(fh,2),np);
111
112fh_inner = fh*fh';
113
114nv = 30;
115
116[u,d] = eigs(fh_inner,nv); d = diag(d);
117
118figure(3);
119for j=1:min(16,nv),
120 subplot(4,4,j);
121 im(reshape(u(:,j),10,10));axis('off');
122 title(num2str(j));
123end
124
125s = 1./sqrt(d);
126
127back_v = (fh'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
128
129figure(4);
130for j=1:min(16,nv),
131 subplot(4,4,j);
132 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
133 title(num2str(j));
134end
135
136
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex3.m
new file mode 100755
index 0000000..2f245ec
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex3.m
@@ -0,0 +1,169 @@
1%%%%%%%%% test histogram on gray levels %%%%%%%%%%%%%
2
3%load st
4
5nf = 24;np = 7442;nbins = 10;
6fvs = colize(ts(:,:,1:nf),Is);
7
8hb.sigs = 0.02*ones(1,nf);
9hb.bmins= -0.6*ones(1,nf);
10hb.bmaxs= 0.6*ones(1,nf);
11hb.nbins= nbins*ones(1,nf);
12
13fh = colize_hist(fvs(1:nf,1:np),hb);
14
15nw = 4;
16fhs = colize_histneighb(fh,Is,nw);
17
18%%%%%%%%%%%%%%%%%%
19figure(12);
20 ct = round(ginput(1));
21 idx = (ct(:,1)-1)*size(Is,1) + ct(:,2);
22
23figure(1);
24subplot(1,2,1);
25imagesc(reshape(fhs(:,idx),nbins,nf))
26subplot(1,2,2);
27imagesc(reshape(fh(:,idx),nbins,nf))
28%%%%%%%%%%
29
30fh = fhs;
31fhs = sqrt(fhs);
32
33fh_inner = fhs*fhs';
34
35nv = 30;
36
37[u,d] = eigs(fh_inner,nv); d = diag(d);
38
39figure(3);
40for j=1:min(16,nv),
41 subplot(4,4,j);
42 %plot(u(:,j));
43 im(reshape(u(:,j),nbins,nf));
44 title(num2str(j));
45end
46
47s = 1./sqrt(d);
48
49back_v = (fhs'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
50
51figure(4);
52for j=1:min(16,nv),
53 subplot(4,4,j);
54 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
55 title(num2str(j));
56end
57
58figure(1);
59semilogy(d,'p-');
60%figure(2);imagesc(u);
61
62%%%%%%%%%
63figure(12);
64 ct = round(ginput(1));
65 idx = (ct(:,1)-1)*size(Is,1) + ct(:,2);
66
67figure(5);
68for j = 1:min(14,nv),
69 subplot(7,2,j);
70 nvv = j;
71 dist = back_v(idx,1:nvv)*back_v(:,1:nvv)';
72 im(reshape(abs(dist).^2,size(Is,1),size(Is,2)));colorbar
73 axis('off');title(num2str(nvv));
74end
75
76
77
78
79%%%%%%%%% try the joint x-I histogram bin %%%%%%%%%%%%%
80
81x = [1:size(Is,1)]'*ones(1,size(Is,2));
82x = reshape(x,size(Is,1),size(Is,2));
83
84joint_f(:,:,1) = x;
85joint_f(:,:,2) = Is;
86
87fvs = colize(joint_f,Is);
88
89nf = 2;np = 7442;nbins = [5,10];
90
91hb.sigs = [4,0.02].*ones(1,nf);
92hb.bmins= [1,0].*ones(1,nf);
93hb.bmaxs= [size(Is,1),1].*ones(1,nf);
94hb.nbins= nbins.*ones(1,nf);
95
96fh = colize_joint_hist(fvs,hb);
97fh = reshape(fh,50,np);
98
99fh_inner = fh*fh';
100
101nv = 30;
102
103[u,d] = eigs(fh_inner,nv); d = diag(d);
104
105figure(3);
106for j=1:min(16,nv),
107 subplot(4,4,j);
108 im(reshape(u(:,j),5,10));axis('off');
109 title(num2str(j));
110end
111
112s = 1./sqrt(d);
113
114back_v = (fh'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
115
116figure(4);
117for j=1:min(16,nv),
118 subplot(4,4,j);
119 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
120 title(num2str(j));
121end
122
123
124%%%%%%%%
125
126
127joint_f = [];
128
129joint_f(:,:,1) = Is;
130joint_f(:,:,2) = ts(:,:,1);
131
132fvs = colize(joint_f,Is);
133
134nf = 2;np = 7442;nbins = [10,10];
135
136hb.sigs = [0.02,0.02].*ones(1,nf);
137hb.bmins= [0,-0.6].*ones(1,nf);
138hb.bmaxs= [1,0.6].*ones(1,nf);
139hb.nbins= nbins.*ones(1,nf);
140
141fh = colize_joint_hist(fvs,hb);
142
143fh = reshape(fh,size(fh,1)*size(fh,2),np);
144
145fh_inner = fh*fh';
146
147nv = 30;
148
149[u,d] = eigs(fh_inner,nv); d = diag(d);
150
151figure(3);
152for j=1:min(16,nv),
153 subplot(4,4,j);
154 im(reshape(u(:,j),10,10));axis('off');
155 title(num2str(j));
156end
157
158s = 1./sqrt(d);
159
160back_v = (fh'*u(:,1:nv)).*(ones(np,1)*s(1:nv)');
161
162figure(4);
163for j=1:min(16,nv),
164 subplot(4,4,j);
165 im(reshape(back_v(:,j),size(Is,1),size(Is,2)));axis('off');
166 title(num2str(j));
167end
168
169
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex4.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex4.m
new file mode 100755
index 0000000..61f1307
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex4.m
@@ -0,0 +1,353 @@
1
2setup_flag = 0;
3cut_window_flag = 0;
4run_flag = 0;
5other_flag = 0;
6test_flag = 1;
7
8
9%%%%%%%%%%%%%%%%%
10if setup_flag == 1,
11% = readpgm('images/134035.pgm');
12
13load st3
14
15I_max = 255;
16tex_max = 40;
17
18I2 = min(1,I2/I_max);
19t2 = t2/tex_max;
20t2 = t2.*(t2<=1) + 1*(t2>1);
21t2 = t2.*(t2>=-1) + (-1)*(t2<-1);
22
23
24end
25
26%%%%%%%%%%
27
28%% for a given sampling rate, get the index for window center
29%%
30
31[nr,nc] = size(I2);
32
33hw = 3;
34st_sz = 2*hw + 1;
35
36nr_chank = floor(nr/st_sz);
37nc_chank = floor(nc/st_sz);
38
39id_chank = [];
40for k=1+hw:st_sz:nc-hw,
41 for j=1+hw:st_sz:nr-hw,
42 id = j+(k-1)*nr;
43 id_chank = [id_chank,id];
44 end
45end
46
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49%%%%%%%%%%%%%%%%%%%%%%%%%%
50%%%%% F1 difference %%%%%
51%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53fvs = 2*I2(:)'; fvs = fvs -1;
54
55nf = 1;
56hb.sigs = 0.02*ones(1,nf);
57hb.bmins= -1*ones(1,nf);
58hb.bmaxs= 1*ones(1,nf);
59hb.nbins= 10*ones(1,nf);
60
61fh = colize_hist(fvs(1:nf,:),hb);
62fhs = colize_histnb_s(fh,I2,nw,hw);
63
64A = fhs'*fhs;
65figure(1);im(A);colorbar;
66
67B = A;
68
69%% display %%%
70figure(12);
71ct = round(ginput(1));
72ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
73ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
74
75idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
76
77figure(3);
78im(reshape(A(idx,:),nr_chank,nc_chank));colorbar;
79
80
81
82%%%%%%%%%%%%%%%%%%%%%%%%%%
83%%%%% F2 difference %%%%%
84%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86nw = 4;hw =3;
87
88tnf = size(t2,3);
89fst = 1;
90r_id = 1;
91for j=1:fst:tnf,
92 nf = fst;
93 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
94 hb.bmaxs= 1*ones(1,nf); hb.nbins= 10*ones(1,nf);
95
96 fvs = colize(t2(:,:,j:j+fst-1),I2);
97 fh = colize_hist(fvs,hb);
98 fhs = colize_histnb_s(fh,I2,nw,hw);
99 A = fhs'*fhs;
100 cm = sprintf('save F%d A fhs',r_id+1);
101 disp(cm);eval(cm);
102 clear fh;
103
104 B = B + A;
105
106 clear A;
107
108
109 r_id = r_id +1;
110end
111
112
113%%%%%% debug + display %%%%%%%%
114
115figure(6);
116for j=2:30,
117 subplot(5,6,j);
118 im(t2(:,:,j-1));axis('off');title(num2str(j-1));
119end
120subplot(5,6,1);im(I2);axis('off');
121
122
123figure(6);
124B = zeros(size(A));
125for j = 1:31,
126 %subplot(5,6,j);
127 cm = sprintf('load F%d;',j);
128 disp(cm);eval(cm);
129
130 fhs1 = sqrt(fhs); A = fhs1'*fhs1;
131% im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');title(num2str(j-1));colorbar;
132 B = B+A;
133end
134
135
136%%%%%% disp dist. %%%%%%
137figure(12);
138ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
139ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
140
141idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
142
143figure(2);
144im(reshape(B(idx,:),nr_chank,nc_chank));axis('off');title('B');colorbar;
145
146
147
148%%%%%%%%%%%%%%%%%%%%%%%%%%
149%%%%% F3 features %%%%%%
150%%%%%%%%%%%%%%%%%%%%%%%%%%
151
152%%% Joint Intensity with filters %%%%
153
154
155tnf = size(t2,3);
156
157plaatjeon = 1;
158if plaatjeon,
159 for j=7:tnf,
160 cm = sprintf('!touch /disks/plaatje/scratch/jshi/FJ%d.mat',j);
161 disp(cm);
162 eval(cm);cm = sprintf('!ln -s /disks/plaatje/scratch/jshi/FJ%d.mat .',j);
163 disp(cm);eval(cm);
164 end
165else
166 for j=1:1,
167 cm = sprintf('!touch ~/store/st/FJ%d.mat',j);
168 disp(cm);eval(cm);
169 cm = sprintf('!ln -s ~/store/st/FJ%d.mat .',j);
170 disp(cm);eval(cm);
171 end
172end
173
174for j=7:tnf,
175 nf = 2;
176 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
177 hb.bmaxs= 1*ones(1,nf); hb.nbins= 10*ones(1,nf);
178
179 fvs = colize(cat(3,t2(:,:,j),I2));
180
181 fhs = colize_histnb_sf(fvs,I2,hb,nw,hw);
182 fhs = sqrt(fhs);
183 A = fhs'*fhs;
184 cm = sprintf('save FJ%d A fhs',j);
185 disp(cm);eval(cm);
186
187end
188
189%%%% reload data %%%%%%%%%%%%%%
190B = zeros(size(A));
191
192figure(3);
193
194for j=1:tnf,
195 cm = sprintf('load FJ%d;',j);
196 disp(cm);eval(cm);
197
198 subplot(5,6,j);
199 im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');title(num2str(j));
200
201 B = B + A;
202end
203
204figure(2);im(reshape(B(idx,:),nr_chank,nc_chank));axis('off');title('B');
205
206
207%%%%%% disp dist. %%%%%%
208figure(12);
209ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
210ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
211idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
212
213figure(2);
214im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');colorbar;
215
216%%%%%% disp Joint Hist %%%%%%%%%
217
218figure(12);
219ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
220ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
221idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
222
223figure(1);
224im(reshape(fhs(:,idx),10,10));axis('off');colorbar;
225
226
227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228%%%%% F4: Joint filters %%%%%%
229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231
232
233tnf = size(t2,3);
234
235nw = 4;hw =3;
236
237for scale=1:5,
238 for angle = 1:3,
239 cm = sprintf('!touch /disks/plaatje/scratch/jshi/FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
240 disp(cm);eval(cm);
241 cm = sprintf('!ln -s /disks/plaatje/scratch/jshi/FFJ_%d_%d_%d_%d.mat .',angle,angle+3,scale,scale);
242 disp(cm);eval(cm);
243 end
244end
245
246
247for scale = 1:5,
248 for angle = 1:3,
249 nf = 2;
250 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
251 hb.bmaxs= 1*ones(1,nf); hb.nbins= 10*ones(1,nf);
252
253 fvs = colize(cat(3,t2(:,:,(scale-1)*6+angle),...
254 t2(:,:,(scale-1)*6+angle+3)));
255
256 fhs = colize_histnb_sf(fvs,I2,hb,nw,hw);
257 fhs = sqrt(fhs);
258 A = fhs'*fhs;
259 cm = sprintf('save FFJ_%d_%d_%d_%d A fhs',angle,angle+3,scale,scale);
260 disp(cm);eval(cm);
261 end
262end
263
264
265%%%%%%%%% load results %%%%%%%%%%%
266%B = zeros(size(A));
267
268figure(3);
269for scale=1:5,
270 for angle = 1:3,
271 cm = sprintf('load FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
272 disp(cm);eval(cm);
273
274 subplot(3,5,scale+(angle-1)*5);
275 im(reshape(A(idx,:),nr_chank,nc_chank));
276 axis('off');title(sprintf('%d-%d,%d',angle,angle+3,scale));
277
278 %B = B + A;
279 end
280end
281
282
283
284
285%%% disp results
286
287angle = 1;scale = 1;
288cm = sprintf('load FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
289disp(cm);eval(cm);
290
291
292
293figure(12);
294ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
295ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
296idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
297
298%figure(1);im(reshape(fhs(:,idx),10,10));axis('off');%colorbar;
299%figure(2);im(reshape(A(idx,:),nr_chank,nc_chank));%axis('off');%title('B');
300figure(4);im(reshape(B(idx,:),nr_chank,nc_chank));%axis('off');%title('B');
301
302
303%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304
305%%%%%% reduction %%%%%%%%%%%%%%%%%
306nv = 50;
307[uB,dB] = eigs(B,nv);dB = diag(dB);
308
309figure(1);subplot(2,1,1);plot(dB,'p-');
310subplot(2,1,2);semilogy(dB,'p-');
311
312figure(2);
313
314for j=1:20,
315 subplot(4,5,j);
316 im(reshape(uB(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
317end
318
319
320%%%%% Ncut without reduction %%%%
321[uNu,dNu] = eig_decomp_v5(B,20);
322
323figure(1);subplot(2,1,1);plot(dNu,'p-');
324subplot(2,1,2);semilogy(dNu,'p-');
325
326figure(2);
327for j=2:6,
328 subplot(1,5,j-1);
329 im(reshape(-uNu(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
330end
331
332%%%%%% Ncut with reduction %%%%%%%%%
333nvv = 6;
334B1 = uB(:,1:nvv)*uB(:,1:nvv)';
335
336
337[uN,dN] = eig_decomp_v5(abs(B1),20);
338
339figure(1);subplot(2,1,1);plot(dN,'p-');
340subplot(2,1,2);semilogy(dN,'p-');
341
342figure(3);
343for j=2:6,
344 subplot(1,5,j-1);
345 im(reshape(uN(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
346end
347
348
349%%%%%%
350
351
352
353
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex5.m
new file mode 100755
index 0000000..2b86e0a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_evtex5.m
@@ -0,0 +1,446 @@
1
2setup_flag = 0;
3cut_window_flag = 0;
4run_flag = 0;
5other_flag = 0;
6test_flag = 1;
7
8
9%%%%%%%%%%%%%%%%%
10if setup_flag == 1,
11
12sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
13szs = szs(length(szs))*ones(1,length(szs));
14num_ori = 6;
15
16compute_flag = 0;
17if compute_flag,
18fnames = [134002,134007,134011,134013,130065,130038,130039,130040,130042,...
19 130045,130046,130056,130068];
20
21for j=1:length(fnames),
22 fname = sprintf('images/%d.pgm',fnames(j));
23
24 cm = sprintf('!touch /disks/plaatje/scratch/jshi/Fe_%d.mat',fnames(j));
25 disp(cm);eval(cm);
26
27 cm = sprintf('!ln -s /disks/plaatje/scratch/jshi/Fe_%d.mat .',fnames(j));
28 disp(cm);eval(cm);
29
30 disp(fname);
31 I = readpgm(fname);figure(3);im(I);title(num2str(fname));drawnow;
32 [text_des,filters] = compute_filter_fft(I,sigs,r,szs,num_ori);
33
34 cm = sprintf('save Fe_%d text_des filters fname sigs r szs num_ori',fnames(j));
35 disp(cm);eval(cm);
36
37 clear text_des filters I
38end
39
40end
41else
42%%%%%%%%%%%%%
43 fname = 134013;
44
45 Iname = sprintf('images/%d.pgm',fname);
46 I = readpgm(Iname);
47
48 cm = sprintf('load Fe_%d.mat',fname);
49 disp(cm);eval(cm);
50
51 figure(1);im(I);
52
53
54 cutsz =20;
55 I = cutoff(I,cutsz);figure(1);im(I);
56 text_des = cutoff(text_des,cutsz);
57
58 figure(2);
59 for j =1:30,
60 subplot(5,6,j);im(text_des(:,:,j));axis('off');
61 end
62
63 I1 = I(20:200,70:240);
64 T1 = text_des(20:200,70:240,:);
65
66 save st_134013 I1 T1 fname sigs szs r num_ori
67
68end
69
70
71
72%%%%%%%%%%% normalization %%%%%%%%%%%
73
74
75I_max = 250;
76tex_max = 40;
77
78I1 = min(1,I1/I_max);
79T1 = T1/tex_max;
80T1 = T1.*(T1<=1) + 1*(T1>1);
81T1 = T1.*(T1>=-1) + (-1)*(T1<-1);
82
83
84end
85
86%%%%%%%%%%
87
88%% for a given sampling rate, get the index for window center
89%%
90
91[nr,nc] = size(I1);
92
93hw = 3;
94st_sz = 2*hw + 1;
95
96nr_chank = floor(nr/st_sz);
97nc_chank = floor(nc/st_sz);
98
99id_chank = [];
100for k=1+hw:st_sz:nc-hw,
101 for j=1+hw:st_sz:nr-hw,
102 id = j+(k-1)*nr;
103 id_chank = [id_chank,id];
104 end
105end
106
107%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109%%%%%%%%%%%%%%%%%%%%%%%%%%
110%%%%% F1 difference %%%%%
111%%%%%%%%%%%%%%%%%%%%%%%%%%
112
113fvs = 2*I1(:)'; fvs = fvs -1;
114
115nf = 1;
116hb.sigs = 0.02*ones(1,nf);
117hb.bmins= -1*ones(1,nf);
118hb.bmaxs= 1*ones(1,nf);
119hb.nbins= 10*ones(1,nf);
120nw = 4;hw =3;
121
122fh = colize_hist(fvs(1:nf,:),hb);
123fhs = colize_histnb_s(fh,I1,nw,hw);
124
125fhs = sqrt(fhs);
126A = fhs'*fhs;
127figure(2);im(A);colorbar;
128
129B = A;
130
131%% display %%%
132figure(2);
133ct = round(ginput(1));
134ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
135ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
136
137idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
138
139figure(3);im(reshape(A(idx,:),nr_chank,nc_chank));colorbar;
140
141subplot(1,2,1);im(reshape(A1(idx,:),nr_chank,nc_chank));colorbar;
142subplot(1,2,2);im(reshape(A2(idx,:),nr_chank,nc_chank));colorbar;
143
144
145%%%%%%%%%%
146save_flag = 0;
147
148fn = 134013;
149
150if save_flag,
151 cm = sprintf('save F1_%d fhs hw nw nr_chank nc_chank',fn);
152 disp(cm);eval(cm);
153
154end
155
156load_flag = 1;
157if load_flag,
158 cm = sprintf('load F1_%d',fn);
159 disp(cm);eval(cm);
160
161 A=fhs'*fhs;
162end
163
164
165%%%%%%%%%%%%%%%%%%%%%%%%%%
166%%%%% F2 difference %%%%%
167%%%%%%%%%%%%%%%%%%%%%%%%%%
168
169nw = 4;hw =3;
170
171tnf = size(T1,3);
172fst = 1;
173
174for j=1:fst:1,
175 nf = fst;
176 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
177 hb.bmaxs= 1*ones(1,nf); hb.nbins= 15*ones(1,nf);
178
179 fvs = colize(T1(:,:,j:j+fst-1),I1);
180 fh = colize_hist(fvs,hb);
181 fhs = colize_histnb_s(fh,I1,nw,hw);
182 fhs = sqrt(fhs);
183
184 A = fhs'*fhs;
185
186 cm = sprintf('save F2_%d_%d fhs hw nw nr_chank nc_chank',j,fn);
187 disp(cm);eval(cm);
188 clear fh;
189
190 B = B + A;
191
192 clear A;
193
194end
195
196
197%%%%%% debug + display %%%%%%%%
198
199figure(6);
200for j=2:30,
201 subplot(5,6,j);
202 im(T1(:,:,j-1));axis('off');title(num2str(j-1));
203end
204subplot(5,6,1);im(I1);axis('off');
205
206
207figure(6);
208B = zeros(size(A));
209for j = 1:31,
210 %subplot(5,6,j);
211 cm = sprintf('load F%d;',j);
212 disp(cm);eval(cm);
213
214 fhs1 = sqrt(fhs); A = fhs1'*fhs1;
215% im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');title(num2str(j-1));colorbar;
216 B = B+A;
217end
218
219
220%%%%%% disp dist. %%%%%%
221weight= 5;
222A = weight*B+B2;
223
224figure(1);
225ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
226ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
227idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
228
229figure(2);
230im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');colorbar; %title('B');
231%figure(3);
232
233
234save_flag = 0;
235if save_flag ,
236 B2 = B;
237 save tmp B2 nr_chank nc_chank
238end
239
240%%%%%%%%%%%%%%%%%%%%%%%%%%
241%%%%% F3 features %%%%%%
242%%%%%%%%%%%%%%%%%%%%%%%%%%
243
244%%% Joint Intensity with filters %%%%
245
246
247tnf = size(T1,3);
248
249plaatjeon = 1;
250if plaatjeon,
251 for j=7:tnf,
252 cm = sprintf('!touch /disks/plaatje/scratch/jshi/FJ%d.mat',j);
253 disp(cm);
254 eval(cm);cm = sprintf('!ln -s /disks/plaatje/scratch/jshi/FJ%d.mat .',j);
255 disp(cm);eval(cm);
256 end
257else
258 for j=1:1,
259 cm = sprintf('!touch ~/store/st/FJ%d.mat',j);
260 disp(cm);eval(cm);
261 cm = sprintf('!ln -s ~/store/st/FJ%d.mat .',j);
262 disp(cm);eval(cm);
263 end
264end
265
266for j=7:tnf,
267 nf = 2;
268 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
269 hb.bmaxs= 1*ones(1,nf); hb.nbins= 10*ones(1,nf);
270
271 fvs = colize(cat(3,T1(:,:,j),I1));
272
273 fhs = colize_histnb_sf(fvs,I1,hb,nw,hw);
274 fhs = sqrt(fhs);
275 A = fhs'*fhs;
276 cm = sprintf('save FJ%d A fhs',j);
277 disp(cm);eval(cm);
278
279end
280
281%%%% reload data %%%%%%%%%%%%%%
282B = zeros(size(A));
283
284figure(3);
285
286for j=1:tnf,
287 cm = sprintf('load FJ%d;',j);
288 disp(cm);eval(cm);
289
290 subplot(5,6,j);
291 im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');title(num2str(j));
292
293 B = B + A;
294end
295
296figure(2);im(reshape(B(idx,:),nr_chank,nc_chank));axis('off');title('B');
297
298
299%%%%%% disp dist. %%%%%%
300figure(12);
301ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
302ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
303idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
304
305figure(2);
306im(reshape(A(idx,:),nr_chank,nc_chank));axis('off');colorbar;
307
308%%%%%% disp Joint Hist %%%%%%%%%
309
310figure(12);
311ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
312ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
313idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
314
315figure(1);
316im(reshape(fhs(:,idx),10,10));axis('off');colorbar;
317
318
319%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320%%%%% F4: Joint filters %%%%%%
321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322
323
324
325tnf = size(T1,3);
326
327nw = 4;hw =3;
328
329for scale=1:5,
330 for angle = 1:3,
331 cm = sprintf('!touch /disks/plaatje/scratch/jshi/FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
332 disp(cm);eval(cm);
333 cm = sprintf('!ln -s /disks/plaatje/scratch/jshi/FFJ_%d_%d_%d_%d.mat .',angle,angle+3,scale,scale);
334 disp(cm);eval(cm);
335 end
336end
337
338
339for scale = 1:5,
340 for angle = 1:3,
341 nf = 2;
342 hb.sigs = 0.02*ones(1,nf); hb.bmins= -1*ones(1,nf);
343 hb.bmaxs= 1*ones(1,nf); hb.nbins= 10*ones(1,nf);
344
345 fvs = colize(cat(3,T1(:,:,(scale-1)*6+angle),...
346 T1(:,:,(scale-1)*6+angle+3)));
347
348 fhs = colize_histnb_sf(fvs,I1,hb,nw,hw);
349 fhs = sqrt(fhs);
350 A = fhs'*fhs;
351 cm = sprintf('save FFJ_%d_%d_%d_%d A fhs',angle,angle+3,scale,scale);
352 disp(cm);eval(cm);
353 end
354end
355
356
357%%%%%%%%% load results %%%%%%%%%%%
358%B = zeros(size(A));
359
360figure(3);
361for scale=1:5,
362 for angle = 1:3,
363 cm = sprintf('load FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
364 disp(cm);eval(cm);
365
366 subplot(3,5,scale+(angle-1)*5);
367 im(reshape(A(idx,:),nr_chank,nc_chank));
368 axis('off');title(sprintf('%d-%d,%d',angle,angle+3,scale));
369
370 %B = B + A;
371 end
372end
373
374
375
376
377%%% disp results
378
379angle = 1;scale = 1;
380cm = sprintf('load FFJ_%d_%d_%d_%d.mat',angle,angle+3,scale,scale);
381disp(cm);eval(cm);
382
383
384
385figure(12);
386ct = round(ginput(1));ct_chank(1) = round((ct(1)-hw-1)/st_sz) + 1;
387ct_chank(2) = round((ct(2)-hw-1)/st_sz) + 1;
388idx = (ct_chank(:,1)-1)*nr_chank + ct_chank(:,2);
389
390%figure(1);im(reshape(fhs(:,idx),10,10));axis('off');%colorbar;
391%figure(2);im(reshape(A(idx,:),nr_chank,nc_chank));%axis('off');%title('B');
392figure(4);im(reshape(B(idx,:),nr_chank,nc_chank));%axis('off');%title('B');
393
394
395%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396
397%%%%%% reduction %%%%%%%%%%%%%%%%%
398nv = 50;
399[uA,dA] = eigs(A,nv);dA = diag(dA);
400
401figure(4);suAplot(2,1,1);plot(dA,'p-');
402subplot(2,1,2);semilogy(dA,'p-');
403
404figure(3);
405
406for j=1:20,
407 subplot(4,5,j);
408 im(reshape(uA(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
409end
410
411
412%%%%% Ncut without reduction %%%%
413
414[uNu,dNu] = eig_decomp_v5(A,20);
415
416figure(4);subplot(2,1,1);plot(dNu,'p-');
417subplot(2,1,2);semilogy(dNu,'p-');
418
419figure(3);
420for j=2:6,
421 subplot(1,5,j-1);
422 im(reshape(-uNu(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
423end
424
425%%%%%% Ncut with reduction %%%%%%%%%
426nvv = 7;
427A1 = uA(:,1:nvv)*uA(:,1:nvv)';
428
429
430[uN,dN] = eig_decomp_v5(abs(A1),20);
431
432figure(1);subplot(2,1,1);plot(dN,'p-');
433subplot(2,1,2);semilogy(dN,'p-');
434
435figure(3);
436for j=2:6,
437 subplot(1,5,j-1);
438 im(reshape(uN(:,j),nr_chank,nc_chank));axis('off');colorbar;title(num2str(j));
439end
440
441
442%%%%%%
443
444
445
446
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion.m
new file mode 100755
index 0000000..91c97f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion.m
@@ -0,0 +1,117 @@
1
2im_sz = [40,40];
3
4ob_szh = [6,3];
5
6ob_c = [15,12];
7
8bg_color = 0.2;
9
10ob_color = 0.8;
11
12mag = 0.2;
13
14I_bg = bg_color + mag*randn(im_sz);
15
16I_obj = ob_color + mag*randn(2*ob_szh+1);
17
18
19w = 3;
20
21v5 = 1;
22Js = [];
23
24if ~v5,
25 for j=1:5,
26 fc = sprintf('J%d = I_bg;',j);
27 eval(fc);
28
29 fc = sprintf('J%d(ob_c(1)-ob_szh(1):ob_c(1)+ob_szh(1),ob_c(2)-ob_szh(2):ob_c(2)+ob_szh(2)) = I_obj;',j);
30 eval(fc);
31
32 ob_c = ob_c+[0,2];
33 end
34else
35 nf = 4;
36 for j = 1:nf,
37
38 J = I_bg;
39 J(ob_c(1)-ob_szh(1):ob_c(1)+ob_szh(1),ob_c(2)-ob_szh(2):ob_c(2)+ob_szh(2)) = I_obj;
40
41 if (j==1),
42 [gy,gx] = grad(J,w);
43 end
44
45 ob_c = ob_c+[0,2];
46
47 Jw = cutoff(J,w);
48 Js(:,:,j) = Jw;
49 end
50
51end
52
53[nr,nc] = size(gx);
54
55for j=1:nf,
56 subplot(1,nf,j);
57 imagesc(Js(:,:,j));axis('tightequal');
58end
59
60
61writepnm5('test_motion.pnm',Js);
62writepnm5('test_motion_gx.pnm',gx);
63writepnm5('test_motion_gy.pnm',gy);
64%imagesc(J1);colorbar;
65
66
67inpara = [2,5,0.5,1,0.5];
68
69[A,D,Ipara] = cas('test_motion',inpara);
70
71B= A+ A';
72clear A;
73
74%BB = B(1:19^2,19^2+(1:19^2));
75%imagesc(BB);
76
77[v,d] = eigs(B);d = diag(d);
78
79k = 2;
80
81figure(1);
82%nf = 5;
83
84nr = nr-5;
85nc = nc-5;
86
87n = nr* nc;
88
89for j =1:nf,
90 subplot(1,nf,j);
91 imagesc(reshape(v((j-1)*n+(1:n),k).*D(1:n),nr,nc)');axis('tightequal');
92end
93
94%%%%%
95
96
97figure(3);
98T = readpnm('test_motion.pnm');
99nf = size(T,3);
100for j=1:nf,
101 subplot(1,nf,j);
102 imagesc(T(:,:,j));axis('tightequal');
103end
104
105
106figure(2);
107Gx = readpnm('test_motion_gx.pnm');
108
109[nr,nc] =size(Gx);
110n = nr*nc;
111
112imagesc(reshape(B(n+1:2*n,6*nc+7),nc,nr)');colorbar
113
114
115
116
117
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion2.m
new file mode 100755
index 0000000..2959fa8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_motion2.m
@@ -0,0 +1,127 @@
1
2im_sz = [40,40];
3
4ob_szh = [4,3];
5
6ob_c = [12,12];
7
8ob_co = [30,28];
9
10bg_color = 0.2;
11
12ob_color = 0.8;
13
14mag = 0.2;
15
16I_bg = bg_color + mag*randn(im_sz);
17
18I_obj = ob_color + mag*randn(2*ob_szh+1);
19
20
21w = 3;
22
23v5 = 1;
24Js = [];
25
26if ~v5,
27 for j=1:5,
28 fc = sprintf('J%d = I_bg;',j);
29 eval(fc);
30
31 fc = sprintf('J%d(ob_c(1)-ob_szh(1):ob_c(1)+ob_szh(1),ob_c(2)-ob_szh(2):ob_c(2)+ob_szh(2)) = I_obj;',j);
32 eval(fc);
33
34 fc = sprintf('J%d(ob_co(1)-ob_szh(1):ob_co(1)+ob_szh(1),ob_co(2)-ob_szh(2):ob_co(2)+ob_szh(2)) = I_obj;',j);
35 eval(fc);
36
37 ob_c = ob_c+[0,2];
38 ob_co = ob_co-[0,2];
39
40 end
41else
42 nf = 4;
43 for j = 1:nf,
44
45 J = I_bg;
46 J(ob_c(1)-ob_szh(1):ob_c(1)+ob_szh(1),ob_c(2)-ob_szh(2):ob_c(2)+ob_szh(2)) = I_obj;
47 J(ob_co(1)-ob_szh(1):ob_co(1)+ob_szh(1),ob_co(2)-ob_szh(2):ob_co(2)+ob_szh(2)) = I_obj;
48
49 if (j==1),
50 [gy,gx] = grad(J,w);
51 end
52
53 ob_c = ob_c+[0,2];
54 ob_co = ob_co-[0,2];
55
56 Jw = cutoff(J,w);
57 Js(:,:,j) = Jw;
58 end
59
60end
61
62[nr,nc] = size(gx);
63
64for j=1:nf,
65 subplot(1,nf,j);
66 imagesc(Js(:,:,j));axis('tightequal');
67end
68
69
70writepnm5('test_motion.pnm',Js);
71writepnm5('test_motion_gx.pnm',gx);
72writepnm5('test_motion_gy.pnm',gy);
73%imagesc(J1);colorbar;
74
75
76inpara = [2,5,0.5,1,0.5];
77
78[A,D,Ipara] = cas('test_motion',inpara);
79
80B= A+ A';
81clear A;
82
83%BB = B(1:19^2,19^2+(1:19^2));
84%imagesc(BB);
85
86[v,d] = eigs(B);d = diag(d);
87
88k = 2;
89
90figure(1);
91%nf = 5;
92
93nr = nr-5;
94nc = nc-5;
95
96n = nr* nc;
97
98for j =1:nf,
99 subplot(1,nf,j);
100 imagesc(reshape(v((j-1)*n+(1:n),k).*D(1:n),nr,nc)');axis('tightequal');
101end
102
103%%%%%
104
105
106figure(3);
107T = readpnm('test_motion.pnm');
108nf = size(T,3);
109for j=1:nf,
110 subplot(1,nf,j);
111 imagesc(T(:,:,j));axis('tightequal');
112end
113
114
115figure(2);
116Gx = readpnm('test_motion_gx.pnm');
117
118[nr,nc] =size(Gx);
119n = nr*nc;
120
121imagesc(reshape(B(n+1:2*n,6*nc+7),nc,nr)');colorbar
122
123
124%%%%%%%%%%%%%
125
126
127K = zeros(im_sz);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_period.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_period.m
new file mode 100755
index 0000000..2994d15
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_period.m
@@ -0,0 +1,58 @@
1flag = 2;
2
3if flag ==1,
4
5ws = [50,50];
6
7figure(1);J = get_win(I,ginput(1),ws);
8figure(4);imagesc(J);
9
10J = J - mean(mean(reshape(J,prod(size(J)),1)));
11X = fftshift(fft2(J));
12
13figure(3);imagesc(abs(X));colorbar
14figure(2);mesh(abs(X));
15
16else
17
18fn = '1.pgm';
19
20% spatial gaussian parameter
21xscale = 1;
22
23% half size of the neighbourhood
24xnb = 5;
25
26% setting the the HSV gaussian parameter:[h s v]
27Iscale = [0.01];
28
29Input_para = [xscale,xnb,Iscale];
30
31% compute the lower half the association matrix
32[A,D,Ipara] = compute_A_pgm(fn,Input_para);
33
34nr = Ipara(1);nc = Ipara(2);
35
36B = A+A';
37clear A;
38
39
40% eigen decompostion
41options.tol = 1e-4;
42num_eig_v = 10;
43fprintf('doing eigs ...\n');
44[v,d] = eigs(B,num_eig_v,options);
45
46k = 1;imagesc(reshape(v(:,k).*D,nc,nr)');colorbar
47
48
49end
50
51
52
53
54
55
56
57
58
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_text.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_text.m
new file mode 100755
index 0000000..4cc5759
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/test_text.m
@@ -0,0 +1,434 @@
1
2
3%case = 1;
4
5read_flag = 1;
6compute_flag = 0;
7load_flag = 0;
8decomp_flag = 0;
9hist_flag = 0;
10
11test_real = 0;
12
13
14if read_flag,
15if caseid == 1,
16 ifn = 'images/130049.pgm';
17elseif caseid == 2,
18 ifn = 'images/130055.pgm';
19elseif caseid == 3,
20 ifn = 'images/130056.pgm';
21elseif caseid == 4,
22 ifn = 'images/130057.pgm';
23elseif caseid == 5,
24 ifn = 'images/130060.pgm';
25elseif caseid == 6,
26 ifn = 'images/130061.pgm';
27elseif caseid == 7,
28 ifn = 'images/130062.pgm';
29elseif caseid == 8,
30 ifn = 'images/130065.pgm';
31elseif caseid == 9,
32 ifn = 'images/130066.pgm';
33elseif caseid == 10,
34 ifn = 'images/130068.pgm';
35elseif caseid == 11,
36 ifn = 'images/130070.pgm';
37else
38 ifn = 'images/130070.pgm';
39end
40
41I = readpgm(ifn);
42figure(1);
43imagesc(I);colormap(gray);drawnow;
44axis('tightequal');
45
46end
47
48%%%%% load %%%
49
50if load_flag,
51 fn = sprintf('load cresult_%d;',caseid);
52 eval(fn);
53end
54
55
56%%%%%%%%%%%%% compute %%%%%%%%%%%
57sig = 0.5;
58r = 3;
59sz = 15;
60Iw = cutoff(I,0.5*sz);
61figure(1);imagesc(Iw);
62axis('image');
63
64if compute_flag,
65
66as = 0:30:150;
67
68Cresult = [];
69
70for j = 1:length(as),
71 fprintf('.');
72 angle = as(j);
73
74 g = doog2( sig,r,angle,sz);
75
76 g = g - mean(reshape(g,prod(size(g)),1));
77
78 g = g/sum(sum(abs(g)));
79
80 c = conv2(I,g,'valid');
81
82 Cresult(:,:,j) = c;
83end
84
85
86fprintf('\n');
87
88
89figure(2);
90
91subplot(2,3,1);
92imagesc(Cresult(:,:,1).^2);axis('tightequal');colorbar
93
94subplot(2,3,2);
95imagesc(Cresult(:,:,2).^2);axis('tightequal');colorbar
96
97subplot(2,3,3);
98imagesc(Cresult(:,:,3).^2);axis('tightequal');colorbar
99
100subplot(2,3,4);
101imagesc(Cresult(:,:,4).^2);axis('tightequal');colorbar
102
103subplot(2,3,5);
104imagesc(Cresult(:,:,5).^2);axis('tightequal');colorbar
105
106subplot(2,3,6);
107imagesc(Cresult(:,:,6).^2);axis('tightequal');colorbar
108
109Cs = [];
110Mcs = [];
111for j=1:length(as),
112 Cs(:,:,j) = reduce(reduce(abs(Cresult(:,:,j))));
113
114 Mcs = [Mcs,max(max(Cs(:,:,j)))];
115
116end
117
118ms = max(Mcs);
119
120figure(3);
121for j=1:6,
122 fn = sprintf('Cs(:,:,%d) = Cs(:,:,%d)/ms;',j,j);
123 eval(fn);
124 fn = sprintf('subplot(2,3,%d);imagesc(Cs(:,:,%d));',j,j);
125 eval(fn);axis('tightequal');colorbar
126end
127
128fn = sprintf('save cresult_%d.mat Cresult Cs',caseid);
129disp(fn);
130eval(fn);
131
132end
133
134%%%%%%%%%%%%%%%%% decomp %%%%%%%%%%%%
135
136
137if decomp_flag,
138
139%writepnm5('txt_2.pnm',Cs);
140
141%writepnm5('130068.pnm',Cs);
142
143
144%I_scale = 0.0025;
145%X_scale = 3^2;
146%[A,D,Ipara] = compute_A_sparmul2(10,I_scale,X_scale);
147
148
149I_scale = 0.02;
150X_scale = 2;
151[A,D,Ipara] = compute_A_pnm('130068.pnm',[X_scale,I_scale]);
152
153nr = Ipara(1);nc = Ipara(2);
154imagesc(reshape(D,nc,nr)');colorbar;
155
156B = A+A';clear A;
157
158options.tol = 1e-7;
159
160[v,d] = eigs(B,9,options);
161
162figure(4);
163k = 1; imagesc(reshape(v(:,k).*D,nc,nr)');
164
165end
166
167
168%%%% histogram %%%%
169
170%hist_flag = 1;
171
172%figure(1);imagesc(Iw);axis('image');
173if hist_flag ==1,
174
175
176ws = [12,12];
177
178figure(7);
179
180cs = ginput(1);
181
182cs = 10*(cs-1)+w/2;
183
184%cs(1,:) = w+(floor((cs(1,:)-w)/gap)*gap);
185%cs(2,:) = w+(floor((cs(2,:)-w)/gap)*gap);
186
187J = get_win(Iw,cs(1,:),ws);
188Jbar = get_win5(Cresult,cs(1,:),ws);
189
190
191figure(2);
192subplot(3,3,1);imagesc(J);colorbar
193for j=1:6,subplot(3,3,1+j);imagesc(abs(Jbar(:,:,j)));colorbar; end
194
195[hists,bins] = get_hist(J,Jbar);show_hist(hists,bins,4);
196cumhists = get_cumhist(hists);show_cumhist(cumhists,bins,6,1,'b-o');
197
198J2 = get_win(Iw,cs(2,:),ws);
199Jbar2 = get_win5(Cresult,cs(2,:),ws);
200
201figure(3);
202subplot(3,3,1);imagesc(J2);colorbar
203for j=1:6,subplot(3,3,1+j);imagesc(abs(Jbar2(:,:,j)));colorbar; end
204
205[hists2,bins2] = get_hist(J2,Jbar2);show_hist(hists2,bins2,5);
206cumhists2 = get_cumhist(hists2);show_cumhist(cumhists2,bins2,6,0,'r-*');
207
208diff.inten = max(abs(cumhists.inten-cumhists2.inten));
209diff.mag = max(abs(cumhists.mag-cumhists2.mag));
210diff.text = max(max(abs(cumhists.text-cumhists2.text)));
211
212figure(7);
213
214disp([diff.inten,diff.mag,diff.text]);
215maxdiff = max([diff.inten,diff.mag,diff.text]);
216disp(1-sigmoid(diff.inten,0.22,0.02));
217
218
219if 0,
220%A = pair_dist_text(Iw,Cresult,15);
221
222r =4;w = 22;gap = 5;sig_x= 20.0;
223inpara = [r,w,gap,sig_x,0.16,0.2,0.2];
224[Cum,tm] = cAh(Iw,mag,abs(Cresult),inpara);
225
226[Cum,Nb,Nc] = cAh4(Iw,mag,abs(Cresult),inpara);
227
228
229B = A+ A';clear A;
230
231figure(1);
232c = ginput(1);
233cx = floor(c(1)/gap);
234cy = floor(c(2)/gap);
235[cx,cy]
236figure(7)
237imagesc(reshape(B(cy*Cum(1)+cx,:),Cum(1),Cum(2))');colorbar
238
239
240cutoff = [0.22,0.2,0.2];
241sig_hist = [0.02,0.04,0.05];
242
243inpara2 = [r,5,cutoff,sig_hist];
244[A,D] = compute_A_hist3(tm,Cum,inpara2);
245
246B = A+A';clear A;
247imagesc(reshape(D,Cum(1),Cum(2))');
248
249
250[v,d] = eigs(B);
251
252
253end
254
255end
256
257%%%%%%%%%%%%% trans_texture %%%%%%%%%%%%
258trans_text = 0;
259
260
261if trans_text,
262 figure(1);
263 cs = ginput(1);
264
265 ws = [40,40];
266
267 J = get_win(Iw,cs(1,:),ws);
268 Jbar = get_win5(Cresult,cs(1,:),ws);
269 Jmag = get_win(mag,cs(1,:),ws);
270
271 figure(3);imagesc(J);
272
273 figure(3);
274 for j=1:6,
275 subplot(2,3,j);imagesc(abs(Jbar(:,:,j)));axis('image');colorbar;
276 end
277
278 f= abs(Jbar(40,38,:));
279 g= abs(Jbar(40,47,:));
280
281 dot(f,g)/max(dot(f,f),dot(g,g))
282
283 ff = myinterp(f,10); gg = myinterp(g,10);
284 dot(ff,gg)/max(dot(ff,ff),dot(gg,gg))
285
286 cum = mc_corr(ff,gg,[-6,6]);
287 max(cum)/max(dot(f,f),dot(g,g))
288
289
290 center = [40,35];
291
292 f = squeeze(abs(Jbar(center(1),center(2),:)));
293 ff = myinterp(f,10);
294 mag_ff = dot(ff,ff);
295 mag_c = Jmag(center(1),center(2));
296 dy = 0;
297
298 cor_cofs = [];
299 mags = [];
300 for dx = -15:15,
301 g = squeeze(abs(Jbar(center(1)+dy,center(2)+dx,:)));
302 gg = myinterp(g,10);
303
304 cum = mc_corr(ff,gg,[-6,6]);
305 cor_cofs = [cor_cofs,max(cum)/max(mag_ff,dot(gg,gg))];
306
307 mags =[mags,max(mag_c,Jmag(center(1)+dy,center(2)+dx,:))];
308
309 end
310
311 simulation_on =0;
312
313 if simulation_on,
314
315 sz = [161,161]
316 SI = zeros(sz);
317
318 for i=2:18:sz(1),
319 SI(i:i+2,:) = 1+SI(i:i+2,:);
320 end
321
322 imagesc(SI);axis('image');
323
324 tmp1 = mimrotate(SI,90,'nearest','crop');
325 tmp2 = mimrotate(SI,45,'nearest','crop');
326
327 ly = round(0.7*sz(1));
328 lx = round(0.7*sz(1));
329 sy = round(0.16*sz(1));
330 sx = round(0.2*sz(2));
331 TI = [tmp1(1:ly,1:lx),tmp2(sy+1:sy+ly,sy+1:sy+round(0.4*lx))];
332
333 TI = TI+0.04*randn(size(TI));
334
335 %sig = 1/sqrt(2);r = 3;sz = round(r*3*sig);
336
337 sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
338 [text_des,TIw] = compute_filter(TI,sigs,r,szs);
339 figure(2);imagesc(TIw);axis('image');
340
341 figure(3);
342 im5(abs(text_des),2,3);
343
344 text_des = abs(text_des);
345
346 text_des = T1;
347
348 numband = size(text_des,3); r = 10;
349 sig_x = 90; sig_inten = 0.15; sig_tex = 0.01;w_inten = 0.03;
350 para = [numband,r,sig_x,sig_inten,sig_tex,w_inten];
351
352 [A,D,Ipara] = compute_A_text(TIw,text_des,para);
353 nr = Ipara(1);nc = Ipara(2);
354 B = A+A'; clear A;
355
356 figure(2);
357 cs = ginput(1);
358 cs = round(cs);id = cs(2)*nc+cs(1);
359
360 figure(4);
361 imagesc(reshape(B(id,:),nc,nr)');axis('image');colorbar
362
363 [v,d] = eigs(B);
364 figure(4);imagesc(reshape(D.*v(:,1),nc,nr)');axis('image');
365
366 end
367
368end
369
370if test_real == 1,
371 sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
372 text_des = compute_filter(I,sigs,r,szs);
373
374 text_des = abs(text_des);
375%save filter_3.mat
376
377 %%%% cutoff margins,
378 margin = 6+10;
379
380 Iw = cutoff(I,margin);
381
382 T1= reshape(text_des,size(text_des,1),size(text_des,2),size(text_des,3)*size(text_des,4));
383 T1 = cutoff(T1,margin);
384
385 %%%%% reduce resolution
386
387 Iwp = compact(Iw,4);
388
389 T1 = reduce_all(T1);
390 T1 = reduce_all(T1);
391
392% T1 = T1/70;
393
394 % writepnm5('test6_image.pnm',Iwp);writepnm5('test6_filter.pnm',T1);
395
396 numband = size(T1,3); r = 2;
397 sig_x = 20; sig_inten = 0.15; sig_tex = 0.01;w_inten = 0.01;
398 para = [numband,r,sig_x,sig_inten,sig_tex,w_inten];
399
400 [A,D,Ipara] = compute_A_text(Iwp,T1,para);
401 nr = Ipara(1);nc = Ipara(2);
402 figure(4);imagesc(reshape(D,nc,nr)');axis('image');
403 drawnow;
404
405
406 numband = 6;
407 r = 5; sig_x = 20.0;
408 sig_tex = 0.01; w_inten = 0.01; w = 2;
409 para = [numband,r,sig_x,sig_tex,w_inten,w,size(T1,2)];
410
411 [A,D,Ipara] = compute_A_text2(Iw,T1(:,:,1:numband)/70,para);
412 nr = Ipara(1);nc = Ipara(2);
413
414
415
416 B = A+A'; clear A;
417
418
419 figure(2);
420 cs = ginput(1);
421 cs = floor(cs/4)+1;id = cs(2)*nc+cs(1);
422
423 figure(4);
424 imagesc(reshape(B(id,:),nc,nr)');axis('image');colorbar
425
426
427end
428
429
430
431
432
433
434
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp.m
new file mode 100755
index 0000000..b932912
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp.m
@@ -0,0 +1,68 @@
1
2sw = 3;
3gap = 2*sw+1;
4
5nw = 6;
6
7for j=1:20,
8 l = max(0,j-1-nw);
9% l = max(0,j-1-2*nw);
10 rs(j) = ceil((l-sw)/gap) + 1;
11 l = min(20,j-1+nw);
12% l = min(20,j-1);
13 re(j) = floor((l-sw)/gap) +1;
14end
15
16plot([1:20],rs,'p-',[1:20],re,'rp-')
17
18
19%%%%%%%%
20
21bin_max = 1.0;
22bin_min = -1.0;
23num_bin = 30;
24sig = 0.2;
25
26data = 0.482;
27
28inc = (bin_max-bin_min)/num_bin;
29
30bs = -100;
31be = bin_min+inc;
32b = [];
33
34for j=1:num_bin,
35
36 b(j) = tmp1(bs,be,data,sig);
37 bs = be;
38 be= be+inc;
39end
40plot(b,'p-');
41
42
43
44bmin = -1;
45
46inc = 0.2;
47a = 0.1;
48b = -1250;
49ovs = 625;
50
51bs = bmin;
52be = bs+inc;
53
54data = -0.482;
55
56for j=1:10,
57 tmp = bs-data;
58 fs = exp(-(tmp*tmp*ovs));
59 ks = b*tmp;
60
61 tmp = be-data;
62 fe = exp(-(tmp*tmp*ovs));
63 ke = b*tmp;
64
65 bin(j) = fs*(2+a*ks) + fe*(2-a*ke);
66 bs = be;
67 be = be+inc;
68end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp1.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp1.m
new file mode 100755
index 0000000..db5dbc1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp1.m
@@ -0,0 +1,25 @@
1function d = tmp1(bs,be,data,sig)
2
3sig = sig^2;
4
5if 1,
6a = (bs+be)*0.5;
7d = (a-bs)*(exp(-(bs-data)^2/sig) + exp(-(a-data)^2/sig)) + ...
8 (be-a)*(exp(-(a-data)^2/sig) + exp(-(be-data)^2/sig));
9d = d*2/sqrt(pi);
10else
11
12a = (be-bs)/2;
13
14h1 = exp(-(bs-data)^2/sig);
15h2 = exp(-(be-data)^2/sig);
16
17k1 = -2*(bs-data)/sig;
18k2 = -2*(be-data)/sig;
19
20d = a*(h1*(2+2*a*k1) + h2*(2-2*a*k2));
21d = d*2/sqrt(pi);
22
23end
24
25
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp2.m
new file mode 100755
index 0000000..b361cdc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp2.m
@@ -0,0 +1,17 @@
1function d = tmp2(bs,be,data,sig)
2
3sig = sig^2;
4
5
6a = (be-bs)/2;
7
8h1 = exp(-(bs-data)^2/sig);
9h2 = exp(-(be-data)^2/sig);
10
11k1 = -2*(bs-data)/sig;
12k2 = -2*(be-data)/sig;
13
14d = (h1*(2+2*a*k1) + h2*(2-2*a*k2));
15%d = a*d*2/sqrt(pi);
16
17
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp3.m
new file mode 100755
index 0000000..c1bffd9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/tmp3.m
@@ -0,0 +1,126 @@
1function result = erfcore(x,jint)
2%ERFCORE Core algorithm for error functions.
3% erf(x) = erfcore(x,0)
4% erfc(x) = erfcore(x,1)
5% erfcx(x) = exp(x^2)*erfc(x) = erfcore(x,2)
6
7% C. Moler, 2-1-91.
8% Copyright (c) 1984-96 by The MathWorks, Inc.
9% $Revision: 5.7 $ $Date: 1996/10/28 20:57:59 $
10
11% This is a translation of a FORTRAN program by W. J. Cody,
12% Argonne National Laboratory, NETLIB/SPECFUN, March 19, 1990.
13% The main computation evaluates near-minimax approximations
14% from "Rational Chebyshev approximations for the error function"
15% by W. J. Cody, Math. Comp., 1969, PP. 631-638.
16
17 if ~isreal(x),
18 error('Input argument must be real.')
19 end
20 result = repmat(NaN,size(x));
21%
22% evaluate erf for |x| <= 0.46875
23%
24 xbreak = 0.46875;
25 k = find(abs(x) <= xbreak);
26 if ~isempty(k)
27 a = [3.16112374387056560e00; 1.13864154151050156e02;
28 3.77485237685302021e02; 3.20937758913846947e03;
29 1.85777706184603153e-1];
30 b = [2.36012909523441209e01; 2.44024637934444173e02;
31 1.28261652607737228e03; 2.84423683343917062e03];
32
33 y = abs(x(k));
34 z = y .* y;
35 xnum = a(5)*z;
36 xden = z;
37 for i = 1:3
38 xnum = (xnum + a(i)) .* z;
39 xden = (xden + b(i)) .* z;
40 end
41 result(k) = x(k) .* (xnum + a(4)) ./ (xden + b(4));
42 if jint ~= 0, result(k) = 1 - result(k); end
43 if jint == 2, result(k) = exp(z) .* result(k); end
44 end
45%
46% evaluate erfc for 0.46875 <= |x| <= 4.0
47%
48 k = find((abs(x) > xbreak) & (abs(x) <= 2.));
49 if ~isempty(k)
50 c = [5.64188496988670089e-1; 8.88314979438837594e00;
51 6.61191906371416295e01; 2.98635138197400131e02;
52 8.81952221241769090e02; 1.71204761263407058e03;
53 2.05107837782607147e03; 1.23033935479799725e03;
54 2.15311535474403846e-8];
55 d = [1.57449261107098347e01; 1.17693950891312499e02;
56 5.37181101862009858e02; 1.62138957456669019e03;
57 3.29079923573345963e03; 4.36261909014324716e03;
58 3.43936767414372164e03; 1.23033935480374942e03];
59
60 y = abs(x(k));
61 xnum = c(9)*y;
62 xden = y;
63 for i = 1:7
64 xnum = (xnum + c(i)) .* y;
65 xden = (xden + d(i)) .* y;
66 end
67 result(k) = (xnum + c(8)) ./ (xden + d(8));
68 if jint ~= 2
69 z = fix(y*16)/16;
70 del = (y-z).*(y+z);
71 result(k) = exp(-z.*z) .* exp(-del) .* result(k);
72 end
73 end
74%
75% evaluate erfc for |x| > 4.0
76%
77 k = find(abs(x) > 2.0);
78 if ~isempty(k)
79if 0,
80 p = [3.05326634961232344e-1; 3.60344899949804439e-1;
81 1.25781726111229246e-1; 1.60837851487422766e-2;
82 6.58749161529837803e-4; 1.63153871373020978e-2];
83 q = [2.56852019228982242e00; 1.87295284992346047e00;
84 5.27905102951428412e-1; 6.05183413124413191e-2;
85 2.33520497626869185e-3];
86
87 y = abs(x(k));
88 z = 1 ./ (y .* y);
89 xnum = p(6).*z;
90 xden = z;
91 for i = 1:4
92 xnum = (xnum + p(i)) .* z;
93 xden = (xden + q(i)) .* z;
94 end
95 result(k) = z .* (xnum + p(5)) ./ (xden + q(5));
96 result(k) = (1/sqrt(pi) - result(k)) ./ y;
97 if jint ~= 2
98 z = fix(y*16)/16;
99 del = (y-z).*(y+z);
100 result(k) = exp(-z.*z) .* exp(-del) .* result(k);
101 k = find(~isfinite(result));
102 result(k) = 0*k;
103 end
104end
105 result(k) = 0;
106 end
107%
108% fix up for negative argument, erf, etc.
109%
110 if jint == 0
111 k = find(x > xbreak);
112 result(k) = (0.5 - result(k)) + 0.5;
113 k = find(x < -xbreak);
114 result(k) = (-0.5 + result(k)) - 0.5;
115 elseif jint == 1
116 k = find(x < -xbreak);
117 result(k) = 2. - result(k);
118 else % jint must = 2
119 k = find(x < -xbreak);
120 z = fix(x(k)*16)/16;
121 del = (x(k)-z).*(x(k)+z);
122 y = exp(z.*z) .* exp(del);
123 result(k) = (y+y) - result(k);
124 end
125
126
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/true_loc.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/true_loc.m
new file mode 100755
index 0000000..7bf060f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/true_loc.m
@@ -0,0 +1,23 @@
1function a = true_loc(loca,g,scale);
2
3if ~exist('scale'),
4 scale = 50;
5end
6
7y = loca(1,:);
8x = loca(2,:);
9
10min_x = min(x);
11min_y = min(y);
12
13x = x - min_x;
14y = y - min_y;
15
16max_x = max(x);max_y = max(y);
17min_scale = min(max_x,max_y);
18
19a(1) = (g(1)-1)*min_scale/(scale);
20a(2) = (g(2)-1)*min_scale/(scale);
21
22a(1) = a(1) + min_x;
23a(2) = a(2) + min_y;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/vmquant.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/vmquant.m
new file mode 100755
index 0000000..ab4eb28
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/vmquant.m
@@ -0,0 +1,112 @@
1function [im, map] = vmquant(arg1,arg2,arg3,arg4,arg5,arg6,arg7)
2%VMQUANT Variance Minimization Color Quantization.
3% [X, MAP] = VMQUANT(R,G,B,K,[Qr Qg Qb],DITHER,Qe) or
4% VMQUANT(RGB,K,[Qr Qg Qb],DITHER,Qe), where RGB is a 3-D array,
5% converts an arbitrary image comprised of RGB triples into an
6% indexed image X with color map MAP. K specifies the number
7% of desired entries in the target color map, and [Qr Qg Qb]
8% specifies the number of quantization bits to assign each color
9% axis during color interpolation. DITHER is a string ('dither' or
10% 'nodither') that indicates whether or not to perform error propagation
11% dither on the output image. Qe specifies the number of bits of
12% quantization used in the error calculations.
13%
14% K is optional and defaults to 256.
15% [Qr Qg Qb] is optional and defaults to [5 5 5].
16% DITHER is optional and defaults to 'nodither'.
17% Qe is optional and defaults to 8.
18%
19% See also: RGB2IND, RGB2GRAY, DITHER, IND2RGB, CMUNIQUE, IMAPPROX.
20
21% This is the wrapper function for the MEX file VMQUANTC.C
22
23% Joseph M. Winograd 6-93
24% Copyright (c) 1993 by The MathWorks, Inc.
25% $Revision: 5.3 $ $Date: 1996/08/22 22:09:03 $
26
27% Reference: Xiaolin Wu, "Efficient Statistical Computation for
28% Optimal Color Quantization," Graphics Gems II, (ed. James
29% Arvo). Academic Press: Boston. 1991.
30
31if nargin < 1,
32 error('Not enough input arguments.');
33end
34
35threeD = (ndims(arg1)==3); % Determine if input includes a 3-D array
36
37if threeD,
38 error( nargchk( 1, 5, nargin ) );
39
40 % NOTE: If you change defaults, change them also
41 % in VMQUANTC.C and recompile the MEX function.
42 if nargin < 5
43 arg5 = 8; % DEFAULT_QE = 8
44 end
45
46 if nargin < 4
47 arg4 = 'n'; % DEFAULT_DITHER = 0
48 end
49
50 if nargin < 3
51 arg3 = [5 5 5]; % DEFAULT_Q = [5 5 5]
52 end
53
54 if nargin < 2
55 arg2 = 256; % DEFAULT_K = 256
56 end
57
58 rout = arg1(:,:,1);
59 g = arg1(:,:,2);
60 b = arg1(:,:,3);
61
62 if strcmp(lower(arg4(1)),'d')
63 dith = 1;
64 else
65 dith = 0;
66 end
67
68 arg7 = arg5;
69 arg5 = arg3;
70 arg4 = arg2;
71
72else
73 error( nargchk( 3, 7, nargin ) );
74
75 if nargin < 7
76 arg7 = 8; % DEFAULT_QE = 8
77 end
78
79 if nargin < 6
80 arg6 = 'n'; % DEFAULT_DITHER = 0
81 end
82
83 if nargin < 5
84 arg5 = [5 5 5]; % DEFAULT_Q = [5 5 5]
85 end
86
87 if nargin < 4
88 arg4 = 256; % DEFAULT_K = 256
89 end
90
91 rout = arg1;
92 g = arg2;
93 b = arg3;
94
95 if strcmp(lower(arg6(1)),'d')
96 dith = 1;
97 else
98 dith = 0;
99 end
100
101end
102
103if (~isa(rout,'uint8'))
104 rout = uint8(round(255*rout));
105end
106if (~isa(g,'uint8'))
107 g = uint8(round(255*g));
108end
109if (~isa(b,'uint8'))
110 b = uint8(round(255*b));
111end
112[im,map] = vmquantc( rout, g, b, arg4, arg5, dith, arg7 );
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm.m
new file mode 100755
index 0000000..915e07d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm.m
@@ -0,0 +1,26 @@
1function [L1,L2,phi,Txx,Txy,Tyy]=wismm(X,N);
2% [L1,L2,phi,T11,T12,T22]=wismm(X,N);
3% Calculate windowed image second moment matrices for image X and return
4% the following values:
5%
6% L1 is the larger eigenvalue (lambda_1)
7% L2 is the smaller eigenvalue (lambda_2)
8% phi is the angle of the 1st eigenvector (phi)
9
10[G1,G2]=gradient(X);
11
12GGTxx=G1.^2;
13GGTxy=G1.*G2;
14GGTyy=G2.^2;
15
16Txx=gaussN(GGTxx,N);
17Txy=gaussN(GGTxy,N);
18Tyy=gaussN(GGTyy,N);
19
20tr=Txx+Tyy;
21V1=0.5*sqrt(tr.^2-4*(Txx.*Tyy-Txy.^2));
22
23L1=real(0.5*tr+V1);
24L2=real(0.5*tr-V1);
25phi=0.5*atan2(2*Txy,Txx-Tyy);
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm2.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm2.m
new file mode 100755
index 0000000..ae62ce9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm2.m
@@ -0,0 +1,66 @@
1function [L1,L2,phi,aniso,pol,con,window_sizes]=wismm2(V);
2% [L1,L2,phi,aniso,pol,con,window_sizes]=wismm2(V);
3% Calculate windowed image second moment matrices for image V and return
4% the following values:
5%
6% L1 is the larger eigenvalue (lambda_1)
7% L2 is the smaller eigenvalue (lambda_2)
8% phi is the angle of the 1st eigenvector (phi)
9%
10
11[Gx,Gy]=gradient(V);
12
13GGTxx=Gx.^2;
14GGTxy=Gx.*Gy;
15GGTyy=Gy.^2;
16
17[r,c]=size(V);
18
19min_window_size=3;
20max_window_size=3*round(min(r,c)/16);
21if (-1)^max_window_size==1
22 max_window_size=max_window_size+1;
23end
24window_step_size=2;
25
26window_sizes=min_window_size:2:max_window_size;
27max_count=length(window_sizes);
28
29L1=zeros(r,c,max_count);
30L2=zeros(r,c,max_count);
31phi=zeros(r,c,max_count);
32pol=zeros(r,c,max_count);
33con=zeros(r,c,max_count);
34
35fprintf(1,'Integration window size: ');
36counter=1;
37for n=window_sizes
38 fprintf(1,'%d ',n);
39 Txx=gaussN(GGTxx,n);
40 Txy=gaussN(GGTxy,n);
41 Tyy=gaussN(GGTyy,n);
42
43 tr=Txx+Tyy;
44 V1=0.5*sqrt(tr.^2-4*(Txx.*Tyy-Txy.^2));
45 V1=real(V1);
46
47 L1(:,:,counter)=0.5*tr+V1;
48 L2(:,:,counter)=0.5*tr-V1;
49 phi(:,:,counter)=0.5*atan2(2*Txy,Txx-Tyy);
50
51 % do polarity stuff here
52 grad_smooth_x=gaussN(Gx,n);
53 grad_smooth_y=gaussN(Gy,n);
54 grad_smooth_mag=sqrt(grad_smooth_x.^2+grad_smooth_y.^2);
55 grad_mag=sqrt(Gx.^2+Gy.^2);
56 grad_mag_smooth=gaussN(grad_mag,n);
57 pol(:,:,counter)=grad_smooth_mag./(grad_mag_smooth+eps);
58
59 % contrast calculation
60 con(:,:,counter)=tr;
61 counter=counter+1;
62end
63fprintf(1,'\n')
64
65aniso=1-L2./(L1+eps);
66
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm3.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm3.m
new file mode 100755
index 0000000..89c56ef
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/wismm3.m
@@ -0,0 +1,71 @@
1function [L1,L2,phi,aniso,pol,con,window_sizes]=wismm3(V);
2% [L1,L2,phi,aniso,pol,con,window_sizes]=wismm3(V);
3% Calculate windowed image second moment matrices for image V and return
4% the following values:
5%
6% L1 is the larger eigenvalue (lambda_1)
7% L2 is the smaller eigenvalue (lambda_2)
8% phi is the angle of the 1st eigenvector (phi)
9%
10
11[Gx,Gy]=gradient(V);
12
13GGTxx=Gx.^2;
14GGTxy=Gx.*Gy;
15GGTyy=Gy.^2;
16
17[r,c]=size(V);
18
19min_window_size=3;
20max_window_size=3*round(min(r,c)/16);
21if (-1)^max_window_size==1
22 max_window_size=max_window_size+1;
23end
24window_step_size=2;
25
26window_sizes=min_window_size:2:max_window_size;
27max_count=length(window_sizes);
28
29L1=zeros(r,c,max_count);
30L2=zeros(r,c,max_count);
31phi=zeros(r,c,max_count);
32pol=zeros(r,c,max_count);
33con=zeros(r,c,max_count);
34
35fprintf(1,'Integration window size: ');
36counter=1;
37for n=window_sizes
38 fprintf(1,'%d ',n);
39 Txx=gaussN(GGTxx,n);
40 Txy=gaussN(GGTxy,n);
41 Tyy=gaussN(GGTyy,n);
42
43 tr=Txx+Tyy;
44 V1=0.5*sqrt(tr.^2-4*(Txx.*Tyy-Txy.^2));
45 V1=real(V1);
46
47 L1(:,:,counter)=0.5*tr+V1;
48 L2(:,:,counter)=0.5*tr-V1;
49 phi(:,:,counter)=0.5*atan2(2*Txy,Txx-Tyy);
50
51 % do polarity stuff here
52 [P,angle_vector]=polarity(Gx,Gy,n);
53 quant_bound=angle_vector(2)/2;
54 % (quantize angle and pull corresponding polarity out of P)
55 % (perhaps use set-theoretic functions for masking out P???)
56 for m=1:length(angle_vector);
57 a=angle_vector(end-m+1);
58 old_pol=pol(:,:,counter);
59 Pmask=abs(cos(phi(:,:,counter)-a))>=cos(quant_bound);
60 Pmask=Pmask&(old_pol==0); % prevent pileup on quant. boundaries
61 pol(:,:,counter)=old_pol+(Pmask.*P(:,:,m));
62 end
63
64 % contrast calculation
65 con(:,:,counter)=tr;
66 counter=counter+1;
67end
68fprintf(1,'\n')
69
70aniso=1-L2./(L1+eps);
71
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_command.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_command.m
new file mode 100755
index 0000000..954a39e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_command.m
@@ -0,0 +1,8 @@
1function write_command(fname,fn_base,para)
2
3fid = fopen(fname,'w');
4
5fprintf(fid,'%s ',fn_base);
6fprintf(fid,'%d ',para);
7fprintf(fid,'\nrun\n');
8fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_test.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_test.m
new file mode 100755
index 0000000..e444c27
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/write_test.m
@@ -0,0 +1,38 @@
1
2I_max = 250;
3tex_max = 30;
4
5%fnames = [130038,130039,130042,130056,130057];
6%fnames = [334074 334031 334044 334003 334065 334000 334039 334018 334002 334029]
7
8fnames = 130057;
9
10for j=1:length(fnames),
11fname = sprintf('images/%d.pgm',fnames(j));
12
13sigs = [1/sqrt(2),1,sqrt(2),2,2*sqrt(2)];r = 3;szs = round(r*3*sigs);
14szs = szs(length(szs))*ones(1,length(szs));
15num_ori = 6;
16
17I = readpgm(fname);
18[text_des,filters] = compute_filter_fft(I,sigs,r,szs,num_ori);
19
20outname = sprintf('plaatje_data/%d',fnames(j));
21
22cutsz =20;
23I = cutoff(I,cutsz);%figure(1);im(I);
24text_des = cutoff(text_des,cutsz);
25
26writeout_feature(I,text_des(:,:,:),outname,I_max,tex_max);
27
28
29if 0,
30for j=0:30,
31 cm = sprintf('!mv plaatje_data/134013.pfm_%d.pfm plaatje_data/134013_%d.pfm',j,j);
32 disp(cm);eval(cm);
33end
34end
35
36end
37
38exit
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writeout_feature.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writeout_feature.m
new file mode 100755
index 0000000..5376d5f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writeout_feature.m
@@ -0,0 +1,40 @@
1function writeout_feature(I,tex,fname,I_max,tex_max)
2%
3% writeout_feature(I,tex,fname,I_max,tex_max)
4%
5%
6
7
8%%%%% print out image
9I_min = min(I(:));
10
11I = I-I_min;
12I = min(1,I/(I_max-I_min));
13
14I = 2*I-1;
15
16j = 0;
17fn = sprintf('%s_%d.pfm',fname,j);
18cm = sprintf('writepfm: I->%s',fn);
19disp(cm);
20writepfm(fn,I);
21
22
23%%% print out texture
24nf = size(tex,3)
25
26for j=1:nf,
27
28 fn = sprintf('%s_%d.pfm',fname,j);
29 cm = sprintf('writepfm:tex_%d->%s',j,fn);
30 disp(cm);
31
32tex(:,:,j) = tex(:,:,j)/tex_max;fprintf('.');
33tex(:,:,j) = tex(:,:,j).*(tex(:,:,j)<=1) + 1*(tex(:,:,j)>1);fprintf('.')
34tex(:,:,j) = tex(:,:,j).*(tex(:,:,j)>=-1) + (-1)*(tex(:,:,j)<-1);fprintf('.');
35
36 writepfm(fn,tex(:,:,j));
37
38
39end
40
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepfm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepfm.m
new file mode 100755
index 0000000..a831970
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepfm.m
@@ -0,0 +1,11 @@
1function writepfm(name,I)
2%
3% writepfm(name,I)
4%
5 [nr,nc] = size(I);
6
7 fid = fopen(name, 'w');
8 fprintf(fid, '%d %d\n', nr,nc);
9 fprintf(fid,'%f ',I);
10 fclose(fid);
11
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepgm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepgm.m
new file mode 100755
index 0000000..113cb18
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepgm.m
@@ -0,0 +1,8 @@
1function I = writepgm(name,I)
2
3 [y,x] = size(I);
4
5 fid = fopen(name, 'w');
6 fprintf(fid, 'P5\n%d %d\n255\n', x,y);
7 fwrite(fid, I', 'uint8');
8 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepmm.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepmm.m
new file mode 100755
index 0000000..675df93
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepmm.m
@@ -0,0 +1,14 @@
1function writepmm(name,I)
2%
3% writepmm(name,I)
4%
5
6 [nr,nc,nb] = size(I);
7
8 fid = fopen(name,'w');
9
10 fprintf(fid, 'P5\n%d %d %d\n255\n', nc,nr,nb);
11
12 fprintf(fid,'%f ',I);
13 fclose(fid);
14
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepnm5.m b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepnm5.m
new file mode 100755
index 0000000..633fba9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filter_hist/writepnm5.m
@@ -0,0 +1,26 @@
1function writepnm5(name,I)
2%
3% writepnm5(name,I)
4%
5% I is a mul-band image
6%
7
8 [nr,nc,nb] = size(I);
9
10 fid = fopen(name,'w');
11
12 fprintf(fid, 'P5\n%d %d %d\n255\n', nc,nr,nb);
13
14 n = nr*nc;
15
16 J = [];
17
18 for j=1:nb,
19 J = [J,reshape(I(:,:,j)',n,1)];
20 end
21
22 J = reshape(J',nb*n,1);
23
24 fprintf(fid,'%f ',J);
25 fclose(fid);
26
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog1.m b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog1.m
new file mode 100755
index 0000000..dd8e87b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog1.m
@@ -0,0 +1,32 @@
1function H=doog1(sig,r,th,N);
2% H=doog1(sig,r,th,N);
3
4
5% by Serge Belongie
6
7no_pts=N; % no. of points in x,y grid
8
9[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
10
11phi=pi*th/180;
12sigy=sig;
13sigx=r*sig;
14R=[cos(phi) -sin(phi); sin(phi) cos(phi)];
15C=R*diag([sigx,sigy])*R';
16
17X=[x(:) y(:)];
18
19Gb=gaussian(X,[0 0]',C);
20Gb=reshape(Gb,N,N);
21
22m=R*[0 sig]';
23
24a=1;
25b=-1;
26
27% make odd-symmetric filter
28Ga=gaussian(X,m/2,C);
29Ga=reshape(Ga,N,N);
30Gb=rot90(Ga,2);
31H=a*Ga+b*Gb;
32
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog2.m b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog2.m
new file mode 100755
index 0000000..a0511cb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/doog2.m
@@ -0,0 +1,38 @@
1function G=doog2(sig,r,th,N);
2% G=doog2(sig,r,th,N);
3% Make difference of offset gaussians kernel
4% theta is in degrees
5% (see Malik & Perona, J. Opt. Soc. Amer., 1990)
6%
7% Example:
8% >> imagesc(doog2(1,12,0,64,1))
9% >> colormap(gray)
10
11% by Serge Belongie
12
13no_pts=N; % no. of points in x,y grid
14
15[x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2);
16
17phi=pi*th/180;
18sigy=sig;
19sigx=r*sig;
20R=[cos(phi) -sin(phi); sin(phi) cos(phi)];
21C=R*diag([sigx,sigy])*R';
22
23X=[x(:) y(:)];
24
25Gb=gaussian(X,[0 0]',C);
26Gb=reshape(Gb,N,N);
27
28m=R*[0 sig]';
29Ga=gaussian(X,m,C);
30Ga=reshape(Ga,N,N);
31Gc=rot90(Ga,2);
32
33a=-1;
34b=2;
35c=-1;
36
37G = a*Ga + b*Gb + c*Gc;
38
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_even2.m b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_even2.m
new file mode 100755
index 0000000..f7f4527
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_even2.m
@@ -0,0 +1,45 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz,enlong)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6if nargin<4,
7 enlong = 3;
8end
9
10enlong = 2*enlong;
11
12% definine filterbank
13%num_ori=6;
14%num_scale=3;
15
16num_scale = length(filter_scales);
17
18M1=wsz; % size in pixels
19M2=M1;
20
21ori_incr=180/num_ori;
22ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
23
24FB=zeros(M1,M2,num_ori,num_scale);
25
26% elongated filter set
27counter = 1;
28
29for m=1:num_scale
30 for n=1:num_ori
31 % r=12 here is equivalent to Malik's r=3;
32 f=doog2(filter_scales(m),enlong,ori_offset+(n-1)*ori_incr,M1);
33 FB(:,:,n,m)=f;
34 end
35end
36
37FB=reshape(FB,M1,M2,num_scale*num_ori);
38total_num_filt=size(FB,3);
39
40for j=1:total_num_filt,
41 F = FB(:,:,j);
42 a = sum(sum(abs(F)));
43 FB(:,:,j) = FB(:,:,j)/a;
44end
45
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_odd2.m b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_odd2.m
new file mode 100755
index 0000000..0059dca
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/make_filterbank_odd2.m
@@ -0,0 +1,46 @@
1function FB = make_filterbank(num_ori,filter_scales,wsz,enlong)
2%
3% F = make_filterbank(num_ori,num_scale,wsz)
4%
5
6if nargin<4,
7 enlong = 3;
8end
9
10enlong = enlong*2;
11
12% definine filterbank
13%num_ori=6;
14%num_scale=3;
15
16num_scale = length(filter_scales);
17
18M1=wsz; % size in pixels
19M2=M1;
20
21ori_incr=180/num_ori;
22ori_offset=ori_incr/2; % helps with equalizing quantiz. error across filter set
23
24FB=zeros(M1,M2,num_ori,num_scale);
25
26
27% elongated filter set
28counter = 1;
29
30for m=1:num_scale
31 for n=1:num_ori
32 % r=12 here is equivalent to Malik's r=3;
33 f=doog1(filter_scales(m),enlong,ori_offset+(n-1)*ori_incr,M1);
34 FB(:,:,n,m)=f;
35 end
36end
37
38FB=reshape(FB,M1,M2,num_scale*num_ori);
39total_num_filt=size(FB,3);
40
41for j=1:total_num_filt,
42 F = FB(:,:,j);
43 a = sum(sum(abs(F)));
44 FB(:,:,j) = FB(:,:,j)/a;
45end
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/quadedgep2.m b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/quadedgep2.m
new file mode 100755
index 0000000..5041377
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/filtersQuad/quadedgep2.m
@@ -0,0 +1,188 @@
1% function [xs,ys,gx,gy,par,threshold,mag,mage,g,FIe,FIo,mago] = quadedgep(I,par,threshold);
2% Input:
3% I = image
4% par = vector for 4 parameters
5% [number of filter orientations, number of scale, filter size, elongation]
6% To use default values, put 0.
7% threshold = threshold on edge strength
8% Output:
9% [x,y,gx,gy] = locations and gradients of an ordered list of edgels
10% x,y could be horizontal or vertical or 45 between pixel sites
11% but it is guaranteed that there [floor(y) + (floor(x)-1)*nr]
12% is ordered and unique. In other words, each edgel has a unique pixel id.
13% par = actual par used
14% threshold = actual threshold used
15% mag = edge magnitude
16% mage = phase map
17% g = gradient map at each pixel
18% [FIe,FIo] = odd and even filter outputs
19% mago = odd filter output of optimum orientation
20
21% Stella X. Yu, 2001
22
23% This is the multi scale version of the filtering
24% For the moment the parameters are defined by default. See line 34
25
26
27function [x,y,gx,gy,par,threshold,mag_s,mage,g,FIe,FIo,mago] = quadedgep2(I,par,data,threshold);
28
29
30if nargin<4 | isempty(threshold),
31 threshold = 0.1;
32end
33
34[r,c] = size(I);
35def_par = [4,30,3];
36
37display_on = 1;
38
39% take care of parameters, any missing value is substituted by a default value
40if nargin<2 | isempty(par),
41 par = def_par;
42end
43% par(end+1:4)=0;
44% par = par(:);
45% j = (par>0);
46% have_value = [ j, 1-j ];
47% j = 1; n_filter = have_value(j,:) * [par(j); def_par(j)];
48% j = 2; n_scale = have_value(j,:) * [par(j); def_par(j)];
49% j = 3; winsz = have_value(j,:) * [par(j); def_par(j)];
50% j = 4; enlong = have_value(j,:) * [par(j); def_par(j)];
51
52n_ori = par(1); %if it doesn't work, par<-def_par
53
54winsz = par(2);
55enlong = par(3);
56
57% always make filter size an odd number so that the results will not be skewed
58j = winsz/2;
59if not(j > fix(j) + 0.1),
60 winsz = winsz + 1;
61end
62
63% filter the image with quadrature filters
64if (isempty(data.W.scales))
65 error ('no scales entered');
66end
67
68n_scale=length(data.W.scales);
69filter_scales=data.W.scales;
70%
71% if strcmp(data.dataWpp.mode,'multiscale')
72% n_scale=size((data.dataWpp.scales),2);
73% filter_scales=data.dataWpp.scales;
74% else
75% filter_scales=data.dataWpp.scales(1);
76% n_scale=1;
77% end
78% if n_scale>0&&strcmp(data.dataWpp.mode,'multiscale')
79% if (~isempty(data.dataWpp.scales))
80% filter_scales=data.dataWpp.scales;
81% else
82% filter_scales=zeros(1,n_scale);
83%
84% for i=1:n_scale,
85% filter_scales(i)=(sqrt(2))^(i-1);
86% end
87% data.dataWpp.scales=filter_scales;
88% end
89% else filter_scale=1;
90% data.dataWpp.scales=filter_scales;
91% end
92%
93% %%%%%%% juste pour que ca tourne
94% if ~strcmp(data.dataWpp.mode,'multiscale')
95% filter_scales=data.dataWpp.scales(1);
96% n_scale=4;
97% end
98% %%%%%%%%%%%%
99
100FBo = make_filterbank_odd2(n_ori,filter_scales,winsz,enlong);
101FBe = make_filterbank_even2(n_ori,filter_scales,winsz,enlong);
102n = ceil(winsz/2);
103f = [fliplr(I(:,2:n+1)), I, fliplr(I(:,c-n:c-1))];
104f = [flipud(f(2:n+1,:)); f; flipud(f(r-n:r-1,:))];
105FIo = fft_filt_2(f,FBo,1);
106FIo = FIo(n+[1:r],n+[1:c],:);
107FIe = fft_filt_2(f,FBe,1);
108FIe = FIe(n+[1:r],n+[1:c],:);
109
110% compute the orientation energy and recover a smooth edge map
111% pick up the maximum energy across scale and orientation
112% even filter's output: as it is the second derivative, zero cross localize the edge
113% odd filter's output: orientation
114
115[nr,nc,nb] = size(FIe);
116
117FIe = reshape(FIe, nr,nc,n_ori,length(filter_scales));
118FIo = reshape(FIo, nr,nc,n_ori,length(filter_scales));
119
120mag_s = zeros(nr,nc,n_scale);
121mag_a = zeros(nr,nc,n_ori);
122
123mage = zeros(nr,nc,n_scale);
124mago = zeros(nr,nc,n_scale);
125mage = zeros(nr,nc,n_scale);
126mago = zeros(nr,nc,n_scale);
127
128
129
130for i = 1:n_scale,
131 mag_s(:,:,i) = sqrt(sum(FIo(:,:,:,i).^2,3)+sum(FIe(:,:,:,i).^2,3));
132 mag_a = sqrt(FIo(:,:,:,i).^2+FIe(:,:,:,i).^2);
133 [tmp,max_id] = max(mag_a,[],3);
134
135 base_size = nr * nc;
136 id = [1:base_size]';
137 mage(:,:,i) = reshape(FIe(id+(max_id(:)-1)*base_size+(i-1)*base_size*n_ori),[nr,nc]);
138 mago(:,:,i) = reshape(FIo(id+(max_id(:)-1)*base_size+(i-1)*base_size*n_ori),[nr,nc]);
139
140 mage(:,:,i) = (mage(:,:,i)>0) - (mage(:,:,i)<0);
141
142 if display_on,
143 ori_incr=pi/n_ori; % to convert jshi's coords to conventional image xy
144 ori_offset=ori_incr/2;
145 theta = ori_offset+([1:n_ori]-1)*ori_incr; % orientation detectors
146 % [gx,gy] are image gradient in image xy coords, winner take all
147
148 ori = theta(max_id);
149 ori = ori .* (mago(:,:,i)>0) + (ori + pi).*(mago(:,:,i)<0);
150 gy{i} = mag_s(:,:,i) .* cos(ori);
151 gx{i} = -mag_s(:,:,i) .* sin(ori);
152 g = cat(3,gx{i},gy{i});
153
154 % phase map: edges are where the phase changes
155 mag_th = max(max(mag_s(:,:,i))) * threshold;
156 eg = (mag_s(:,:,i)>mag_th);
157 h = eg & [(mage(2:r,:,i) ~= mage(1:r-1,:,i)); zeros(1,nc)];
158 v = eg & [(mage(:,2:c,i) ~= mage(:,1:c-1,i)), zeros(nr,1)];
159 [y{i},x{i}] = find(h | v);
160 k = y{i} + (x{i}-1) * nr;
161 h = h(k);
162 v = v(k);
163 y{i} = y{i} + h * 0.5; % i
164 x{i} = x{i} + v * 0.5; % j
165 t = h + v * nr;
166 gx{i} = g(k) + g(k+t);
167 k = k + (nr * nc);
168 gy{i} = g(k) + g(k+t);
169
170% figure(1);
171% clf;
172% imagesc(I);colormap(gray);
173% hold on;
174% quiver(x,y,gx,gy); hold off;
175% title(sprintf('scale = %d, press return',i));
176
177 % pause;
178 0;
179else
180 x = [];
181 y = [];
182 gx = [];
183 gy =[];
184 g= [];
185 end
186end
187
188
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m b/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m
new file mode 100755
index 0000000..919e82e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/convert422.m
@@ -0,0 +1,27 @@
1image_current = '/hid/jshi';
2
3image_dir = 'vr05_5 ';
4pg_path = '/hid/jshi/422toppm/422toppm';
5
6cm = sprintf('cd %s',image_dir);
7disp(cm);
8eval(cm);
9
10d = dir('seq*');
11filename = char(sort({d.name}));
12
13for j=1:size(filename),
14 cm = sprintf('!%s %s',pg_path,deblank(filename(j,:)));
15disp(cm);
16eval(cm);
17end
18
19
20%%% change back
21cm = sprintf('cd %s',image_current);
22disp(cm);eval(cm);
23
24
25if 0,
26 deblank(filename(f,:));
27end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m b/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m
new file mode 100755
index 0000000..590cd9b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/im_vd.m
@@ -0,0 +1,6 @@
1function J = im_vd(I);
2
3J(:,:,1) = I(1:2:end,1:2:end);
4J(:,:,2) = I(2:2:end,1:2:end);
5
6montage2(J);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m b/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m
new file mode 100755
index 0000000..27a5e4b
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/imread2.m
@@ -0,0 +1,45 @@
1function I = imread2(fname,im_dir);
2%
3% I = imread2(fname,im_dir);
4%
5
6cur_dir = pwd;
7
8if nargin>1,
9 cd(im_dir);
10end
11
12%%% put on the necessary extension
13d = dir(fname);
14
15if isempty(d),
16 d = dir([fname,'*']);
17end
18
19if isempty(d),
20 I = [];
21else
22
23 fname = d.name;
24
25 %%% find extension
26 k = findstr(fname,'.');
27 ext = fname(k(end)+1:end);
28
29 if (ext == 'bz2'),
30 cm = sprintf('!bzip2 -d %s',fname);
31 disp(cm);eval(cm);
32 I = imread2(fname(1:k(end-1)-1));
33 cm = sprintf('!bzip2 %s',fname(1:k(end)-1));
34 disp(cm);eval(cm);
35 elseif (ext == 'ppm');
36 I = readppm(fname);
37 elseif (ext == 'pgm');
38 I = readpgm(fname);
39 else
40 I = imread(fname);
41I = double(I)/255;
42 end
43end
44
45cd(cur_dir);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m b/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m
new file mode 100755
index 0000000..13e54cd
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/peek_pgm_size.m
@@ -0,0 +1,19 @@
1function [nr,nc] = peek_pgm_size(filename)
2% function [nr,nc] = peek_pgm_size(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7
8fid = fopen(filename,'r');
9fscanf(fid, 'P5\n');
10cmt = '#';
11while findstr(cmt, '#'),
12 cmt = fgets(fid);
13 if length(findstr(cmt, '#')) ~= 1,
14 YX = sscanf(cmt, '%d %d');
15 nc = YX(1); nr = YX(2);
16 end
17end
18
19fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m b/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m
new file mode 100755
index 0000000..49a35a8
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/pgmread.m
@@ -0,0 +1,24 @@
1function [img,header] = pgmread(filename)
2%
3% [img,header] = pgmread(filename)
4
5[fid, msg] = fopen(filename, 'r');
6if fid == -1,
7 error(msg)
8end
9
10head = [];
11good = 0;
12while (good == 0) ,
13 l = fgetl(fid);
14 if (length(l) == 3),
15 if (l == '255'),
16 good = 1;
17 sze = sscanf(header,'%d');
18 end
19 end
20 header= l;
21end
22
23img = fread(fid, sze', 'uchar')';
24fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m b/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m
new file mode 100755
index 0000000..ce47e45
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/ppmtojpg.m
@@ -0,0 +1,25 @@
1function []= ppm2jpg(fname,dlm,ori)
2%
3% ppm2jpg(fname,dlm,ori)
4%
5% dlm =1, remove the file extension from fname
6% before convert
7% ori =1, transpose the image
8%
9
10if dlm,
11 dlm = findstr(fname,'.');
12 fname = fname(1:dlm(end)-1);
13end
14
15fname_1 = sprintf('%s.ppm',fname);
16I = readppm(fname_1);
17
18if ori == 1,
19 I = permute(I,[2 1 3]);
20end
21
22
23fname_2 = sprintf('%s.jpg',fname);
24imwrite(I,fname_2,'jpeg','Quality',90);
25
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read422.m b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m
new file mode 100755
index 0000000..31a27f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m
@@ -0,0 +1,45 @@
1function I = read422(fname,nc);
2%
3% I = read422(fname,width);
4%
5% read in a .422 file, need to pass image width, default = 640
6%
7
8% assume image width = 640
9if nargin<2,
10 nc = 640;
11end
12
13%% find the image size
14fid = fopen(fname);
15fseek(fid,0,1);
16fsize = ftell(fid);
17
18nr = fsize/nc/2;
19fseek(fid,0,-1);
20
21%% read in Ybr data
22data = fread(fid,fsize,'uchar');
23
24%%% extract Y, Cb, Cr
25Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)';
26Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)';
27Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)';
28
29Cb = zeros(size(Y1));
30Cr = zeros(size(Y1));
31
32Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1;
33%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]);
34
35Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1;
36%Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]);
37
38%%% convert to r,g,b
39r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0);
40g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0);
41b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0);
42
43I = cat(3,r,g,b);
44I = max(0,min(I,255));
45I = I/255;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m b/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m
new file mode 100755
index 0000000..0063000
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read422f.m
@@ -0,0 +1,50 @@
1function I = read422(fname,nc);
2%
3% I = read422(fname,width);
4%
5% read in a .422 file, need to pass image width, default = 640
6%
7
8% assume image width = 640
9if nargin<2,
10 nc = 640;
11end
12
13%% find the image size
14fid = fopen(fname);
15fseek(fid,0,1);
16fsize = ftell(fid);
17
18nr = fsize/nc/2;
19
20fseek(fid,0,-1);
21
22%% read in Ybr data
23data = fread(fid,fsize,'uchar');
24
25%%% extract Y, Cb, Cr
26Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)';
27Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)';
28Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)';
29
30Cb = zeros(size(Y1));
31Cr = zeros(size(Y1));
32
33Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1;
34%Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]);
35
36Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1;
37%Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]);
38
39%%% convert to r,g,b
40r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0);
41g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0);
42b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0);
43
44r = flipud(max(0,min(r,255)));
45g = flipud(max(0,min(g,255)));
46b = flipud(max(0,min(b,255)));
47
48I = cat(3,r,g,b);
49
50I = permute(I/255,[2,1,3]);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m
new file mode 100755
index 0000000..d5df7f5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_cimgs.m
@@ -0,0 +1,40 @@
1function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img)
2%
3% Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img)
4%
5
6
7
8command = ['%s%s%s%.',num2str(digits),'d%s'];
9
10fname = sprintf(command,homedir,imgdir,prename,startid,postname);
11disp(fname);
12if (strcmp('.ppm',postname)),
13 I1 = readppm(fname);
14else
15 I1 = imread(fname);
16end
17
18
19Is = zeros(size(I1,1),size(I1,2),size(I1,3),1+floor((endid-startid)/step_img));
20Is(:,:,:,1) = I1;
21im_id = 1;
22for j = startid+step_img:step_img:endid,
23 command = ['%s%s%s%.',num2str(digits),'d%s'];
24 fname = sprintf(command,homedir,imgdir,prename,j,postname);
25 disp(fname);
26 im_id = im_id+1;
27
28 if (strcmp('.ppm',postname)),
29 Is(:,:,:,im_id) = readppm(fname);
30 else
31 a = imread(fname);
32 Is(:,:,:,im_id) = a;
33 end
34end
35
36
37
38
39
40
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m
new file mode 100755
index 0000000..3f7b69d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm.m
@@ -0,0 +1,26 @@
1function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs)
2%
3% evs = read_ev_pgm(basename,start_id,end_id,neigs)
4%
5%
6
7fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1)
8[nr,nc] = peek_pgm_size(fname);
9
10evs = zeros(nr,nc,neigs-1,start_id-end_id+1);
11ev_info = zeros(4,neigs-1,start_id-end_id+1);
12
13for j=start_id:end_id,
14 for k=1:neigs-1,
15
16 fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k);
17 [I,info] = readpgm_evinfo(fname);
18
19 if (length(info)<4)
20 info = [0;0;0;0];
21 end
22
23 evs(:,:,k,j-start_id+1) = I;
24 ev_info(:,k,j-start_id+1) = info';
25 end
26end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m
new file mode 100755
index 0000000..b0cc3f9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm2.m
@@ -0,0 +1,29 @@
1function [evs,ev_info] = read_ev_pgm2(basename,start_id,end_id,neigs)
2%
3% evs = read_ev_pgm(basename,start_id,end_id,neigs)
4%
5% read_ev_pgm.m modified by SXY in Feb. 2001.
6% The first eigenvector is also included
7
8fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1)
9[nr,nc] = peek_pgm_size(fname);
10
11evs = zeros(nr,nc,neigs,start_id-end_id+1);
12ev_info = zeros(4,neigs,start_id-end_id+1);
13
14for j=start_id:end_id,
15
16 for k=1:neigs,
17
18 fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1);
19
20 [I,info] = readpgm_evinfo(fname);
21
22 if (length(info)<4)
23 info = [0;0;0;0];
24 end
25
26 evs(:,:,k,j-start_id+1) = I;
27 ev_info(:,k,j-start_id+1) = info';
28 end
29end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m
new file mode 100755
index 0000000..d985679
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_ev_pgm_real.m
@@ -0,0 +1,30 @@
1function [evs,ev_info] = read_ev_pgm(basename,start_id,end_id,neigs)
2%
3% evs = read_ev_pgm(basename,start_id,end_id,neigs)
4%
5%
6
7fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,start_id,1);
8[nr,nc] = peek_pgm_size(fname);
9
10evs = zeros(nr,nc,neigs-1,start_id-end_id+1);
11ev_info = zeros(4,neigs-1,start_id-end_id+1);
12
13for j=start_id:end_id,
14 for k=1:neigs,
15
16 fname = sprintf('%s_ev_%.2d.%.2d.pgm',basename,j,k-1);
17 [I,info] = readpgm_evinfo(fname);
18
19 evs(:,:,k,j-start_id+1) = I;
20 ev_info(:,k,j-start_id+1) = info';
21 end
22end
23
24evs = squeeze(evs);
25
26for j=1:neigs,
27 evs(:,:,j) = (evs(:,:,j)/ev_info(3,j)) +ev_info(1,j);
28 %evs(:,:,j) = evs(:,:,j)/norm(reshape(evs(:,:,j),nr*nc,1));
29end
30
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m
new file mode 100755
index 0000000..f84486c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_imgs.m
@@ -0,0 +1,47 @@
1function Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img)
2%
3% Is = read_imgs(homedir,imgdir,prename,postname,digits,startid,endid,step_img)
4%
5
6
7
8command = ['%s%s%s%.',num2str(digits),'d%s'];
9
10fname = sprintf(command,homedir,imgdir,prename,startid,postname);
11disp(fname);
12if (strcmp('.pgm',postname)),
13 I1 = readpgm(fname);
14elseif (strcmp('.ppm',postname))
15 a = readppm(fname);
16 I1 = sum(a,3);
17else
18 a = imread(fname); a = sum(double(a),3);
19 I1 = a;
20end
21
22
23Is = zeros(size(I1,1),size(I1,2),1+floor((endid-startid)/step_img));
24Is(:,:,1) = I1;
25im_id = 1;
26for j = startid+step_img:step_img:endid,
27 command = ['%s%s%s%.',num2str(digits),'d%s'];
28 fname = sprintf(command,homedir,imgdir,prename,j,postname);
29 disp(fname);
30 im_id = im_id+1;
31
32 if (strcmp('.pgm',postname)),
33 Is(:,:,im_id) = readpgm(fname);
34 elseif (strcmp('.ppm',postname))
35 a = readppm(fname);
36 Is(:,:,im_id) = sum(a,3);
37 else
38 a = imread(fname); a = sum(double(a),3);
39 Is(:,:,im_id) = a;
40 end
41end
42
43
44
45
46
47
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m
new file mode 100755
index 0000000..9e2eed1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_pmm.m
@@ -0,0 +1,12 @@
1function I = read_pmm(fname)
2
3fid = fopen(fname,'r');
4
5[A] = fscanf(fid,'%d\n',3);
6
7I = fscanf(fid,'%d',prod(A));
8
9
10I = reshape(I,A(2),A(1))';
11
12I = squeeze(I);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m
new file mode 100755
index 0000000..6ad818a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_scan.m
@@ -0,0 +1,42 @@
1function [img,sizeinfo] = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7
8fname_header = sprintf('%s.h01',filename);
9fname_data = sprintf('%s.i01',filename);
10
11fid = fopen(fname_header,'r');
12
13
14done = 0;
15while done~=3,
16 cmt = fgets(fid)
17 if (findstr(cmt,'!matrix size[1]')),
18 nc = sscanf(cmt,'!matrix size[1] :=%d');
19 done = done+1;
20 elseif (findstr(cmt,'!matrix size[2]')),
21 nr = sscanf(cmt,'!matrix size[2] :=%d');
22 done = done+1;
23 elseif (findstr(cmt,'!matrix size[3]')),
24 ns = sscanf(cmt,'!matrix size[3] :=%d');
25 done = done+1;
26 end
27end
28fclose(fid);
29
30fid = fopen(fname_data,'r');
31
32%img = fscanf(fid,'%d',size);
33%img = img';
34
35img = fread(fid,nc*nr*ns,'uint8');
36img = reshape(img,nc,nr,ns);
37
38sizeinfo(1) = nr;
39sizeinfo(2) = nc;
40sizeinfo(3) = ns;
41
42fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m b/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m
new file mode 100755
index 0000000..a056ebc
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/read_seg_file.m
@@ -0,0 +1,36 @@
1function [seg_map,seg] = read_seg(filename)
2%
3% function seg = read_seg(filename)
4%
5
6fid = fopen(filename,'r');
7if (fid < 0),
8 error(sprintf('can not find file: %s',filename));
9end
10
11header_done =0;
12while ~header_done,
13
14 cmt = fgets(fid);
15 if length(findstr(cmt,'#')) ~=1,
16 header_done = 1;
17 cmt = fgets(fid);
18 nc = sscanf(cmt,'width %d\n');
19 cmt = fgets(fid);
20 nr = sscanf(cmt,'height %d\n');
21 cmt = fgets(fid);
22 mseg = sscanf(cmt,'segments %d\n');
23 cmt = fgets(fid);
24 end
25end
26
27seg = fscanf(fid,'%d',100*nr);
28tmp = length(seg(:))/4;
29seg = reshape(seg,4,tmp)';
30
31seg_map = zeros(nr,nc);
32
33for j=1:tmp,
34 seg_map(seg(j,2)+1,1+seg(j,3):1+seg(j,4)) = seg(j,1);
35end
36
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m b/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m
new file mode 100755
index 0000000..90bc944
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readlines.m
@@ -0,0 +1,30 @@
1function [lines,indexes] = readlines(fname)
2%
3% [lines,indexes] = readlines(fname)
4% Read Edges points from .Ins file produced by "getlines"
5% lines: a num_pointsx2 matrix of the edge points
6% indexes: the braking point the lines
7%
8
9fid = fopen(fname,'r');
10
11done = 0;
12lines = [];
13indexes = [];
14
15first_line = fscanf(fid,'%s',1);
16
17while (~done),
18 num_lines = sscanf(first_line(3:length(first_line)),'%d');
19 disp(num_lines);
20 indexes = [indexes,num_lines];
21 a = fscanf(fid,'%f',[2,num_lines]);
22 lines = [lines;a'];
23
24 first_line = fscanf(fid,'%s',1);
25 if (first_line == []),
26 done = 1;
27 end
28end
29
30
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m
new file mode 100755
index 0000000..c21fc48
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpdm3.m
@@ -0,0 +1,16 @@
1function I = readpdm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',3)
6A(3) = max(1,A(3));
7
8I = fscanf(fid,'%d',[A(1)*A(2)*A(3)]);
9
10%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
11
12I = reshape(I,A(2),A(1),A(3));
13
14I = permute(I,[2,1,3]);
15
16fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m
new file mode 100755
index 0000000..37910b9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpdmc.m
@@ -0,0 +1,12 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%d',[A(2),A(1)]);
7%I = fscanf(fid,'%d',[300,1000]);
8I = I';
9
10%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
11
12fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m
new file mode 100755
index 0000000..48ecd78
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm.m
@@ -0,0 +1,10 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%f',[A(1),A(2)]);
7
8%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
9
10fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m
new file mode 100755
index 0000000..15ba959
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfm3.m
@@ -0,0 +1,17 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',3);
6A(3) = max(1,A(3));
7
8I = fscanf(fid,'%f',[A(1)*A(2)*A(3)]);
9
10%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
11
12I = reshape(I,A(2),A(1),A(3));
13I = permute(I,[2,1,3]);
14
15I = squeeze(I);
16
17fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m
new file mode 100755
index 0000000..2039002
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpfmc.m
@@ -0,0 +1,11 @@
1function I = readpfm(filename)
2
3fid = fopen(filename,'r');
4
5A = fscanf(fid,'%d',2);
6I = fscanf(fid,'%f',[A(2),A(1)]);
7I = I';
8
9%I = fscanf(fid,'%f',A(2)*A(1));I = reshape(I,A(1),A(2));
10
11fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m
new file mode 100755
index 0000000..7aaf998
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm.m
@@ -0,0 +1,30 @@
1function img = pgmread(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% this program also corrects for the shifts in the image from pm file.
6
7
8fid = fopen(filename,'r');
9if (fid < 0),
10 error(sprintf('can not find file: %s',filename));
11end
12
13fscanf(fid, 'P5\n');
14cmt = '#';
15while findstr(cmt, '#'),
16 cmt = fgets(fid);
17 if length(findstr(cmt, '#')) ~= 1,
18 YX = sscanf(cmt, '%d %d');
19 y = YX(1); x = YX(2);
20 end
21end
22
23fgets(fid);
24
25%img = fscanf(fid,'%d',size);
26%img = img';
27
28img = fread(fid,[y,x],'uint8');
29img = img';
30fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m
new file mode 100755
index 0000000..69f80ba
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpgm_evinfo.m
@@ -0,0 +1,35 @@
1function [img,ev_info] = pgmread_evinfo(filename)
2% function img = pgmread(filename)
3% this is my version of pgmread for the pgm file created by XV.
4%
5% return the information in line #
6
7
8fid = fopen(filename,'r');
9
10if (fid <0),
11 error(sprintf('can not find file %s',filename));
12end
13
14fscanf(fid, 'P5\n');
15cmt = '#';
16while findstr(cmt, '#'),
17 cmt = fgets(fid);
18 if findstr(cmt,'#'),
19 ev_info = sscanf(cmt,'# minv: %f, maxv: %f, scale: %f, eigval: %f');
20 end
21 if length(findstr(cmt, '#')) ~= 1,
22 YX = sscanf(cmt, '%d %d');
23 y = YX(1); x = YX(2);
24 end
25end
26
27fgets(fid);
28
29%img = fscanf(fid,'%d',size);
30%img = img';
31
32img = fread(fid,[y,x],'uint8');
33img = img';
34fclose(fid);
35
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m
new file mode 100755
index 0000000..88fe907
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readpmm.m
@@ -0,0 +1,22 @@
1function I=readpmm(name)
2%
3% I=writepmm(name)
4%
5% I is a mul-band image
6%
7 fid = fopen(name,'r');
8
9 if (fid <0),
10 error(sprintf('can not find file %s',name));
11 end
12
13 a = fscanf(fid,'%d',3);
14 nr = a(1);nc = a(2);nb = a(3);
15
16
17 I = fscanf(fid, '%f\n', nr*nc*nb);
18
19 I = reshape(I,nc,nr,nb)';
20 I = squeeze(I);
21
22 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m b/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m
new file mode 100755
index 0000000..b9dd566
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/readppm.m
@@ -0,0 +1,23 @@
1function [I,r, g, b] = readppm(name)
2
3 fid = fopen(name, 'r');
4 fscanf(fid, 'P6\n');
5 cmt = '#';
6 while findstr(cmt, '#'),
7 cmt = fgets(fid);
8 if length(findstr(cmt, '#')) ~= 1
9 YX = sscanf(cmt, '%d %d');
10 y = YX(1); x = YX(2);
11 end
12 end
13 fgets(fid);
14 packed = fread(fid,[3*y,x],'uint8')';
15 r = packed(:,1:3:3*y);
16 g = packed(:,2:3:3*y);
17 b = packed(:,3:3:3*y);
18 fclose(fid);
19
20 I(:,:,1) = r;
21 I(:,:,2) = g;
22 I(:,:,3) = b;
23 I = I/255;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m b/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m
new file mode 100755
index 0000000..113cb18
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/writepgm.m
@@ -0,0 +1,8 @@
1function I = writepgm(name,I)
2
3 [y,x] = size(I);
4
5 fid = fopen(name, 'w');
6 fprintf(fid, 'P5\n%d %d\n255\n', x,y);
7 fwrite(fid, I', 'uint8');
8 fclose(fid);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m b/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m
new file mode 100755
index 0000000..3d2fed1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/io/writeppm.m
@@ -0,0 +1,14 @@
1function writeppm(name,I)
2
3 [y,x,nb] = size(I);
4
5 fid = fopen(name, 'w');
6 fprintf(fid, 'P6\n%d %d\n255\n', x,y);
7
8 I1 = reshape(I(:,:,1)',1,x*y);
9 I2 = reshape(I(:,:,2)',1,x*y);
10 I3 = reshape(I(:,:,3)',1,x*y);
11
12 fwrite(fid, [I1;I2;I3], 'uint8');
13 fclose(fid);
14
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m
new file mode 100755
index 0000000..3ddb232
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m
@@ -0,0 +1,26 @@
1%Functions related to the assignment problem.
2%Version 1.0, 25-May-1999.
3%
4%Copyright (c) 1995-1999 Niclas Borlin, Dept. of Computing Science,
5% Umea University, SE-901 87 UMEA, Sweden.
6% Niclas.Borlin@cs.umu.se.
7% www.cs.umu.se/~niclas.
8%
9%All standard disclaimers apply.
10%
11%You are free to use this code as you wish. If you use it for a
12%publication or in a commercial package, please include an
13%acknowledgement and/or at least send me an email. (Looks good in my CV :-).
14%
15%Main functions:
16% hungarian - calculate a solution of the square assignment
17% problem. See HELP for a reference.
18% condass - calculate a condition number of the solution to the
19% assignment problem. See HELP for a reference.
20% allcosts - calculate the costs of all possible assignments.
21% allperms - calculate all possible permutations/assignments of a
22% given problem size.
23%
24%Test/demo functions.
25% demo - short demonstration of the main functions.
26% test - test/verification of the main functions.
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m
new file mode 100755
index 0000000..ffdb8b9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m
@@ -0,0 +1,17 @@
1function [c,p]=allcosts(C)
2%ALLCOSTS Calculate all costs for an assignment problem.
3%
4%[c,p]=allcosts(C)
5%c returns the costs, p the corresponding permutations.
6
7% v1.0 95-07-18. Niclas Borlin, niclas@cs.umu.se.
8
9p=allperm(size(C,1));
10
11c=zeros(size(p,1),1);
12
13I=eye(size(C,1));
14
15for i=1:size(p,1)
16 c(i)=sum(C(logical(sparse(p(i,:),1:size(C,1),1))));
17end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m
new file mode 100755
index 0000000..b8d419e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m
@@ -0,0 +1,17 @@
1function p=allperm(n)
2%ALLPERM All permutation matrix.
3%
4%p=allperm(n)
5%Returns a matrix with all permutations of 1:n stored row-wise.
6
7% v1.0 95-07-18. Niclas Borlin, niclas@cs.umu.se.
8
9if (n<=1)
10 p=1;
11else
12 q=allperm(n-1);
13 p=[];
14 for i=1:n
15 p=[p;i*ones(size(q,1),1) q+(q>=i)];
16 end
17end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m
new file mode 100755
index 0000000..82552e7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m
@@ -0,0 +1,54 @@
1function [k,C1,T1,C2,T2]=condass(A)
2%CONDASS Calculate condition number of the assigment problem.
3%
4%[k,C1,T1,C2,T2]=condass(A)
5%A - A square cost matrix.
6%k - The condition number of the assigment problem.
7%C1 - The best assigment.
8%T1 - The lowest cost.
9%C2 - The second best assignment.
10%T2 - The second lowest cost.
11%
12%The condition number is calculated as the relative difference between
13%the best and second best solutions, as described in Nystrom, Soderkvist,
14%and Wedin, "A Note on some Identification Problems Arising in Roentgen
15%Stereo Photogrammetric Analysis", J of Biomechanics, 27(10):1291-1294,
16%1994.
17
18% v1.0 96-09-14. Niclas Borlin, niclas@cs.umu.se.
19
20% A substantial effort was put into this code. If you use it for a
21% publication or otherwise, please include an acknowledgement and notify
22% me by email. /Niclas
23
24% Create a large number used to block selected assignments.
25big=sum(sum(A))+1;
26
27% Get best assigment.
28[C1,T1]=hungarian(A);
29
30% Initialize second best solution.
31T2=inf;
32C2=zeros(size(C1));
33
34% Create a work matrix.
35B=A;
36for i=1:length(C1)
37 % Block assigment in column i.
38 B(C1(i),i)=big;
39 % Get best assigment with this one blocked.
40 [C,T]=hungarian(B);
41 if (T<T2)
42 % Remember it if it's the best so far.
43 T2=T;
44 C2=C;
45 end
46 % Remove blocking in column i.
47 B(C1(i),i)=A(C1(i),i);
48end
49
50% Calculate difference...
51mu=T2-T1;
52
53% ...and condition number.
54k=T1/mu;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m
new file mode 100755
index 0000000..2d34e37
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m
@@ -0,0 +1,38 @@
1A=magic(10);
2B=A(4:7,4:7);
3disp('Cost matrix:')
4disp(B)
5disp('Calculating best assignment...');
6[c,t]=hungarian(B);
7disp('Best assignment (as row indices):')
8disp(c)
9disp('Best assignment (as logical matrix):')
10disp(logical(full(sparse(c,1:4,1))))
11disp('Lowest cost:')
12disp(t)
13
14disp(sprintf('\nCalculating condition number for solution...'));
15[k,c1,t1,c2,t2]=condass(B);
16disp('Lowest cost (should be same as above): ')
17disp(t1)
18disp('corresponding assignment (should be same as above):')
19disp(c1)
20disp('Second lowest cost: ')
21disp(t2)
22disp('corresponding assignment:')
23disp(c2)
24disp('Condition number for solution:')
25disp(k)
26
27disp(sprintf('\nCalculating all possible costs...'));
28[c,p]=allcosts(B);
29% Sort by cost.
30[y,i]=sort(c);
31disp('The three lowest costs:')
32disp(c(i(1:3)))
33disp('Corresponding assignments:')
34disp(p(i(1:3),:))
35disp('The three highest costs:')
36disp(c(i(end+[-2:0])))
37disp('Corresponding assignments:')
38disp(p(i(end+[-2:0]),:))
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/hungarian.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/hungarian.m
new file mode 100755
index 0000000..0b493f0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/hungarian.m
@@ -0,0 +1,464 @@
1function [C,T]=hungarian(A)
2%HUNGARIAN Solve the Assignment problem using the Hungarian method.
3%
4%[C,T]=hungarian(A)
5%A - a square cost matrix.
6%C - the optimal assignment.
7%T - the cost of the optimal assignment.
8
9% Adapted from the FORTRAN IV code in Carpaneto and Toth, "Algorithm 548:
10% Solution of the assignment problem [H]", ACM Transactions on
11% Mathematical Software, 6(1):104-111, 1980.
12
13% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.
14% Department of Computing Science, Umeå University,
15% Sweden.
16% All standard disclaimers apply.
17
18% A substantial effort was put into this code. If you use it for a
19% publication or otherwise, please include an acknowledgement or at least
20% notify me by email. /Niclas
21
22[m,n]=size(A);
23
24if (m~=n)
25 error('HUNGARIAN: Cost matrix must be square!');
26end
27
28% Save original cost matrix.
29orig=A;
30
31% Reduce matrix.
32A=hminired(A);
33
34% Do an initial assignment.
35[A,C,U]=hminiass(A);
36
37% Repeat while we have unassigned rows.
38while (U(n+1))
39 % Start with no path, no unchecked zeros, and no unexplored rows.
40 LR=zeros(1,n);
41 LC=zeros(1,n);
42 CH=zeros(1,n);
43 RH=[zeros(1,n) -1];
44
45 % No labelled columns.
46 SLC=[];
47
48 % Start path in first unassigned row.
49 r=U(n+1);
50 % Mark row with end-of-path label.
51 LR(r)=-1;
52 % Insert row first in labelled row set.
53 SLR=r;
54
55 % Repeat until we manage to find an assignable zero.
56 while (1)
57 % If there are free zeros in row r
58 if (A(r,n+1)~=0)
59 % ...get column of first free zero.
60 l=-A(r,n+1);
61
62 % If there are more free zeros in row r and row r in not
63 % yet marked as unexplored..
64 if (A(r,l)~=0 & RH(r)==0)
65 % Insert row r first in unexplored list.
66 RH(r)=RH(n+1);
67 RH(n+1)=r;
68
69 % Mark in which column the next unexplored zero in this row
70 % is.
71 CH(r)=-A(r,l);
72 end
73 else
74 % If all rows are explored..
75 if (RH(n+1)<=0)
76 % Reduce matrix.
77 [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR);
78 end
79
80 % Re-start with first unexplored row.
81 r=RH(n+1);
82 % Get column of next free zero in row r.
83 l=CH(r);
84 % Advance "column of next free zero".
85 CH(r)=-A(r,l);
86 % If this zero is last in the list..
87 if (A(r,l)==0)
88 % ...remove row r from unexplored list.
89 RH(n+1)=RH(r);
90 RH(r)=0;
91 end
92 end
93
94 % While the column l is labelled, i.e. in path.
95 while (LC(l)~=0)
96 % If row r is explored..
97 if (RH(r)==0)
98 % If all rows are explored..
99 if (RH(n+1)<=0)
100 % Reduce cost matrix.
101 [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR);
102 end
103
104 % Re-start with first unexplored row.
105 r=RH(n+1);
106 end
107
108 % Get column of next free zero in row r.
109 l=CH(r);
110
111 % Advance "column of next free zero".
112 CH(r)=-A(r,l);
113
114 % If this zero is last in list..
115 if(A(r,l)==0)
116 % ...remove row r from unexplored list.
117 RH(n+1)=RH(r);
118 RH(r)=0;
119 end
120 end
121
122 % If the column found is unassigned..
123 if (C(l)==0)
124 % Flip all zeros along the path in LR,LC.
125 [A,C,U]=hmflip(A,C,LC,LR,U,l,r);
126 % ...and exit to continue with next unassigned row.
127 break;
128 else
129 % ...else add zero to path.
130
131 % Label column l with row r.
132 LC(l)=r;
133
134 % Add l to the set of labelled columns.
135 SLC=[SLC l];
136
137 % Continue with the row assigned to column l.
138 r=C(l);
139
140 % Label row r with column l.
141 LR(r)=l;
142
143 % Add r to the set of labelled rows.
144 SLR=[SLR r];
145 end
146 end
147end
148
149% Calculate the total cost.
150T=sum(orig(logical(sparse(C,1:size(orig,2),1))));
151
152
153function A=hminired(A)
154%HMINIRED Initial reduction of cost matrix for the Hungarian method.
155%
156%B=assredin(A)
157%A - the unreduced cost matris.
158%B - the reduced cost matrix with linked zeros in each row.
159
160% v1.0 96-06-13. Niclas Borlin, niclas@cs.umu.se.
161
162[m,n]=size(A);
163
164% Subtract column-minimum values from each column.
165colMin=min(A);
166A=A-colMin(ones(n,1),:);
167
168% Subtract row-minimum values from each row.
169rowMin=min(A')';
170A=A-rowMin(:,ones(1,n));
171
172% Get positions of all zeros.
173[i,j]=find(A==0);
174
175% Extend A to give room for row zero list header column.
176A(1,n+1)=0;
177for k=1:n
178 % Get all column in this row.
179 cols=j(k==i)';
180 % Insert pointers in matrix.
181 A(k,[n+1 cols])=[-cols 0];
182end
183
184
185function [A,C,U]=hminiass(A)
186%HMINIASS Initial assignment of the Hungarian method.
187%
188%[B,C,U]=hminiass(A)
189%A - the reduced cost matrix.
190%B - the reduced cost matrix, with assigned zeros removed from lists.
191%C - a vector. C(J)=I means row I is assigned to column J,
192% i.e. there is an assigned zero in position I,J.
193%U - a vector with a linked list of unassigned rows.
194
195% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.
196
197[n,np1]=size(A);
198
199% Initalize return vectors.
200C=zeros(1,n);
201U=zeros(1,n+1);
202
203% Initialize last/next zero "pointers".
204LZ=zeros(1,n);
205NZ=zeros(1,n);
206
207for i=1:n
208 % Set j to first unassigned zero in row i.
209 lj=n+1;
210 j=-A(i,lj);
211
212 % Repeat until we have no more zeros (j==0) or we find a zero
213 % in an unassigned column (c(j)==0).
214
215 while (C(j)~=0)
216 % Advance lj and j in zero list.
217 lj=j;
218 j=-A(i,lj);
219
220 % Stop if we hit end of list.
221 if (j==0)
222 break;
223 end
224 end
225
226 if (j~=0)
227 % We found a zero in an unassigned column.
228
229 % Assign row i to column j.
230 C(j)=i;
231
232 % Remove A(i,j) from unassigned zero list.
233 A(i,lj)=A(i,j);
234
235 % Update next/last unassigned zero pointers.
236 NZ(i)=-A(i,j);
237 LZ(i)=lj;
238
239 % Indicate A(i,j) is an assigned zero.
240 A(i,j)=0;
241 else
242 % We found no zero in an unassigned column.
243
244 % Check all zeros in this row.
245
246 lj=n+1;
247 j=-A(i,lj);
248
249 % Check all zeros in this row for a suitable zero in another row.
250 while (j~=0)
251 % Check the in the row assigned to this column.
252 r=C(j);
253
254 % Pick up last/next pointers.
255 lm=LZ(r);
256 m=NZ(r);
257
258 % Check all unchecked zeros in free list of this row.
259 while (m~=0)
260 % Stop if we find an unassigned column.
261 if (C(m)==0)
262 break;
263 end
264
265 % Advance one step in list.
266 lm=m;
267 m=-A(r,lm);
268 end
269
270 if (m==0)
271 % We failed on row r. Continue with next zero on row i.
272 lj=j;
273 j=-A(i,lj);
274 else
275 % We found a zero in an unassigned column.
276
277 % Replace zero at (r,m) in unassigned list with zero at (r,j)
278 A(r,lm)=-j;
279 A(r,j)=A(r,m);
280
281 % Update last/next pointers in row r.
282 NZ(r)=-A(r,m);
283 LZ(r)=j;
284
285 % Mark A(r,m) as an assigned zero in the matrix . . .
286 A(r,m)=0;
287
288 % ...and in the assignment vector.
289 C(m)=r;
290
291 % Remove A(i,j) from unassigned list.
292 A(i,lj)=A(i,j);
293
294 % Update last/next pointers in row r.
295 NZ(i)=-A(i,j);
296 LZ(i)=lj;
297
298 % Mark A(r,m) as an assigned zero in the matrix . . .
299 A(i,j)=0;
300
301 % ...and in the assignment vector.
302 C(j)=i;
303
304 % Stop search.
305 break;
306 end
307 end
308 end
309end
310
311% Create vector with list of unassigned rows.
312
313% Mark all rows have assignment.
314r=zeros(1,n);
315rows=C(C~=0);
316r(rows)=rows;
317empty=find(r==0);
318
319% Create vector with linked list of unassigned rows.
320U=zeros(1,n+1);
321U([n+1 empty])=[empty 0];
322
323
324function [A,C,U]=hmflip(A,C,LC,LR,U,l,r)
325%HMFLIP Flip assignment state of all zeros along a path.
326%
327%[A,C,U]=hmflip(A,C,LC,LR,U,l,r)
328%Input:
329%A - the cost matrix.
330%C - the assignment vector.
331%LC - the column label vector.
332%LR - the row label vector.
333%U - the
334%r,l - position of last zero in path.
335%Output:
336%A - updated cost matrix.
337%C - updated assignment vector.
338%U - updated unassigned row list vector.
339
340% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.
341
342n=size(A,1);
343
344while (1)
345 % Move assignment in column l to row r.
346 C(l)=r;
347
348 % Find zero to be removed from zero list..
349
350 % Find zero before this.
351 m=find(A(r,:)==-l);
352
353 % Link past this zero.
354 A(r,m)=A(r,l);
355
356 A(r,l)=0;
357
358 % If this was the first zero of the path..
359 if (LR(r)<0)
360 ...remove row from unassigned row list and return.
361 U(n+1)=U(r);
362 U(r)=0;
363 return;
364 else
365
366 % Move back in this row along the path and get column of next zero.
367 l=LR(r);
368
369 % Insert zero at (r,l) first in zero list.
370 A(r,l)=A(r,n+1);
371 A(r,n+1)=-l;
372
373 % Continue back along the column to get row of next zero in path.
374 r=LC(l);
375 end
376end
377
378
379function [A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR)
380%HMREDUCE Reduce parts of cost matrix in the Hungerian method.
381%
382%[A,CH,RH]=hmreduce(A,CH,RH,LC,LR,SLC,SLR)
383%Input:
384%A - Cost matrix.
385%CH - vector of column of 'next zeros' in each row.
386%RH - vector with list of unexplored rows.
387%LC - column labels.
388%RC - row labels.
389%SLC - set of column labels.
390%SLR - set of row labels.
391%
392%Output:
393%A - Reduced cost matrix.
394%CH - Updated vector of 'next zeros' in each row.
395%RH - Updated vector of unexplored rows.
396
397% v1.0 96-06-14. Niclas Borlin, niclas@cs.umu.se.
398
399n=size(A,1);
400
401% Find which rows are covered, i.e. unlabelled.
402coveredRows=LR==0;
403
404% Find which columns are covered, i.e. labelled.
405coveredCols=LC~=0;
406
407r=find(~coveredRows);
408c=find(~coveredCols);
409
410% Get minimum of uncovered elements.
411m=min(min(A(r,c)));
412
413% Subtract minimum from all uncovered elements.
414A(r,c)=A(r,c)-m;
415
416% Check all uncovered columns..
417for j=c
418 % ...and uncovered rows in path order..
419 for i=SLR
420 % If this is a (new) zero..
421 if (A(i,j)==0)
422 % If the row is not in unexplored list..
423 if (RH(i)==0)
424 % ...insert it first in unexplored list.
425 RH(i)=RH(n+1);
426 RH(n+1)=i;
427 % Mark this zero as "next free" in this row.
428 CH(i)=j;
429 end
430 % Find last unassigned zero on row I.
431 row=A(i,:);
432 colsInList=-row(row<0);
433 if (length(colsInList)==0)
434 % No zeros in the list.
435 l=n+1;
436 else
437 l=colsInList(row(colsInList)==0);
438 end
439 % Append this zero to end of list.
440 A(i,l)=-j;
441 end
442 end
443end
444
445% Add minimum to all doubly covered elements.
446r=find(coveredRows);
447c=find(coveredCols);
448
449% Take care of the zeros we will remove.
450[i,j]=find(A(r,c)<=0);
451
452i=r(i);
453j=c(j);
454
455for k=1:length(i)
456 % Find zero before this in this row.
457 lj=find(A(i(k),:)==-j(k));
458 % Link past it.
459 A(i(k),lj)=A(i(k),j(k));
460 % Mark it as assigned.
461 A(i(k),j(k))=0;
462end
463
464A(r,c)=A(r,c)+m;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/test.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/test.m
new file mode 100755
index 0000000..4c238f2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/test.m
@@ -0,0 +1,87 @@
1disp('Testing hungarian...');
2A=magic(10);
3B=A(4:7,4:7);
4[c,t]=hungarian(B);
5if (any(c~=[2 1 3 4]))
6 disp('Wrong coupling!');
7elseif (t~=77)
8 disp('Wrong solution!');
9else
10 disp('Hungarian appears OK.');
11end
12
13disp('Testing condass...');
14[k,c1,t1,c2,t2]=condass(B);
15if (any(c1~=[2 1 3 4]))
16 disp('Wrong best coupling!');
17elseif (t1~=77)
18 disp('Wrong lowest cost!');
19elseif (any(c2~=[1 2 3 4]))
20 disp('Wrong second best coupling!');
21elseif (t2~=102)
22 disp('Wrong second lowest cost!');
23elseif (k~=t1/(t2-t1))
24 disp('Wrong condition number!');
25else
26 disp('condass appears OK.');
27end
28
29disp('Testing allcosts...');
30[c,p]=allcosts(B);
31cTrue=[ 102
32 127
33 202
34 227
35 222
36 222
37 77
38 102
39 182
40 202
41 202
42 197
43 177
44 202
45 182
46 202
47 302
48 297
49 202
50 202
51 207
52 202
53 307
54 302
55];
56pTrue=[ 1 2 3 4
57 1 2 4 3
58 1 3 2 4
59 1 3 4 2
60 1 4 2 3
61 1 4 3 2
62 2 1 3 4
63 2 1 4 3
64 2 3 1 4
65 2 3 4 1
66 2 4 1 3
67 2 4 3 1
68 3 1 2 4
69 3 1 4 2
70 3 2 1 4
71 3 2 4 1
72 3 4 1 2
73 3 4 2 1
74 4 1 2 3
75 4 1 3 2
76 4 2 1 3
77 4 2 3 1
78 4 3 1 2
79 4 3 2 1
80 ];
81if (any(c~=cTrue))
82 disp('Wrong costs!');
83elseif (any(p~=pTrue))
84 disp('Wrong permutations!');
85else
86 disp('allcosts appears OK.');
87end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/091399fbn-jets.3.jpg b/SD-VBS/common/toolbox/toolbox_basic/pyramid/091399fbn-jets.3.jpg
new file mode 100755
index 0000000..b91732f
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/091399fbn-jets.3.jpg
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/expand.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/expand.m
new file mode 100755
index 0000000..64e9fda
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/expand.m
@@ -0,0 +1,8 @@
1function J = expand(I)
2%
3%
4
5[sy,sx] = size(I);
6[x,y] = meshgrid(1:2*sx+1,1:2*sy+1);
7
8nx = \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/gauss_lowpass.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/gauss_lowpass.m
new file mode 100755
index 0000000..87ad4f1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/gauss_lowpass.m
@@ -0,0 +1,9 @@
1function J = gauss_lowpass(I,a)
2
3if (nargin < 2),
4 a = 0.4;
5end
6
7w = gen_w(a);
8
9J = conv2(conv2(I,w,'same'),w','same');
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/gen_w.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/gen_w.m
new file mode 100755
index 0000000..b255751
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/gen_w.m
@@ -0,0 +1,12 @@
1function w = gen_w(a)
2%
3
4if (nargin == 0),
5 a = 0.4;
6end
7
8w(3) = a;
9w(1) = 1/4 - a/2;
10w(5) = 1/4 - a/2;
11w(2) = 1/4;
12w(4) = 1/4;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/reduce.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/reduce.m
new file mode 100755
index 0000000..6837e8a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/reduce.m
@@ -0,0 +1,7 @@
1function J = reduce(I)
2
3[nr,nc,nb] = size(I);
4for j=1:nb,
5 tmp = gauss_lowpass(I(:,:,j));
6 J(:,:,j) = tmp(1:2:nr,1:2:nc);
7end \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/session.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/session.m
new file mode 100755
index 0000000..9d0aa6c
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/session.m
@@ -0,0 +1,26 @@
1%image_dir = '/home/barad-dur/d/malik/jshi/';
2%I = gifread([image_dir,'tape9/t9a1_L.40.gif']);
3I = pgmread('car100x100_0001');
4Io = I;
5
6B = [];
7
8done = 0;
9st = 2;
10sz = size(I);
11while (~done),
12 w = max(1,round(0.05*size(I,1)));
13 b = zeros(round(0.5*size(Io)),round(0.5*size(I)));
14 %J = smooth(I,w);
15 %I = J(1:st:size(J,1),1:st:size(J,2));
16 I = reduce(I);
17 sz = [sz;size(I)];
18 b(1:size(I,1),1:size(I,2)) = I;
19 disp(int2str(size(I,1)));
20
21 B = [B,b];
22
23 if (size(I,1) < 8),
24 done = 1;
25 end
26end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/pyramid/startup.m b/SD-VBS/common/toolbox/toolbox_basic/pyramid/startup.m
new file mode 100755
index 0000000..f86f9f4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/pyramid/startup.m
@@ -0,0 +1,5 @@
1home_dir = '/home/nef0/malik/jshi/jshi/matlab/';
2path([home_dir,'toolbox/io'], path)
3path([home_dir,'toolbox/filter'],path)
4path(path,[home_dir,'vision/vision94/tracking/'])
5clear home_dir \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/remap_angle.m b/SD-VBS/common/toolbox/toolbox_basic/remap_angle.m
new file mode 100755
index 0000000..09f8cff
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/remap_angle.m
@@ -0,0 +1,4 @@
1function a = remap_angle(theta,min,max)
2
3a = (theta<=min).*(theta+pi) + (theta>=max).*(theta-pi) +...
4 ((theta>min)&(theta<max)).*theta; \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/spmtimesd.c b/SD-VBS/common/toolbox/toolbox_basic/spmtimesd.c
new file mode 100755
index 0000000..a98dc0a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/spmtimesd.c
@@ -0,0 +1,141 @@
1/*================================================================
2* spmtimesd.c
3* This routine computes a sparse matrix times a diagonal matrix
4* whose diagonal entries are stored in a full vector.
5*
6* Examples:
7* spmtimesd(m,d,[]) = diag(d) * m,
8* spmtimesd(m,[],d) = m * diag(d)
9* spmtimesd(m,d1,d2) = diag(d1) * m * diag(d2)
10* m could be complex, but d is assumed real
11*
12* Stella X. Yu's first MEX function, Nov 9, 2001.
13
14% test sequence:
15
16m = 1000;
17n = 2000;
18a=sparse(rand(m,n));
19d1 = rand(m,1);
20d2 = rand(n,1);
21tic; b=spmtimesd(a,d1,d2); toc
22tic; bb = spdiags(d1,0,m,m) * a * spdiags(d2,0,n,n); toc
23e = (bb-b);
24max(abs(e(:)))
25
26*=================================================================*/
27
28# include "mex.h"
29
30void mexFunction(
31 int nargout,
32 mxArray *out[],
33 int nargin,
34 const mxArray *in[]
35)
36{
37 /* declare variables */
38 int i, j, k, m, n, nzmax, cmplx, xm, yn;
39 int *pir, *pjc, *qir, *qjc;
40 double *x, *y, *pr, *pi, *qr, *qi;
41
42 /* check argument */
43 if (nargin != 3) {
44 mexErrMsgTxt("Three input arguments required");
45 }
46 if (nargout>1) {
47 mexErrMsgTxt("Too many output arguments.");
48 }
49 if (!(mxIsSparse(in[0]))) {
50 mexErrMsgTxt("Input argument #1 must be of type sparse");
51 }
52 if ( mxIsSparse(in[1]) || mxIsSparse(in[2]) ) {
53 mexErrMsgTxt("Input argument #2 & #3 must be of type full");
54 }
55
56 /* computation starts */
57 m = mxGetM(in[0]);
58 n = mxGetN(in[0]);
59 pr = mxGetPr(in[0]);
60 pi = mxGetPi(in[0]);
61 pir = mxGetIr(in[0]);
62 pjc = mxGetJc(in[0]);
63
64 i = mxGetM(in[1]);
65 j = mxGetN(in[1]);
66 xm = ((i>j)? i: j);
67
68 i = mxGetM(in[2]);
69 j = mxGetN(in[2]);
70 yn = ((i>j)? i: j);
71
72 if ( xm>0 && xm != m) {
73 mexErrMsgTxt("Row multiplication dimension mismatch.");
74 }
75 if ( yn>0 && yn != n) {
76 mexErrMsgTxt("Column multiplication dimension mismatch.");
77 }
78
79
80 nzmax = mxGetNzmax(in[0]);
81 cmplx = (pi==NULL ? 0 : 1);
82 out[0] = mxCreateSparse(m,n,nzmax,cmplx);
83 if (out[0]==NULL) {
84 mexErrMsgTxt("Not enough space for the output matrix.");
85 }
86
87 qr = mxGetPr(out[0]);
88 qi = mxGetPi(out[0]);
89 qir = mxGetIr(out[0]);
90 qjc = mxGetJc(out[0]);
91
92 /* left multiplication */
93 x = mxGetPr(in[1]);
94 if (yn==0) {
95 for (j=0; j<n; j++) {
96 qjc[j] = pjc[j];
97 for (k=pjc[j]; k<pjc[j+1]; k++) {
98 i = pir[k];
99 qir[k] = i;
100 qr[k] = x[i] * pr[k];
101 if (cmplx) {
102 qi[k] = x[i] * pi[k];
103 }
104 }
105 }
106 qjc[n] = k;
107 return;
108 }
109
110 /* right multiplication */
111 y = mxGetPr(in[2]);
112 if (xm==0) {
113 for (j=0; j<n; j++) {
114 qjc[j] = pjc[j];
115 for (k=pjc[j]; k<pjc[j+1]; k++) {
116 qir[k] = pir[k];
117 qr[k] = pr[k] * y[j];
118 if (cmplx) {
119 qi[k] = qi[k] * y[j];
120 }
121 }
122 }
123 qjc[n] = k;
124 return;
125 }
126
127 /* both sides */
128 for (j=0; j<n; j++) {
129 qjc[j] = pjc[j];
130 for (k=pjc[j]; k<pjc[j+1]; k++) {
131 i = pir[k];
132 qir[k]= i;
133 qr[k] = x[i] * pr[k] * y[j];
134 if (cmplx) {
135 qi[k] = x[i] * qi[k] * y[j];
136 }
137 }
138 qjc[n] = k;
139 }
140
141}
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m
new file mode 100755
index 0000000..ec014d0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/afromncut.m
@@ -0,0 +1,73 @@
1% function a = afromncut(v,s,d,visimg,no_rep,pixel_loc)
2% Input:
3% v = eigenvectors of d*a*d, starting from the second.
4% (the first is all one over some constant determined by d)
5% s = eigenvalues
6% d = normalization matrix 1/sqrt(rowsum(abs(a)))
7% visimg = 1/0 if each eigenvector is/not 2D (so v is 3D)
8% no_rep = 1 (default), affinity has attraction only
9% if 1, the first column of v is the second eigenvector
10% if 0, the first column of v is the first eigenvector.
11% pixel_loc = nx1 matrix, each is a pixel location
12% Output:
13% a = diag(1/d) * na * diag(1/d);
14% If pixel_loc = []; a is returned, if not out of memory
15% otherwise, only rows of a at pixel_loc are returned.
16%
17% This routine is used to estimate the original affinity matrix
18% through the first few eigenvectors and its normalization matrix.
19
20% A test sequence includes:
21% a = randsym(5);
22% [na,d] = normalize(a);
23% [v,s] = ncut(a,5);
24% v = v(:,2:end); s = s(2:end);
25% aa = afromncut(v,s,d);
26% max(abs(aa(:) - a(:)))
27
28% Stella X. Yu, 2000.
29
30function a = afromncut(v,s,d,visimg,no_rep,pixel_loc)
31
32[nr,nc,nv] = size(v);
33if nargin<4 | isempty(visimg),
34 visimg = (nv>1);
35end
36
37if nargin<5 | isempty(no_rep),
38 no_rep = 1;
39end
40
41if visimg,
42 nr = nr * nc;
43else
44 nv = nc;
45end
46
47if nargin<6 | isempty(pixel_loc),
48 pixel_loc = 1:nr;
49end
50
51% D^(1/2)
52d = 1./(d(:)+eps);
53
54% first recover the first eigenvector
55if no_rep,
56 u = (1/norm(d)) + zeros(nr,1);
57 s = [1;s(:)];
58 nv = nv + 1;
59else
60 u = [];
61end
62
63% the full set of generalized eigenvectors
64v = [u, reshape(v,[nr,nv-no_rep])];
65
66% This is the real D, row sum
67d = d.^2;
68
69% an equivalent way to compute v = diag(d) * v;
70v = v .* d(:,ones(nv,1)); % to avoid using a big matrix diag(d)
71
72% synthesis
73a = v(pixel_loc,:)*diag(s)*v';
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m b/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m
new file mode 100755
index 0000000..4e419a0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/dispimg.m
@@ -0,0 +1,65 @@
1% function dispimg(g,fmt,lgd,cmap) display multiple images in one figure.
2% Input:
3% g = a cell and fmt is a 1x2 vector specifying the layout.
4% lgd = a string cell for the title of each image.
5% cmap = the colormap (default is the gray, -1 for the inverted gray).
6% ishori = a vector of 1/0 to display real and imag parts horizontally / vertically
7
8% Stella X. Yu, 2000.
9
10function dispimg(g,fmt,lgd,cmap,ishori);
11
12cellg = iscell(g);
13if cellg,
14 num_fig = length(g);
15else
16 num_fig = size(g,3);
17end;
18
19if nargin<2 | isempty(fmt),
20 m = ceil(sqrt(num_fig));
21 n = ceil(num_fig / m);
22else
23 m = fmt(1);
24 n = fmt(2);
25end
26
27if nargin<3 | isempty(lgd),
28 lgd = 1:num_fig;
29end
30if isnumeric(lgd),
31 lgd = cellstr(num2str(lgd(:),3));
32end
33i = size(lgd);
34if i(1)==1,
35 lgd = [lgd, cell(1,num_fig-i(2))];
36else
37 lgd = [lgd; cell(num_fig-i(1),1)];
38end
39
40if nargin<5 | isempty(ishori),
41 ishori = ones(num_fig,1);
42end
43ishori(end+1:num_fig) = ishori(end);
44
45for k=1:num_fig,
46 subplot(m,n,k);
47 if cellg,
48 showim(g{k},[],ishori(k));
49 else
50 showim(g(:,:,k),[],ishori(k));
51 end
52 title(lgd{k});
53end
54
55if nargin<4 | isempty(cmap),
56 cmap = gray;
57end
58if length(cmap)==1,
59 if cmap==1,
60 cmap = gray;
61 else
62 cmap = flipud(gray);
63 end
64end
65colormap(cmap);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m
new file mode 100755
index 0000000..a22077d
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/firstncut.m
@@ -0,0 +1,67 @@
1% function [v,s,d] = firstncut(base_name,rec_num)
2% Input:
3% base_name = image name
4% rec_num = parameter record number
5% Output:
6% v = eigenvectors
7% s = eigenvalues
8% d = normalization matrix d = 1/sqrt(rowsum(abs(a)))
9% Convert Jianbo Shi's Ncut Ccode results from images to matlab matrices.
10
11% Stella X. Yu, 2000.
12
13function [v,s,d] = firstncut(base_name,rec_num);
14
15if nargin<2 | isempty(rec_num),
16 rec_num = 1;
17end
18
19cur_dir = pwd;
20globalenvar;
21cd(IMAGE_DIR);
22cd(base_name);
23 feval([base_name,'_par']);
24 j = length(p);
25 if rec_num>j,
26 disp(sprintf('parameter record number %d out of range %d, check %s!',rec_num,j,[base_name,'_par.m']));
27 Qlabel = [];
28 v = [];
29 s = [];
30 ev_info = [];
31 return;
32 end
33 nv = p(rec_num).num_eigvecs;
34 no_rep = (p(rec_num).offset<1e-6);
35
36 % read the image
37 cm=sprintf('I = readppm(''%s.ppm'');',base_name);
38 eval(cm);
39
40 % read eigenvectors
41 base_name_hist = sprintf('%s_%d_IC',base_name,rec_num);
42 if no_rep,
43 [v,ev_info] = read_ev_pgm(base_name_hist,1,1,nv);
44 else
45 [v,ev_info] = read_ev_pgm2(base_name_hist,1,1,nv);
46 end
47 s = ev_info(4,:)';
48
49 % read the normalization matrix
50 d = readpfmc(sprintf('%s_%d_D_IC.pfm',base_name,rec_num));
51cd(cur_dir);
52
53% D^(1/2)
54dd = (1./(d(:)+eps));
55
56% recover real eigenvectors
57for j = 1:nv-no_rep,
58 vmin = ev_info(1,j);
59 vmax = ev_info(2,j);
60 y = v(:,:,j).*((vmax - vmin)/256) + vmin;
61 %validity check: x = D^(1/2)y should be normalized
62 x = norm(y(:).*dd);
63 v(:,:,j) = y./x;
64end
65
66dispimg(cat(3,mean(I,3),v),[],[{'image'};cellstr(num2str(s,3))]);
67
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m b/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m
new file mode 100755
index 0000000..4990451
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/getfnames.m
@@ -0,0 +1,47 @@
1% function [fn,dn] = getfnames(direc,opt)
2% Input:
3% direc = directory
4% opt = wildcat
5% Output:
6% fn = a cell with all filenames under direc and with opt
7% dn = a cell with all directory names under direc and with opt
8% For example, getfnames('19990910','*.jpg');
9% Set IS_PC according to your platform in globalenvar.m
10
11% Stella X. Yu, 2000.
12
13function [fn,dn] = getfnames(direc,opt)
14
15if (nargin<1 | isempty(direc)),
16 direc = '.';
17end
18
19if nargin<2 | isempty(opt),
20 opt = [];
21end
22
23fn = {};
24dn = {};
25
26cur_dir = pwd;
27cd(direc);
28s = dir(opt);
29if isempty(s),
30 disp('getfnames: no data');
31 return;
32end
33
34n = length(s);
35i = 1;
36j = 1;
37for k=1:n,
38 if s(k).isdir,
39 dn{j,1} = s(k).name;
40 j = j + 1;
41 else
42 fn{i,1} = s(k).name;
43 i = i + 1;
44 end
45end
46 cd(cur_dir)
47%[fn{1:n,1}]=deal(s.name);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m b/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m
new file mode 100755
index 0000000..945ddd2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/getimage2.m
@@ -0,0 +1,46 @@
1% function f = getimage2(imagefile) returns a normalized intensity image.
2% If the file postfix is not given, then I will search any possible image file
3% under the IMAGE_DIR.
4
5% Stella X. Yu, March 1999
6
7function f = getimage2(imagefile)
8
9if exist(imagefile)==2,
10 g = {imagefile};
11else
12 g = {};
13end
14globalenvar;
15g = [g; getfnames(IMAGE_DIR,[imagefile,'.*'])];
16
17j = 1;
18for i=1:length(g),
19 k = findstr(g{i},'.');
20 gp = g{i}(k(end)+1:end);
21 if strcmp(gp,'ppm'),
22 f = double(readppm(g{i}));
23 j = 0;
24 elseif sum(strcmp(gp,{'jpg','tif','jpeg','tiff','bmp','png','hdf','pcx','xwd'}))>0,
25 f = double(imread(g{i}));
26 j = 0;
27 end
28 if j==0,
29 disp(sprintf('This is an image read from %s under %s',g{i},IMAGE_DIR));
30 break;
31 end
32end
33if j,
34 f = [];
35 disp('Image not found');
36 return;
37end
38
39if size(f,3)>1,
40 %f = sum(f,3)./3;
41 f = rgb2ntsc(f);
42 f = f(:,:,1);
43end
44minf = min(f(:));
45maxf = max(f(:));
46f = (f - minf) ./ (maxf - minf);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m b/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m
new file mode 100755
index 0000000..1e61b61
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/globalenvar.m
@@ -0,0 +1,6 @@
1% globalenvar
2
3HOME_DIR = '/hid/jshi/Research/walking/stella';
4IMAGE_DIR = '/hid/jshi/test_images';
5C_DIR = '/hid/jshi/Research/Ncut_code_C';
6IS_PC = 0;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
new file mode 100755
index 0000000..d0f11cb
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincut.m
@@ -0,0 +1,94 @@
1% function [par, rec_num] = jshincut(par,image_dir)
2% Input:
3% par = a structure with parameters for command_ncut.tex
4% image_dir = the directory where the imagefile is stored
5% Output:
6% par = parameters used
7% rec_num = record number in the NCut database
8% Jianbo Shi's ncut_IC is applied to the image
9% (If there is no .ppm format for the named image,
10% conversion from related files would be attempted.)
11% Results are organized according to the parameters.
12% Example: jshincut('240018s');
13% See also: jshincutdefpar; ncutcheckin
14% Set IS_PC according to your platform in globalenvar.m
15
16% Stella X. Yu, 2000.
17
18function [par,rec_num] = jshincut(par,image_dir)
19
20rec = jshincutdefpar;
21
22fields = fieldnames(rec);
23nf = length(fields);
24
25if ischar(par),
26 imagename = par;
27 par = rec;
28 par.fname_base = imagename;
29end
30
31globalenvar;
32
33if nargin<2 | isempty(image_dir),
34 image_dir = IMAGE_DIR;
35end
36
37imagename = getfield(par,fields{1});
38for i=2:nf,
39 t = getfield(par,fields{i});
40 if isempty(t),
41 par = setfield(par,fields{i},getfield(rec,fields{i}));
42 end
43end
44
45% dir and filename
46catchar = {'/','\'};
47catchar = catchar{IS_PC+1};
48
49% first check if there is a ppm file for this image
50if not(exist([image_dir,catchar,imagename,'.ppm'])),
51 j = getfnames(image_dir,[imagename,'.*']);
52 if isempty(j),
53 disp('Image not found.');
54 return;
55 end
56 k = 0;
57 for i=1:length(j),
58 k = k + not(isempty(im2ppm(j{i},image_dir)));
59 if k==1,
60 disp(sprintf('%s -> %s.ppm succeeded.',j{i},imagename));
61 break;
62 end
63 end
64 if k==0,
65 disp('Sorry. Attempt to convert your named image into ppm format failed.');
66 return;
67 end
68end
69
70cd(C_DIR);
71
72% generate command_ncut.tex file
73fn = 'command_ncut.tex';
74fid = fopen(fn,'w');
75fprintf(fid,'%21s\t%s%c%s\n',fields{1},image_dir,catchar,imagename);
76for i=2:nf,
77 t = getfield(par,fields{i});
78 if isnumeric(t),
79 t = num2str(t);
80 end
81 fprintf(fid,['%21s\t%s\n'],fields{i},t);
82end
83fclose(fid);
84%disp('You can check and modify command_ncut.tex before I run ncut_IC on it. Good?');pause(1);
85
86% run ncut_IC
87unix(['.',catchar,'ncut_IC']);
88cd(HOME_DIR);
89
90% check in
91copyfile([C_DIR,catchar,fn],[image_dir,catchar,fn]);
92rec_num = ncutcheckin(fn,image_dir,image_dir);
93%delete([image_dir,catchar,imagename,'.ppm']);
94%delete([image_dir,catchar,fn]);
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m
new file mode 100755
index 0000000..4f07192
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/jshincutdefpar.m
@@ -0,0 +1,20 @@
1% function rec = jshincutdefpar;
2% default parameter setting for Jianbo Shi's NCut C codes
3
4% Stella X. Yu, 2000.
5
6function rec = jshincutdefpar;
7
8rec.fname_base = '240018s';
9rec.fname_ext = 'ppm';
10rec.num_eigvecs = 15;
11rec.spatial_neighborhood_x=20;
12rec.sigma_x= 10;
13rec.sig_I= -0.16;
14rec.sig_IC= 0.01;
15rec.hr= 2;
16rec.eig_blk_sze= 3;
17rec.power_D= 1;
18rec.offset = 0.0;
19rec.sig_filter = 1.0;
20rec.elong_filter = 3.0;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m
new file mode 100755
index 0000000..cd82ee5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/ncutcheckin.m
@@ -0,0 +1,136 @@
1% function rec_num = ncutcheckin(fn,sdir,tdir)
2% Input:
3% fn = parameter file name, default = 'command_ncut.tex'
4% sdir = source dir for fn as well as data files
5% tdir = target dir to check in, both default = IMAGE_DIR
6% Output:
7% rec_num = the number of current parameter records
8% The imagefile_par.m is updated if fn contains a new
9% parameter set. Data files are tagged and copied over to
10% a subdir under tdir.
11% Example: ncutcheckin;
12% Set IS_PC, IMAGE_DIR according to your platform in globalenvar.m
13
14% Stella X. Yu, 2000.
15
16function rec_num = ncutcheckin(fn,sdir,tdir)
17
18globalenvar;
19
20cur_dir = pwd;
21
22if nargin<1 | isempty(fn),
23 fn = 'command_ncut.tex';
24end
25
26if nargin<2 | isempty(sdir),
27 sdir = IMAGE_DIR;
28end
29
30if nargin<3 | isempty(tdir),
31 tdir = IMAGE_DIR;
32end
33
34rec = jshincutdefpar;
35
36% first, generate a parameter record from fn
37cd(sdir);
38[names,values] = textread(fn,'%s %s','commentstyle','shell');
39n = length(names);
40s = rec;
41for i=1:n,
42 j = str2num(values{i});
43 if isempty(j),
44 s = setfield(s,names{i},values{i});
45 else
46 s = setfield(s,names{i},j);
47 end
48end
49cd(cur_dir);
50
51% special care to extract the image file name
52imagename = getfield(s,names{1});
53catchar = {'/','\'};
54catchar = catchar{IS_PC + 1};
55k = max([0,findstr(imagename,catchar)]);
56imagename = imagename(k+1:end);
57s = setfield(s,names{1},imagename);
58
59% second, check if the target dir contains a profile for the image
60cd(tdir);
61if not(exist(imagename,'dir')),
62 mkdir(imagename);
63 cd(cur_dir);
64 j = [catchar,imagename,'.',getfield(s,names{2})];
65 copyfile([sdir,j],[tdir,catchar,imagename,j]);
66 cd(tdir);
67end
68cd(imagename);
69j = [imagename,'_par'];
70if not(exist(j)),
71 rec_num = 1;
72 p = s;
73else
74 % load par file
75 feval(j);
76 rec_num = length(p);
77 i = 1;
78 while (i<=rec_num),
79 k = 0;
80 for j=1:n,
81 k = k + sum(getfield(s,names{j})-getfield(p(i),names{j}));
82 end
83 if k==0,
84 if not(isempty(input(['Data already existed as record # ',num2str(i),...
85 '\nPress any non-return key to Overwrite'],'s'))),
86 break;
87 else
88 rec_num = i; % have checked in already, no update
89 cd(cur_dir);
90 return;
91 end
92 else
93 i = i + 1;
94 end
95 end
96 rec_num = i; % new parameter setting
97 p(rec_num)=s;
98end
99tdir = [tdir,catchar,imagename];
100cd(cur_dir);
101
102% third, check in data files
103% leave .ppm and _edgecon, _phase files
104% if not(exist([tdir,catchar,imagename,'.ppm'])),
105% copyfile([sdir,catchar,imagename,'.ppm'],[tdir,catchar,imagename,'.ppm']);
106% end
107
108% IC files only
109dn = getfnames(sdir,[imagename,'*_IC*.*']);
110header = sprintf('%s%c%s_%d_',tdir,catchar,imagename,rec_num);
111j = length(imagename)+2;
112k = length(dn);
113for i=1:k,
114 copyfile([sdir,catchar,dn{i}],[header,dn{i}(j:end)]);
115 delete([sdir,catchar,dn{i}]);
116end
117disp(sprintf('%d files checked in as record #%d',k,rec_num));
118
119
120% finally, update parameter file
121cd(tdir);
122fid = fopen([imagename,'_par.m'],'w');
123fprintf(fid,'%% Last checked in at %s\n\n',datestr(now));
124for i=1:rec_num,
125 for j=1:n,
126 k = getfield(p(i),names{j});
127 if ischar(k),
128 fprintf(fid,'p(%d).%s=\''%s\'';\n',i,names{j},k);
129 else
130 fprintf(fid,'p(%d).%s=%s;\n',i,names{j},num2str(k));
131 end
132 end
133 fprintf(fid,'\n');
134end
135fclose(fid);
136cd(cur_dir); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m b/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m
new file mode 100755
index 0000000..e677014
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/openfigure.m
@@ -0,0 +1,52 @@
1% function openfigure(m,n,caption,isnew)
2function h = openfigure(m,n,caption,isnew)
3
4if nargin<3,
5 caption = ' ';
6end
7
8if nargin<4,
9 isnew = 1;
10end
11
12if (m<=0 | n<=0)
13 return;
14end
15
16if isnew,
17 h = figure; colormap(gray);
18else
19 h = gcf;
20end
21clf
22
23subplot('position',[0,0,0.1,0.1]); axis off;
24text(0.1,0.15,sprintf('S. X. Yu, %s',date),'FontSize',8);
25
26subplot('position',[0,0.96,0.1,0.1]); axis off;
27text(0.1,0.15,caption,'FontSize',8);
28
29subplot(m,n,1);
30%return
31
32if (m==1 & n==1),
33 return;
34end
35
36%set(gcf,'PaperPosition',[0.25, 8, 8,2.5*m]);
37% set(gcf,'PaperPosition',[0.25,0.25,8,10.5]);
38%return
39
40if (m<=n),
41 set(gcf,'PaperOrientation','landscape','PaperPosition',[0.25,0.25,10.5,8]);
42else
43 set(gcf,'PaperPosition',[0.25,0.25,8,10.5]);
44end
45
46% comment on PaperPosition
47% [a,b,c,d]
48% (a,b) is the coordinate of the lower-left corner of the figure
49% (a,b) = (0,0) is the lower-left corner of the paper
50% (c,d) is the coordinate of the upper-right corner of the figure relative to the lower-left corner of the figure
51% Therefore, c>=a, d>=b
52% Full paper position would be [0,0,8.5,11] in inches
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m b/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m
new file mode 100755
index 0000000..10db297
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/showim.m
@@ -0,0 +1,36 @@
1% function showim(f,cmap) display real or complex image.
2% When it is complex, the real part and imaginary part
3% are displayed as [real,imag] in one image.
4% cmap is the colormap. default = gray, -1 = inverted gray.
5
6% Stella X. Yu, 2000.
7
8function showim(f,cmap,ishori)
9
10if not(isreal(f)),
11 i = [real(f(:)); imag(f(:))];
12 j = [min(i), max(i)];
13 [nr,nc] = size(f);
14 if nargin<3 | isempty(ishori),
15 ishori = nr>nc;
16 end
17 if ishori,
18 i = zeros(nr,1);
19 f = [real(f), [i+j(1),i+j(2)], imag(f)];
20 else
21 i = zeros(1,nc);
22 f = [real(f); [i+j(1);i+j(2)]; imag(f)];
23 end
24end
25imagesc(f); axis off; axis image;
26
27if nargin<2 | isempty(cmap),
28 return;
29end
30
31if cmap==1,
32 cmap = gray;
33elseif cmap==-1,
34 cmap = flipud(gray);
35end
36colormap(cmap); \ No newline at end of file
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m b/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m
new file mode 100755
index 0000000..b1fe1f4
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/showncut.m
@@ -0,0 +1,92 @@
1% function [g,lgd,v,s,dd] = showncut(fn,rec_num)
2% Input:
3% fn = file / image name
4% rec_num = Ncut record number
5% Output:
6% g = a cell contains 1D, 2D and 3D embeddings
7% lgd = legend for g
8% v = eigenvectors
9% s = eigenvalues
10% dd = normalization matrix = 1/sqrt(rowsum(abs(a)))
11% an image is displayed
12
13function [g,lgd,v,s,dd] = showncut(fn,rec_num)
14
15globalenvar; cd(IMAGE_DIR);cd(fn); feval([fn,'_par']);cd(HOME_DIR);
16par = p(rec_num);
17no_rep = (par.offset<1e-6);
18
19[v,s,dd] = firstncut(fn,rec_num);
20[m,n,nc] = size(v);
21
22% generate images for display
23nr = 5;
24num_plots = nc * nr;
25g = cell(num_plots,1);
26lgd = g;
27names = {'r','\theta','\phi'};
28x = cell(3,1);
29for j=1:nc,
30 g{j} = v(:,:,j);
31 lgd{j} = sprintf('%s_{%d} = %1.2f','\lambda', j+no_rep, s(j));
32
33 if j<nc,
34 [x{2},x{1}] = cart2pol(v(:,:,j),v(:,:,j+1));
35 k = j;
36 for t=1:2,
37 k = k + nc;
38 g{k} = x{t};
39 lgd{k} = sprintf('%s_{%d,%d}',names{t},j+[0:1]+no_rep);
40 end
41
42 if j<nc-1,
43 [x{2},x{3},x{1}] = cart2sph(v(:,:,j),v(:,:,j+1),v(:,:,j+2));
44 for t=[1,3], % theta must be the same as 2D embedding, so ignore it
45 k = k + nc;
46 g{k} = x{t};
47 lgd{k} = sprintf('%s_{%d,%d,%d}',names{t},j+[0:2]+no_rep);
48 end
49 end
50 end
51end
52
53% fill in slots by image f and affinity pattern
54j = nc + nc; g{j} = getimage2(fn); lgd{j} = sprintf('%d x %d image',m,n);
55j = nr * nc; g{j} = readpcm([fn,'_phase.pfm']); lgd{j} = 'phase';
56j = j - 1; g{j} = exp(-(readpfmc([fn,'_edgecon.pfm'])/(255*par.sig_IC)).^2); lgd{j} = 'IC';
57
58i = round(m*[1;3]./4);
59%i = i([1,1,2,2]);
60j = round(n*[1;3]./4);
61%j = j([1,2,1,2]);
62k = m * (j-1) + i;
63
64a = afromncut(v,s,dd,1,no_rep,k);
65
66y = [4*nc-1, 4*nc, 5*nc-1, 5*nc, 6*nc-1, 6*nc];
67for t=1:length(k),
68 g{y(t)} = reshape(a(t,:),[m,n]);
69 lgd{y(t)} = sprintf('a at (%d,%d)',i(t),j(t));
70end
71
72% find parameters
73fg_title = sprintf('%s: %s=%d, %s=%d, %s=%3.2f, %s=%3.2f',...
74par.fname_base,...
75'r_x', par.spatial_neighborhood_x,...
76'\sigma_x',par.sigma_x,...
77'\sigma_{IC}',par.sig_IC,...
78'repulsion',par.offset);
79
80openfigure(nr,nc,fg_title,0);
81dispimg(g,[nr,nc],lgd);
82
83% fix
84subplot(nr,nc,nc*3);
85plot(s,'ro'); title('\lambda');
86axis square; axis tight; set(gca,'XTick',[]);
87for t=1:length(k),
88 subplot(nr,nc,y(t));
89 hold on;
90 text(j(t),i(t),'+');
91end
92hold off
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m b/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m
new file mode 100755
index 0000000..262429a
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/startup.m
@@ -0,0 +1,18 @@
1globalenvar;
2
3addpath(IMAGE_DIR);
4
5addpath(HOME_DIR);
6
7path(path,['/hid/jshi/Research/walking']);
8
9tb_dir = ['/hid/jshi/matlab/toolbox/'];
10
11path(path,[tb_dir,'io']);
12path(path,[tb_dir,'filter']);
13path(path,[tb_dir,'filter_hist']);
14path(path,[tb_dir,'disp']);
15path(path,[tb_dir,'common']);
16path(path,[tb_dir,'textons']);
17path(path,[tb_dir,'pyramid']);
18
diff --git a/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m b/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m
new file mode 100755
index 0000000..c9b46ab
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/stella/test_ncutm.m
@@ -0,0 +1,38 @@
1fn = 'walk1';
2
3repulsion_test = 1;
4
5if 1,
6 f = getimage2(fn);
7 par = jshincutdefpar;
8 par.fname_base = fn;
9 par.spatial_neighborhood_x = 10;
10 par.sigma_x = 3 * par.spatial_neighborhood_x;
11 par.sig_IC = 0.03;
12 par.num_eigvecs = 10;
13 par.offset = 0.00;
14 par.sig_filter = 1.0;
15 par.elong_filter = 3.0;
16 [par,rec_num] = jshincut(par);
17 [g,lgd,v,s,dd] = showncut(fn,rec_num);
18
19if repulsion_test,
20 par.offset = 0.1;
21 [par,rec_num] = jshincut(par);
22 figure;
23 [g,lgd,v,s,dd] = showncut(fn,rec_num);
24end
25end
26
27if 0,
28 x = v(:,:,1);
29 y = v(:,:,2);
30 figure;
31 subplot(2,1,1); plot(x(:),y(:),'ro');
32 r = sqrt(x.^2+y.^2);
33 x = x./r;
34 y = y./r;
35 subplot(2,1,2); im([x,y]*[x,y]');
36 % mask = (x>0) & y>0;
37 % showmask(f,mask);
38end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/tars/TOOLBOX_calib.tar b/SD-VBS/common/toolbox/toolbox_basic/tars/TOOLBOX_calib.tar
new file mode 100755
index 0000000..bb418a5
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/tars/TOOLBOX_calib.tar
Binary files differ
diff --git a/SD-VBS/common/toolbox/toolbox_basic/textons/dist2.m b/SD-VBS/common/toolbox/toolbox_basic/textons/dist2.m
new file mode 100755
index 0000000..f2d93e1
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/textons/dist2.m
@@ -0,0 +1,27 @@
1function n2 = dist2(x, c)
2%DIST2 Calculates squared distance between two sets of points.
3%
4% Description
5% D = DIST2(X, C) takes two matrices of vectors and calculates the
6% squared Euclidean distance between them. Both matrices must be of
7% the same column dimension. If X has M rows and N columns, and C has
8% L rows and N columns, then the result has M rows and L columns. The
9% I, Jth entry is the squared distance from the Ith row of X to the
10% Jth row of C.
11%
12% See also
13% GMMACTIV, KMEANS, RBFFWD
14%
15
16% Copyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)
17
18[ndata, dimx] = size(x);
19[ncentres, dimc] = size(c);
20if dimx ~= dimc
21 error('Data dimension does not match dimension of centres')
22end
23
24n2 = (ones(ncentres, 1) * sum((x.^2)', 1))' + ...
25 ones(ndata, 1) * sum((c.^2)',1) - ...
26 2.*(x*(c'));
27
diff --git a/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m
new file mode 100755
index 0000000..e7fa4b0
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons.m
@@ -0,0 +1,46 @@
1function [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter);
2% [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter);
3%
4% find textons using kmeans for windowed portion FIw of filtered image
5%
6% to start with centers pulled randomly from image, set centers_in=[]
7
8% define number of textons
9%ncenters=25;
10
11[N1,N2,N3]=size(FIw);
12% reshape filtered image stack into a long array of feature vectors
13fv=reshape(FIw,N1*N2,N3);
14% (each row is a feature vector)
15
16%centers=.01^2*randn(ncenters,N3);
17% take centers randomly from within image
18if isempty(centers_in)
19 rndnum=1+floor(N1*N2*rand(1,ncenters));
20 centers_in=fv(rndnum,:);
21end
22
23options = foptions;
24options(1)=1; % Prints out error values.
25options(5) = 0;
26if nargin<4
27 n_iter=15;
28end
29options(14) = n_iter; % Number of iterations.
30
31[centers,options,d2,post]=kmeans2(centers_in,fv,options);
32
33% reshuffle the centers so that the one closest to the origin
34% (featureless) comes last
35norms=sum(centers.^2,2);
36[sortval,sortind]=sort(-norms);
37centers=centers(sortind,:);
38d2=reshape(d2,N1,N2,ncenters);
39post=reshape(post,N1,N2,ncenters);
40d2=d2(:,:,sortind);
41post=post(:,:,sortind);
42
43
44% retrieve cluster number assigned to each feature vector
45[minval,label]=min(d2,[],3);
46
diff --git a/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons1.m b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons1.m
new file mode 100755
index 0000000..b192015
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/textons/find_textons1.m
@@ -0,0 +1,37 @@
1function [centers,label,post,d2]=find_textons(fv,ncenters,centers_in,n_iter);
2% [centers,label,post,d2]=find_textons(FIw,ncenters,centers_in,n_iter);
3%
4% find textons using kmeans for windowed portion FIw of filtered image
5%
6% to start with centers pulled randomly from image, set centers_in=[]
7
8[N1,N2] =size(fv);
9
10% take centers randomly from within image
11if isempty(centers_in)
12 rndnum=1+floor(N1*rand(1,ncenters));
13 centers_in=fv(rndnum,:);
14end
15
16options = foptions;
17options(1)=1; % Prints out error values.
18options(5) = 0;
19if nargin<4
20 n_iter=15;
21end
22options(14) = n_iter; % Number of iterations.
23
24[centers,options,d2,post]=kmeans2(centers_in,fv,options);
25
26
27% retrieve cluster number assigned to each feature vector
28[minval,label]=min(d2,[],2);
29
30
31h = hist(label(:),[1:max(label(:))]);
32a = h>0;
33a = cumsum(a);
34
35[nr,nc] = size(label);
36label = reshape(a(label(:)),nr,nc);
37
diff --git a/SD-VBS/common/toolbox/toolbox_basic/textons/kmeans2.m b/SD-VBS/common/toolbox/toolbox_basic/textons/kmeans2.m
new file mode 100755
index 0000000..0bd87b2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/textons/kmeans2.m
@@ -0,0 +1,127 @@
1function [centres, options, d2, post, errlog] = kmeans2(centres, data, options)
2%KMEANS Trains a k means cluster model.
3%
4% Description
5% CENTRES = KMEANS(CENTRES, DATA, OPTIONS) uses the batch K-means
6% algorithm to set the centres of a cluster model. The matrix DATA
7% represents the data which is being clustered, with each row
8% corresponding to a vector. The sum of squares error function is used.
9% The point at which a local minimum is achieved is returned as
10% CENTRES. The error value at that point is returned in OPTIONS(8).
11%
12% [CENTRES, OPTIONS, POST, ERRLOG] = KMEANS(CENTRES, DATA, OPTIONS)
13% also returns the cluster number (in a one-of-N encoding) for each
14% data point in POST and a log of the error values after each cycle in
15% ERRLOG. The optional parameters have the following
16% interpretations.
17%
18% OPTIONS(1) is set to 1 to display error values; also logs error
19% values in the return argument ERRLOG. If OPTIONS(1) is set to 0, then
20% only warning messages are displayed. If OPTIONS(1) is -1, then
21% nothing is displayed.
22%
23% OPTIONS(2) is a measure of the absolute precision required for the
24% value of CENTRES at the solution. If the absolute difference between
25% the values of CENTRES between two successive steps is less than
26% OPTIONS(2), then this condition is satisfied.
27%
28% OPTIONS(3) is a measure of the precision required of the error
29% function at the solution. If the absolute difference between the
30% error functions between two successive steps is less than OPTIONS(3),
31% then this condition is satisfied. Both this and the previous
32% condition must be satisfied for termination.
33%
34% OPTIONS(14) is the maximum number of iterations; default 100.
35%
36% See also
37% GMMINIT, GMMEM
38%
39
40% Copyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)
41
42[ndata, data_dim] = size(data);
43[ncentres, dim] = size(centres);
44
45if dim ~= data_dim
46 error('Data dimension does not match dimension of centres')
47end
48
49if (ncentres > ndata)
50 error('More centres than data')
51end
52
53% Sort out the options
54if (options(14))
55 niters = options(14);
56else
57 niters = 100;
58end
59
60store = 0;
61if (nargout > 3)
62 store = 1;
63 errlog = zeros(1, niters);
64end
65
66% Check if centres and posteriors need to be initialised from data
67if (options(5) == 1)
68 % Do the initialisation
69 perm = randperm(ndata);
70 perm = perm(1:ncentres);
71
72 % Assign first ncentres (permuted) data points as centres
73 centres = data(perm, :);
74end
75% Matrix to make unit vectors easy to construct
76id = eye(ncentres);
77
78% Main loop of algorithm
79for n = 1:niters
80
81 % Save old centres to check for termination
82 old_centres = centres;
83
84 % Calculate posteriors based on existing centres
85 d2 = dist2(data, centres);
86 % Assign each point to nearest centre
87 [minvals, index] = min(d2', [], 1);
88 post = id(index,:);
89
90 num_points = sum(post, 1);
91 % Adjust the centres based on new posteriors
92 for j = 1:ncentres
93 if (num_points(j) > 0)
94 centres(j,:) = sum(data(find(post(:,j)),:), 1)/num_points(j);
95 end
96 end
97
98 % Error value is total squared distance from cluster centres
99 e = sum(minvals);
100 tmp = sort(minvals);
101 e95 = sqrt(tmp(round(length(tmp) * 0.95)));
102 erms = sqrt(e/ndata);
103 if store
104 errlog(n) = e;
105 end
106 if options(1) > 0
107 fprintf(1, ' Cycle %4d RMS Error %11.6f 95-tier Error %11.6f\n', n, erms,e95);
108 end
109
110 if n > 1
111 % Test for termination
112 if max(max(abs(centres - old_centres))) < options(2) & ...
113 abs(old_e - e) < options(3)
114 options(8) = e;
115 return;
116 end
117 end
118 old_e = e;
119end
120
121% If we get here, then we haven't terminated in the given number of
122% iterations.
123options(8) = e;
124%if (options(1) >= 0)
125% disp('Warning: Maximum number of iterations has been exceeded');
126%end
127