Home > Source > 2D > register_2d_images.m

register_2d_images

PURPOSE ^

==============================================================.

SYNOPSIS ^

function [status] = register_2d_images(number_of_images, image_width, image_height, position, width, height, width_variation, height_variation)

DESCRIPTION ^

 ==============================================================.
 REGISTER_2D_IMAGES: Genrates examples of 2-D images and warps them

    GENERAL

      [status] = register_2d_images(number_of_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
 ==============================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [status] = register_2d_images(number_of_images, image_width, image_height, position, width, height, width_variation, height_variation)
0002 % ==============================================================.
0003 % REGISTER_2D_IMAGES: Genrates examples of 2-D images and warps them
0004 %
0005 %    GENERAL
0006 %
0007 %      [status] = register_2d_images(number_of_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          
0138          warp_params.green = 'biharmCPS';
0139          param_list = [];
0140           %%%% The following are the ref and images: warped_images, reference_image_vector
0141         [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points); 
0142                             % do this knowt-point selection in 2-D. see the brain equivalent which
0143                             % picks up points around the skull. in the above, steps are the points
0144                             % in 1-D - see GRID_TEST
0145             % now with knotpoints chosen in 2-D space....
0146          warped_grid = grid;
0147             % copy these knot-points. grid should be called knot-points or something similar. Maybe a 2-d grid
0148          [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);
0149             % find good paramters to achieve good similarity to the reference image
0150          param_list(size(param_list,1)+1,:).d = params;
0151             % copy the parameters of the warp. Meaning of the notation above is still unknown.
0152          warped_grid = grid + params;
0153              % append parameters to the grip. Perhaps parameters are offests to the grid
0154          start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0155              % non-rigid transformation applied
0156          start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0157             % interpolate the image
0158          warped_points = start_points;
0159          warped_image = start_image;
0160            % copy some values
0161     end    
0162 end    
0163 
0164 
0165 status = 0;
0166      % report okay status
0167      % if problems have occurred earlier on in this function, set this flag to 1.
0168      
0169      
0170      
0171 % The following is taken from the MATLAB logo function and can be used to
0172 % show the 2D set as a plain with startling lighting effects.
0173 %
0174 % L = point_vectors(:,:,1);
0175 % axes('CameraPosition', [-193.4013 -265.1546  220.4819],...
0176 %     'CameraTarget',[26 26 10], ...
0177 %     'CameraUpVector',[0 0 1], ...
0178 %     'CameraViewAngle',9.5, ...
0179 %     'DataAspectRatio', [1 1 .9],...
0180 %     'Position',[0 0 1 1], ...
0181 %     'Visible','off', ...
0182 %     'XLim',[1 51], ...
0183 %     'YLim',[1 51], ...
0184 %     'ZLim',[-13 40]);
0185 % s = surface(L, ...
0186 %     'EdgeColor','none', ...
0187 %     'FaceColor',[0.8 0.2 0.2], ...
0188 %     'FaceLighting','phong', ...
0189 %     'AmbientStrength',0.3, ...
0190 %     'DiffuseStrength',0.6, ...
0191 %     'Clipping','off',...
0192 %     'BackFaceLighting','lit', ...
0193 %     'SpecularStrength',1.1, ...
0194 %     'SpecularColorReflectance',1, ...
0195 %     'SpecularExponent',7);
0196 % l1 = light('Position',[40 100 20], ...
0197 %     'Style','local', ...
0198 %     'Color',[0 0.7 0.7]);
0199 % l2 = light('Position',[.5 -1 .4], ...
0200 %     'Color',[1 1 0]);

Generated on Thu 13-May-2004 18:00:46 by m2html © 2003