BuildTRCDoc.Tioga
Written by: Mik Lamming
Last Edited by: Lamming, November 9, 1984 4:44:37 pm PST
THE BUILDTRC TOOL
THE BUILDTRC TOOL
CEDAR 5.2 — FOR INTERNAL XEROX USE ONLY
CEDAR 5.2 — FOR INTERNAL XEROX USE ONLY
The BuildTRC Tool
An Interactive Tool for Constructing Tone Reproduction Curves (TRCs) for Digital Image Processing
By Mik Lamming for Steve Wallgren


Release as: [Indigo]<Cedar5.2>Documentation>BuildTRCDoc.Tioga

© Copyright 1984 Xerox Corporation. All rights reserved.
XEROXXerox Corporation
Palo Alto Research Center
3333 Coyote Hill Road
Palo Alto, California 94304

For Internal Xerox Use Only
1. Introduction
What is a Tone Reproduction Curve?
A common requirement that arises when printing an image is the need to adjust the highlight or shadow densities, or to adjust the overall contrast. In each case, one must specify a function that transforms the gray values in the source image. A tone reproduction curve (hereafter called a TRC) is used to describe how the source values are to be mapped. In the case of the program described here, it specifies how the 256 different input gray values found in an 8-bit AIS separation file are to be mapped into the 256 available output values.
What does this tool do?
BuildTRC is an interactive tool for constructing TRCs. It provides facilities for creating, editing and filing TRC's. When used in conjunction with an image displayed on the color CRT it can simulate the effect a given TRC would produce if applied to the image. It cannot display images or even apply TRCs to images.
Getting started
BuildTRC is in the Cedar release. Bringover BuildTRC.df and type BuildTRC. After some considerable time the TRC Icon will appear. It looks like this.
TRCDisplay0.AIS dotSize: 0.32 mm
Open up the icon. Be patient - some of the fonts this tool uses may take a few seconds to scan convert. Open up the viewer so that it fills the whole column. It should look like this now.
TRCDisplay1.AIS width: 6 in
At the top of the screen is a control panel. It contains a number of buttons and type-in fields for specifying file names and so forth. Below the control panel is the graph area. It displays the TRC data. What you see is a very simple TRC - a straight line connecting the origin to (255, 255). This is the identity transformation.
--
Vertices and Pins
Every TRC is made up from a list of 256 pairs of numbers, hereafter called vertices. Straight lines are drawn between the vertices to make the graph. The identity TRC shown above is actually made up from 255 tiny line segments connecting vertex 0 to vertex 1 ... vertex 255. You can freehand sketch a new section of TRC curve with the mouse if you want. How you do this will be explained later. It might look like this:
TRCDisplay2.AIS width: 2 in
At the top, right hand corner (255, 255) of the TRC and at the extremities of the freehand section you can see a small dot. This is a pin. Pins provide an easy way of specifying the position of a series of vertices. If you move a pin, then the position of each vertex to the left and right of the pin, as far as the nearest neighboring pin is recomputed. By default, all the vertices between two pins are moved into the line connecting the pins. After inserting and moving pins around your TRC might look like this example:
TRCDisplay3.AIS width: 2 in
--
Simulating the effect of the TRC
Another useful feature of BuildTRC is its ability to provide a limited simulation of the effect of applying the TRC. To use this feature you must first get some other program to display the image with which you wish to experiment on the color display. Now by pressing the button marked Simulate, BuildTRC will track changes to the TRC design and adjust the displayed image to reflect the effect of the transformation. For example here is what an image looks like on the color display without any TRC adjustment:
TRCDisplay4.AIS width: 1.5 in
If we use this TRC:
TRCDisplay5.AIS height: 2 in
It looks like this:
TRCDisplay6.AIS width: 1.5 in
--
2. Editing the TRC
The TRC is adjusted using the mouse. Four functions are supported: Add Pin, Delete Pin, Move Pin and Sketch Vertices.
Sketching
Vertices may be sketched in using the mouse. This operation is carried out in the graph area. To redefine a section of the TRC move the mouse to the leftmost vertex to be moved, and hold down the RIGHT or BLUE mouse button. Now move the mouse to the right, indicating the shape of curve you require. When you reach the leftmost vertex to be modified release the mouse-button. As you move the mouse it will leave a trail of dots like this:
TRCDisplay7.AIS width: 4 in
--
When you release the mouse button the dots will be joined up and a pin will be placed at each extremitiy of the new section. It will look like this:
TRCDisplay8.AIS width: 2 in
Inserting and moving pins
New pins are inserted by pointing at the new pin position and clicking the LEFT or RED button. After the button has gone down, but before it has been released, you can move the pin around to position it exactly. You will not be able to move it past its neighboring pins though.
To move an existing pin use the MIDDLE or YELLOW button. Simply point somewhere close to the pin you want to move and hold down yellow. The pin will now track the mouse until you release the button. When you release the button after either an insert or a move operation, BuildTRC will reconnect the pins to make a new TRC.
Note that if you move one of the pins that gets inserted as part of a sketch operation, the sketched portion will be recomputed to form a straight line.
Deleting pins
To delete a pin, point close by it, hold down shift and click LEFT or RED.
--
Feedback - Exact positioning
In the graph area, close to the origin, some numbers are displayed.
TRCDisplay9.AIS dotSize: 0.32 mm
When you move the mouse around, you will see the numbers change. The top line of numbers, labelled "In" displays the position of the mouse along the In (x) axis. The left number represents the gray value to be mapped. In(0) which normally means 'black' is close to the origin and In(255) which normally means 'white' is to the extreme right. Next to the the gray value, inside parentheses, is another number followed by either a 'D' or an 'R'. These numbers display the reflectance (R) or the density (D) of the input gray value. We shall say more about these numbers later when we discuss "Scale Buttons". For now it is sufficient to note that reflectance increases with gray value whilst density decreases. Below the In data is the Out data. It is recorded in the same format and corresponds to the position of the mouse along the Out (y) axis. Output values are the ones that get displayed on the screen and used to generate the new image.
To position a pin exactly, simply keep your eye on the In/Out feedback at the bottom. Release the mouse when you see the vertex position you are trying to hit.
3. Pin Connection Modes
Earlier we said that when a pin is moved, the vertices to the left and right are recomputed so that they lie in a straight line. For most applications this is the desired behavior but in a few cases this connection protocol is not quite right. When the input data is reflectance coded (like it is when it arrives from the Eikonix scanner) it probably needs to be mapped into density space before it can be printed. This involves passing the gray data through a logging function. It is not always easy to approximate the required curve with straight lines so BuildTRC provides an alternative connection strategy.
--
At the top, left hand corner of the control panel there are two buttons, one marked Linear , the other Log
TRCDisplay10.AIS dotSize: 0.32 mm
The button marked Linear is displayed in reverse video. This indicates that the linear connection strategy is in effect. Bugging the Log button will set the other connection strategy. If (0, 0) is connected to (255, 255) with the log strategy, it looks like this.
TRCDisplay11.AIS width: 2 in
Given any two pins, a whole family of curves can be found that pass through them. BuildTRC picks one that best matches the range of output densities to be generated. If we chose the same pin positions but indicated that the maximum output density was much less, a different curve - closer to the straight line, would be generated.
TRCDisplay12.AIS width: 2 in
How you go about changing the maximum output density is described below in the section in "Scale Buttons".
--
4. Simple transformations - SHIFT, ROTATE etc.
We have seen how the Linear and Log buttons can be used to transform the curve shape. There are some other transformations that BuildTRC can perform. They are invoked through four buttons on the top line of the command panel.
TRCDisplay13.AIS dotSize: 0.32 mm
Negative
This button simply flips the TRC top to bottom. If you start off with an identity TRC and bug Negative, the TRC will then look like this:
TRCDisplay14.AIS width: 2 in
And our image will look like this:
TRCDisplay15.AIS width: 2 in
Shift
The shift button moves all the vertices one position to the left if the command is invoked with the left mouse button, and one position to the right if it is invoked with the right mouse button. If you hold down control, the shift is 4 positions; hold down the shift key and it is 16; hold down both control and shift and it is 64. Values and pins shifted off one end are lost. Values shifted in at the other end will duplicate the previous value at that location.
Rotate
Rotate behaves like shift. The difference is that vertices shifted off one end will appear at the other end.
Init
Init deletes all existing pins and creates a pin at (0,0) and one at (255,255). It then connects them using the current connect strategy.
5. Saving and Restoring your TRC. Working directory
When you have created your TRC you will want to save it. Another tool will then be able to read it and apply it to an image. The controls to save and restore TRC descriptions are located on the top and middle lines of the control panel towards the left. On the top line there is a type-in field
TRCDisplay16.AIS dotSize: 0.32 mm
Working Directory (WD)
All file operations assume a working directory specified by the WD type-in field unless a working directory is explicitly specified in the file name. To set the working directory, bug the button marked WD. This will select the WD type-in field for you. Type in a working directory name.
The working directory can be initialised on start-up from the user.profile file. See the section on User Profile Entries for a description of how to do this. By default WD is initialised to the current directory setting of the command tool that invoked BuildTRC.
Saving
To save your TRC, you need to specify a file name. Bug the button marked TRC. This will select the type in field. Type in your file name. If you do not specify a file name extension then BuildTRC will look in your user.profile for a suitable one (See the section on User Profile entries). If it can't get any help from the user.profile it will use ".TRC". The format of the file is described in the section onTRC File Format.
Restoring
To restore a TRC, you go through the same set of steps as for saving. In this case you bug Restore instead of Save. If the file cannot be found or the TRC is badly formatted the screen will blink and a diagnostic message will be displayed in the message window. After the file has been restored, the new data will be displayed.
6. Histograms and the Equalization Command
Before constructing a histogram for a particular image it is sometimes useful to see how the gray values are distributed. Images with little contrast may only use a narrow range of gray values. To increase the contrast these values must be spread out. This means building a TRC that rises steeply in the area where the input data lies, and yet is relatively flat in the around the unused input values. For example, here is a low contrast image and its histogram:
TRCDisplay17.AIS width: 2 in
TRCDisplay18.AIS width: 2 in
By looking at the histogram it is clear where the steepest part of the TRC should be!
The histogram controls are located on the bottom of the control panel towards the right.
TRCDisplay19.AIS dotSize: 0.32 mm
--
"Calc" and "Off" Buttons - Constructing the histogram.
To make the histogram first bug the "Hist" button and then type in an AIS file name. Next bug "Calc". Providing that the file exists and is in the right format there will be a pause of several seconds while BuildTRC scans the image and constructs the histogram.
When it has finished, the histogram will be displayed in the graph area background. You can still edit the TRC as usual. BuildTRC will maintain the histogram until you generate another or press the "Off" button. You can restore the histogram by pressing the "Off" button once more. Whilst BuildTRC has valid histogram data available for display the "Hist" button will show white on black.
The histogram shows the relative frequency of occurrence of each gray value in the sampled file. Gray values are plotted along the "In" axis and frequency of occurrence is plotted along the "Out" axis.
Black and White.
If your image has a predominance of one gray value - usually black or white, other values may have such relatively low frequencies that they do not show up on the histogram. This may be overcome by restricting the calculation phase to only consider values that lie in a specified subrange. This is done by specifying the minimum (Black) and maximum (White) values to be considered. To do this bug the appropriate button and type in a gray value in the range 0..255. For example, if the image has a white background one might set White=254. BuildTRC will then construct a histogram which excludes white from its calculations and the other values will assume more significance.
Automatic Equalization
For some images one would prefer the gray values to be uniformly distributed across the gray gamut. BuildTRC can automatically generate a TRC that will approximately do this. This process is called "Histogram Equalization". To generate an equalization histogram first generate a histogram and then bug "Eq" For the low contrast image and histogram shown above the TRC looks like this.
TRCDisplay20.AIS width: 2 in
If this histogram is applied it generates an image as below. Remember that you can't increase the amount of information in an image, just redistribute it. This may not produce quite what you want!
TRCDisplay21.AIS width: 2 in
7. Scale and Gamma Buttons
The Scale Buttons
The scale buttons are located on the second line of the control panel towards the left.
TRCDisplay22.AIS dotSize: 0.32 mm
Their most simple application is to specify the type of feedback to be generated. In their default settings they request density encoded feedback, i.e. the numbers near the origin will be postfixed with a D and will measure the density of the gray value at that point on the axis.
Left or right clicking either the MaxDIn button or the MaxDOut button will switch the feedback into Reflectance mode. The feedback numbers will be postfixed with an 'R'.
The range of values displayed during feedback is determined by the user. In density mode the value must be greater than zero and defines the density of a gray value 0. A typical value might be 1.6. In reflectance mode the buttons display "MinRIn" and "MinROut" and show the reflectance of gray 0. The value must lie in the range 0..1.
To change these values simply select the type-in field (by middle-clicking the appropriate button) and then type in an appropriate value. Middle click the button again to get BuildTRC to read the new value.
Effect of scale changes on connections
If you are using a "Log" connection strategy you may notice the shape of the curve change as you alter the Out scale value. This is because the curve shape is selected by considering the range of ouput densities being generated.
Effect of output scale change on simulations
In simulation mode the Output scale function has yet another function. It defines whether the display should simulate a device that is linear in density (MaxDout) or one that is linear in reflectance (MinRIn).
Note: Except for specialised cases you will probably want both scale buttons in the same mode and a linear connection strategy. If you are correcting for a printer, use density modes and set MaxDOut to the maximum density the printer can supply.
To show how a reflectance encodes file might look on a linear-density device set the input mode to reflectance, set the output mode to Density and enter an appropriate maximum output density for that device. Bug Init and set Log connection strategy.
The Gamma Button
The type-in field is used to specify the value the display should use for "Gamma correction". It can be set from the user profile. If you need to know about this ask a Guru. It will probably be OK to leave it at its default setting of 2.2.
8. User profile
Some of the type-in fields of BuildTRC can be initialised from the user.profile file. Available options are
BuildTRC.WD: <working directory>   - default is current directory
BuildTRC.MaxInputDensity: <Maximum input density>  - default 3.0
BuildTRC.MaxOutputDensity: <Maximum output density>  - default 3.0
BuildTRC.Gamma: <Display gamma correction value> - default 2.2
Other useful entries that are not specific to BuildTRC are:
AISExtensions: <file extensions for AIS files>   - default .AIS
TRCExtensions: <file extensions for TRC files>   - default .TRC
9. TRC File Format
TRC files have a very simple format. The file contains a one line header describing the connection strategy which can be "Linear" or "Log". It is followed by any number of vertex records - one per line. Each vertex record has three parts: the vertex index, its output value and an optional '*' indicating that there is a pin at this vertex. The BNF for the format is
TRCFile ::= ConnectFlag $( VertexRecord )
ConnectFlag ::= 'Log' | 'Linear'
VertexRecord := VertexIndex OutputValue PinFlag
VertexIndex ::= [0..255]
OutputValue := [0..255]
PinFlag := '*' | EMPTY
It is not necessary for the file to specify every vertex. Unspecified vertices will be generated using the specified connection strategy. Note that unspecified vertices are computed from the nearest available specified vertices which may not be the nearest pins.