//returns a transposed version of resized image //matlab leftover! int *mexResizeTranspose(float *im, const int rows, const int cols, const int channels, const int rRows, const int rCols) { const float scaleFactor = (float)rRows/(float)rows; //assert((int)cols*scaleFactor == rCols); if(scaleFactor > 1 || scaleFactor <=0) { fprintf(stderr,"mexResize:: invalid scaling factor\n"); return NULL; } // if(channels != 3) { // fprintf(stderr,"mexResize:: image should be 3 channeled\n"); // return NULL; // } printf("rRows %d; rCols %d\n",rRows,rCols); float *dst = (float *) esvmMalloc(rRows*rCols*channels*sizeof(float)); float *tmp = (float *) esvmMalloc(rRows*cols*channels*sizeof(int)); resize1dtran(im,rows,tmp,rRows,cols,channels); resize1dtran(tmp,cols,dst,rCols,rRows,channels); free(tmp); int *dstInt = (int *) esvmMalloc(rRows*rCols*channels*sizeof(int)); for(int i=0;i<rRows*rCols*channels;i++) { dstInt[i] = (int)dst[i]; } free(dst); return dstInt; }
IplImage* FeatPyramid::resize (const IplImage *mxsrc, const float mxscale) { float *src = getImgData <float> (mxsrc); int sdims[3]; getDimensions(mxsrc, sdims); float scale = mxscale; if (scale > 1.0) cout << "Invalid scaling factor" << endl; int ddims[3]; ddims[0] = (int)round(sdims[0]*scale); ddims[1] = (int)round(sdims[1]*scale); ddims[2] = sdims[2]; assert (ddims[0] > 0); assert (ddims[1] > 0); CvSize size = cvSize(ddims[1], ddims[0]); IplImage *mxdst = cvCreateImage (size, IPL_DEPTH_32F, 3); assert (mxdst != NULL); assert (ddims[2] > 0); float *dst = new float [ddims[0] * ddims[1] * ddims[2]]; assert (dst != NULL); for (int l = 0; l < ddims[0] * ddims[1] * ddims[2]; l++) dst[l] = 0; assert (sdims[1] > 0); assert (sdims[2] > 0); float *tmp = new float [ddims[0] * sdims[1] * sdims[2]]; assert (tmp != NULL); for (int l = 0; l < ddims[0] * sdims[1] * sdims[2]; l++) tmp[l] = 0; resize1dtran(src, sdims[0], tmp, ddims[0], sdims[1], sdims[2]); resize1dtran(tmp, sdims[1], dst, ddims[1], ddims[0], sdims[2]); setImgData (mxdst, dst); delete[] src; delete[] dst; delete[] tmp; return mxdst; }
//accepts a transpose image. returns a non-transposed, resized image. int *mexResize(float *im, const int rows, const int cols, const int channels, const int rRows, const int rCols) { const float scaleFactor = (float)rRows/(float)rows; //assert((int)cols*scaleFactor == rCols); if(scaleFactor > 1 || scaleFactor <=0) { fprintf(stderr,"mexResize:: invalid scaling factor\n"); return NULL; } if(channels!=3) { fprintf(stderr,"mexResize:: input image is not 3 channeled. This is odd, but I will process it anyway.\n"); } float *dst = (float *) esvmMalloc(rRows*rCols*channels*sizeof(float)); float *tmp = (float *) esvmMalloc(rRows*cols*channels*sizeof(int)); resize1dtran(im,rows,tmp,rRows,cols,channels); resize1dtran(tmp,cols,dst,rCols,rRows,channels); free(tmp); int *dstInt = (int *) esvmMalloc(rRows*rCols*channels*sizeof(int)); const int dim1 = rRows*rCols; for(int i=0;i<rRows;i++) { for(int j=0;j<rCols;j++) { dstInt[0*dim1+i*rCols+j] = (int)dst[0*dim1+j*rRows+i]; dstInt[1*dim1+i*rCols+j] = (int)dst[1*dim1+j*rRows+i]; dstInt[2*dim1+i*rCols+j] = (int)dst[2*dim1+j*rRows+i]; } } free(dst); return dstInt; }