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

📄 wavelet.cpp

📁 基于小波的图像配准
💻 CPP
字号:
/* These are two functions to do wavelet transform,
   one (cd) is for original data is unsigned char type (image data)
   another (dd) is for original data is double type (medial data)

   dataArray : data to be transformed, unsigned char* or double*
   array_width : data row length
   array_height : data column length
   h_coefficient: wavelet transform parameters, low filter
   h_substar: start subscript of h parameters of wavelet
   h_subend : end subscript of h parameters of wavelet */

#include "wavelet.h"

void cc_wavelet_transform(unsigned char* dataArray,
					      unsigned char* LL,unsigned char* LH,
					      unsigned char* HL,unsigned char* HH,
					      long array_width,long array_height,
					      double* h_coefficient,
					      int h_substar,int h_subend)
{
	int count,g_substar,g_subend,n,m;
	double* g_coefficient;

//set g parameters, high filter
	count = h_subend - h_substar +1;
	g_substar = 1 - h_subend;
	g_subend  = 1 - h_substar;
	g_coefficient = (double *)malloc(sizeof(double)*count);
	for(n=0;n<count;n++){
		m = g_substar + n;
		if(m%2==0)
			 g_coefficient[n] = - h_coefficient[1-m-h_substar];
		else g_coefficient[n] =   h_coefficient[1-m-h_substar];
//		printf("g_coefficient[%d] = %15.12f\n",n,g_coefficient[n]);
	}

	double* medialresult;
	medialresult = (double *)malloc(sizeof(double)*
		           (array_width/2)*array_height);

//to create LL and LH	
	//low filtering first
	cd_convolve(dataArray,medialresult,array_width,array_height,
		     h_coefficient,h_substar,h_subend);

	//LL: low filtering second
	dc_convolve(medialresult,LL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);
	//LH: high filtering second
	dc_convolve(medialresult,LH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

	
//to create HL and HH
	//high filtering first
	cd_convolve(dataArray,medialresult,array_width,array_height,
		        g_coefficient,g_substar,g_subend);

	//HL: lowfiltering second
	dc_convolve(medialresult,HL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);

	//HH: high filtering second
	dc_convolve(medialresult,HH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

	free(g_coefficient);
	return;
}
void cd_wavelet_transform(unsigned char* dataArray,
					      double* LL,double* LH,
					      double* HL,double* HH,
					      long array_width,long array_height,
					      double* h_coefficient,
					      int h_substar,int h_subend)
{
	int count,g_substar,g_subend,n,m;
	double* g_coefficient;

//set g parameters, high filter
	count = h_subend - h_substar +1;
	g_substar = 1 - h_subend;
	g_subend  = 1 - h_substar;
	g_coefficient = (double *)malloc(sizeof(double)*count);
	for(n=0;n<count;n++){
		m = g_substar + n;
		if(m%2==0)
			 g_coefficient[n] = - h_coefficient[1-m-h_substar];
		else g_coefficient[n] =   h_coefficient[1-m-h_substar];
//		printf("g_coefficient[%d] = %15.12f\n",n,g_coefficient[n]);
	}

	double* medialresult;
	medialresult = (double *)malloc(sizeof(double)*
		           (array_width/2)*array_height);

//to create LL and LH	
	//low filtering first
	cd_convolve(dataArray,medialresult,array_width,array_height,
		     h_coefficient,h_substar,h_subend);

	//LL: low filtering second
	dd_convolve(medialresult,LL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);
	//LH: high filtering second
	dd_convolve(medialresult,LH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

	
//to create HL and HH
	//high filtering first
	cd_convolve(dataArray,medialresult,array_width,array_height,
		        g_coefficient,g_substar,g_subend);

	//HL: lowfiltering second
	dd_convolve(medialresult,HL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);

	//HH: high filtering second
	dd_convolve(medialresult,HH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

	free(g_coefficient);
	return;
}

void dd_wavelet_transform(double* dataArray,
					      double* LL,double* LH,
					      double* HL,double* HH,
					      long array_width,long array_height,
					      double* h_coefficient,
					      int h_substar,int h_subend)
{
	int count,g_substar,g_subend,n,m;
	double* g_coefficient;

//set g parameters, high filter
	count = h_subend - h_substar +1;
	g_substar = 1 - h_subend;
	g_subend  = 1 - h_substar;
	g_coefficient = (double *)malloc(sizeof(double)*count);
	for(n=0;n<count;n++){
		m = g_substar + n;
		if(m%2==0)
			 g_coefficient[n] = - h_coefficient[1-m-h_substar];
		else g_coefficient[n] =   h_coefficient[1-m-h_substar];
//		printf("g_coefficient[%d] = %15.12f\n",n,g_coefficient[n]);
	}

	double* medialresult;
	medialresult = (double *)malloc(sizeof(double)*
		           (array_width/2)*array_height);

//to create LL and LH	
	//low filtering first
	dd_convolve(dataArray,medialresult,array_width,array_height,
		     h_coefficient,h_substar,h_subend);

	//LL: low filtering second
	dd_convolve(medialresult,LL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);
	//LH: high filtering second
	dd_convolve(medialresult,LH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

//to create HL and HH
	//high filtering first
	dd_convolve(dataArray,medialresult,array_width,array_height,
		     g_coefficient,g_substar,g_subend);

	//HL: lowfiltering second
	dd_convolve(medialresult,HL,array_height,array_width/2,
		     h_coefficient,h_substar,h_subend);
	//HH: high filtering second
	dd_convolve(medialresult,HH,array_height,array_width/2,
		     g_coefficient,g_substar,g_subend);

	free(g_coefficient);
	return;
}







	









⌨️ 快捷键说明

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