Keywords: front-page

## Lab: Histogram Principles / ASCII Data Processing

[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:

1. Perform a sorted histogram comparison.

   1. 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:

      1. Glyphs:Input/Output:Data Files:User defined
      2. Glyphs:Visualization:Non-Interactive Display:Display Image
      3. Glyphs:Data Manip:Histogram Operators:Histogram
      4. Glyphs:Visualization:Plot Display:Display 2D Plot
      5. Glyphs:Input/Output:Information:Data Object Info
      6. Glyphs:Input/Output:Information:File Viewer

   2. To convert the 2D data into a 1D column table use the Reorient operator

      1. Glyphs:Data Manip:Reorganize Data:Reorient
      2. 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.

   3. Convert to ASCII data using the Supported Formats operator

      1. Glyphs:Input/Output:Export Data:Supported Formats
      2. Open the Supported Formats pane and select "ASCII" as the "output data ".

   4. To call a standard UNIX command, use the Command Icon as follows:

      1. Glyphs:Program Utilities:General:Command Icon
      2. 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.

   5. Use the operator "ASCII to Value" to create an image from the sorted data

      1. Glyphs:Input/Output:Import Data:ASCII to Value
      2. Open the ASCII to Value pane, and set the "Data Type" and "Value Size" to be the same as that of the original image.

   6. Finally, display the sorted image, determine its histogram and plot it. Compare this histogram with that of the original image.

Exercises

1. How can the histograms be precisely compared?
2. Change the sort order from ascending to descending.

Khoros Workspace
Execute the visual program c2s11sort-pixels.wk