/*! */ image max(const image& lhs,const image& rhs) { CvSize lhs_sz = lhs.dim(); CvSize rhs_sz = rhs.dim(); if((lhs_sz.height != rhs_sz.height) || (lhs_sz.width != rhs_sz.width)) throw exception(); image res = lhs; cvMax(lhs,rhs,res); return res; }
/*! */ image operator /(const image& lhs,const image& rhs) { CvSize lhs_sz = lhs.dim(); CvSize rhs_sz = rhs.dim(); if((lhs_sz.width != rhs_sz.width) || (lhs_sz.height !=rhs_sz.height)) throw exception(); image result = lhs; cvDiv(lhs,rhs,result); return result; }
/*! */ image operator*(const image& lhs,float val) { CvSize lhs_sz = lhs.dim(); image result(lhs_sz.height,lhs_sz.width); cvScale(lhs,result,val); return result; }
/*! */ image operator-(const image& lhs,float val) { CvSize lhs_sz = lhs.dim(); image result(lhs_sz.height,lhs_sz.width); cvSubS(lhs,cvRealScalar(val),result); return result; }
void imwrite(image& img,const char* file_name) { CvSize sz = img.dim(); IplImage* dst = cvCreateImage(sz,IPL_DEPTH_8U,1); cvConvertScale(imscale(img),dst,255); int ret = cvSaveImage(file_name,dst); if(!ret) throw exception(); cvReleaseImage(&dst); }
/*! */ image abs(const image& img) { CvSize sz = img.dim(); image res(sz.height,sz.width); for(int i=0;i<sz.height;i++) for(int j=0;j<sz.width;j++) res[i][j] = fabs(img[i][j]); return res; }
/*! */ image sqrt(const image& img) { CvSize sz = img.dim(); image res = img; for(int i=0;i<sz.height;i++) for(int j=0;j<sz.width;j++) res[i][j]=sqrt(img[i][j]+1e-14); return res; }
/*! */ void imdisplay(image& img,const char* title) { CvSize sz = img.dim(); IplImage* dst = cvCreateImage(sz,IPL_DEPTH_8U,1); cvConvertScale(imscale(img),dst,255); cvNamedWindow(title,CV_WINDOW_AUTOSIZE); cvShowImage(title,dst); cvWaitKey(1); cvReleaseImage(&dst); }
void img2buf(const image& img,double* buf,int col_aligned=1) { CvSize sz = img.dim(); for(int i=0;i<sz.height;i++) { for(int j=0;j<sz.width;j++) if(col_aligned) buf[j*sz.height+i] = img[i][j]; else buf[i*sz.width+j] = img[i][j]; } }
/*! */ image imscale(image& img) { CvPoint min_pos; CvPoint max_pos; float min_val = 1e10; float max_val = -1e10; image result = img; /*get max and min*/ CvSize sz = img.dim(); for(int i=0;i<sz.height;i++) for(int j=0;j<sz.width;j++) { float pxval=img[i][j]; if(pxval > max_val) max_val = pxval; if(pxval < min_val) min_val = pxval; } float scale = 1.0/(max_val-min_val+1e-10); cvConvertScale(img,result,scale,-min_val*scale); return result; }