head	1.1;
access
	monica
	thoth;
symbols;
locks
	monica:1.1; strict;
comment	@// @;


1.1
date	94.10.18.20.33.56;	author monica;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@// template_example.04.c
//
// Demonstrates image algebra approach to inverse smoothing of an image.
//

#include <stdlib.h>
#include "DDTempl.h"
#include "IntConv.h"
// #include "test071.c"

// histogram.c
//    This is the implementation file for the template versions of
//    the histogram and cumulative histogram programs.


 #include "UcharDI.h"
 #include "IntDI.h"

 #include "PSIter.h"
 #include "DDTempl.h"
 #include "ClosureDT.h"

//////////////////////////////////////////////////////////////////
//
// class IA_HistogramTemplt<IA_Image<P,T>>
//
//////////////////////////////////////////////////////////////////

// Create a parameterized template which will evaluate
//   to a one point image at each point in the
//   parameterized template domain.

template <class I>
class IA_HistogramTemplt
: public IA_ClosureDT<IA_Image<IA_Point<int>,int> > {
private:
    I im;   // The image we are creating a histogram for

public:
    IA_HistogramTemplt( const I &inImage )
    : IA_ClosureDT<IA_Image<IA_Point<int>,int> >(inImage.domain()),
      im(inImage) {}

    IA_Image<IA_Point<int>,int>
    operator() (const IA_Point<int> &aPt) const;

    IA_ClosureDT<IA_Image<IA_Point<int>,int> > *clone_self() const;

    ostream &print_this(ostream &o) const;
};



template <class I>
IA_Image<IA_Point<int>,int>
IA_HistogramTemplt<I>::operator() (const IA_Point<int> &aPt) const {

    // We return an image that is defined only on the support,
    // namely the one point associated with a non-zero value.

    // Hence, we return a one point image, only defined at the
    // template\'s support.
    return
	IA_Image<IA_Point<int>,int>(
	    IA_Set<IA_Point<int> >( IA_Point<int>(im(aPt)) ),
	    1 );
}


template <class I>
IA_ClosureDT<IA_Image<IA_Point<int>,int> > *
IA_HistogramTemplt<I>::clone_self() const {
    return new IA_HistogramTemplt<I>(this->im);
}


template <class I>
ostream & IA_HistogramTemplt<I>::print_this(ostream &o) const {

    IA_PSIter<IA_Point<int> >  htIter( (this->im).domain() );
    // The template point set

    IA_Point<int>          iPt;

    while ( htIter( iPt ) ) {  // for each point in the domain
	o   << "(" << iPt << ","
	    << this->operator()(iPt)  // range value is an image
	    << ")";
    }
    return o;
}


int main() {
    
    IA_Image<IA_Point<int>,u_char> a, out_uchar;
    
// read and display source image
    
    a = IA_Image< IA_Point<int>,u_char>::read_PGM("/cis/research/iac++/depot/src/test_image/RCS/sr71.pgm");

    // Here we use the closure constructor for templates.
    // Since IA_HistogramTemplt is derieved from IA_ClosureDT<I>
    //   it is a closure also.

    // The histogram template is parameterized by the image
    //   we want the histogram of, in this case image a.

    IA_DDTemplate< IA_Image<IA_Point<int>,int> >
	h( IA_HistogramTemplt< IA_Image<IA_Point<int>,u_char> >(a) );

    // Now define an image which is simply the template sum
    //   of the histogram template.  
    IA_Image<IA_Point<int>,int>
	a_histogram( sum( a.domain(),
			  h,
			  IA_boxy_pset( IA_Point<int>(min(a)),
					IA_Point<int>(max(a)) )
			  ) );

    cout << a_histogram << endl;

    exit( 0 );

}









@
