|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 2977 (0xba1) Types: TextFile Names: »correlate.c++«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki └─⟦this⟧ »EUUGD11/euug-87hel/sec1/image/vartools/correlate.c++«
/* This is the source file for correlation routines */ #include <stream.h> #include <stdio.h> #include <string.h> #include <for.h++> #include <double_image.h++> #include "vartools.h++" // this routine correlates the image at a point double do_correlate(double_image& template, double_image& input) { // total sums up the correlation double total = 0.; // iterate through the template FOR(int i1 = 0 ; i1 < template.n_rows() ; i1++) { FOR(int i2 = 0 ; i2 < template.n_cols() ; i2++) { total += template.get_w_e(i1,i2)*input.get_w_e(i1,i2); } ENDFOR } ENDFOR return total; } // this one takes 2 images and returns an image containing the correlation double_image& correlate2(double_image& template, double_image& input, FILE *output_file) { // check that the template is smaller than the input if ( (template.n_rows() > input.n_rows()) || (template.n_cols() > input.n_cols()) ) { cerr << form ( "Template[%d,%d] is larger than image[%d,%d]!\n", template.n_rows(), template.n_cols(), input.n_rows(), input.n_cols(), ); abort(); } // the output will only have points of the input that // can be completely calculated (template does not fall off edge) double_image *output_pointer = new double_image ( CREATE, input.n_rows() - template.n_rows() + 1, input.n_cols() - template.n_cols() + 1, output_file ); double_image& output = *output_pointer; // make sure the window size is the same as the template size // for the input input.resize_window(template.n_cols(),template.n_rows()); // make the entire template random accessable template.window_entire_image(); // iterate through image correlating while(++input,++output) { output() = do_correlate(template,input); } // return the output image return output; } // this one takes 3 file pointers void correlate(FILE *template_file, FILE *input_file, FILE *output_file, char *comment) { // read in the template and input file double_image template(READ,template_file); double_image input(READ,input_file); // do the correlation double_image& output = correlate2(template,input,output_file); // construct the comments output.set_comments(comment,strlen(comment)); output.add_comment("Engaged in correlation, template is:\n",strlen("Engaged in correlation, template is:\n")); output.add_comment((char *) template.the_comments(), template.c_length()); output.add_comment("\nImage is:\n",strlen("\nImage is:\n")); output.add_comment((char *) input.the_comments(), input.c_length()); // write the image to file output.write(); } /* Copyright (C) 1986, David Sher in the University of Rochester Permission is granted to any individual or institution to use, copy, or redistribute this software so long as it is not sold for profit, provided this copyright notice is retained. */