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


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

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

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

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


desc
@Initial version of the Otsu algorithm, with debug msgs intact.
@


1.4
log
@Deleted redundant line with name of section.
@
text
@// otsu.c               Section: 3.7
// Threshold Selection by Maximizing Between Class Variance
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
//

#include "otsu.h"
#include "otsu-image.h"
#include "histogram.h"


///////////////////////////////////////////////////////////////////////
// otsu()
//   Calculate the possible partition points for image: a
//   based on the given partiton count.
//   Note that the number of partition points is one less
//   than the number of requested partitions.
//
template <class P, class T>
IA_Set<IA_Point<int> >      // Could also return an IA_Array
otsu( unsigned int partitionCount, const IA_Image<P,T> & a ) {

    IA_Image<IA_Point<int>,float>
	nh = normalized_histogram( a );

    // An OtsuImage may be thought of as a
    //    IA_Image<IA_Point<int>,float>
    // Each point in its domain represents a possible
    //    partitioning of the histogram.
    // The value at that point is the value of the objective function
    //    sigma-sub-b-squared as defined in the Otsu algoritm.
    IA_Image<IA_Point<int>,float>
	oim = OtsuImage( partitionCount - 1, nh );

    // A value set that only contains the maximum value in the image.
    IA_Set<float>
	oim_vs = max( oim );

    // Restrict the image to its maximum values.
    IA_Image<IA_Point<int>,float>
	oim_restrict( oim.restrict( oim_vs ) );

    // Return the domain of the restricted image.
    // Each point in this domain represents a possible partitioning
    //    where the OtsuImage obtained a maximum value.
    return oim_restrict.domain();
}
@


1.3
log
@Added algorithm to standard header.  Comment and style changes.
@
text
@a4 1
// Threshold Selection by Maximizing Between Class Variance
@


1.2
log
@First version of Otsu without debug stmts.  Seems to work, however the
  closure still had problems, it generates spurious iac++ instantiations.
@
text
@d2 1
d18 1
a18 1
//   than the nuber of requested partitions.
d33 1
a33 1
    OtsuImage
d38 1
a38 6
	oim_vs( max( oim ) );

    // restrict() is not defined on IA_ClosureI<P,T> images, so
    //    construct a IA_Image<P,float> image.
    IA_Image<IA_Point<int>,float>
	fdi_oim( oim );
d42 1
a42 1
	oim_restrict( fdi_oim.restrict( oim_vs ) );
@


1.1
log
@Initial revision
@
text
@a4 1
// Just template definitions in this file.
d30 2
a31 2
    // The value at that point is the objective function
    //    sigma-sub-b-squared
d35 1
a35 1
    float	f = max(oim);
d37 1
a37 1
	oim_vs( f );
d39 2
a40 3
    cerr << "oim_vs.contains( " << f << " ): "
	 << oim_vs.contains(f) << endl;

d42 1
a42 59
	fdi_oim(oim);  // Need FDI to restrict()

    float       g = max(fdi_oim);

    cerr << "Image range contain its maximum ? ........." << endl;
    cerr << "max(fdi_oim): " << g << endl;
    cerr << "fdi_oim.range().contains( g ): "
	 <<  fdi_oim.range().contains( g ) << endl;

    cerr << "fdi_oim.range().contains( max(fdi_oim) ): "
	 <<  fdi_oim.range().contains( max(fdi_oim) ) << endl << endl;

    IA_Set<float>
	fdi_oim_range( fdi_oim.range() ),
	fdi_oim_vs_g( g ),
	fdi_oim_vs_max( max(fdi_oim) );

    cerr << "Extracted image range contain image max ? ....." << endl;
    cerr << "fdi_oim_range.contains( g ): "
	 <<  fdi_oim_range.contains( g ) << endl;
    cerr << "fdi_oim_range.contains( max(fdi_oim) ): "
	 << fdi_oim_range.contains( max(fdi_oim) ) << endl << endl;


    IA_Array<float>  fdi_va( fdi_oim.value_array() );
    int va_len = fdi_va.len(), va_i, va_j;
    cerr << "Extracted image value_array().len(): " << va_len << endl;
    //
    float va_max = fdi_va[0];
    va_j = 0;
    for (va_i=1; va_i<va_len; va_i++) {
	if (fdi_va[va_i] > va_max) {
	    va_j = va_i;
	    va_max = fdi_va[ va_i ];
	}
    }
    cerr << "Maximum fdi_va[" << va_j << "] = " << va_max << endl;
    //
    va_j = ( va_len > 4 ? 4 : va_len-1 );
    cerr << "Values from: fdi_va[" << 0 << ".."
	 << va_j << "] =";
    for( va_i=0; va_i <= va_j; va_i++ ) {
	cerr << "  " << fdi_va[va_i];
    }
    cerr <<  endl << endl;
    va_i = (va_len-5 < 0 ? 0 : va_len-5 );
    cerr << "Values from: fdi_va[" << va_i << ".."
	 << va_len-1 << "] =";
    for( ; va_i < va_len; va_i++ ) {
	cerr << "  " << fdi_va[va_i];
    }
    cerr << endl << endl << endl;


    cerr << "Value set contain its only value ? ...." << endl;
    cerr << "fdi_oim_vs_g.contains( g ): "
	 << fdi_oim_vs_g.contains( g ) << endl;
    cerr << "fdi_oim_vs_max.contains( max(fdi_oim) ): "
	 << fdi_oim_vs_max.contains( max(fdi_oim) ) << endl << endl;
d44 1
d46 1
a46 1
	oim_restrict( fdi_oim.restrict(fdi_oim_vs_max) );
d48 3
@
