2 #include "opencv2/imgproc/imgproc_c.h"
3 #include "_lsvm_resizeimg.h"
8 IplImage* resize_opencv(IplImage* img, float scale)
17 tW = (int)(((float)W) * scale + 0.5);
18 tH = (int)(((float)H) * scale + 0.5);
20 imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels);
21 cvResize(img, imgTmp, CV_INTER_AREA);
28 // * Fast image subsampling.
29 // * This is used to construct the feature pyramid.
32 //// struct used for caching interpolation values
38 //// copy src into dst using pre-computed interpolation values
39 //void alphacopy(float *src, float *dst, alphainfo *ofs, int n) {
41 // for(i = 0; i < n; i++){
42 // dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si];
46 //int round(float val){
47 // return (int)(val + 0.5);
49 //void bzero(float * arr, int cnt){
51 // for(i = 0; i < cnt; i++){
55 //// resize along each column
56 //// result is transposed, so we can apply it twice for a complete resize
57 //void resize1dtran(float *src, int sheight, float *dst, int dheight,
58 // int width, int chan) {
60 // float scale = (float)dheight/(float)sheight;
61 // float invscale = (float)sheight/(float)dheight;
63 // // we cache the interpolation values since they can be
64 // // shared among different columns
65 // int len = (int)ceilf(dheight*invscale) + 2*dheight;
76 // ofs = (alphainfo *) malloc (sizeof(alphainfo) * len);
77 // for (dy = 0; dy < dheight; dy++) {
78 // fsy1 = dy * invscale;
79 // fsy2 = fsy1 + invscale;
80 // sy1 = (int)ceilf(fsy1);
81 // sy2 = (int)floorf(fsy2);
83 // if (sy1 - fsy1 > 1e-3) {
85 // assert(sy1 - 1 >= 0);
86 // ofs[k].di = dy*width;
88 // ofs[k++].alpha = (sy1 - fsy1) * scale;
91 // for (sy = sy1; sy < sy2; sy++) {
93 // assert(sy < sheight);
94 // ofs[k].di = dy*width;
96 // ofs[k++].alpha = scale;
99 // if (fsy2 - sy2 > 1e-3) {
101 // assert(sy2 < sheight);
102 // ofs[k].di = dy*width;
104 // ofs[k++].alpha = (fsy2 - sy2) * scale;
108 // // resize each column of each color channel
109 // bzero(dst, chan*width*dheight);
110 // for (c = 0; c < chan; c++) {
111 // for (x = 0; x < width; x++) {
112 // s = src + c*width*sheight + x*sheight;
113 // d = dst + c*width*dheight + x;
114 // alphacopy(s, d, ofs, k);
120 //IplImage * resize_article_dp(IplImage * img, float scale, const int k){
121 // IplImage * imgTmp;
123 // unsigned char *dataSrc;
125 // float *src, *dst, *tmp;
126 // int i, j, kk, channels;
131 // W = (float)img->width;
132 // H = (float)img->height;
133 // channels = img->nChannels;
134 // widthStep = img->widthStep;
136 // tW = (int)(((float)W) * scale + 0.5f);
137 // tH = (int)(((float)H) * scale + 0.5f);
139 // src = (float *)malloc(sizeof(float) * (int)(W * H * 3));
141 // dataSrc = (unsigned char*)(img->imageData);
143 // for (kk = 0; kk < channels; kk++)
145 // for (i = 0; i < W; i++)
147 // for (j = 0; j < H; j++)
149 // src[index++] = (float)dataSrc[j * widthStep + i * channels + kk];
154 // imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
156 // dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
157 // tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
159 // resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
161 // resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
164 // //dataf = (float*)imgTmp->imageData;
165 // for (kk = 0; kk < channels; kk++)
167 // for (i = 0; i < tW; i++)
169 // for (j = 0; j < tH; j++)
171 // dataf = (float*)(imgTmp->imageData + j * imgTmp->widthStep);
172 // dataf[ i * channels + kk] = dst[index++];
183 //IplImage * resize_article_dp1(IplImage * img, float scale, const int k){
184 // IplImage * imgTmp;
187 // float *src, *dst, *tmp;
188 // int i, j, kk, channels;
193 // W = (float)img->width;
194 // H = (float)img->height;
195 // channels = img->nChannels;
196 // widthStep = img->widthStep;
198 // tW = (int)(((float)W) * scale + 0.5f);
199 // tH = (int)(((float)H) * scale + 0.5f);
201 // src = (float *)malloc(sizeof(float) * (int)(W * H) * 3);
204 // for (kk = 0; kk < channels; kk++)
206 // for (i = 0; i < W; i++)
208 // for (j = 0; j < H; j++)
210 // src[index++] = (float)(*( (float *)(img->imageData + j * widthStep) + i * channels + kk));
215 // imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
217 // dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
218 // tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
220 // resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
222 // resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
225 // for (kk = 0; kk < channels; kk++)
227 // for (i = 0; i < tW; i++)
229 // for (j = 0; j < tH; j++)
231 // dataf = (float *)(imgTmp->imageData + j * imgTmp->widthStep);
232 // dataf[ i * channels + kk] = dst[index++];