📄 edge.c
字号:
/****************************************************************************
File Name : edge.c
Purpose : provides routines to compute edge map marking the location,
strength and direction of edge points.
Release : Version 1.0
Date : Aug 31,1995
GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
University (NTU), Singapore.
These software programs are available to the user without any license or royalty fees. Permission is hereby granted to use, copy, modify, and distribute this software and its documentation for any purpose. ITI and NTU gives no warranty, express, implied, or statuary for the software and/or documentation provided, including, without limitation, waranty of merchantibility and warranty of fitness for a particular purpose. The software provided hereunder is on an "as is" basis, and ITI and NTU has no obligation to provide maintenance, support, updates, enhancements, or modifications.
GSNAKE API is available for any UNIX compatible system. User feedback, bugs, or software and manual suggestions should be sent via electronic mail to one of the following, who may or may not act on them as he/she desires :
asschan@ntu.ac.sg
kflai@iti.gov.sg
***************************************************************************/
#include "xwindow.h"
#include "gsnake.h"
/* frees Edgemap memory and sets pointers back to NULL */
void EDGE::reset()
{
if (Mag) delete Mag;
if (Ang) delete Ang;
Mag = Ang = NULL;
}
/* Method init uses parameters row and col to initialise image objects
for Magnitude and Angle of edge gradients */
EDGE::init(int _row, int _col)
{
int status ;
if( !(Mag = new IMAGE) || !(Ang = new IMAGE) )
return MEMORYERROR ;
if( (status = Mag->init(_row, _col)) != NOERROR )
return status ;
return Ang->init(_row, _col);
}
/* Method compute performs calculation of edge gradient magnitude and
angle information from image. The data is stored onto Mag and Ang
matrices of Edge class. Parameter required is the image pointer. It
returns an integer status showing error if any */
EDGE::compute(IMAGE *img, int verbose, double low_pct, double high_pct,
double low_val, double high_val, double exp)
{
int status ;
register short i,j;
double dx, dy;
double value;
float right, left, up, down;
float mag ;
if(verbose)
fprintf(stdout, "\t\tComputing Edge : ");
if ( (status = init(img->getRow(), img->getCol()) ) != NOERROR )
return status;
for (i=0 ; i<img->getRow()-1 ; i++) {
if(verbose && !(i%10)) {
fprintf(stdout, "#");
fflush(stdout);
}
for (j=0 ; j<img->getCol()-1 ; j++) {
dx = dy = 0; /* initialize gradient */
/* least square estimation */
down = img->get(i,j) + img->get(i,j+1) ;
up = img->get(i+1,j) + img->get(i+1,j+1);
right = img->get(i,j+1) + img->get(i+1,j+1);
left = img->get(i,j) + img->get(i+1,j);
dy = 0.5 * (up - down);
dx = 0.5 * (right - left);
/* put in gradient magnitude and angle values in edgemap */
putMag( i, j, mag = hypot(dx, dy) );
putAng( i, j, ATAN2(dy,dx) );
}
} /* end for i */
Mag->condition(low_pct,high_pct,low_val,high_val,exp);
if(verbose) fprintf(stdout, "\n");
return NOERROR;
}
void EDGE::show(unsigned char _magnify, int h_offset, int v_offset)
{
if( !h_offset && !v_offset)
xwin_raiseWindow(_magnify*getCol()*2, _magnify*getRow());
Mag->generateX(_magnify);
Ang->generateX(_magnify);
xwin_drawImg(Mag->ximg, h_offset, v_offset);
xwin_drawImg(Ang->ximg, _magnify*getCol()+h_offset, v_offset);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -