📄 pyramid.c
字号:
/****************************************************************************
File Name : pyramid.c
Purpose : generates a pyramid of Gaussian images and edge maps
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"
PYRAMID::PYRAMID()
{
edgemap = NULL;
gaussImg = NULL;
rawImg = NULL;
numLevel = 0;
}
PYRAMID::~PYRAMID()
{
reset();
if (rawImg) delete rawImg ;
rawImg = NULL;
edgemap = NULL;
rawImg = NULL;
}
void PYRAMID::reset()
{
short i;
for ( i=0; i < numLevel; i++ ) {
if(edgemap[i]) {
delete edgemap[i];
edgemap[i] = NULL;
}
if( gaussImg[i] ) {
delete gaussImg[i];
gaussImg[i] = NULL;
}
}
numLevel = 0;
if ( edgemap ) _iMemFree( edgemap );
if ( gaussImg ) _iMemFree( gaussImg );
}
int PYRAMID::init(short level)
{
/* _iMemFree previous memory */
if (numLevel)
reset();
/* assign pyramid level */
numLevel = level;
/* allocate memory for gaussImg */
if( !(edgemap = (EDGE **) _iMemAlloc(numLevel*sizeof(EDGE *))) )
{
fprintf(stderr," <PYRAMID::init> : memory allocation error\n");
return MEMORYERROR;
}
memset(edgemap, 0, numLevel*sizeof(EDGE *)) ;
/* allocate memory for gaussImg */
if( !(gaussImg = (IMAGE **) _iMemAlloc(numLevel*sizeof(IMAGE *))) )
{
fprintf(stderr," <PYRAMID::init> : memory allocation error\n");
return MEMORYERROR;
}
memset(gaussImg, 0, numLevel*sizeof(IMAGE *)) ;
/* returns 0 */
return NOERROR;
}
/*
* generate multiple level gaussian images
*/
PYRAMID::generate( short level, int verbose,double low_pct,
double high_pct, double low_val,
double high_val, double exp,
EEXTTYPE EextType )
{
register short i;
IMAGE *PyramidImg;
IMAGE Template;
int SubSample_Step = 2;
if(verbose) fprintf(stdout, "Generating Pyramid : \n");
/* build gaussian generating kernel */
Template.initAsGauss();
/* allocate memory */
if ( init(level) ) return MEMORYERROR;
/* generate gaussian pyramid images */
for (i=0; i<numLevel; i++)
{
if(verbose) fprintf(stdout, "\tLevel %d\n", i);
PyramidImg = (i) ? gaussImg[i-1] : rawImg;
SubSample_Step = (i) ? 2 : 1;
/* perform correlation betw. input image and template */
gaussImg[i] = PyramidImg->correlate(&Template, SubSample_Step,
SubSample_Step, verbose);
/* Compute EdgeMap */
if (EextType != _INTENSITY) {
edgemap[i] = new EDGE;
edgemap[i]->compute( gaussImg[i], verbose,
low_pct,high_pct,low_val,high_val,exp);
}
}
if(EextType == _INTENSITY)
for(i=0; i<numLevel; i++)
gaussImg[i]->condition(low_pct,high_pct,low_val,high_val,exp);
return NOERROR;
}
int PYRAMID::duplicate( PYRAMID *pyramid )
{
short register i;
/* raw image */
pyramid->rawImg = rawImg->copy();
if ( pyramid->init( numLevel ) == MEMORYERROR )
return MEMORYERROR;
for ( i = 0; i < numLevel; i++ ) {
if ( pyramid->edgemap[i] ) {
pyramid->edgemap[i]->putMagImg(
edgemap[i]->getMagImg()->copy() );
pyramid->edgemap[i]->putAngImg(
edgemap[i]->getAngImg()->copy() );
}
pyramid->gaussImg[i] = gaussImg[i]->copy();
}
return NOERROR;
}
void PYRAMID::print(int level)
{
short i, j;
printf("Magnitude \n");
for (i = 0; i<edgemap[level]->getRow() - 1; i++) {
for (j=0; j<edgemap[level]->getCol() - 1;j++)
printf("%d ", (unsigned char)
edgemap[level]->getMag(i,j));
printf("\n");
}
printf("Angle\n");
for (i = 0; i<edgemap[level]->getRow(0) - 1; i++) {
for (j=0; j<edgemap[level]->getCol(0) - 1 ;j++)
printf("%f ", edgemap[level]->getAng(i,j));
printf("\n");
}
}
int PYRAMID::putRawImg( char *filename )
{
if ( rawImg ) delete rawImg;
if ( !( rawImg = new IMAGE ) ) {
fprintf(stderr,
"<PYRAMID::putRawImg> memory allocation error\n");
return MEMORYERROR;
}
return ( rawImg->read( filename ) );
}
void PYRAMID::show(unsigned magnify,int level)
{
short i, v_offset=0, h_offset=0;
short win_size=0;
if (level>numLevel) level=numLevel;
/* Calculating the tolal height of all the images */
for (i=0; i<level; i++)
win_size += gaussImg[i]->getRow()*magnify;
xwin_raiseWindow(magnify*gaussImg[0]->getCol()*3, win_size );
/* Generating the X images */
for (i=0; i<level; i++)
gaussImg[i]->generateX(magnify);
for(i=0; i<level ; i++)
{
xwin_drawImg(gaussImg[i]->ximg,0,v_offset);
if(edgemap[i]) {
edgemap[i]->show(magnify,gaussImg[i]->getCol()*magnify,
v_offset);
v_offset = v_offset+ gaussImg[i]->getRow()*magnify ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -