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

📄 surfaceletfilterbank.cpp

📁 A set of C++ and Matlab routines implementing the surfacelet transform surfacelet的一个非常好用的工具箱
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////
//	SurfBox-C++ (c)
//////////////////////////////////////////////////////////////////////////
//
//	Yue Lu and Minh N. Do
//
//	Department of Electrical and Computer Engineering
//	Coordinated Science Laboratory
//	University of Illinois at Urbana-Champaign
//
//////////////////////////////////////////////////////////////////////////
//
//	SurfaceletFilterBank.cpp
//	
//	First created: 04-02-06
//	Last modified: 04-14-06
//
//////////////////////////////////////////////////////////////////////////

#include "SurfaceletFilterBank.h"
#include <math.h>
#include <cassert>

extern void MessageLog(const char*, const char*, const char*);


//////////////////////////////////////////////////////////////////////////
//	Constructor
//////////////////////////////////////////////////////////////////////////

SurfaceletRecInfo::SurfaceletRecInfo()
{
	// Initialize the pointer
	NdfbLevels = NULL;
}


//////////////////////////////////////////////////////////////////////////
//	Destructor
//////////////////////////////////////////////////////////////////////////

SurfaceletRecInfo::~SurfaceletRecInfo()
{
	// Release memory resource
	if (NdfbLevels)
	{
		assert(PyrLevel >= 1);
		for (int i = 0; i < PyrLevel; i++)
			delete [] NdfbLevels[i];

		delete [] NdfbLevels;
	}
}


//////////////////////////////////////////////////////////////////////////
//	Set decomposition and reconstruction parameters
//////////////////////////////////////////////////////////////////////////

void SurfaceletRecInfo::SetParameters(int nDims_, int bo_, int mSize_, double beta_, double lambda_, int PyrLevel_,
		enum Pyramid_Mode pyr_mode_, enum SmoothFunctionType func_type_, string& dir_info)
{
	assert(NdfbLevels == NULL);
	
	nDims = nDims_;
	assert(nDims >= 2);

	bo = bo_;
	mSize = mSize_;
	beta = beta_;
	lambda = lambda_;

	PyrLevel = PyrLevel_;
	assert(PyrLevel >= 1);

	pyr_mode = pyr_mode_;
	func_type = func_type_;

	try
	{
		// Get the checkerboard filters
		ndfb_fb.GetCheckerboardFilters(bo, true, Dec_filter0, Dec_center0, Dec_filter1, Dec_center1, dir_info);
		ndfb_fb.GetCheckerboardFilters(bo, false, Rec_filter0, Rec_center0, Rec_filter1, Rec_center1, dir_info);
	}
	catch (...)
	{
		// filter coefficients files not found
		throw;
	}
	
	// allocate memory space
	try
	{
		NdfbLevels = new int * [PyrLevel];
		for (int i = 0; i < PyrLevel; i++)
			NdfbLevels[i] = new int [nDims * nDims];
	}
	catch (std::bad_alloc)
	{
		MessageLog("SurfaceletRecInfo", "SetParameters", "Out of memory!");
		throw;
	}
}


//////////////////////////////////////////////////////////////////////////
//	Set decomposition and reconstruction parameters (without reading the filter coefficients files)
//////////////////////////////////////////////////////////////////////////

void SurfaceletRecInfo::SetParameters(int nDims_, int mSize_, double beta_, double lambda_, 
	int PyrLevel_, enum Pyramid_Mode pyr_mode_, enum SmoothFunctionType func_type_)
{
	assert(NdfbLevels == NULL);

	nDims = nDims_;
	assert(nDims >= 2);

	mSize = mSize_;
	beta = beta_;
	lambda = lambda_;

	PyrLevel = PyrLevel_;
	assert(PyrLevel >= 1);

	pyr_mode = pyr_mode_;
	func_type = func_type_;

	// allocate memory space
	try
	{
		NdfbLevels = new int * [PyrLevel];
		for (int i = 0; i < PyrLevel; i++)
			NdfbLevels[i] = new int [nDims * nDims];
	}
	catch (std::bad_alloc)
	{
		MessageLog("SurfaceletRecInfo", "SetParameters", "Out of memory!");
		throw;
	}
}


//////////////////////////////////////////////////////////////////////////
//	Directly set the checkerboard filters
//////////////////////////////////////////////////////////////////////////

void SurfaceletRecInfo::SetFilters(double *pFilter0, int pDims0[], int center0[], 
	double *pFilter1, int pDims1[], int center1[], double *pFilter2, int pDims2[], int center2[],
	double *pFilter3, int pDims3[], int center3[])
{
	// Decomposition filter 0
	Dec_filter0.AllocateSpace(pDims0[0], pDims0[1]);
	memcpy(Dec_filter0.GetPointer(), pFilter0, pDims0[0] * pDims0[1] * sizeof(double));
	Dec_center0[0] = center0[0];
	Dec_center0[1] = center0[1];

	// Decomposition filter 1
	Dec_filter1.AllocateSpace(pDims1[0], pDims1[1]);
	memcpy(Dec_filter1.GetPointer(), pFilter1, pDims1[0] * pDims1[1] * sizeof(double));
	Dec_center1[0] = center1[0];
	Dec_center1[1] = center1[1];

	// Reconstruction filter 0
	Rec_filter0.AllocateSpace(pDims2[0], pDims2[1]);
	memcpy(Rec_filter0.GetPointer(), pFilter2, pDims2[0] * pDims2[1] * sizeof(double));
	Rec_center0[0] = center2[0];
	Rec_center0[1] = center2[1];

	// Reconstruction filter 1
	Rec_filter1.AllocateSpace(pDims3[0], pDims3[1]);
	memcpy(Rec_filter1.GetPointer(), pFilter3, pDims3[0] * pDims3[1] * sizeof(double));
	Rec_center1[0] = center3[0];
	Rec_center1[1] = center3[1];
}

//////////////////////////////////////////////////////////////////////////
//	Get the decomposition level info at a certain scale
//////////////////////////////////////////////////////////////////////////
//
//	PARAMETERS:
//
//	scale:
//		Specifying pyramid scale
//
//	Level:
//		An int array of dimension nDims * nDims to be filled with the decomposition levels

void SurfaceletRecInfo::GetNdfbLevel(int scale, int Level[]) const
{
	assert((scale >= 0) && (scale < PyrLevel));

	memcpy(Level, NdfbLevels[scale], nDims * nDims * sizeof(int));
}


//////////////////////////////////////////////////////////////////////////
//	Set the decomposition level info at a certain scale
//////////////////////////////////////////////////////////////////////////
//
//	PARAMETERS:
//
//	scale:
//		Specifying pyramid scale
//
//	Level:
//		An int array of dimension nDims * nDims storing the decomposition levels

void SurfaceletRecInfo::SetNdfbLevel(int scale, int Level[])
{
	assert((scale >= 0) && (scale < PyrLevel));
	assert(NdfbLevels != NULL);

	memcpy(NdfbLevels[scale], Level, nDims * nDims * sizeof(int));
}


//////////////////////////////////////////////////////////////////////////
//	Constructor
//////////////////////////////////////////////////////////////////////////

SurfaceletFilterBank::SurfaceletFilterBank()
{
	// do nothing
}


//////////////////////////////////////////////////////////////////////////
//	Destructor
//////////////////////////////////////////////////////////////////////////

SurfaceletFilterBank::~SurfaceletFilterBank()
{
	// do nothing
}


//////////////////////////////////////////////////////////////////////////
//	Surfacelet filter bank decomposition
//////////////////////////////////////////////////////////////////////////
//
//	PARAMETERS:
//
//	InArray
//		The input array
//	
//	OutHighpassArrays
//		The resulting highpass directional subbands
//
//	LowpassArray
//		The lowpass subband
//
//	ReconstructionInfo
//		Filter bank parameters

bool SurfaceletFilterBank::GetDecomposition(SurfArray &InArray, SurfArray **OutHighpassArrays[], SurfArray &OutLowpassAray, 
	SurfaceletRecInfo &ReconstructionInfo)
{
	// First check the validity of the parameters
	if (!CheckParameters(InArray, ReconstructionInfo))
		return false;
	
	int nDims = InArray.GetRank();
	assert(nDims >= 2);
		
	SurfArray *Pyr_Subbands;
	int iLevel, *NDFB_levels;
	int PyrLevel = ReconstructionInfo.PyrLevel;

	try
	{
		Pyr_Subbands = new SurfArray [PyrLevel + 1];
		NDFB_levels = new int [nDims * nDims];

	}
	catch(std::bad_alloc)
	{
		MessageLog("SurfaceletFilterBank", "GetDecomposition", "Out of memory!");
		throw;
	}

	// Multidimensional multiscale pyramid decomposition
	pyr_fb.GetDecomposition(InArray, Pyr_Subbands, PyrLevel, true, 
		ReconstructionInfo.pyr_mode, ReconstructionInfo.func_type);

	// Copy lowpass array

⌨️ 快捷键说明

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