DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T c

⟦3d950019a⟧ TextFile

    Length: 2994 (0xbb2)
    Types: TextFile
    Names: »cap.c++«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/image/vartools/cap.c++« 

TextFile

/*
    This is the routines that take the pixels of an image and place an
    upper or lower bound on them.
*/

#include <stream.h>
#include <stdio.h>
#include <string.h>
#include <double_image.h++>
#include <vartools.h++>

/*
    This code places an upper bound on the values of the pixels.
    If a pixel exceeds the bound it is set to the bound.
*/
double_image&
upper_bound2(double bound, double_image& input, FILE * output_file)
    {
    // create the image
    double_image *output_pointer = 
	new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
    double_image& output = *output_pointer;
    // iterate through the images copying when it is a good idea
    while(++input,++output)
	{
	double pixel = input();
	output() = (pixel > bound) ? bound : pixel;
	}

    return output;
    }

/*
    This code places an lower bound on the values of the pixels.
    If a pixel exceeds the bound it is set to the bound.
*/
double_image&
lower_bound2(double bound, double_image& input, FILE * output_file)
    {
    // create the image
    double_image *output_pointer = 
	new double_image(CREATE,input.n_rows(),input.n_cols(),output_file);
    double_image& output = *output_pointer;
    // iterate through the images copying when it is a good idea
    while(++input,++output)
	{
	double pixel = input();
	output() = (pixel < bound) ? bound : pixel;
	}

    return output;
    }


/*
    This code is like upper_bound2 but with files (for C)
*/
void
upper_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
    {
    // read in the input image
    double_image input(READ,input_file);
    // apply the upper bound to it and get the output
    double_image& output = upper_bound2(bound,input,output_file);
    // set up the comments
    output.set_comments(comment,strlen(comment));
    char *string = form("Applying Upper Bound of %e to image:\n",bound);
    output.add_comment(string,strlen(string));
    output.add_comment((char *) input.the_comments(),input.c_length());
    // write the result to file
    output.write();
    }

/*
    This code is like lower_bound2 but with files (for C)
*/
void
lower_bound(double bound, FILE * input_file, FILE * output_file, char *comment)
    {
    // read in the input image
    double_image input(READ,input_file);
    // apply the upper bound to it and get the output
    double_image& output = lower_bound2(bound,input,output_file);
    // set up the comments
    output.set_comments(comment,strlen(comment));
    char *string = form("Applying Lower Bound of %e to image:\n",bound);
    output.add_comment(string,strlen(string));
    output.add_comment((char *) input.the_comments(),input.c_length());
    // write the result 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.
*/