Main Page | Data Structures | Directories | File List | Data Fields | Globals

Sadie_Contrast.c File Reference

A Tcl/Tk interface to the SADIE contrast manipulation functions. More...

#include <tcl.h>
#include <tk.h>
#include <sadie.h>
#include "tclsadie.h"

Go to the source code of this file.

SADIE library globals

Global variables within the SADIE library that augment function arguments.

*uint32_t nlev
 Used by STRETCH, TFQUANT & WTFMAJ.
PIXEL gain
 Used by STRETCH & TFLINEAR.
PIXEL bias
 Used by STRETCH & TFLINEAR.
PIXEL gmin
 Used by STRETCH, TFQUANT, TFSAT, TFSCALE & WTFMAJ.
PIXEL gmax
 Used by STRETCH, TFINVERT, TFQUANT, TFSAT & TFSCALE.
PIXEL thresh
 Used by STRETCH, TFTHRESH, WINDOW & WTFCAVG.
PIXEL gbrk [2][4]
 Used by STRETCH & TFPLT.
PIXEL * table
 Used by STRETCH & TFTABLE.

Functions

int Sadie_Contrast_NormStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Normalize the contrast within an image.
int Sadie_Contrast_HisteqStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a histogram equalization to an image.
int Sadie_Contrast_LinearStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a linear contrast stretch to an image.
int Sadie_Contrast_LogStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a log transform to an image.
int Sadie_Contrast_PWLStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a three-segment piecewise linear transformation to an image.
int Sadie_Contrast_RootStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a square root transformation to an image.
int Sadie_Contrast_SqrStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Square all the image pixel values.
int Sadie_Contrast_TblStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Re-map image greylevels using an arbitrary look-up table.
int Sadie_Contrast_QntStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Quantize image pixel values to a specified number of greylevels.
int Sadie_Contrast_SatStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Apply a saturation stretch to an image.
int Sadie_Contrast_ThreshStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Convert a continuous image to a binary (two-valued) one.
int Sadie_Contrast_AdaptStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Transform an image with the Local Range Modification algorithm.
int Sadie_Contrast_RefStretchCmd (ClientData client_data, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Transform the greylevels in an image to match those in a reference image.
int Sadie_Contrast_Init (Tcl_Interp *interp)
 Make the commands defined in this file accessible to the Tcl interpreter.


Detailed Description

A Tcl/Tk interface to the SADIE contrast manipulation functions.

The SADIE library includes several operations to re-scale pixel values, notably contrast stretching operations. Unfortunately several of these use shared global data structures within the library, and are not thread-safe or re-entrant even in versions that protect other shared data with locks: see the list of extern declarations within this file for details.

Author:
University of Arizona Digital Image Analysis Lab
Date:
1999, 2004
Version:
Id
Sadie_Contrast.c,v 2.6 2005/03/25 07:23:44 mmunro Exp

Definition in file Sadie_Contrast.c.


Function Documentation

int Sadie_Contrast_AdaptStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Transform an image with the Local Range Modification algorithm.

The SADIE library function VSTRETCH does all the real work, evaluating a maximal linear stretch for fixed-size square regions that completely tile the image, interpolating between these to give a per-pixel transformation, and applying this to the image. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(blocksize) the size of the square regions (in pixels).
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 566 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadieUintFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_HisteqStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a histogram equalization to an image.

Given an image and the number of histogram bins, this uses the SADIE library function HISTEQ to re-map the image values using the empirically determined value distribution as a look-up table, optionally downsampling the image in the process. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(res) the number of histogram bins.
  • tcl_array_name(incr) downsampling spacing (pixel units).
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) equalized image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 130 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadieUintFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_Init Tcl_Interp *  interp  ) 
 

Make the commands defined in this file accessible to the Tcl interpreter.

Parameters:
[in] interp the main Tcl interpreter.
Returns:
TCL_OK on success.

Definition at line 645 of file Sadie_Contrast.c.

References Sadie_Contrast_AdaptStretchCmd(), Sadie_Contrast_HisteqStretchCmd(), Sadie_Contrast_LinearStretchCmd(), Sadie_Contrast_LogStretchCmd(), Sadie_Contrast_NormStretchCmd(), Sadie_Contrast_PWLStretchCmd(), Sadie_Contrast_QntStretchCmd(), Sadie_Contrast_RefStretchCmd(), Sadie_Contrast_RootStretchCmd(), Sadie_Contrast_SatStretchCmd(), Sadie_Contrast_SqrStretchCmd(), Sadie_Contrast_TblStretchCmd(), and Sadie_Contrast_ThreshStretchCmd().

Referenced by Tcl_AppInit().

int Sadie_Contrast_LinearStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a linear contrast stretch to an image.

We select either the SADIE library function TFSCALE, which uses linear interpolation between the specified maximum and minimum levels, or TFLINEAR, which uses new_value = bias + gain * old_value for each pixel. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(minorbias) minimum for TFSCALE, or TFLINEAR bias.
  • tcl_array_name(maxorgain) maximum for TFSCALE, or TFLINEAR gain.
  • tcl_array_name(type) zero for TFSCALE, non-zero for TFLINEAR.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 173 of file Sadie_Contrast.c.

References bias, gain, GetSadieDoubleFromObj2(), GetSadieImageFromObj2(), GetSadieIntFromObj2(), gmax, gmin, and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_LogStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a log transform to an image.

This is simply an interface to the SADIE library function TFLOG, which applies the log10 function to the pixel values, while retaining values less than or equal to zero. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 226 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_NormStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Normalize the contrast within an image.

Taking an arbitrary input image, this generates an output image whose pixels have the specified mean and standard deviation (optionally down-sampling in the process), using the SADIE library function CONTNORM. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) raw image ID string.
  • tcl_array_name(incr) downsampling spacing (pixel units).
  • tcl_array_name(sigma) desired standard deviation.
  • tcl_array_name(mean) desired mean.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) re-scaled image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 84 of file Sadie_Contrast.c.

References GetSadieDoubleFromObj2(), GetSadieImageFromObj2(), GetSadiePixelFromObj2(), GetSadieUintFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_PWLStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a three-segment piecewise linear transformation to an image.

We define the linear segments by the values (breakpoints) of their ends in both the original image and the transformed image, so for three segments we need two sets of four breakpoint values. The SADIE library function TFPLT handles the actual transformation.

The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(in1) breakpoint 1 in the original image.
  • tcl_array_name(in2) breakpoint 2 in the original image.
  • tcl_array_name(in3) breakpoint 3 in the original image.
  • tcl_array_name(in4) breakpoint 4 in the original image.
  • tcl_array_name(out1) breakpoint 1 in the transformed image.
  • tcl_array_name(out2) breakpoint 2 in the transformed image.
  • tcl_array_name(out3) breakpoint 3 in the transformed image.
  • tcl_array_name(out4) breakpoint 4 in the transformed image.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 270 of file Sadie_Contrast.c.

References gbrk, GetSadieImageFromObj2(), GetSadiePixelFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_QntStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Quantize image pixel values to a specified number of greylevels.

Given a image whose greylevels are continuous (down to the numerical precision of the PIXEL type), this generates a new image with at most the specified number of levels between a maximum and minimum value, using the SADIE library function TFQUANT. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(steps) the number of levels.
  • tcl_array_name(gmin) the maximum level.
  • tcl_array_name(gmax) the minimum level.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) quantized image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 447 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadiePixelFromObj2(), GetSadieUintFromObj2(), gmax, gmin, nlev, and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_RefStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Transform the greylevels in an image to match those in a reference image.

Given an arbitrary image to be transformed and a reference image (of identical size), the SADIE library function MATCH can apply a reference stretch according two one of two selectable algorithms: either by inverting the cumulative distribution function (CDF) of the reference image, or by using the observed joint distribution of greylevels in the two images to derive an averaged look-up table (LUT). The SADIE library refers to the LUT option as the "least squares transformation", but it does not do any kind of regression. The Tcl data should conform to the patterns:

  • tcl_array_name(inimg,addr1) the original image ID.
  • tcl_array_name(inimg,addr1) the reference image ID.
  • tcl_array_name(nlevels) the number of LUT entries or CDF bins.
  • tcl_array_name(option) one of CDF or LSQ (as defined in sadie.h).
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 611 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadieUintFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_RootStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a square root transformation to an image.

This is simply an interface to the SADIE library function TFROOT, which takes the square root of the pixel values, not generating complex values if they are negative. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 321 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_SatStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Apply a saturation stretch to an image.

Re-assign image pixel values above a specified threshold to the maximum value in the image, and those below a specified threshold to the minimum value in the image, using the SADIE library function TFSAT. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(gmin) set to the minimum below this level.
  • tcl_array_name(gmax) set to the maximum above this level.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) thresholded image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 489 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadiePixelFromObj2(), gmax, gmin, and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_SqrStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Square all the image pixel values.

This is an interface to the SADIE library function TFSQUARE, which computes the squares of all the pixel values. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) squared image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 354 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), and SetSadieImageObj2().

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_TblStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Re-map image greylevels using an arbitrary look-up table.

We require not only an image to transform, but a Tcl array (not a list) whose indices include the numeric value of each greylevel in the range found within the image, assigned a the new value to replace this in the transformed image. The SADIE library function TFTABLE handles the actual trasformation. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(index,(numeric_value)) individual look-up table values.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) transformed image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 391 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadiePixelFromObj2(), nlev, SetSadieImageObj2(), and table.

Referenced by Sadie_Contrast_Init().

int Sadie_Contrast_ThreshStretchCmd ClientData  client_data,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const   objv[]
 

Convert a continuous image to a binary (two-valued) one.

This maps all the pixel values below a theshold to the current minimum value, and all the pixel values greater than or equal to the threshold to the current maximum value, using the SADIE library TFTHRESH function. The Tcl data should conform to the patterns:

  • tcl_array_name(DEFAULT_IN_IMAGE_ADDR_INDEX) original image ID.
  • tcl_array_name(threshold) values set to minimum below, maximum above.
  • tcl_array_name(DEFAULT_OUT_IMAGE_NAME_INDEX) two-valued image name.

Parameters:
[in] client_data (unused).
[in] interp the Tcl interpreter.
[in] objc number of Tcl object arguments (always two).
[in] objv Tcl object argument list (the Tcl array name).
Returns:
TCL_OK on success, TCL_ERROR on errors.

Definition at line 528 of file Sadie_Contrast.c.

References GetSadieImageFromObj2(), GetSadiePixelFromObj2(), SetSadieImageObj2(), and thresh.

Referenced by Sadie_Contrast_Init().


Generated on Fri Jul 8 14:55:02 2005 for tclSadie by  doxygen 1.4.2