============================================================== MAKE_2D_IMAGES: Genrates examples of 2-D images and warps them in 1-D a scan-line at a time. GENERAL [status] = make_2d_images(n_images, image_width, image_height, position, width, height, width_variation, height_variation) INPUT/S -number_of_images: The number of images to generate. -image_width: The width of the 2-D images to be created. -image_height: The width of the 2-D images to be created. -width: The width of the object in the image. -width_variation: The width variation of the object in the image. -position: The horizontal position of the object in the image. -height: The height of the object in the image. -height_variation: The height variation of the object in the image. OUTPUT/S -status Status on the success of the process. PENDING WORK KNOWN BUG/S - COMMENT/S RELATED FUNCTION/S MAKE_1D_IMAGES, MAKE_1D_BUMP, REGISTER_2D_IMAGES ABOUT -Created: January 6th, 2003 -Last update: January 6th, 2003 -Revision: 0.0.1 -Author: R. S. Schestowitz, University of Manchester ==============================================================
0001 function [status] = make_2d_images(number_of_images, image_width, image_height, position, width, height, width_variation, height_variation) 0002 % ============================================================== 0003 % MAKE_2D_IMAGES: Genrates examples of 2-D images and warps them in 1-D 0004 % a scan-line at a time. 0005 % 0006 % GENERAL 0007 % 0008 % [status] = make_2d_images(n_images, image_width, 0009 % image_height, position, width, height, width_variation, height_variation) 0010 % 0011 % INPUT/S 0012 % 0013 % -number_of_images: 0014 % The number of images to generate. 0015 % 0016 % -image_width: 0017 % The width of the 2-D images to be created. 0018 % 0019 % -image_height: 0020 % The width of the 2-D images to be created. 0021 % 0022 % -width: 0023 % The width of the object in the image. 0024 % 0025 % -width_variation: 0026 % The width variation of the object in the image. 0027 % 0028 % -position: 0029 % The horizontal position of the object in the image. 0030 % 0031 % -height: 0032 % The height of the object in the image. 0033 % 0034 % -height_variation: 0035 % The height variation of the object in the image. 0036 % 0037 % OUTPUT/S 0038 % 0039 % -status 0040 % Status on the success of the process. 0041 % 0042 % PENDING WORK 0043 % 0044 % 0045 % KNOWN BUG/S 0046 % 0047 % - 0048 % 0049 % COMMENT/S 0050 % 0051 % 0052 % RELATED FUNCTION/S 0053 % 0054 % MAKE_1D_IMAGES, MAKE_1D_BUMP, REGISTER_2D_IMAGES 0055 % 0056 % ABOUT 0057 % 0058 % -Created: January 6th, 2003 0059 % -Last update: January 6th, 2003 0060 % -Revision: 0.0.1 0061 % -Author: R. S. Schestowitz, University of Manchester 0062 % ============================================================== 0063 0064 0065 warp_flag = 1; 0066 % should the images be warped (else only displayed) 0067 verbose_mode = 1; 0068 % internally controlled parameter 0069 debugging_mode = 1; 0070 % does extra tests 0071 0072 subplot_fig = figure; 0073 H = figure(subplot_fig); 0074 0075 for i=1:number_of_images, 0076 if (verbose_mode == 1) 0077 disp(['generating image #',num2str(i),' of ',num2str(number_of_images)]); 0078 end 0079 [index,current_image_vectors,current_point_vectors] = make_2d_bump(1, image_width, image_height, position, width, height, width_variation, height_variation); 0080 if (debugging_mode == 1) % view it if debugging 0081 size(current_image_vectors) 0082 index 0083 end 0084 subplot(number_of_images+4,2,i); 0085 hold on; 0086 title(['Generated image #',num2str(i)]); 0087 imshow(current_image_vectors); 0088 image_vectors(:,:,i) = current_image_vectors; 0089 point_vectors(:,:,i) = current_point_vectors; 0090 hold off; 0091 end 0092 0093 if( warp_flag == 1), 0094 number_of_iterations = 1; 0095 % how many iterations of the optimisation/warping to run 0096 0097 reference_points_vector = point_vectors(:,:,1); 0098 reference_image_vector = image_vectors(:,:,1); 0099 % set reference to be the first image 0100 if (debugging_mode == 1) % view it if debugging 0101 subplot(number_of_images+4,2,number_of_images+2); 0102 hold on; 0103 title('Reference image'); 0104 imshow(reference_image_vector); 0105 hold off; 0106 end 0107 0108 warped_images = image_vectors; 0109 warped_points = point_vectors; % copy these values as warped variables are dynamic 0110 0111 for n=1:number_of_iterations, 0112 % images are now warped one by one with respect to reference image 0113 for i=1:number_of_images, 0114 if (verbose_mode == 1) 0115 disp(['Warping image #',num2str(i),' of ',num2str(number_of_images)]); 0116 end 0117 current_image_vector_to_warp = warped_images(:,:,i); 0118 current_point_vector_to_warp = warped_points(:,:,i); 0119 0120 % warp image using one objective function or another - currently msd_opt_together 0121 0122 0123 scores_mi(i) = mi(reference_image_vector, warped_images(:,:,i),10); 0124 scores_smsd(i) = sum(msd(reference_image_vector, warped_images(:,:,i))); 0125 % get similarity measures 0126 subplot(number_of_images+4,2,number_of_images+3); 0127 hold on; 0128 title('MI scores'); 0129 plot(scores_mi,'*'); 0130 hold off; 0131 0132 subplot(number_of_images+4,2,number_of_images+4); 0133 hold on; 0134 title('MSD scores'); 0135 plot(scores_smsd,'*'); 0136 hold off; 0137 end 0138 for current_scan_line=1:size(warped_images,1), 0139 % get scan lines of all images and a reference at a time 0140 current_lines = warped_images (current_scan_line,:,:) 0141 current_reference_line = reference_image_vector (current_scan_line,:) 0142 [images_post_registration(current_scan_line), points] = register_1d_images_set( 0143 end 0144 0145 % create diagonal control points 0146 % send to 1-d registration function and save vectors on a new variable 0147 % append all vectors to form matrices 0148 % display matrices as images which are 1-d scanline warps 0149 % make this a pseudo NRR in 2-D which deals with scanlines in 1-D in practice 0150 % and generate gegistration videos or images 'pre-reg' and 'post-reg' to be put on public_html 0151 0152 % last_score = sum(msd(reference_image_vector, warped_images(:,:,2))) 0153 % last_score = sum(msd(reference_image_vector, current_image_vector_to_warp)) 0154 % last_score = mi(reference_image_vector, warped_images(:,:,2),10) 0155 % last_score = mi(reference_image_vector, current_image_vector_to_warp,10) 0156 % 0157 % [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points); 0158 % 0159 % 0160 % 0161 % warp_params.green = 'biharmCPS'; 0162 % param_list = []; 0163 % start_image = current_image_vector_to_warp; 0164 % start_points = current_point_vector_to_warp; 0165 % 0166 % 0167 % warped_grid = grid; 0168 % last_score = eval_msd_multi_warp(zeros(size(grid)),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params); 0169 % [params, score] = fminsearch(@eval_msd_multi_warp,zeros(size(grid)),optimset('Display',verbose,'TolX',1e-10),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params); 0170 % param_list(size(param_list,1)+1,:).d = params; 0171 % warped_grid = grid + params; 0172 % start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]); 0173 % start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0); 0174 % disp(['Initial score: ',num2str(last_score),' Final score: ',num2str(score)]); 0175 % warped_points = start_points; 0176 % warped_image = start_image; 0177 end 0178 end 0179 0180 0181 status = 0; 0182 % report okay status