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


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


desc
@Ploting algorithm designed to select and plot lines based on the
  output of the Hough transform and user input.
@


1.1
log
@Initial revision
@
text
@// plot-lines.c         Section: 10.3, Line Detection using the Hough Transform
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
//
// Calculate the Hough image and then plot the desired number of lines.

#include "hough.h"
#include "find-max-points.h"
#include "hough-line.h"
#include "UcharDI.h"
#include "IntPS.h"
#include "PSIter.h"

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

    // We accept up to three arguments, the 1st is mandatory
    // 1st arg: in_image,    this is the original image the accumulator
    //                       image was derived from.
    // 2nd arg: NUM_TO_FIND, default = 5  (how many lines to look for)
    // 3rd arg: DISPLAY,     default = 0  (do not display intermediates)

    // P_ROWS,      default = 20 (positive rows requested)
    // COLS,        default = 20 (total columns requested)
    unsigned int P_ROWS, COLS, NUM_TO_FIND, DISPLAY, i_arg;

    if ( argc == 1 ) {
	cerr << "Usage:" << endl
	     << "\t" << argv[0] << " test-hough-input.pgm "
	     << "[number-of-lines-to-find [display-intermediates]] "
	     << "< test-hough-accumulator-ouput.pgm > ploted-lines.pbm"
	     << endl;
	return 1;
    }

    i_arg = ( argc > 2 ? atoi(argv[2]) : 0 );
    NUM_TO_FIND = ( i_arg > 1 ? i_arg : 5 );

    i_arg   = ( argc > 3 ? atoi(argv[3]) : 0 );
    DISPLAY = ( i_arg != 0 );

    // Read in the  test-hough-input.pgm  image, the 1st argument
    IA_Image<IA_Point<int>,IA_Bit>
	in_image( to_bit( read_uchar_PGM(argv[1]) ) );

    // Read in the  test-hough-accumulator-output.pgm  image
    IA_Image<IA_Point<int>,int>
	accum_image = read_int_PGM( cin );

    //Calculate the positive rows from the accumulator image
    P_ROWS = (accum_image.domain().sup())( 0 ) / 2;

    // Calculate the number of columns in the accumulator image
    COLS   = (accum_image.domain().sup())( 1 ) + 1;

    // Print out some information about what we are doing.
    cerr << "\nOriginal Hough image ...." << endl
	 << "inf() = " << in_image.domain().inf() << ", "
	 << "sup() = " << in_image.domain().sup() << endl;
    cerr << "Accumulator size: " << 2*P_ROWS+1 << " x " << COLS << endl;
    cerr << "Will attempt to find " << NUM_TO_FIND << " lines." << endl;
    cerr << "Intermediate results"
	 << (DISPLAY ? " will be " : " will not be " )
	 << "displayed." << endl;


    // Now let\'s do some acutal work......

    cerr << "Finding candiate lines...";
    cerr.flush();
    IA_Set<IA_Point<int> >
	lines = find_max_points( accum_image, NUM_TO_FIND );
    cerr << "done. Found: " << NUM_TO_FIND << " candiate lines." << endl;


    cerr << "\nPlotting lines...";
    cerr.flush();

    IA_PSIter<IA_Point<int> >
	siter( lines );

    IA_Point<int> p;
    IA_Image<IA_Point<int>,IA_Bit>
	lines_image( in_image.domain(), IA_Bit( 0 ) );

    while( siter( p ) ) {
	HoughLine  hl( p, P_ROWS, COLS,
		       HoughTemplate(in_image,P_ROWS,COLS).R );
	hl.plot( lines_image );
	if (DISPLAY) {
	    cerr << "Image pid: " 
		 << display( IA_Image<IA_Point<int>,u_char>( lines_image ) )
		 << " for point: " << p << endl;
	}
    }

    cerr << "done." << endl;

    lines_image.write_PBM( cout );

    return 0;
}
@
