• Nenhum resultado encontrado

sobre os diferentes módulos, para sua posterior extracção através da ferramenta

CDOC(1) existente no XITE.

/*

________________________________________________________________ showlines.c

@(#)lshowlines.c 1.00 94/03/30, Copyright 1994, DEEC, FEUP Departamento de Engenharia Electrotecnica e de Computadores Faculdade de Engenharia

Rua dos Bragas 4099 PORTO CODEX PORTUGAL

E-mail: gpai@obelix.fe.up.pt

________________________________________________________________ biff.h

@(#)biff.h 1.23 92/04/10, Copyright 1990, Blab, UiO Image processing lab, Department of Informatics University of Oslo

E-mail: blab@ifi.uio.no

________________________________________________________________ readarg.h

@(#)readarg.h 1.3 92/01/15, Copyright 1990, Blab, UiO Image processing lab, Department of Informatics University of Oslo

E-mail: blab@ifi.uio.no

________________________________________________________________ message.h

@(#)message.h 1.3 92/01/15, Copyright 1990, Blab, UiO Image processing lab, Department of Informatics

University of Oslo E-mail: blab@ifi.uio.no

________________________________________________________________

Permission to use, copy, modify and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that this copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation and that the name of B-lab, Department of Informatics or University of Oslo not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

B-LAB DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL B-LAB BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/

/*******************************************************************/ static char *SccsId = "@(#)showlines.c 1.00 94/03/30, DEEC, FEUP"; /*******************************************************************/ /* INCLUDES */ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <blab/biff.h> #include <blab/readarg.h> #include <blab/message.h> /*******************************************************************/ /* GLOBAL VARIABLES */

FILE *fptin, *fptout; /* file's pointers */

/*******************************************************************/ /*F:showl*

________________________________________________________________ showl

________________________________________________________________ Name: showl - drawing input lines in an output band

Syntax: | int showl(band, lcolor, bcolor, nline) | IBAND band;

| int lcolor, bcolor, nline;

The output lines will be drawing in 'band' with color 'lcolor' in a background 'bcolor'.

'nline' is the minimum number of line's pixels to a line could be considered as a good line.

'*fptin' it's a global pointer to the file with the initial and final coordinates of all the lines to be considered.

'*fptout' it's a global pointer to the file in which the initial and final coordinates of all lines could be writing (if fptout!=NULL). Return value: | 0 => Ok.

Example: | Try yourself. Restrictions: None. Author: Joao Tavares

Id: @(#)showl.c 1.00 94/03/11

________________________________________________________________ */

int showl(band, lcolor, bcolor, nline) IBAND band;

int lcolor, bcolor, nline; {

register int i, j;

int xsize, ysize, xi, yi, xf, yf, aint1, aint2; /* make all the pixels in band as bcolor */ xsize = Ixsize(band);

ysize = Iysize(band); for (i = 1; i <= xsize; ++i) {

for (j = 1; j <= ysize; ++j) band[j][i] = bcolor; }

/* find good lines in the input file */

aint1 = xi-xf; aint1 *= aint1; aint2 = yi-yf; aint2 *= aint2;

if (sqrt((float)(aint1+aint2)) >= nline) dda(band, xi, yi, xf, yf, lcolor); fscanf(fptin, "%d %d %d %d", &xi, &yi, &xf, &yf);

} return(0); } /*******************************************************************/ /*F:dda* ________________________________________________________________ dda ________________________________________________________________ Name: dda - drawing a segment of line using the algorithm of Bresenham Syntax: | dda(xi, yi, xf, yf, band, color)

| IBAND band; | int xi, yi, xf, yf, color;

Description: 'dda' draw the segment of line between the initial pixel 'xi, yi' and the final pixel 'xf, yf' in the band 'band' with color as 'color'. If the global pointer 'fptout' is different of NULL the initial and final points of all segments will be writing in 'fptout''s file. Return value: | 0 => Ok.

Example: | Try yourself. Restrictions: None. Author: Joao Tavares

Id: @(#)dda.c 1.00 93/05/05

________________________________________________________________ */

int dda(band, xi, yi, xf, yf, color) IBAND band;

int xi, yi, xf, yf, color; {

register int t, distance;

int xsize, ysize, xerr, yerr, delta_x, delta_y, incx, incy;

/* write in file, if it was desire, the coordinates of the initial and final pixels of the segment */ if (fptout != NULL) fprintf(fptout, "\t%d %d\t%d %d\n", xi, yi, xf, yf);

xsize = Ixsize(band); ysize = Iysize(band); xerr = 0;

yerr = 0;

/* calculation of delta x and delta y */ delta_x = xf-xi;

delta_y = yf-yi;

/* determination of increment x and increment y */ if (delta_x > 0) incx = 1;

else if (delta_x == 0) incx = 0; else incx = -1;

if (delta_y > 0) incy = 1; else if (delta_y == 0) incy = 0; else incy = -1;

/* determination of the distance */ delta_x = abs(delta_x);

delta_y = abs(delta_y);

if (delta_x > delta_y) distance = delta_x; else distance = delta_y;

/* mark the closest point to the line with color */ for (t = 0; t <= distance; t++) {

band[yi][xi] = color; xerr += delta_x; yerr += delta_y; if (xerr >= distance) { xerr -= distance; xi += incx; } if (yerr >= distance) { yerr -= distance; yi += incy; } } return(0); } /*******************************************************************/ /*P:showlines* ________________________________________________________________ showlines ________________________________________________________________ Name: showlines - drawing input lines in an output image

Syntax: | [-t <title>] [-l <lineColor>] [-b <backColor>] [-x <xsize>] | [-y <ysize>] [-n <nPixGoLine>] [-f <outputFilename] <inputFile> | <outputImage>

Description: 'showlines' performs the drawing of input lines in the output image 'outputImage'.

The output image will have the 'title' which is indicate through flag '-t', by default the 'title' is "Lines in file".

The output lines will be design in 'outputImage' image with color 'lineColor' in a 'backColor' background.

The color of the output lines 'outputImage' image can be indicate trough flag '-l'. By default 'lineColor' is 0 (black).

trough flag '-b'. By default 'backColor' is 255 (white).

The size of output image in x direction can be indicate trough flag '-x'. By default 'xsize' is 256.

The size of output image in y direction can be indicate trough flag '-y'. By default 'ysize' is 256.

The minimum number of line's pixels to a line could be considered as a good line can be indicate through flag '-n'. By default 'nPixGoLine' is 20.

The initial and final point's of each output line can be writing in the file 'outputFilename' if the flag '-f' is on, by default this flag is off. The input file 'inputFile' have the coordinates of the initial and final pixel of all the lines.

Return value: | 1 => Wrong value for line color %d; it must be greater than or | equal to 0 and smaller than or equal to 255.

| 2 => Wrong value for background color %d; it must be greater than | or equal to 0 and smaller than or equal to 255.

| 3 => Can't open input file <inputFile>. | 4 => Can't make output image <outputImage>. | 5 => Can't make band of output image <outputImage>. | 6 => Can't open output file <ouputFilename>. Examples: | Try yourself.

Restrictions: The value for line color and for background color must be greater than or equal to 0 and smaller than or equal to 255.

Author: Joao Tavares

Id: @(#)showlines.c 1.0 94/03/11 ________________________________________________________________ */ #ifdef MAIN main(argc, argv) int argc; char **argv; { IMAGE imgout;

int lcolor, bcolor, xsize, ysize, nline; char *filename, *title, arg[300];

InitMessage(&argc, argv, "Usage: %s\n [-t <title>] [-l <lineColor>] [-b <backColor>] [-x <xsize>] [-y <ysize>] [-n <nPixGoLine>] [-f <outputFilename] <inputFile> <outputImage>\n"); Iset_message(1);

Iset_abort(1); /* read switches */

title = read_switch(&argc, argv, "-t", 1, "Lines in file"); lcolor = atoi(read_switch(&argc, argv, "-l", 1, "0")); bcolor = atoi(read_switch(&argc, argv, "-b", 1, "255")); xsize = atoi(read_switch(&argc, argv, "-x", 1, "256")); ysize = atoi(read_switch(&argc, argv, "-y", 1, "256")); nline = atoi(read_switch(&argc, argv, "-n", 1, "10")); filename = read_switch(&argc, argv, "-f", 1, NULL); if (argc == 1) Usage(1, (char*)0);

if (argc != 3) Usage(2, "\nBad number of arguments.\n");

if (lcolor < 0 || lcolor > 255) exit(Error(1, "\nWrong value for line color %d; it must be greater than or equal to 0 and smaller than or equal to 255.\n", lcolor));

if (bcolor < 0 || bcolor > 255) exit(Error(2, "\nWrong value for background color %d; it must be greater than or equal to 0 and smaller than or equal to 255.\n", bcolor));

/* open the input file */ fptin = fopen(argv[1], "r");

if (fptin == NULL) exit(Error(3, "\nCan't open input file %s.\n", argv[1])); /* make the output image */

imgout = Init_image(1, title);

if (imgout == NULL) exit(Error(4, "\nCan't make output image %s.\n", argv[2])); /* make band of the output image */

imgout[1] = Imake_band(Iu_byte_typ, xsize, ysize);

if (imgout[1] == NULL) exit(Error(5, "\nCan't make band of output image %s.\n", argv[2])); sprintf(arg, "Results for %s in %s with:\n\n\tMinimum number of pixels to be considered as a line: %d.\n\n", argv[0], argv[1], nline);

/* open the output, file if it was desire, and write arg */ if (filename != NULL) {

fptout = fopen(filename, "a");

if (fptout == NULL) exit(Error(6, "\nCan't open output file %s.\n", filename)); fprintf(fptout, arg);

}

/* call the showl function */

showl(imgout[1], lcolor, bcolor, nline, fptin, fptout); /* close the input file */

fclose(fptin);

/* close output file if it was desire */ if (fptout != NULL) fclose(fptout); /* write the output image with history */ Ihistory(imgout, argv[0], arg);

Iwrite_image(imgout,argv[2]); }

#endif

Seguimento de Segmentos de Recta ao Longo de Sequências de Imagens e