ImageTools in Maple
Go to Maple Portal Maple Portal for Engineers
The ImageTools package in Maple contains a large number of image processing functions. Before using the commands found within the ImageTools package, load the package into the workspace using the with command. This enables use of the short form of the command names.
withImageTools:
This document below uses a sample image to illustrate how the commands in the ImageTools package work.
Extract Input Image
Histogram Manipulation
Smoothing & Edge Detection
See Also
The image in Figure 1, which is located in Maple's data directory, is imported into the worksheet by using the Read command.
Figure 1: Tree image
FileLocation≔catkerneloptsdatadir,/images/tree.jpg:
TreeImage≔ReadFileLocation
Note: Since backslashes are special characters, backslashes used in filenames must be escaped by "doubling up," that is, using two backslashes as was done in defining FileLocation. Alternatively, use the form <Maple>/data/images/tree.jpg, where <Maple> represents the pathway to Maple directory. See backslash and file for more information about backslashes and file names.
Use the View command to view the image stored in TreeImage. The image is displayed in a Maplet dialog.
ViewTreeImage
The image can be converted into a grayscale image with the ToGreyscale command.
TreeImageGrayscale≔ToGrayscaleTreeImage:
ViewTreeImageGrayscale
Figure 2: Grayscale tree image
View histograms of the colored and grayscale images using the PlotHistogram command.
PlotHistogramTreeImage
PlotHistogramTreeImageGrayscale
The following steps show how to manipulate the pixel intensities; the grayscale image is used in this example. Adjust the histogram of the grayscale image by applying the function to all the pixels in the image. Since this operation will cause the pixel intensities to no longer fit between 0 and 1, the pixel intensities are then rescaled using the FitIntensity command.
sqrtImage≔mapevalhfsqrt, TreeImageGrayscale:
SqrtTreeImageGrayscale≔FitIntensitysqrtImage
In a similar manner, you can intensify the grayscale image by applying an exponential operator.
expImage≔mapevalhfx→ⅇ2⁢x,TreeImageGrayscale:
ExpTreeImageGrayscale≔FitIntensityexpImage
View the images to see the effects of adjusting the histogram.
ViewTreeImageGrayscale,SqrtTreeImageGrayscale,ExpTreeImageGrayscale
Histogram Manipulations
Original Image
Decreased Intensity Image
Increase Intensity Image
You can plot the histograms of the original and modified images. The histogram can be normalized using the normalized option to the PlotHistogram command.. See PlotHistogram for information on normalized and other options.
plotsdisplayPlotHistogramTreeImageGrayscale, 80, normalized,color=Red,legend=Original Image, PlotHistogramSqrtTreeImageGrayscale, 80, normalized,color=Blue,legend=Sqrt Image,PlotHistogramExpTreeImageGrayscale, 80, normalized, color=Green,legend=Exp Image,thickness=2
Use plots[display] to display multiple plots on the same axes.
An edge detector can be constructed by applying a convolution mask to the image.
The Robert's Cross is a typical edge mask that can be used to extract the horizontal and vertical edges of an image. The Robert's Cross mask is defined below.
Gx≔Matrix0,1,−1,0:Gy≔Matrix1,0,0,−1:
Use the Convolution command to obtain the horizontal and vertical edge operators for the image defined in TreeImageGrayscale.
RCHorizontalEdgeOperator≔ConvolutionTreeImageGrayscale, Gx:RCVerticalEdgeOperator≔ConvolutionTreeImageGrayscale, Gy:
Detect the horizontal and vertical edges of the image.
HorizontalEdgeDetection≔mapevalhfabs, RCHorizontalEdgeOperator:
VerticalEdgeDetection≔mapevalhfabs, RCVerticalEdgeOperator:
TotalEdgeDetection≔mapevalhfsqrt, RCHorizontalEdgeOperator2 +RCVerticalEdgeOperator2:
View the results of the edge detection.
ViewTreeImageGrayscale,FitIntensityTotalEdgeDetection,FitIntensityHorizontalEdgeDetection,FitIntensityVerticalEdgeDetection
Horizontal and Vertical Edge Detection
Horizontal & Vertical Edge Detection
Horizontal Edge Detection
Vertical Edge Detection
Using the Threshold command you can extract the edges that were detected.
HorizontalEdgeExtraction≔ThresholdHorizontalEdgeDetection:
VerticalEdgeExtraction≔ThresholdVerticalEdgeDetection:
TotalEdgeExtraction ≔ ThresholdTotalEdgeDetection:
The results of the extraction are shown in the plots below.
ViewTreeImageGrayscale,TotalEdgeExtraction,HorizontalEdgeExtraction,VerticalEdgeExtraction
Horizontal and Vertical Edge Extraction
Horizontal & Vertical Edge Extraction
Horizontal Edge Extraction
Vertical Edge Extraction
Another useful feature found in the ImageTools package is the ability to take the color complement of an image using the Complement command. For instance, the complement of the image defined in TotalEdgeExtraction can be seen in the plots below.
TotalEdgeExtractionCompliment≔ComplementTotalEdgeExtraction:
ViewTotalEdgeExtraction,TotalEdgeExtractionCompliment
Complement
Edge Extracted Image
Complement of Edge Extracted Image
backslash, cat, file, ImageTools, kernelopts(datadir), map[evalhf]
Download Help Document