({{, (RefLink[ImageGraphics, paclet:ref/ImageGraphics])[image] 
returns the content of image in the form of scalable vector graphics.}, {, (RefLink[ImageGraphics, paclet:ref/ImageGraphics])[image,n]
uses up to n colors for the vector graphics.}, {, (RefLink[ImageGraphics, paclet:ref/ImageGraphics])[image,colors]
creates vector graphics containing the specified colors.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ImageGraphics, paclet:ref/ImageGraphics]) is also known as image vectorization or auto tracing.

(RefLink[ImageGraphics, paclet:ref/ImageGraphics]) works with arbitrary 2D images and returns a (RefLink[Graphics, paclet:ref/Graphics]) object.

(RefLink[ImageGraphics, paclet:ref/ImageGraphics]) has the same options as (RefLink[Graphics, paclet:ref/Graphics]), with the following changes and additions:

Possible settings for (RefLink[Method, paclet:ref/Method]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Convert a color image into vector graphics:

ImageGraphics[]

Convert a natural image to vector graphics using 8 colors:

ImageGraphics[,8]

OpenersExampleSection1(Spacer1)Scope  (3)

Convert a bitmap of a digit to vector graphics:

ImageGraphics[,2]

Convert a grayscale image to vector graphics:

ExampleData[{"TestImage","Clock"}]//ImageGraphics

By default, an automatic color quantization is performed:

i=;

ImageGraphics[i]

Specify the number of colors to use:

ImageGraphics[i,3]

Specify the explicit colors to use in the vector graphics:

ImageGraphics[i,{White,Black,Pink}]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)Method  (1)

Exact segment contours:

i=;

ImageGraphics[i,Method->"Exact"]

Simplified contours by connecting linearly separable segments:

ImageGraphics[i,Method->"LinearSeparable"]

Smooth contours by rounding corners of less than 90° with Bézier splines:

ImageGraphics[i,Method->{"LinearSeparable",90°}]

Use marching squares:

ImageGraphics[i,Method->"MarchingSquares"]

Use dual marching squares:

ImageGraphics[i,Method->"DualMarchingSquares"]

OpenersExampleSubsection1(Spacer1)MinColorDistance  (1)

By default, the minimum color distance is automatically chosen:

i=;

ImageGraphics[i]

Specify a minimum color distance:

ImageGraphics[i,MinColorDistance->.35]

Smaller value for color distance results in more colors:

ImageGraphics[i,MinColorDistance->.05]

OpenersExampleSubsection2(Spacer1)DistanceFunction  (1)

The color metric defined by (RefLink[DistanceFunction, paclet:ref/DistanceFunction]) influences the image segmentation:

i=;

ImageGraphics[i, MinColorDistance-> 1/8]

ImageGraphics[i, MinColorDistance-> 1/8, DistanceFunction->"CIE94"]

OpenersExampleSection3(Spacer1)Applications  (3)

Successively simplify the color regions of an image with a mean-shift filter:

wolf=;

δ=1/6;
NestList[MeanShiftFilter[#,1,0.576738 δ,MaxIterations->16]&,wolf,2]

ImageGraphics[#,MinColorDistance->δ,ImageSize->150]&/@%

Generate vector graphic maps. Import a pixel-based map of the Rocky Mountains near Denver:

img=ImageTrim[
Import["http://www.innovativegis.com/basis/supplements/bm_dec_02/Ironing_Colorado_files/image001.png"],
{{361,405},{719,643}}
]

Delete county borders:

map=Inpaint[img,ColorNegate@Binarize[img,0]]

Convert colored elevation map into graphic contours:

vmap=ImageGraphics[map,MinColorDistance->1/8,PlotRangePadding->None]

Perform vector graphic operations introducing contour lines and changing colors:

vmap2=Graphics[
{EdgeForm[{Black,Thin}],Replace[First[vmap],col_?ColorQ:>Lighter[col],{3}]},
PlotRangePadding->None, ImageSize-> 360
]

Transform the map without altering line thickness:

tf=LinearFractionalTransform[{{{1,1/2},{0,1/2}},{0,0},{0,1},1}];

dims = ImageDimensions[img];
MapAt[tf[#/dims]&,vmap2,{1,2,1,All}]

Compare the result with the corresponding pixel-based transformation:

ImagePerspectiveTransformation[
Rasterize[vmap2,"Image"],
tf,
360,
DataRange->{{0,1},{0,1}},
PlotRange->All,
Padding->Transparent
]

Creating a scalable icon of a kingfisher:

img = ;

Obtain a rough mask:

mask=AlphaChannel[RemoveBackground[img,{"Background","Blurred"}]]

Refine the mask with the grow-cut algorithm:

mask2=DeleteSmallComponents[Image[GrowCutComponents[img,{Erosion[ColorNegate[mask],2],Erosion[mask,2]}]-1,"Bit"]]

Regularize the color segments via curvature flow:

img2=CurvatureFlowFilter[img,6,1]

Cover the background with green:

img3=RemoveAlphaChannel[SetAlphaChannel[img2,mask2],Green]

Select the dominant colors of the bird and add green as the background color:

colors=Append[DominantColors[img3,MinColorDistance->1/7, DistanceFunction-> "CIE2000", Masking-> mask2], Green]

Generate a vector graphic:

gr1=ImageGraphics[img3,colors, ImageSize-> 160]

Remove the green background segment:

gr2 = Delete[gr1,Map[Most,Position[gr1,ColorConvert[Green,"LAB"]]]]

Insert the expression into a larger graphic to obtain a scalable icon:

Graphics[{
{,Disk[{220,220},200]},
Translate[First[gr2],{50,70}],
{ ,Annulus[{220,220},{200,220}]}
}]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

Typically, the scalable graphics version of the image is much smaller in byte count:

i=;

g=ImageGraphics[i]

ByteCount/@{i,g}

OpenersExampleSection5(Spacer1)Possible Issues  (3)

"MarchingSquares" and "DualMarchingSquares" introduce gaps at T-junctions:

ImageGraphics[, Method->#, ImageSize-> 80]&/@
{"Exact","MarchingSquares","DualMarchingSquares"}

Lines and curves of one-pixel thickness may not be detected correctly:

i=Rasterize[,"Image"];

ImageGraphics[i]

Make the lines thicker for a better conversion:

ImageGraphics[Erosion[i,1]]

If the minimum color distance is larger than the image color variation, the output may be of a single color:

ImageGraphics[,MinColorDistance->1/2]

Lower the color distance:

ImageGraphics[,MinColorDistance->1/6]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ImageMesh, paclet:ref/ImageMesh])  ▪  (RefLink[Image, paclet:ref/Image])  ▪  (RefLink[Graphics, paclet:ref/Graphics])  ▪  (RefLink[Rasterize, paclet:ref/Rasterize])  ▪  (RefLink[ColorQuantize, paclet:ref/ColorQuantize])  ▪  (RefLink[DominantColors, paclet:ref/DominantColors])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Computer Vision, paclet:guide/ComputerVision])}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}})}})