PxThresholdImage

Gamma/Photon: Using Gamma™ with the Photon microGUIŽ, Version 4.0
Prev |  | Next

# `PxThresholdImage`

`PxThresholdImage` -- converts grey-scale images to black and white.

## Syntax

    PxThresholdImage (image, threshold, low?, high?)

## Arguments

`image`

  PhImage, previously grey-scaled with a call to PxGreyImage.

`threshold`

  An integer that determines the threshold level between black and white.

`low`

  Optional integer setting for black values, default = 0.

`high`

  Optional integer setting for white values, default = -1.

## Returns

A PhImage.

## Description

This function converts greys to black and white, at a given threshold point. As the `threshold` increases, the image darkens.

## Example

This example, `ex_PxThresholdImage.g`, is included in the `gamma_ph_`#`_examples_1_QNX4.tgz` file available on the Cogent Web Site.

    #!/usr/cogent/bin/phgamma

    /*
    The following example demonstrates PxCopyImage(), PxGreyImage(),
    and PxThresholdImage().  An image is loaded and converted to grey
    scales.  Then four threshold images are created.
    */

    PtInit(nil);
    require_lisp("PhotonWidgets.lsp");

    win = new(PtWindow);

    // Load and display the image.
    pic1 = PxLoadImage("taj.bmp");
    lab1 = new(PtLabel);
    lab1.label_type = Pt_IMAGE;
    lab1.label_data = pic1;

    // Copy the image and convert the colors to grey scales.
    pic2 = PxCopyImage(pic1);
    pic2 = PxGreyImage(pic2);
    lab2 = new(PtLabel);
    lab2.label_type = Pt_IMAGE;
    lab2.label_data = pic2;
    lab2.SetPos(300,0);

    // Copy the grey_scale and make a threshold image
    // with a medim_level threshold and reversed high/low.
    pic3 = PxCopyImage(pic2);
    pic3 = PxThresholdImage(pic3, 150, -2, 1);
    lab3 = new(PtLabel);
    lab3.label_type = Pt_IMAGE;
    lab3.label_data = pic3;
    lab3.SetPos(600,0);

    // Copy the grey_scale and make a threshold image
    // with a low_level threshold.
    pic4 = PxCopyImage(pic2);
    pic4 = PxThresholdImage(pic4, 100, 1, -2);
    lab4 = new(PtLabel);
    lab4.label_type = Pt_IMAGE;
    lab4.label_data = pic4;
    lab4.SetPos(0,200);

    // Copy the grey_scale and make a threshold image
    // with a medium_level threshold.
    pic5 = PxCopyImage(pic2);
    pic5 = PxThresholdImage(pic5, 150, 1, -2);
    lab5 = new(PtLabel);
    lab5.label_type = Pt_IMAGE;
    lab5.label_data = pic5;
    lab5.SetPos(300,200);

    // Copy the grey_scale and make a threshold image
    // with a high_level threshold.
    pic6 = PxCopyImage(pic2);
    pic6 = PxThresholdImage(pic6, 200, 1, -2);
    lab6 = new(PtLabel);
    lab6.label_type = Pt_IMAGE;
    lab6.label_data = pic6;
    lab6.SetPos(600,200);

    PtRealizeWidget(win);
    PtMainLoop();

## See Also

PxCopyImage, PxGreyImage, PxConvolveImage

Prev | Home | Next
`PxSubImage` | Up | Photon Functions

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.