WOLFRAM

10 Images

10Images
Get the current image from your computer’s camera (here, me working on this book):
 
 
You can apply functions to images just like you apply functions to numbers or lists or anything else. The function ColorNegate that we saw in connection with colors also works on images, giving a “negative image”.
Negate the colors in the image (making me look pretty weird):
 
 
Blur the image:
 
 
 
 
You can make a table of the results of different amounts of blurring:
 
 
ImageCollage puts images together:
 
 
There’s lots of analysis one can do on images. For example, DominantColors finds a list of the most important colors in an image.
 
 
Binarize makes an image black and white:
 
 
Not surprisingly, the dominant colors in the result are black and white:
 
 
Another type of analysis is edge detection: finding where in the image there are sharp changes in color. The result looks a bit like a sketch derived from the original image.
Pick out edges in the original image:
 
 
 
 
It’s often convenient to do image processing interactively, creating interfaces using Manipulate. For example, Binarize lets you specify a threshold for what will be turned black as opposed to white. And often the best way to find the right threshold is just to interactively experiment with it.
Make an interface to adjust the threshold for binarizing an image:
 
 
There are lots of sophisticated things you can do to images in the Wolfram Language. ImageRestyle, for example, “restyles” one image to be in the style of another.
Restyle an image of me to be in “van Gogh” style:
 
 
CurrentImage[ ] capture the current image from your computer, etc.
ColorNegate[  ] negate the colors in an image
Binarize[  ] convert an image to black and white
Blur[  , 5] blur an image
EdgeDetect[  ] detect the edges in an image
DominantColors[  ] get a list of dominant colors in an image
ImageCollage[{  , , }] put together images in a collage
ImageAdd[  , ] add color values of two images
ImageRestyle[  , ] make one image have the style of another
10.1Color negate the result of edge detecting an image. (Use CurrentImage[ ] or any other image.) »
Sample expected output:
Out[]=
10.2Use Manipulate to make an interface for blurring an image from 0 to 20. »
Sample expected output:
Out[]=
10.3Make a table of the results from edge detecting an image with blurring from 1 to 10. »
Sample expected output:
Out[]=
10.4Make an image collage of an image together with the results of blurring, edge detecting and binarizing it. »
Sample expected output:
Out[]=
Sample expected output:
Out[]=
10.6Create a Manipulate to display edges of an image as it gets blurred from 0 to 20. »
Sample expected output:
Out[]=
10.7Image operations work on Graphics and Graphics3D. Edge detect a picture of a sphere. »
Expected output:
Out[]=
10.8Make a Manipulate to make an interface for blurring a purple pentagon from 0 to 20. »
Expected output:
Out[]=
10.9Create a collage of 9 images of disks, each with a random color. »
Sample expected output:
Out[]=
10.10Use ImageCollage to make a combined image of spheres with hues from 0 to 1 in steps of 0.2. »
Expected output:
Out[]=
10.11Make a table of blurring a disk by an amount from 0 to 30 in steps of 5. »
Expected output:
Out[]=
10.12Use ImageAdd to add an image to an image of a disk. »
Sample expected output:
Out[]=
10.13Use ImageAdd to add an image to an image of a red octagon. »
Sample expected output:
Out[]=
10.14Add an image to the color negated version of the edge detected image. »
Sample expected output:
Out[]=
+10.1Edge detect a binarized image. »
Sample expected output:
Out[]=
+10.2Color negate the result of edge detecting an image of a regular pentagon. »
Expected output:
Out[]=
+10.3Use ImageAdd to add an image to itself. »
Sample expected output:
Out[]=
+10.4Use ImageAdd to add together the images of regular polygons with between 3 and 100 sides. »
Expected output:
Out[]=
What if I don’t have a camera on my computer, or can’t use it?
Instead of CurrentImage[], just get a test image using for example ExampleData[{"TestImage", "Mandrill"}].
What does the number in Blur mean?
It’s the range of pixels that get blurred together.
How does DominantColors decide what colors to give?
It clumps together similar colors, and gives you a representative color from each clump. The most common colors in the image are listed first.
How does Binarize decide what’s black and what’s white?
If you don’t tell it a threshold, it will pick one based on analyzing the distribution of colors in the image.
How does ImageRestyle work?
It uses machine learning. It’s trained to find the important features of images, then to translate how they appear in one image to how they appear in the other.
Next Section