head	1.4;
access;
symbols;
locks; strict;
comment	@// @;


1.4
date	94.10.13.07.02.29;	author rjj;	state Exp;
branches;
next	1.3;

1.3
date	94.08.09.01.02.50;	author rjj;	state Exp;
branches;
next	1.2;

1.2
date	94.08.08.01.36.12;	author rjj;	state Exp;
branches;
next	1.1;

1.1
date	94.07.05.19.42.54;	author rjj;	state Exp;
branches;
next	;


desc
@Simply filter to apply threshold images to.
@


1.4
log
@Added algorithm name to header.  Corrected spelling and style.
@
text
@// global-threshold.c   Section: 3.2  Global Thresholding
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.

// This application actually will do several types of thresholding:
//
//      Threshold on a single value.
//      Threshold on an interval of values.
//      Threshold over a percentage of values.

#include "Set.h"
#include "BitDI.h"
#include "UcharDI.h"

int main( int argc, char * argv[] ) {

    if ( argc == 1 ) {
	cerr << "Usage: 3 ways to threshold" << endl
	     << "  " << argv[0]
	     << " threshold-value < inImage > outImage ; absolute threshold"
	     << endl << "- OR -" << endl
	     << "  " << argv[0]
	     << " start end < inImage > outImage ; threshold on interval"
	     << endl << "- OR -" << endl
	     << "  " << argv[0]
	     << " real-value < inImage > outImage ; Percentage threshold ***"
	     << endl;
	cerr << "\t*** Note: real-value < 1.0 => percentage threshold."
	     << endl;
	return -1;
    }


    IA_Image<IA_Point<int>,u_char> image = read_uchar_PGM( cin );
    u_char  mn = min( image ), mx = max( image );
    if ( ! image.domain().empty() ) {
	cerr << "cin image min: "  << int( mn )
	     << ", max: " << int( mx ) << endl;
    }


    double arg = atof( argv[1] );

    u_char
	start = u_char( arg ),  // A good guess as to the starting value
	end;

    cerr << endl;
    if (arg < 1.0) {  // Percentage threshold
	double  dthreshold = arg * (mx - mn);

	start = u_char( dthreshold );
	end   = mx;

	cerr << "Percentage threshold on: ";
    } else if (argc == 2 ) {	// Value threshold
	end = start;
	cerr << "\nValue thresholding on: " ;
    } else {	// Value interval threshold
	end = u_char( atoi( argv[2] ) );
	if (end < start) {
	    u_char t = end;
	    end = start;
	    start = t;
	}
	cerr << "\nInterval thresholding on: ";
    }

    u_char * interval = new u_char[end - start + 1];
    for( u_char u=start; u<=end; u++ ) {
	interval[ u-start ] = u;
    }
    IA_Set<u_char>
	threshold_set( interval,
		       (unsigned int)(end - start + 1) );
    delete[] interval;

    cerr << "[" << int( start ) 
	 << "," << int( end ) << "]" << endl;

    write_PBM( chi_contains( image, threshold_set ),
	       cout );

    return 0;
}
@


1.3
log
@Renamed the test program global-threshold.c
@
text
@d1 1
a1 1
// global-threshold.c   Section: 3.2
d12 1
d15 1
a15 1
void main( int argc, char * argv[] ) {
d28 1
a28 1
	cerr << "\t*** Note: threshold-value < 1.0 => percentage threshold."
d30 1
a30 1
	return ;
d34 2
a35 2
    IA_Image<IA_Point<int>,u_char> image( read_uchar_PGM( cin ) );
    u_char  mn( min( image ) ), mx( max( image ) );
d42 1
a42 1
    double arg( atof( argv[1] ) );
d45 1
a45 1
	start( u_char( arg ) ),  // A good guess as the the starting value
d50 1
a50 1
	double  dthreshold( arg * (mx - mn) );
d57 1
a57 1
	end   = start;
d62 3
a64 1
	    u_char t(end); end = start; start = t;
a79 3
    image *=
	IA_Image<IA_Point<int>,u_char>(
	    chi_contains( image, threshold_set ) );
d81 4
a84 1
    image.write_PGM( cout );
@


1.2
log
@Modified so no attempt is made to read cin before checking if
  appropriate command line arguments have been supplied.
@
text
@d1 1
a1 1
// apply-threshold.c    Section: 3.2
a13 2


d66 2
a67 2
    u_char * interval = new u_char[end - start];
    for( u_char u=start; u<end; u++ ) {
d72 1
a72 1
		       (unsigned int)(end - start) );
@


1.1
log
@Initial revision
@
text
@d1 9
a9 1
// apply-threshold.c
a10 1

a17 7
    IA_Image<IA_Point<int>,u_char> image( read_uchar_PGM( cin ) );
    u_char  mn( min( image ) ), mx( max( image ) );
    if ( ! image.domain().empty() ) {
	cerr << "cin image min: "  << int( mn )
	     << ", max: " << int( mx ) << endl;
    }

d32 8
@
