[Exercises]
[Workspace]
Purpose:
This exercise covers basic histogram principles, and
illustrates that two very different images can have identical
histograms. The exercise also explains how to execute UNIX commands as
part of a cantata network.
Khoros does not have an operator to sort the pixels of an
image. To do this we can use the UNIX "sort" command. This example
illustrates how we can integrate other standard tools into cantata.
The general idea is to convert the pixels into an ASCII table,
sort it using the UNIX "sort" command, and then convert the data back
to the kdf . Several tricks are necessary to make this work.
Following is a procedure to create a sorted version (raster
scan ascending order) and compare their histograms.
Activities:
-
Perform a sorted histogram comparison.
-
Read and display an image, take its histogram and plot it. Also
look at the object information for data type and size information. Use
the following operators:
-
Glyphs:Input/Output:Data Files:User defined
-
Glyphs:Visualization:Non-Interactive Display:Display Image
-
Glyphs:Data Manip:Histogram Operators:Histogram
-
Glyphs:Visualization:Plot Display:Display 2D Plot
-
Glyphs:Input/Output:Information:Data Object Info
-
Glyphs:Input/Output:Information:File Viewer
-
To convert the 2D data into a 1D column table use the Reorient
operator
-
Glyphs:Data Manip:Reorganize Data:Reorient
-
Set up the Reorient operator so that it maps the original
image's "Width" and "Height" dimensions to a single new "Height"
dimension. The output data file will be laid out in a long column
(along height). The data from the first row(width) is stored first,
then the row, etc. This will come into play in part E where you are
reading the ASCII data back in.
-
Convert to ASCII data using the Supported Formats operator
-
Glyphs:Input/Output:Export Data:Supported Formats
-
Open the Supported Formats pane and select "ASCII" as the
"output data ".
-
To call a standard UNIX command, use the Command Icon as follows:
-
Glyphs:Program Utilities:General:Command Icon
-
Open the Command Icon pane, and type the command "sort -n" in
the "Command" window. The input and output files are piped through
"stdin" and "stdout" channels. This operator will sort the pixels in
the table.
-
Use the operator "ASCII to Value" to create an image from the
sorted data
-
Glyphs:Input/Output:Import Data:ASCII to Value
-
Open the ASCII to Value pane, and set the "Data Type" and
"Value Size" to be the same as that of the original image.
-
Finally, display the sorted image, determine its histogram and plot
it. Compare this histogram with that of the original image.
Exercises
-
How can the histograms be precisely compared?
-
Change the sort order from ascending to descending.
Khoros Workspace
Execute the visual program c2s11sort-pixels.wk
Main DIP Menu
DIP Feedback Form
Copyright © 1997-1995 KRI, ISTEC, Ramiro Jordán, Roberto Lotufo. All Rights Reserved