⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map.c

📁 该程序把数字图像处理与小波变换结合起来
💻 C
字号:
#include "map.h"
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* 
 * Mow-Song, Ng 2/9/2002
 * msng@mmu.edu.my
 * http://www.pesona.mmu.edu.my/~msng
 *
 * I do not claim copyright to the code, but if you use them or modify them,
 * please drop me a mail.
 *
 */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
MAP *MapAlloc(int hsize, int vsize, int nsteps)
{
	MAP *map;
	int i;
	int *lowHSize, *lowVSize, *highHSize, *highVSize;

	assert(nsteps > 0);

	if ((map = (MAP *)malloc(sizeof(MAP)))==NULL){
		MapError("Fail to allocate map.\n");
	}

	map->hsize = hsize;
	map->vsize = vsize;
	map->nsteps = nsteps;

	/* ensure that all status starts with value 0 */
	map->symbol = (int *)calloc(map->hsize*map->vsize, sizeof(int));
	
	map->nSubbands		= 3*map->nsteps+1;
	map->subbandSize	= (int *)calloc(map->nSubbands, sizeof(int));
	map->subbandHSize = (int *)calloc(map->nSubbands, sizeof(int));
	map->subbandVSize = (int *)calloc(map->nSubbands, sizeof(int));
	map->subbandPtr	= (int **)calloc(map->nSubbands, sizeof(int *));

	lowHSize = (int *)calloc(map->nsteps, sizeof(int));
	lowVSize = (int *)calloc(map->nsteps, sizeof(int));
	highHSize = (int *)calloc(map->nsteps, sizeof(int));
	highVSize = (int *)calloc(map->nsteps, sizeof(int));

	lowHSize[map->nsteps-1] = (map->hsize+1)/2;
	lowVSize[map->nsteps-1] = (map->vsize+1)/2;
	highHSize[map->nsteps-1] = map->hsize/2; 
	highVSize[map->nsteps-1] = map->vsize/2;
	
	/* set the sizes for each blocks */
	for (i = map->nsteps-2; i >= 0; i--) {
		lowHSize[i] = (lowHSize[i+1]+1)/2;
		lowVSize[i] = (lowVSize[i+1]+1)/2;
		highHSize[i] = lowHSize[i+1]/2;
		highVSize[i] = lowVSize[i+1]/2; 
	}
	
	/* subband[0] */
	map->subbandPtr[0] = map->symbol;
	map->subbandHSize[0] = lowHSize[0];
	map->subbandVSize[0] = lowVSize[0];
	map->subbandSize[0] = map->subbandHSize[0]*map->subbandVSize[0];
	
	/* all other high pass subbands, do each scale at once */
	for (i = 0; i < map->nsteps; i++) {
		map->subbandHSize[3*i+1] = highHSize[i];
		map->subbandVSize[3*i+1] = lowVSize[i];
		map->subbandHSize[3*i+2] = lowHSize[i];
		map->subbandVSize[3*i+2] = highVSize[i];
		map->subbandHSize[3*i+3] = highHSize[i];
		map->subbandVSize[3*i+3] = highVSize[i];
	}
	
	/* set the data pointers */
	for (i = 1; i < map->nSubbands; i++) {
		map->subbandSize[i] = map->subbandHSize[i]*map->subbandVSize[i];
		map->subbandPtr[i] = map->subbandPtr[i-1] + map->subbandSize[i-1];
	}
	
	/* release allocated memory */
	free(lowHSize);
	free(lowVSize);
	free(highHSize);
	free(highVSize);
	
	return map;
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void MapDealloc(MAP *map)
{
	if (map!=NULL){
		free(map->symbol);
		free(map->subbandSize);
		free(map->subbandHSize);
		free(map->subbandVSize);
		free(map->subbandPtr);
		free(map);
	}
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
int MapGetNodeSymbol(MAP *map, int scale, int orientation, int x, int y)
{
	int idx;

	if (scale==0){
		idx = 0;	
	}
	else{
		idx = 3*scale - 2 + orientation;
	}
	
	return (map->subbandPtr[idx][y*map->subbandHSize[idx] + x]);
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void MapSetNodeSymbol(MAP *map, int scale, int orientation, int x, int y, 
							 int symbol)
{
	int idx;

	if (scale==0){
		idx = 0;
	}
	else{
		idx = 3*scale - 2 + orientation;
	}

	map->subbandPtr[idx][y*map->subbandHSize[idx] + x] = symbol;

	return;
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	
void MapError(char *fmt, ...)
{
	va_list argptr;
	
	va_start( argptr, fmt );
	fprintf(stderr, "MapError: " );
	vprintf( fmt, argptr );
	va_end( argptr );
	exit( -1 );
}

/*----------------------------------------------------------------------------*/	
/*----------------------------------------------------------------------------*/	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -