ColorTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Graphics : Packages : ColorTools : ColorTools/ColorsFromImage

ColorTools

  

ColorsFromImage

  

extract the colors from an image

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

ColorsFromImage(image)

Parameters

image

-

a string that is the name of an image file or an image array

Options

• 

number= positive integer - limit on how many colors to process

• 

scale= true, false, or non-negative number - if false the image will not be scaled before pixels are extracted into colors, if a number that number will be used for scaling.

• 

space=string - color space of the returned colors or "hex"

• 

threshold=positive float - a percent threshold for removing infrequently appearing colors

Description

• 

This command extracts the unique colors from an image file into a list of Color objects or hex strings. The image is usually scaled also so that its maximum dimension in pixels is no more than the square root of number which is 1000 by default.  Use scale=false to have every pixel in the orginal image processed--note that this may cause the command to be very slow and is not recommended for very large images.

• 

At most number colors will be returned. If there are more than number unique colors in the image they will be returned in order of how frequently they appear. This command will not choose arbitrarily among colors of the same frequency, but will either remove or return all colors of any given frequency.

• 

If threshold option is given, then only colors that appear in more than that percent of pixels will be returned.  No more than number colors will be returned and at least one color will be returned.

• 

This command does not attempt to combine similar colors. To process the colors to reduce to the distinct shades use the ColorTools[ReducePalette] command.

Examples

withColorTools:

imgfilecatkerneloptsdatadir,/images/tree.jpg:

ImageTools:-EmbedImageTools:-Readimgfile

fullColorsFromImageimgfile:

numelemsfull

119

(5.1)

full50..75

RGB : 0.318 0.404 0.122,RGB : 0.494 0.651 0.792,RGB : 0.533 0.69 0.827,RGB : 0.506 0.678 0.816,RGB : 0.984 0.973 0.937,RGB : 0.722 0.757 0.792,RGB : 0.533 0.682 0.824,RGB : 0.482 0.647 0.796,RGB : 0.51 0.541 0.208,RGB : 0.988 0.976 0.949,RGB : 0.514 0.682 0.82,RGB : 0.855 0.851 0.843,RGB : 0.82 0.82 0.82,RGB : 0.467 0.643 0.796,RGB : 0.267 0.384 0.0941,RGB : 0.71 0.745 0.78,RGB : 0.804 0.8 0.82,RGB : 0.569 0.706 0.816,RGB : 0.545 0.698 0.827,RGB : 0.439 0.51 0.173,RGB : 0.984 0.969 0.933,RGB : 0.984 0.973 0.945,RGB : 0.369 0.459 0.192,RGB : 0.463 0.635 0.788,RGB : 0.278 0.396 0.122,RGB : 0.549 0.702 0.831

(5.2)

moreColorsFromImageimgfile,scale=0.11,number=1200:

numelemsmore

1107

(5.3)

ReducePalettemore

Lab : 66.5 -4.96 -23.7,Lab : 4.89 -6.07 4.74,Lab : 64.6 -2.04 66.5,Lab : 33.8 -23.7 35.5,Lab : 96.2 0.256 4.17,Lab : 51.5 -7.48 7.88,Lab : 17.8 -16.2 19.5,Lab : 48.3 -14.3 46.8,Lab : 72.5 -2.51 1.43,Lab : 33.7 1.35 35.3,Lab : 27.8 -3.61 1.01,Lab : 69.2 -11.1 24.5,Lab : 56.3 -8.93 -5.4,Lab : 82.3 -0.00141 -1.75,Lab : 41.5 -7.17 5.25,Lab : 59.9 -17.5 57.2,Lab : 27.7 -13.5 17.4,Lab : 54.4 -1.68 46.2,Lab : 57.8 -0.4 2.27,Lab : 72.5 -1.5 -7.8

(5.4)

Setting infolevel for ColorTools to 2 or greater will give useful information.

infolevelColorTools2

infolevelColorTools2

(5.5)

imgImageTools:-Readimgfile

img0.9137254901960780.9450980392156860.6588235294117650.4705882352941180.7882352941176470.9764705882352940.4941176470588240.8000000000000000.6431372549019610.458823529411765...0.9176470588235290.9843137254901960.7960784313725490.6509803921568630.4627450980392160.9411764705882350.6666666666666670.4784313725490200.7921568627450980.631372549019608...0.8980392156862750.9725490196078430.4862745098039220.7921568627450980.6352941176470590.9882352941176470.8039215686274510.6588235294117650.4666666666666670.784313725490196...0.9137254901960780.9372549019607840.6588235294117650.4745098039215690.7882352941176470.9764705882352940.4941176470588240.8000000000000000.6431372549019610.462745098039216...0.9137254901960780.9843137254901960.8039215686274510.6549019607843140.4627450980392160.9411764705882350.6666666666666670.4823529411764710.7960784313725490.635294117647059...0.9058823529411760.9725490196078430.4901960784313730.7960784313725490.6352941176470590.9882352941176470.8039215686274510.6549019607843140.4666666666666670.788235294117647...0.8980392156862750.9450980392156860.6627450980392160.4705882352941180.7882352941176470.9764705882352940.4941176470588240.8000000000000000.6431372549019610.901960784313726...0.8980392156862750.9725490196078430.8078431372549020.6509803921568630.4588235294117650.9411764705882350.6666666666666670.4784313725490200.7960784313725490.898039215686275...0.8980392156862750.9607843137254900.4862745098039220.7921568627450980.6313725490196080.9882352941176470.8039215686274510.6509803921568630.4666666666666670.890196078431372...0.8980392156862750.9411764705882350.6588235294117650.4745098039215690.7764705882352940.9764705882352940.4901960784313730.7960784313725490.6431372549019610.901960784313726...`:``:``:``:``:``:``:``:``:``:`slice of 266 × 400 × 3 Array

(5.6)

threshColorsFromImageimg,threshold=0.003

ColorsFromImage: processing a 266 by 400 pixel image
ColorsFromImage: scaling factor=0.111803
ColorsFromImage: scaled to a 30 by 45 pixel image
ColorsFromImage: found 1350 colors total
ColorsFromImage: found 1174 unique colors
ColorsFromImage: returning the 14 colors that appear at least 4 times

threshRGB : 0.541 0.694 0.824,RGB : 0.576 0.659 0.733,RGB : 0.49 0.655 0.804,RGB : 0.988 0.976 0.941,RGB : 0.984 0.973 0.937,RGB : 0.502 0.671 0.808,RGB : 0.267 0.384 0.0941,RGB : 0.467 0.643 0.796,RGB : 0.984 0.969 0.933,RGB : 0.486 0.659 0.804,RGB : 0.51 0.678 0.816,RGB : 0.514 0.671 0.812,RGB : 0.482 0.655 0.8,RGB : 0.498 0.667 0.804

(5.7)

Compatibility

• 

The ColorTools[ColorsFromImage] command was introduced in Maple 18.

• 

For more information on Maple 18 changes, see Updates in Maple 18.

• 

The ColorTools[ColorsFromImage] command was updated in Maple 2019.

• 

The image parameter was updated in Maple 2019.

• 

The scale and threshold options were introduced in Maple 2019.

• 

For more information on Maple 2019 changes, see Updates in Maple 2019.

See Also

ColorTools

ColorTools/Color

ColorTools/ColorSpaces

ImageTools