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