Home > Source > Helper > find_image_closest_to_mean.m

find_image_closest_to_mean

PURPOSE ^

==============================================================

SYNOPSIS ^

function [image_number] = find_image_closest_to_mean (images, image_width, number_of_images, type, distance_type)

DESCRIPTION ^

 ==============================================================
 FIND_IMAGE_CLOSEST_TO_MEAN: Find the image closest to the mean image

    GENERAL

      [image_number] = find_image_closest_to_mean (images)

    INPUT/S

      -images:
            All the images.

      -image_width:
            The width of the images.

      -number_of_images:
            The number of images.

      -type:
            Allows other (inverse) operations.

      -distance_type:
            The way to meausre distance from the mean.
           
    OUTPUT/S

      -image_number:
           The number of the image closest to the mean.

    PENDING WORK

      -

    KNOWN BUG/S

      -None.

    COMMENT/S

      -

    RELATED FUNCTION/S

      

    ABOUT

      -Created:     May 1st, 2004
      -Last update: May 1st, 2004
      -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 [image_number] = find_image_closest_to_mean (images, image_width, number_of_images, type, distance_type)
0002 
0003 % ==============================================================
0004 % FIND_IMAGE_CLOSEST_TO_MEAN: Find the image closest to the mean image
0005 %
0006 %    GENERAL
0007 %
0008 %      [image_number] = find_image_closest_to_mean (images)
0009 %
0010 %    INPUT/S
0011 %
0012 %      -images:
0013 %            All the images.
0014 %
0015 %      -image_width:
0016 %            The width of the images.
0017 %
0018 %      -number_of_images:
0019 %            The number of images.
0020 %
0021 %      -type:
0022 %            Allows other (inverse) operations.
0023 %
0024 %      -distance_type:
0025 %            The way to meausre distance from the mean.
0026 %
0027 %    OUTPUT/S
0028 %
0029 %      -image_number:
0030 %           The number of the image closest to the mean.
0031 %
0032 %    PENDING WORK
0033 %
0034 %      -
0035 %
0036 %    KNOWN BUG/S
0037 %
0038 %      -None.
0039 %
0040 %    COMMENT/S
0041 %
0042 %      -
0043 %
0044 %    RELATED FUNCTION/S
0045 %
0046 %
0047 %
0048 %    ABOUT
0049 %
0050 %      -Created:     May 1st, 2004
0051 %      -Last update: May 1st, 2004
0052 %      -Revision:    0.0.1
0053 %      -Author:      R. S. Schestowitz, University of Manchester
0054 % ==============================================================
0055 for current_image_number = 1:number_of_images,   
0056     for i = 1:image_width - 1,
0057       if (images(i, current_image_number) == 0 & images(i + 1, current_image_number) ~= 0)
0058         lo(current_image_number) = i;
0059       elseif (images(i, current_image_number) ~= 0 & images(i + 1, current_image_number) == 0)
0060         hi(current_image_number) = i;
0061       end
0062     end
0063 end
0064 
0065 mean_low = mean(lo);
0066 mean_high = mean(hi);
0067 
0068 for current_image_number = 1:number_of_images,
0069    switch distance_type,
0070        case 'absolute_values'    
0071          distance_measure(current_image_number) = abs(mean_low - lo(current_image_number)) ...
0072           + abs(mean_high - hi(current_image_number));
0073        case 'sum_of_squared_distances'
0074          distance_measure(current_image_number) = (mean_low - lo(current_image_number)).^2 ...
0075           + (mean_high - hi(current_image_number)).^2;
0076        otherwise
0077          error('Unknown distance type.');
0078    end
0079 end
0080 
0081 % OPTIMISATION NOTE: In the above, very many identical tests are run for
0082 % all images.
0083 
0084 if (strcmp(type,'closest')),
0085   required_distance = min (distance_measure);
0086 elseif (strcmp(type,'farthest')),
0087   required_distance = max (distance_measure);
0088 end
0089 
0090 for current_image_number = 1:number_of_images,
0091   if (distance_measure(current_image_number) == required_distance),
0092       image_number = current_image_number;
0093   end
0094 end

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