经过Gabor后的图像,经由这个程序进行DCT的降维处理并保存成arff文件--2012-12-20
来源:互联网 发布:tvb网络电视直播手机版 编辑:程序博客网 时间:2024/05/16 06:03
/*cv200d.libcvaux200d.libcxcore200d.libcxts200d.libhighgui200d.libml200d.lib*/#include <iostream>#include <vector>#include <cv.h>#include <highgui.h>#include <fstream>#include <string>using namespace std;//zigzag变换,只在把矩阵变成一个向量。void ZigZag(double *DCTMatrix,int width,int height,double *zigzagVector){int h = 1,v = 1;int vmin = 1,hmin = 1;int vmax = height, hmax = width; //vertical, horizontalint i;memset(zigzagVector, 0, sizeof(float) * height * width );i=1;while(v<=vmax && h<=hmax){if((h+v)%2==0){if(v==vmin){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);if(h==hmax){v=v+1;}else{h=h+1;}i=i+1;}else if((h==hmax) && (v<vmax)){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);v=v+1;i=i+1;}else if((v>vmin) && (h<hmax)){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);v=v-1;h=h+1;i=i+1;}}else{if((v==vmax) && (h<=hmax)){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);h=h+1;i=i+1;}else if(h==hmin){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);if(v==vmax)h=h+1;elsev=v+1;i=i+1;}else if((v<vmax) && (h>hmin)){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);v=v+1;h=h-1;i=i+1;}}if((v==vmax) && (h==hmax)){zigzagVector[i-1]=*(DCTMatrix + width*(v-1) + h-1);break;}}}vector<double> DCTtransform(IplImage* image){//CvMat* OldMat=cvCreateMat(image->height,image->width,CV_32FC1); //原矩阵cout << image->nChannels <<endl;IplImage *r = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);IplImage *g = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);IplImage *b = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);cvSplit(image,r,g,b,NULL);IplImage* s = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);cvAddWeighted(r,1./3.,g,1./3.,0.0,s);cvAddWeighted(s,2./3.,b,1./3.,0.0,s);CvMat* Mat=cvCreateMat(s->height,s->width,CV_64FC1);//因为特征信息是以列向量存储的,所以要将矩阵进行转置,这个矩阵为转置之后的矩阵CvMat* DCT=cvCreateMat(s->height,s->width,CV_64FC1);//DCT变换后的矩阵,用DCT变换要保证图像的高和宽都要为偶数 cvConvert(s, Mat);//将源图像内容赋值给矩阵(Mat)cvSacle//cvTranspose(image,Mat);//转置操作cvDCT(Mat,DCT, CV_DXT_FORWARD);//对矩阵进行DCT变化,结果在矩阵DCT中//将DCT变换的矩阵结果通过ZigZag算法,取其前100位,实现DCT降维unsigned int width = DCT->cols;unsigned int height =DCT->rows;double * orig = new double[height*width];int i1 = 0;for( int y=0;y<DCT->rows;++y)//取矩阵值{for(int x=0;x<DCT->cols;++x){*(orig + i1) = cvmGet(DCT,y,x);i1++;}}double * zigzagVector = new double[width*height];memset(zigzagVector , 0 ,sizeof(float) * width*height);ZigZag(orig,width,height,zigzagVector); //ZigZag变换vector<double> vec; //ZigZag之后的完整向量vector<double> vec1; //截取前100位的向量for(unsigned int i = 0; i < height; ++i){for(unsigned int j = 0;j < width;++j){if(vec.size()<=200) {vec.push_back(*(zigzagVector + i * height +j));}elsevec.push_back(0);}}for(vector<double>::size_type i = 0; i <200; ++i){vec1.push_back(vec[i]);}cvReleaseMat(&DCT); //释放内存空间cvReleaseMat(&Mat);delete orig;delete zigzagVector;return vec1;}void main(){char num[3];vector<vector<double>> AllVector; vector<double> v; for(int i=1;i<=39;i++)//图片个数{itoa(i,num,10);string FileName=string("C:\\Users\\user\\Desktop\\mouth\\Gabor\\angry\\rename\\angry-")+num;//图片的存储路径和命名习惯FileName = FileName + string(".png");cout << FileName <<endl;IplImage *p =cvLoadImage((char *)FileName.c_str());v = DCTtransform(p);AllVector.push_back(v);}//输出到文件ofstream OutFile("C:\\Users\\user\\Desktop\\mouth\\Gabor\\angry\\rename\\mouth-angry-200.arff");//arff的保存路径if(!OutFile.is_open()){cout << "输出文件,未被打开。。。"<<endl;} OutFile<<"@relation 'FER'"<<endl; char *ch = new char; for(int i=1;i<=200;i++) { itoa(i,ch,10); OutFile<<"@attribute feature"+string(ch)+" real"<<endl; } OutFile << "@attribute 'class' {angry,disgust,fear,happy,sad,surprise}"<<endl; OutFile << "@data" << endl;for(vector<vector<double>>::size_type i=0; i != AllVector.size(); ++i){for(vector<double>::size_type j=0; j != v.size(); ++j){OutFile << AllVector.at(i).at(j) << ",";}OutFile <<"angry" << endl;//arff文件中,每一条特征的标识位}OutFile.close();}
这是第二篇论文的程序。
以上程序,是将昨晚Gabor变换的图片,进行DCT变换,然后再用zigzag变换提取200维特征,然后格式化成arff文件,为weka提供数据。在进行分类识别。。
- 经过Gabor后的图像,经由这个程序进行DCT的降维处理并保存成arff文件--2012-12-20
- 【OpenCV图像处理】七、图像的DCT
- 信号处理中用DCT进行图像处理
- 《python》学习笔记(Day2),读入磁盘文件,经过处理,保存成相应的磁盘文件
- SSE指令指令集进行程序加速、DCT的优化处理
- Gabor滤波进行目标图像纹理特征的提取
- weka关联的ARFF文件
- 构造arff格式的文件
- 对文件txt里的颜色名即颜色编码进行提取并处理保存
- 二维图像的DCT变换
- 对上传的图片进行裁剪处理后保存
- 读取和保存arff文件
- C45的.data和.names文件转化成Arff数据
- 【图像处理】Gabor滤波器
- 【图像处理】Gabor滤波器
- 使用eclipse进行JavaEE开发,查看经过Tomcat编译后的字节码文件路径
- opencv2改变图像像素大小到指定像素并保存改变后的图像
- 用NSUrlSession批量下载文件并保存文件的处理
- BGP Confederation(BGP联盟)
- Conversion to Dalvik format failed with error 1
- Doxygen 的简单注释
- 苹果官方单例模式(考虑了多线程)
- Kmeans算法的实现二
- 经过Gabor后的图像,经由这个程序进行DCT的降维处理并保存成arff文件--2012-12-20
- Linux系统调用过程
- Solaris 10 卸载软件
- linux驱动学习之并发和竞争控制
- 李洋谈Android系统启动过程剖析
- 宏
- http协议(超文本传输协议)(上)
- Linux alsa驱动中的CODEC寄存器配置问题
- Android 源码分析 -- (一) Android启动过程