0001 function [image_number] = find_image_closest_to_mean (images, image_width, number_of_images, type, distance_type)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
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
0082
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