Line 139 should be

    double temp = output[(3*k+1)*row*col+ i * col +j - k*col];
instead of

        double temp = output[(3*k+1)*row*col+ i * col +j];
This commit is contained in:
rafat.hsn@gmail.com 2011-08-09 07:33:07 +00:00
parent 74a24e5089
commit 5b6b0fd4b1

View File

@ -1,172 +1,172 @@
//============================================================================ //============================================================================
// Name : swt2Ddemo.cpp // Name : swt2Ddemo.cpp
// Author : Rafat Hussain // Author : Rafat Hussain
// Version : // Version :
// Copyright : // Copyright :
// Description : 2D SWT Demo using OPENCV // Description : 2D SWT Demo using OPENCV
//============================================================================ //============================================================================
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <string> #include <string>
#include <complex> #include <complex>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include "wavelet.h" #include "wavelet.h"
#include "cv.h" #include "cv.h"
#include "highgui.h" #include "highgui.h"
#include "cxcore.h" #include "cxcore.h"
using namespace std; using namespace std;
using namespace cv; using namespace cv;
void* maxval(vector<vector<double> > &arr, double &max){ void* maxval(vector<vector<double> > &arr, double &max){
max = 0; max = 0;
for (unsigned int i =0; i < arr.size(); i++) { for (unsigned int i =0; i < arr.size(); i++) {
for (unsigned int j =0; j < arr[0].size(); j++) { for (unsigned int j =0; j < arr[0].size(); j++) {
if (max <= arr[i][j]){ if (max <= arr[i][j]){
max = arr[i][j]; max = arr[i][j];
} }
} }
} }
return 0; return 0;
} }
int main() { int main() {
IplImage* img = cvLoadImage("cameraman.bmp"); IplImage* img = cvLoadImage("cameraman.bmp");
if (!img){ if (!img){
cout << " Can't read Image. Try Different Format." << endl; cout << " Can't read Image. Try Different Format." << endl;
exit(1); exit(1);
} }
int height, width; int height, width;
height = img->height; height = img->height;
width = img->width; width = img->width;
int nc = img->nChannels; int nc = img->nChannels;
// uchar* ptr2 =(uchar*) img->imageData; // uchar* ptr2 =(uchar*) img->imageData;
int pix_depth = img->depth; int pix_depth = img->depth;
CvSize size; CvSize size;
size.width =width; size.width =width;
size.height=height; size.height=height;
cout << "depth" << pix_depth << "Channels" << nc << endl; cout << "depth" << pix_depth << "Channels" << nc << endl;
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE); cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
cvShowImage("Original Image", img); cvShowImage("Original Image", img);
cvWaitKey(); cvWaitKey();
cvDestroyWindow("Original Image"); cvDestroyWindow("Original Image");
cvSaveImage("orig.bmp",img); cvSaveImage("orig.bmp",img);
int rows =(int) height; int rows =(int) height;
int cols =(int) width; int cols =(int) width;
Mat matimg(img); Mat matimg(img);
vector<vector<double> > vec1(rows, vector<double>(cols)); vector<vector<double> > vec1(rows, vector<double>(cols));
int k =1; int k =1;
for (int i=0; i < rows; i++) { for (int i=0; i < rows; i++) {
for (int j =0; j < cols; j++){ for (int j =0; j < cols; j++){
unsigned char temp; unsigned char temp;
temp = ((uchar*) matimg.data + i * matimg.step)[j * matimg.elemSize() + k ]; temp = ((uchar*) matimg.data + i * matimg.step)[j * matimg.elemSize() + k ];
vec1[i][j] = (double) temp; vec1[i][j] = (double) temp;
} }
} }
string nm = "db2"; string nm = "db2";
// vector<double> l1,h1,l2,h2; // vector<double> l1,h1,l2,h2;
// filtcoef(nm,l1,h1,l2,h2); // filtcoef(nm,l1,h1,l2,h2);
vector<double> output; vector<double> output;
int J =3; int J =3;
swt_2d(vec1,J,nm,output); swt_2d(vec1,J,nm,output);
cout << "OUTPUT size" << output.size() << endl; cout << "OUTPUT size" << output.size() << endl;
cout << "LOOP OK" << endl; cout << "LOOP OK" << endl;
int row,col; int row,col;
dwt_output_dim(vec1, row, col ); dwt_output_dim(vec1, row, col );
// Extract and Display Low Pass Image at the Jth stage // Extract and Display Low Pass Image at the Jth stage
vector<vector<double> > blur(row,vector<double>(col)); vector<vector<double> > blur(row,vector<double>(col));
for (int i=0;i < row; i++){ for (int i=0;i < row; i++){
for (int j=0; j < col;j++){ for (int j=0; j < col;j++){
double temp = output[i*col + j]; double temp = output[i*col + j];
blur[i][j]= temp; blur[i][j]= temp;
} }
} }
double max; double max;
maxval(blur,max); maxval(blur,max);
// Creating Image in OPENCV // Creating Image in OPENCV
IplImage *cvImg; // image used for output IplImage *cvImg; // image used for output
CvSize imgSize; // size of output image CvSize imgSize; // size of output image
imgSize.width = col; imgSize.width = col;
imgSize.height = row; imgSize.height = row;
cvImg = cvCreateImage( imgSize, 8, 1 ); cvImg = cvCreateImage( imgSize, 8, 1 );
for (int i = 0; i < imgSize.height; i++ ) { for (int i = 0; i < imgSize.height; i++ ) {
for (int j = 0; j < imgSize.width; j++ ){ for (int j = 0; j < imgSize.width; j++ ){
if ( blur[i][j] <= 0.0){ if ( blur[i][j] <= 0.0){
blur[i][j] = 0.0; blur[i][j] = 0.0;
} }
((uchar*)(cvImg->imageData + cvImg->widthStep*i))[j] = ((uchar*)(cvImg->imageData + cvImg->widthStep*i))[j] =
(char) ( (blur[i][j] / max) * 255.0); (char) ( (blur[i][j] / max) * 255.0);
} }
} }
cvNamedWindow( "Low Pass Image", 1 ); // creation of a visualisation window cvNamedWindow( "Low Pass Image", 1 ); // creation of a visualisation window
cvShowImage( "Low Pass Image", cvImg ); // image visualisation cvShowImage( "Low Pass Image", cvImg ); // image visualisation
cvWaitKey(); cvWaitKey();
cvDestroyWindow("Low Pass Image"); cvDestroyWindow("Low Pass Image");
// Displaying BandPass Images // Displaying BandPass Images
vector<vector<double> > detail(3*row,vector<double>(J * col)); vector<vector<double> > detail(3*row,vector<double>(J * col));
for (int k=0; k < J; k++) { for (int k=0; k < J; k++) {
for (int i=0; i < 3*row; i++) { for (int i=0; i < 3*row; i++) {
for(int j=0+ k*col; j < (k+1)*col; j++) { for(int j=0+ k*col; j < (k+1)*col; j++) {
double temp = output[(3*k+1)*row*col+ i * col +j]; double temp = output[(3*k+1)*row*col+ i * col +j - k*col];
detail[i][j]= temp; detail[i][j]= temp;
} }
} }
} }
IplImage *dvImg; // image used for output IplImage *dvImg; // image used for output
CvSize imgSz; // size of output image CvSize imgSz; // size of output image
imgSz.width = J*col; imgSz.width = J*col;
imgSz.height = 3*row; imgSz.height = 3*row;
dvImg = cvCreateImage( imgSz, 8, 1 ); dvImg = cvCreateImage( imgSz, 8, 1 );
for (int i = 0; i < imgSz.height; i++ ) { for (int i = 0; i < imgSz.height; i++ ) {
for (int j = 0; j < imgSz.width; j++ ){ for (int j = 0; j < imgSz.width; j++ ){
if ( detail[i][j] <= 0.0){ if ( detail[i][j] <= 0.0){
detail[i][j] = 0.0; detail[i][j] = 0.0;
} }
((uchar*)(dvImg->imageData + dvImg->widthStep*i))[j] = ((uchar*)(dvImg->imageData + dvImg->widthStep*i))[j] =
(char) detail[i][j]; (char) detail[i][j];
} }
} }
cvNamedWindow( "Band Pass Image", 1 ); // creation of a visualisation window cvNamedWindow( "Band Pass Image", 1 ); // creation of a visualisation window
cvShowImage( "Band Pass Image", dvImg ); // image visualisation cvShowImage( "Band Pass Image", dvImg ); // image visualisation
cvWaitKey(); cvWaitKey();
cvDestroyWindow("Band Pass Image"); cvDestroyWindow("Band Pass Image");
cvSaveImage("detail.bmp",dvImg); cvSaveImage("detail.bmp",dvImg);
return 0; return 0;
} }