A non-transitory computer readable storage medium having stored thereon a computer program that causes image processing to be performed that expresses small regions in an image with not more than a predetermined number of representative colors, the image processing being carried out for each of the small regions, by causing a computer to execute:
- a first selection step of, with respect to a plurality of pixels in the small region, based on variation values that indicate the extent of variation, in the small region, of values of a plurality of color variables that express a color of each of the pixels, selecting one of the color variables as a first target color variable;
- a first reference value calculation step of, from among values from a maximum value to a minimum value of the first target color variable in the small region, obtaining a value of the first target color variable for which the number of pixels is “0” as a first reference value for grouping the pixels;
- a first grouping step of grouping the pixels in the small region based on first the reference value obtained in the reference value calculation step;
- a second selection step of determining the variation value for each color variable in each group obtained in the first grouping step, selecting the group with the largest variation value as a target group and selecting the color variable with the largest variation value as a second target color variable, based on the variation values of the color variables in each of the groups obtained by the first grouping portion;
- a second reference value calculation step of, from among values from a maximum value of the second target color variable in the target group, when there is a value of the second target color variable for which the number of pixels is “0”, obtaining the value of the second target color variable in the target group as a second reference value for grouping the pixels;
- a second grouping step of grouping the pixels in the target group based on the second reference value obtained by the second reference value calculation portion;
- and
- a representative color calculation step of, for each of groups obtained in the second grouping step, obtaining a representative color based on a value of each of the color variables of pixels that belong to the group.