Home > Source > 2D > register_2d_images.m

register_2d_images

PURPOSE ^

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

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 % REGISTER_2D_IMAGES: Genrates examples of 2-D images and warps them
0003 %
0004 %    GENERAL
0005 %
0006 %      [status] = register_2d_images(number_of_images, image_width,
0007 %        image_height, position, width, height, width_variation, height_variation)
0008 %
0009 %    INPUT/S
0010 %
0011 %      -number_of_images:
0012 %           The number of images to generate.
0013 %
0014 %      -image_width:
0015 %           The width of the 2-D images to be created.
0016 %
0017 %      -image_height:
0018 %           The width of the 2-D images to be created.
0019 %
0020 %      -width:
0021 %            The width of the object in the image.
0022 %
0023 %      -width_variation:
0024 %            The width variation of the object in the image.
0025 %
0026 %      -position:
0027 %            The horizontal position of the object in the image.
0028 %
0029 %      -height:
0030 %            The height of the object in the image.
0031 %
0032 %      -height_variation:
0033 %            The height variation of the object in the image.
0034 %
0035 %    OUTPUT/S
0036 %
0037 %      -status
0038 %           Status on the success of the process.
0039 %
0040 %    PENDING WORK
0041 %
0042 %
0043 %    KNOWN BUG/S
0044 %
0045 %      -
0046 %
0047 %    COMMENT/S
0048 %
0049 %
0050 %    RELATED FUNCTION/S
0051 %
0052 %      MAKE_1D_IMAGES, MAKE_1D_BUMP, REGISTER_2D_IMAGES
0053 %
0054 %    ABOUT
0055 %
0056 %      -Created:     January 6th, 2003
0057 %      -Last update: January 6th, 2003
0058 %      -Revision:    0.0.1
0059 %      -Author:      R. S. Schestowitz, University of Manchester
0060 % ==============================================================
0061 
0062 
0063 warp_flag = 1;
0064           % should the images be warped (else only displayed)
0065 verbose_mode = 1;
0066           % internally controlled parameter
0067 debugging_mode = 1;
0068           % does extra tests
0069 
0070 subplot_fig = figure;
0071 H = figure(subplot_fig);
0072 
0073 for i=1:number_of_images,
0074    if (verbose_mode == 1) 
0075      disp(['generating image #',num2str(i),' of ',num2str(number_of_images)]);
0076    end
0077    [index,current_image_vectors,current_point_vectors]=make_2d_bump(1, image_width, image_height, position, width, height, width_variation, height_variation);
0078    if (debugging_mode == 1) % view it if debugging
0079        size(current_image_vectors)
0080        index
0081    end 
0082    subplot(number_of_images+4,2,i);
0083    hold on;
0084    title(['Generated image #',num2str(i)]);   
0085    imshow(current_image_vectors);
0086    image_vectors(:,:,i) = current_image_vectors;
0087    point_vectors(:,:,i) = current_point_vectors;
0088    hold off;
0089 end
0090 
0091 if( warp_flag == 1),    
0092     number_of_iterations = 1;
0093          % how many iterations of the optimisation/warping to run
0094     
0095     reference_points_vector = point_vectors(:,:,1);
0096     reference_image_vector = image_vectors(:,:,1);
0097                 % set reference to be the first image
0098     if (debugging_mode == 1) % view it if debugging
0099       subplot(number_of_images+4,2,number_of_images+2);
0100       hold on;
0101       title('Reference image');
0102       imshow(reference_image_vector);
0103       hold off;
0104     end 
0105          
0106     warped_images = image_vectors;
0107     warped_points = point_vectors;   % copy these values as warped variables are dynamic
0108          
0109     for n=1:number_of_iterations,
0110                             % images are now warped one by one with respect to reference image
0111          for i=1:number_of_images,
0112                 if (verbose_mode == 1) 
0113                    disp(['Warping image #',num2str(i),' of ',num2str(number_of_images)]);
0114                 end
0115                 current_image_vector_to_warp = warped_images(:,:,i);
0116                 current_point_vector_to_warp = warped_points(:,:,i);
0117                 
0118                 % warp image using one objective function or another - currently msd_opt_together
0119                 
0120 
0121                 scores_mi(i) = mi(reference_image_vector, warped_images(:,:,i),10);
0122                 scores_smsd(i) = sum(msd(reference_image_vector, warped_images(:,:,i)));
0123                              % get similarity measures
0124                 subplot(number_of_images+4,2,number_of_images+3);        
0125                 hold on;
0126                 title('MI scores');
0127                 plot(scores_mi,'*');
0128                 hold off;   
0129                 
0130                 subplot(number_of_images+4,2,number_of_images+4);
0131                 hold on;
0132                 title('MSD scores'); 
0133                 plot(scores_smsd,'*');
0134                 hold off;
0135          end
0136          
0137          warp_params.green = 'biharmCPS';
0138          param_list = [];
0139           %%%% The following are the ref and images: warped_images, reference_image_vector
0140         [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points); 
0141                             % do this knowt-point selection in 2-D. see the brain equivalent which
0142                             % picks up points around the skull. in the above, steps are the points
0143                             % in 1-D - see GRID_TEST
0144             % now with knotpoints chosen in 2-D space....
0145          warped_grid = grid;
0146             % copy these knot-points. grid should be called knot-points or something similar. Maybe a 2-d grid
0147          [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);
0148             % find good paramters to achieve good similarity to the reference image
0149          param_list(size(param_list,1)+1,:).d = params;
0150             % copy the parameters of the warp. Meaning of the notation above is still unknown.
0151          warped_grid = grid + params;
0152              % append parameters to the grip. Perhaps parameters are offests to the grid
0153          start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0154              % non-rigid transformation applied
0155          start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0156             % interpolate the image
0157          warped_points = start_points;
0158          warped_image = start_image;
0159            % copy some values
0160     end    
0161 end    
0162 
0163 
0164 status = 0;
0165      % report okay status
0166      % if problems have occurred earlier on in this function, set this flag to 1.
0167      
0168      
0169      
0170 % The following is taken from the MATLAB logo function and can be used to
0171 % show the 2D set as a plain with startling lighting effects.
0172 %
0173 % L = point_vectors(:,:,1);
0174 % axes('CameraPosition', [-193.4013 -265.1546  220.4819],...
0175 %     'CameraTarget',[26 26 10], ...
0176 %     'CameraUpVector',[0 0 1], ...
0177 %     'CameraViewAngle',9.5, ...
0178 %     'DataAspectRatio', [1 1 .9],...
0179 %     'Position',[0 0 1 1], ...
0180 %     'Visible','off', ...
0181 %     'XLim',[1 51], ...
0182 %     'YLim',[1 51], ...
0183 %     'ZLim',[-13 40]);
0184 % s = surface(L, ...
0185 %     'EdgeColor','none', ...
0186 %     'FaceColor',[0.8 0.2 0.2], ...
0187 %     'FaceLighting','phong', ...
0188 %     'AmbientStrength',0.3, ...
0189 %     'DiffuseStrength',0.6, ...
0190 %     'Clipping','off',...
0191 %     'BackFaceLighting','lit', ...
0192 %     'SpecularStrength',1.1, ...
0193 %     'SpecularColorReflectance',1, ...
0194 %     'SpecularExponent',7);
0195 % l1 = light('Position',[40 100 20], ...
0196 %     'Style','local', ...
0197 %     'Color',[0 0.7 0.7]);
0198 % l2 = light('Position',[.5 -1 .4], ...
0199 %     'Color',[1 1 0]);

Generated on Fri 14-May-2004 10:05:30 by m2html © 2003