initial update by yizhang
This commit is contained in:
parent
e8881d83f0
commit
ddc3ed0736
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
.DS_Store
|
BIN
C++ Wavelet Libraries.webarchive
Normal file
BIN
C++ Wavelet Libraries.webarchive
Normal file
Binary file not shown.
26
CMakeLists.txt
Normal file
26
CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
|
||||
# 设置工程名称和语言
|
||||
project(LIBWAVELET)
|
||||
|
||||
# 设置库版本号
|
||||
set(VERSION_MAJOR 1)
|
||||
set(VERSION_MINOR 0)
|
||||
|
||||
# 添加源文件地址
|
||||
add_subdirectory(src/)
|
||||
|
||||
# 设置安装地址(通过homebrew安装时需要注释掉)
|
||||
set(CMAKE_INSTALL_PREFIX /usr/local)
|
||||
|
||||
# 构建一个 CPack 安装包
|
||||
include (InstallRequiredSystemLibraries)
|
||||
set(CPACK_OUTPUT_FILE_PREFIX "${PROJECT_SOURCE_DIR}/package")
|
||||
#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
|
||||
#set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
|
||||
set(PROJECT_VERSION_FULL ${VERSION_MAJOR}.${VERSION_MINOR})
|
||||
set(CPACK_SOURCE_GENERATOR "TGZ")
|
||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME liblgd-${PROJECT_VERSION_FULL})
|
||||
include (CPack)
|
@ -12,3 +12,10 @@ Non FFTW Options - See the folders wavelib-nofftw and wavelib-nofftw-vs for opti
|
||||
Recommended Alternatives - A faster , completely self-contained implementation of 1D DWT,SWT and MODWT with BSD license is available at https://github.com/rafat/wavelib
|
||||
|
||||
Contact - rafat.hsn@gmail.com
|
||||
|
||||
|
||||
## Continued By Yi Zhang
|
||||
|
||||
* Update to FFTW-3.3.8
|
||||
* Move file from src to src_deprecated
|
||||
* Copy files from src_MSVC to src
|
58
src/CMakeLists.txt
Normal file
58
src/CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
# 设定源文件文件夹
|
||||
aux_source_directory(lib/ WAVELETLIB_SRC)
|
||||
|
||||
# 添加头文件搜索地址
|
||||
include_directories(/usr/local/include)
|
||||
|
||||
# 以下部分为例子程序的编译
|
||||
# 设置可执行文件的输出地址
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
# 以下部分为库的编译
|
||||
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||
add_library(wlet SHARED ${WAVELETLIB_SRC})
|
||||
# 首先添加静态库的生成命令
|
||||
add_library(wlet_static STATIC ${WAVELETLIB_SRC})
|
||||
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||
set_target_properties(wlet_static PROPERTIES OUTPUT_NAME "wlet")
|
||||
# 设置输出目标属性以同时输出动态库与静态库
|
||||
set_target_properties(wlet PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(wlet_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
# 设置动态库的版本号
|
||||
set_target_properties(wlet PROPERTIES VERSION 1.0 SOVERSION 1.0)
|
||||
# 设置库文件的输出地址
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
find_library(FFTW_LIB fftw3 HINTS /usr/local/lib)
|
||||
find_library(FFTW_A_LIB libfftw3.a HINTS /usr/local/lib)
|
||||
target_link_libraries(wlet PUBLIC ${FFTW_LIB})
|
||||
target_link_libraries(wlet_static ${FFTW_A_LIB})
|
||||
|
||||
# 设置编译选项
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O2")
|
||||
|
||||
# 库的安装命令
|
||||
install(TARGETS wlet wlet_static
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
# 头文件安装命令
|
||||
install(FILES lib/wlet.h DESTINATION include)
|
||||
|
||||
# 添加示例程序编译宏
|
||||
macro(add_sample name)
|
||||
# 添加头文件搜索地址
|
||||
include_directories(/usr/local/include/opencv4)
|
||||
# 添加可执行文件 命令行
|
||||
add_executable(${name} sample/${name}.cpp)
|
||||
# 为安装文件添加动态库的搜索地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH "/usr/local/lib")
|
||||
# 链接动态库
|
||||
target_link_libraries(${name} PUBLIC wlet)
|
||||
endmacro()
|
||||
|
||||
# 添加例子
|
||||
add_sample(swtdemo)
|
||||
#add_sample(swt2Ddemo)
|
||||
#add_sample(wavedemo)
|
||||
#add_sample(imagedemo)
|
5665
src/lib/wlet2d.cpp
Normal file
5665
src/lib/wlet2d.cpp
Normal file
File diff suppressed because it is too large
Load Diff
155
src/lib/wlet2d.h
Normal file
155
src/lib/wlet2d.h
Normal file
@ -0,0 +1,155 @@
|
||||
#ifndef WAVELET2D_H
|
||||
#define WAVELET2D_H
|
||||
|
||||
#include <vector>
|
||||
#include <complex>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// 1D Functions
|
||||
|
||||
void* dwt1(string, vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
void* dyadic_zpad_1d(vector<double> &);
|
||||
|
||||
double convol(vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
int filtcoef(string , vector<double> &, vector<double> &, vector<double> &,
|
||||
vector<double> &);
|
||||
|
||||
void downsamp(vector<double> &, int , vector<double> &);
|
||||
|
||||
void upsamp(vector<double> &, int, vector<double> &);
|
||||
|
||||
void circshift(vector<double> &, int );
|
||||
|
||||
int sign(int);
|
||||
|
||||
void* idwt1(string wname, vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
int vecsum(vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
|
||||
|
||||
// 1D Symmetric Extension DWT Functions
|
||||
|
||||
|
||||
|
||||
void* dwt_sym(vector<double> &, int ,string , vector<double> &,vector<double> &,
|
||||
vector<int> &);
|
||||
|
||||
void* dwt1_sym(string , vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
void* idwt_sym(vector<double> &,vector<double> &, string,vector<double> &, vector<int> &);
|
||||
|
||||
void* symm_ext(vector<double> &, int );
|
||||
|
||||
void* idwt1_sym(string, vector<double> &, vector<double> &, vector<double> &); // Not Tested
|
||||
|
||||
// 1D Stationary Wavelet Transform
|
||||
|
||||
void* swt(vector<double> &, int , string , vector<double> &, int &) ;
|
||||
|
||||
void* iswt(vector<double> &,int , string, vector<double> &);
|
||||
|
||||
void* per_ext(vector<double> &, int );
|
||||
|
||||
|
||||
|
||||
|
||||
// 2D Functions
|
||||
|
||||
void* branch_lp_dn(string , vector<double> &, vector<double> &);
|
||||
|
||||
void* branch_hp_dn(string , vector<double> &, vector<double> &);
|
||||
|
||||
void* branch_lp_hp_up(string ,vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
//void* dwt_2d(vector<vector<double> > &, int , string , vector<vector<double> > &
|
||||
// , vector<double> &) ;
|
||||
|
||||
//void* idwt_2d(vector<vector<double> > &,vector<double> &, string ,vector<vector<double> > &);
|
||||
|
||||
void* dyadic_zpad_2d(vector<vector<double> > &,vector<vector<double> > &);
|
||||
|
||||
void* dwt_output_dim(vector<vector<double> >&, int &, int & );
|
||||
|
||||
void* zero_remove(vector<vector<double> > &,vector<vector<double> > &) ;
|
||||
|
||||
void* getcoeff2d(vector<vector<double> > &, vector<vector<double> > &,
|
||||
vector<vector<double> > &,vector<vector<double> > &,vector<double> &, int &);
|
||||
|
||||
void* idwt2(string ,vector<vector<double> > &, vector<vector<double> > &,
|
||||
vector<vector<double> > &, vector<vector<double> > &, vector<vector<double> > &);
|
||||
|
||||
void* dwt2(string ,vector<vector<double> > &, vector<vector<double> > &,
|
||||
vector<vector<double> > &, vector<vector<double> > &, vector<vector<double> > &);
|
||||
|
||||
void* downsamp2(vector<vector<double> > &,vector<vector<double> > &, int, int);
|
||||
|
||||
void* upsamp2(vector<vector<double> > &,vector<vector<double> > &, int, int);
|
||||
|
||||
// 2D DWT (Symmetric Extension) Functions
|
||||
|
||||
void* dwt_2d_sym(vector<vector<double> > &, int , string , vector<double> &, vector<double> & ,
|
||||
vector<int> &);
|
||||
|
||||
void* dwt2_sym(string ,vector<vector<double> > &, vector<vector<double> > &,
|
||||
vector<vector<double> > &, vector<vector<double> > &, vector<vector<double> > &);
|
||||
|
||||
void* idwt_2d_sym(vector<double> &,vector<double> &, string ,vector<vector<double> > &,
|
||||
vector<int> &);
|
||||
|
||||
void* circshift2d(vector<vector<double> > &, int , int );
|
||||
|
||||
void symm_ext2d(vector<vector<double> > &,vector<vector<double> > &, int );
|
||||
|
||||
void* dispDWT(vector<double> &,vector<vector<double> > &, vector<int> &, vector<int> &, int ) ;
|
||||
|
||||
void* dwt_output_dim_sym(vector<int> &,vector<int> &, int );
|
||||
|
||||
//2D Stationary Wavelet Transform
|
||||
|
||||
void* swt_2d(vector<vector<double> > &,int , string , vector<double> &);
|
||||
|
||||
void* per_ext2d(vector<vector<double> > &,vector<vector<double> > &, int );
|
||||
|
||||
// FFT functions
|
||||
|
||||
|
||||
double convfft(vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
double convfftm(vector<double> &, vector<double> &, vector<double> &);
|
||||
|
||||
void* fft(vector<complex<double> > &,int ,unsigned int);
|
||||
|
||||
void* bitreverse(vector<complex<double> > &);
|
||||
|
||||
void* freq(vector<double> &, vector<double> &);
|
||||
|
||||
//New
|
||||
|
||||
|
||||
void* dwt1_sym_m(string wname, vector<double> &signal, vector<double> &cA, vector<double> &cD);//FFTW3 for 2D
|
||||
|
||||
void* idwt1_sym_m(string wname, vector<double> &X, vector<double> &app, vector<double> &detail);
|
||||
|
||||
void* dwt(vector<double> &sig, int J, string nm, vector<double> &dwt_output
|
||||
, vector<double> &flag, vector<int> &length );
|
||||
|
||||
void* idwt(vector<double> &,vector<double> &, string,vector<double> &, vector<int> &);
|
||||
|
||||
void* dwt_2d(vector<vector<double> > &, int , string , vector<double> &, vector<double> & ,
|
||||
vector<int> &);
|
||||
void* dwt1_m(string wname, vector<double> &signal, vector<double> &cA, vector<double> &cD) ;
|
||||
|
||||
void* idwt_2d(vector<double> &dwtop,vector<double> &flag, string nm,
|
||||
vector<vector<double> > &idwt_output, vector<int> &length);
|
||||
|
||||
void* idwt1_m(string wname, vector<double> &X, vector<double> &cA, vector<double> &cD);
|
||||
|
||||
void* dwt_output_dim2(vector<int> &length, vector<int> &length2, int J);
|
||||
|
||||
|
||||
#endif/* WAVELET2D_H */
|
197
src/sample/imagedemo.cpp
Normal file
197
src/sample/imagedemo.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
//============================================================================
|
||||
// Name : imagedemo1.cpp
|
||||
// Author : Rafat Hussain
|
||||
// Version :
|
||||
// Copyright :
|
||||
// Description : DWT of arbitrary size image using symmetric or periodic extension
|
||||
//============================================================================
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include "../lib/wlet2d.h"
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void* maxval(vector<vector<double> > &arr, double &max){
|
||||
max = 0;
|
||||
for (unsigned int i =0; i < arr.size(); i++) {
|
||||
for (unsigned int j =0; j < arr[0].size(); j++) {
|
||||
if (max <= arr[i][j]){
|
||||
max = arr[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* maxval1(vector<double> &arr, double &max){
|
||||
max = 0;
|
||||
for (unsigned int i =0; i < arr.size(); i++) {
|
||||
if (max <= arr[i]){
|
||||
max = arr[i];
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
IplImage* img = cvLoadImage("snow.jpg");
|
||||
if (!img){
|
||||
cout << " Can't read Image. Try Different Format." << endl;
|
||||
exit(1);
|
||||
}
|
||||
int height, width;
|
||||
height = img->height;
|
||||
width = img->width;
|
||||
int nc = img->nChannels;
|
||||
// uchar* ptr2 =(uchar*) img->imageData;
|
||||
int pix_depth = img->depth;
|
||||
CvSize size;
|
||||
size.width =width;
|
||||
size.height=height;
|
||||
cout << "depth" << pix_depth << "Channels" << nc << endl;
|
||||
|
||||
|
||||
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
|
||||
cvShowImage("Original Image", img);
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("Original Image");
|
||||
cvSaveImage("orig.bmp",img);
|
||||
|
||||
|
||||
int rows =(int) height;
|
||||
int cols =(int) width;
|
||||
Mat matimg(img);
|
||||
|
||||
vector<vector<double> > vec1(rows, vector<double>(cols));
|
||||
|
||||
|
||||
int k =1;
|
||||
for (int i=0; i < rows; i++) {
|
||||
for (int j =0; j < cols; j++){
|
||||
unsigned char temp;
|
||||
temp = ((uchar*) matimg.data + i * matimg.step)[j * matimg.elemSize() + k ];
|
||||
vec1[i][j] = (double) temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
string nm = "db3";
|
||||
vector<double> l1,h1,l2,h2;
|
||||
filtcoef(nm,l1,h1,l2,h2);
|
||||
// unsigned int lf=l1.size();
|
||||
// int rows_n =(int) (rows+ J*(lf-1));
|
||||
// int cols_n =(int) (cols + J * ( lf -1));
|
||||
|
||||
// Finding 2D DWT Transform of the image using symetric extension algorithm
|
||||
// Extension is set to 3 (eg., int e = 3)
|
||||
|
||||
vector<int> length;
|
||||
vector<double> output,flag;
|
||||
int J =3;
|
||||
dwt_2d_sym(vec1,J,nm,output,flag,length);
|
||||
|
||||
double max;
|
||||
vector<int> length2;
|
||||
// This algorithm computes DWT of image of any given size. Together with convolution and
|
||||
// subsampling operations it is clear that subsampled images are of different length than
|
||||
// dyadic length images. In order to compute the "effective" size of DWT we do additional
|
||||
// calculations.
|
||||
dwt_output_dim_sym(length,length2,J);
|
||||
// length2 is gives the integer vector that contains the size of subimages that will
|
||||
// combine to form the displayed output image. The last two entries of length2 gives the
|
||||
// size of DWT ( rows_n by cols_n)
|
||||
|
||||
int siz = length2.size();
|
||||
int rows_n=length2[siz-2];
|
||||
int cols_n = length2[siz-1];
|
||||
|
||||
vector<vector< double> > dwtdisp(rows_n, vector<double>(cols_n));
|
||||
dispDWT(output,dwtdisp, length ,length2, J);
|
||||
|
||||
// dispDWT returns the 2D object dwtdisp which will be displayed using OPENCV's image
|
||||
// handling functions
|
||||
|
||||
vector<vector<double> > dwt_output= dwtdisp;
|
||||
|
||||
maxval(dwt_output,max);// max value is needed to take care of overflow which happens because
|
||||
// of convolution operations performed on unsigned 8 bit images
|
||||
|
||||
//Displaying Scaled Image
|
||||
// Creating Image in OPENCV
|
||||
IplImage *cvImg; // image used for output
|
||||
CvSize imgSize; // size of output image
|
||||
|
||||
imgSize.width = cols_n;
|
||||
imgSize.height = rows_n;
|
||||
|
||||
cvImg = cvCreateImage( imgSize, 8, 1 );
|
||||
// dwt_hold is created to hold the dwt output as further operations need to be
|
||||
// carried out on dwt_output in order to display scaled images.
|
||||
vector<vector<double> > dwt_hold(rows_n, vector<double>( cols_n));
|
||||
dwt_hold = dwt_output;
|
||||
// Setting coefficients of created image to the scaled DWT output values
|
||||
for (int i = 0; i < imgSize.height; i++ ) {
|
||||
for (int j = 0; j < imgSize.width; j++ ){
|
||||
if ( dwt_output[i][j] <= 0.0){
|
||||
dwt_output[i][j] = 0.0;
|
||||
}
|
||||
if ( i <= (length2[0]) && j <= (length2[1]) ) {
|
||||
((uchar*)(cvImg->imageData + cvImg->widthStep*i))[j] =
|
||||
(char) ( (dwt_output[i][j] / max) * 255.0);
|
||||
} else {
|
||||
((uchar*)(cvImg->imageData + cvImg->widthStep*i))[j] =
|
||||
(char) (dwt_output[i][j]) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cvNamedWindow( "DWT Image", 1 ); // creation of a visualisation window
|
||||
cvShowImage( "DWT Image", cvImg ); // image visualisation
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("DWT Image");
|
||||
cvSaveImage("dwt.bmp",cvImg);
|
||||
|
||||
// Finding IDWT
|
||||
|
||||
vector<vector<double> > idwt_output(rows, vector<double>(cols));
|
||||
|
||||
idwt_2d_sym(output,flag, nm, idwt_output,length);
|
||||
|
||||
|
||||
|
||||
//Displaying Reconstructed Image
|
||||
|
||||
IplImage *dvImg;
|
||||
CvSize dvSize; // size of output image
|
||||
|
||||
dvSize.width = idwt_output[0].size();
|
||||
dvSize.height = idwt_output.size();
|
||||
|
||||
cout << idwt_output.size() << idwt_output[0].size() << endl;
|
||||
dvImg = cvCreateImage( dvSize, 8, 1 );
|
||||
|
||||
for (int i = 0; i < dvSize.height; i++ )
|
||||
for (int j = 0; j < dvSize.width; j++ )
|
||||
((uchar*)(dvImg->imageData + dvImg->widthStep*i))[j] =
|
||||
(char) (idwt_output[i][j]) ;
|
||||
|
||||
cvNamedWindow( "Reconstructed Image", 1 ); // creation of a visualisation window
|
||||
cvShowImage( "Reconstructed Image", dvImg ); // image visualisation
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("Reconstructed Image");
|
||||
cvSaveImage("recon.bmp",dvImg);
|
||||
|
||||
return 0;
|
||||
}
|
178
src/sample/swt2Ddemo.cpp
Normal file
178
src/sample/swt2Ddemo.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
//============================================================================
|
||||
// Name : swt2Ddemo.cpp
|
||||
// Author : Rafat Hussain
|
||||
// Version :
|
||||
// Copyright :
|
||||
// Description : 2D SWT Demo using OPENCV
|
||||
//============================================================================
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include "../lib/wlet2d.h"
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/imgproc/imgproc_c.h>
|
||||
#include <opencv2/imgproc/types_c.h>
|
||||
#include <opencv2/highgui/highgui_c.h>
|
||||
//#include "cv.h"
|
||||
//#include "highgui.h"
|
||||
//#include "cxcore.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void* maxval(vector<vector<double> > &arr, double &max){
|
||||
max = 0;
|
||||
for (unsigned int i =0; i < arr.size(); i++) {
|
||||
for (unsigned int j =0; j < arr[0].size(); j++) {
|
||||
if (max <= arr[i][j]){
|
||||
max = arr[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Mat img = imread("lena512.bmp");
|
||||
if (!img){
|
||||
cout << " Can't read Image. Try Different Format." << endl;
|
||||
exit(1);
|
||||
}
|
||||
int height, width;
|
||||
height = img->height;
|
||||
width = img->width;
|
||||
int nc = img->nChannels;
|
||||
// uchar* ptr2 =(uchar*) img->imageData;
|
||||
int pix_depth = img->depth;
|
||||
CvSize size;
|
||||
size.width =width;
|
||||
size.height=height;
|
||||
cout << "depth" << pix_depth << "Channels" << nc << endl;
|
||||
|
||||
|
||||
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
|
||||
imshow("Original Image", img);
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("Original Image");
|
||||
imwrite("orig.bmp",img);
|
||||
|
||||
|
||||
int rows =(int) height;
|
||||
int cols =(int) width;
|
||||
Mat matimg(img);
|
||||
|
||||
vector<vector<double> > vec1(rows, vector<double>(cols));
|
||||
|
||||
|
||||
int k =1;
|
||||
for (int i=0; i < rows; i++) {
|
||||
for (int j =0; j < cols; j++){
|
||||
unsigned char temp;
|
||||
temp = ((uchar*) matimg.data + i * matimg.step)[j * matimg.elemSize() + k ];
|
||||
vec1[i][j] = (double) temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
string nm = "db2";
|
||||
// vector<double> l1,h1,l2,h2;
|
||||
// filtcoef(nm,l1,h1,l2,h2);
|
||||
|
||||
|
||||
vector<double> output;
|
||||
int J =3;
|
||||
swt_2d(vec1,J,nm,output);
|
||||
cout << "OUTPUT size" << output.size() << endl;
|
||||
cout << "LOOP OK" << endl;
|
||||
|
||||
int row,col;
|
||||
row=vec1.size();
|
||||
col=vec1[0].size();
|
||||
|
||||
// Extract and Display Low Pass Image at the Jth stage
|
||||
|
||||
vector<vector<double> > blur(row,vector<double>(col));
|
||||
|
||||
for (int i=0;i < row; i++){
|
||||
for (int j=0; j < col;j++){
|
||||
double temp = output[i*col + j];
|
||||
blur[i][j]= temp;
|
||||
}
|
||||
}
|
||||
|
||||
double max;
|
||||
maxval(blur,max);
|
||||
|
||||
// Creating Image in OPENCV
|
||||
IplImage *cvImg; // image used for output
|
||||
CvSize imgSize; // size of output image
|
||||
|
||||
imgSize.width = col;
|
||||
imgSize.height = row;
|
||||
|
||||
cvImg = cvCreateImage( imgSize, 8, 1 );
|
||||
|
||||
for (int i = 0; i < imgSize.height; i++ ) {
|
||||
for (int j = 0; j < imgSize.width; j++ ){
|
||||
if ( blur[i][j] <= 0.0){
|
||||
blur[i][j] = 0.0;
|
||||
}
|
||||
|
||||
((uchar*)(cvImg->imageData + cvImg->widthStep*i))[j] =
|
||||
(char) ( (blur[i][j] / max) * 255.0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cvNamedWindow( "Low Pass Image", 1 ); // creation of a visualisation window
|
||||
imshow( "Low Pass Image", cvImg ); // image visualisation
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("Low Pass Image");
|
||||
imwrite("blur.bmp",cvImg);
|
||||
|
||||
// Displaying BandPass Images
|
||||
|
||||
vector<vector<double> > detail(3*row,vector<double>(J * col));
|
||||
|
||||
for (int k=0; k < J; k++) {
|
||||
for (int i=0; i < 3*row; i++) {
|
||||
for(int j=0+ k*col; j < (k+1)*col; j++) {
|
||||
double temp = output[(3*k+1)*row*col+ i * col +j - k*col];
|
||||
detail[i][j]= temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
Mat dvImg; // image used for output
|
||||
CvSize imgSz; // size of output image
|
||||
|
||||
imgSz.width = J*col;
|
||||
imgSz.height = 3*row;
|
||||
|
||||
dvImg = cvCreateImage( imgSz, 8, 1 );
|
||||
|
||||
for (int i = 0; i < imgSz.height; i++ ) {
|
||||
for (int j = 0; j < imgSz.width; j++ ){
|
||||
if ( detail[i][j] <= 0.0){
|
||||
detail[i][j] = 0.0;
|
||||
}
|
||||
|
||||
((uchar*)(dvImg->imageData + dvImg->widthStep*i))[j] =
|
||||
(char) detail[i][j];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
cvNamedWindow( "Band Pass Image", 1 ); // creation of a visualisation window
|
||||
imshow( "Band Pass Image", dvImg ); // image visualisation
|
||||
cvWaitKey();
|
||||
cvDestroyWindow("Band Pass Image");
|
||||
imwrite("detail.bmp",dvImg);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
93
src/sample/swtdemo.cpp
Normal file
93
src/sample/swtdemo.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
//============================================================================
|
||||
// Name : swtdemo.cpp
|
||||
// Author : Rafat Hussain
|
||||
// Version :
|
||||
// Copyright :
|
||||
// Description : 1D Stationary Wavelet Transform Demo
|
||||
//============================================================================
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "../lib/wlet2d.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
cout << "********J- LEVEL DISCRETE WAVELET TRANSFORM IMPLEMENTATION*********" << endl; // prints
|
||||
cout << "This program accepts signal from the user in a file format " << endl;
|
||||
cout << "and performs Discrete Wavelet Transform with specified " << endl;
|
||||
cout << "wavelet. " << endl;
|
||||
cout << " " << endl;
|
||||
cout << " The Following Wavelets are in the Database: " << endl;
|
||||
cout << " haar, db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, " << endl;
|
||||
cout << " db11, db12, db13, db14, db15. " << endl;
|
||||
cout << " bior1.1, bio1.3, bior1.5, bior2.2, bior2.4,bior2.6,bior2.8, " << endl;
|
||||
cout << " bior3.1, bior3.3, bior3.5, bior3.7, bior3.9, bior4.4," << endl;
|
||||
cout << " bior5.5, bior6.8." << endl;
|
||||
cout << " coif1, coif2, coif3, coif4, coif5." << endl;
|
||||
cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl;
|
||||
|
||||
string nm; // nm will store the name of Wavelet Family
|
||||
cin >> nm;
|
||||
cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl;
|
||||
char inp[50];
|
||||
cin >> inp;
|
||||
vector<double> sig;
|
||||
ifstream sig_inp(inp);
|
||||
if ( !sig_inp.good()){
|
||||
cout << "The File doesn't exist"<< endl;
|
||||
}
|
||||
while (sig_inp) {
|
||||
double temp;
|
||||
sig_inp >> temp;
|
||||
sig.push_back(temp);
|
||||
}
|
||||
sig.pop_back();
|
||||
vector<double> original;
|
||||
original = sig; // Make a copy of the signal if you want to use original signal
|
||||
// later on. The other option is to use IDWT output as the SWt/ISWT system is
|
||||
// Perefect Reconstruction system.
|
||||
cout << "Please Enter the Number of DWT Stages J :" << endl;
|
||||
|
||||
int J;
|
||||
cin >> J ;
|
||||
|
||||
vector<double> swt_output;
|
||||
|
||||
// perform J-Level DWT
|
||||
int length;// All coefficients are of same length. Variable "length" returns length
|
||||
// of coefficients. It is not required for ISWT computations.
|
||||
|
||||
|
||||
|
||||
swt(sig, J, nm, swt_output, length);
|
||||
cout << "coeff-len = " << length << endl;
|
||||
|
||||
ofstream swtcoeff("swtcoeff.txt");
|
||||
for (unsigned int i=0; i < swt_output.size(); i++) {
|
||||
swtcoeff << swt_output[i] << endl;
|
||||
}
|
||||
|
||||
// remove high level details
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
swt_output[200+i] = 0.0;
|
||||
}
|
||||
|
||||
vector<double> iswt_output;
|
||||
iswt(swt_output,J, nm,iswt_output);
|
||||
ofstream sig1("recon.txt");
|
||||
ofstream diff("diff.txt");
|
||||
|
||||
cout <<" Recon signal size" << iswt_output.size() << endl;
|
||||
for (unsigned int i = 0; i < iswt_output.size(); i++){
|
||||
sig1 << iswt_output[i] << " " << original[i] << endl;
|
||||
diff << iswt_output[i] - original[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
83
src/sample/wavedemo.cpp
Normal file
83
src/sample/wavedemo.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
//============================================================================
|
||||
// Name : wavedemo1.cpp
|
||||
// Author : Rafat Hussain
|
||||
// Version :
|
||||
// Copyright :
|
||||
// Description : 1D DWT Demo
|
||||
//============================================================================
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "../lib/wlet2d.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
cout << "********J- LEVEL DISCRETE WAVELET TRANSFORM IMPLEMENTATION*********" << endl; // prints
|
||||
cout << "This program accepts signal from the user in a file format " << endl;
|
||||
cout << "and performs Discrete Wavelet Transform with specified " << endl;
|
||||
cout << "wavelet. " << endl;
|
||||
cout << " " << endl;
|
||||
cout << " The Following Wavelets are in the Database: " << endl;
|
||||
cout << " haar, db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, " << endl;
|
||||
cout << " db11, db12, db13, db14, db15. " << endl;
|
||||
cout << " bior1.1, bio1.3, bior1.5, bior2.2, bior2.4,bior2.6,bior2.8, " << endl;
|
||||
cout << " bior3.1, bior3.3, bior3.5, bior3.7, bior3.9, bior4.4," << endl;
|
||||
cout << " bior5.5, bior6.8." << endl;
|
||||
cout << " coif1, coif2, coif3, coif4, coif5." << endl;
|
||||
cout << "Please Enter the Wavelet Name at the Prompt( No quotes) :" << endl;
|
||||
|
||||
string nm; // nm will store the name of Wavelet Family
|
||||
cin >> nm;
|
||||
cout << "Enter the name of signal file at the Prompt eg., signal.txt :" << endl;
|
||||
char inp[50];
|
||||
cin >> inp;
|
||||
vector<double> sig;
|
||||
ifstream sig_inp(inp);
|
||||
if ( !sig_inp.good()){
|
||||
cout << "The File doesn't exist"<< endl;
|
||||
}
|
||||
while (sig_inp) {
|
||||
double temp;
|
||||
sig_inp >> temp;
|
||||
sig.push_back(temp);
|
||||
}
|
||||
sig.pop_back();
|
||||
vector<double> original;
|
||||
original = sig;
|
||||
cout << "Please Enter the Number of DWT Stages J :" << endl;
|
||||
|
||||
int J;
|
||||
cin >> J ;
|
||||
|
||||
vector<double> dwt_output, flag;
|
||||
|
||||
// perform J-Level DWT
|
||||
vector<int> length;
|
||||
|
||||
dwt_sym(sig, J, nm, dwt_output,flag,length);
|
||||
ofstream dwtout("dwtout.txt");
|
||||
for (unsigned int i = 0; i < dwt_output.size(); i++){
|
||||
dwtout << dwt_output[i] << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Perform J-Level IDWT
|
||||
vector<double> output;
|
||||
idwt_sym(dwt_output, flag,nm,output,length);
|
||||
|
||||
ofstream sig1("recon.txt");
|
||||
ofstream diff("diff.txt");
|
||||
|
||||
cout <<" Recon signal size" << output.size() << endl;
|
||||
for (unsigned int i = 0; i < output.size(); i++){
|
||||
sig1 << output[i] << endl;
|
||||
diff << output[i] - original[i] << endl;
|
||||
|
||||
}
|
||||
//gnudwtplot(J);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user