8 #define STB_IMAGE_IMPLEMENTATION 10 #define STB_IMAGE_WRITE_IMPLEMENTATION 15 float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} };
19 float ratio = ((float)x/max)*5;
33 for(j = 0; j < n; ++j){
34 int offset = j*123457 % n;
38 for(i = 0; i < im.
w*im.
h; ++i){
39 im.
data[i + 0*im.
w*im.
h] += mask.
data[j*im.
h*im.
w + i]*red;
40 im.
data[i + 1*im.
w*im.
h] += mask.
data[j*im.
h*im.
w + i]*green;
41 im.
data[i + 2*im.
w*im.
h] += mask.
data[j*im.
h*im.
w + i]*blue;
47 static float get_pixel(
image m,
int x,
int y,
int c)
49 assert(x < m.
w && y < m.
h && c < m.
c);
50 return m.
data[c*m.
h*m.
w + y*m.
w + x];
52 static float get_pixel_extend(
image m,
int x,
int y,
int c)
54 if(x < 0 || x >= m.
w || y < 0 || y >= m.
h)
return 0;
61 if(c < 0 || c >= m.
c)
return 0;
62 return get_pixel(m, x, y, c);
64 static void set_pixel(
image m,
int x,
int y,
int c,
float val)
66 if (x < 0 || y < 0 || c < 0 || x >= m.
w || y >= m.
h || c >= m.
c)
return;
67 assert(x < m.
w && y < m.
h && c < m.
c);
68 m.
data[c*m.
h*m.
w + y*m.
w + x] = val;
70 static void add_pixel(
image m,
int x,
int y,
int c,
float val)
72 assert(x < m.
w && y < m.
h && c < m.
c);
73 m.
data[c*m.
h*m.
w + y*m.
w + x] += val;
76 static float bilinear_interpolate(
image im,
float x,
float y,
int c)
78 int ix = (int) floorf(x);
79 int iy = (int) floorf(y);
84 float val = (1-dy) * (1-dx) * get_pixel_extend(im, ix, iy, c) +
85 dy * (1-dx) * get_pixel_extend(im, ix, iy+1, c) +
86 (1-dy) * dx * get_pixel_extend(im, ix+1, iy, c) +
87 dy * dx * get_pixel_extend(im, ix+1, iy+1, c);
95 for(k = 0; k < source.
c; ++k){
96 for(y = 0; y < source.
h; ++y){
97 for(x = 0; x < source.
w; ++x){
98 float val = get_pixel(source, x, y, k);
99 float val2 = get_pixel_extend(dest, dx+x, dy+y, k);
100 set_pixel(dest, dx+x, dy+y, k, val * val2);
110 for(k = 0; k < b.
c; ++k){
111 for(y = 0; y < b.
h; ++y){
112 for(x = 0; x < b.
w; ++x){
113 float val = get_pixel_extend(a, x - border, y - border, k);
114 if(x - border < 0 || x - border >= a.
w || y - border < 0 || y - border >= a.
h) val = 1;
115 set_pixel(b, x, y, k, val);
135 if(size > 7) size = 7;
138 image l = characters[size][(int)*
string];
153 if (r - h >= 0) r = r - h;
156 for(j = 0; j < h && j + r < a.
h; ++j){
157 for(i = 0; i < w && i + c < a.
w; ++i){
158 for(k = 0; k < label.
c; ++k){
159 float val = get_pixel(label, i, j, k);
160 set_pixel(a, i+c, j+r, k, rgb[k] * val);
166 void draw_box(
image a,
int x1,
int y1,
int x2,
int y2,
float r,
float g,
float b)
171 if(x1 >= a.
w) x1 = a.
w-1;
173 if(x2 >= a.
w) x2 = a.
w-1;
176 if(y1 >= a.
h) y1 = a.
h-1;
178 if(y2 >= a.
h) y2 = a.
h-1;
180 for(i = x1; i <= x2; ++i){
184 a.
data[i + y1*a.
w + 1*a.
w*a.
h] = g;
185 a.
data[i + y2*a.
w + 1*a.
w*a.
h] = g;
187 a.
data[i + y1*a.
w + 2*a.
w*a.
h] = b;
188 a.
data[i + y2*a.
w + 2*a.
w*a.
h] = b;
190 for(i = y1; i <= y2; ++i){
194 a.
data[x1 + i*a.
w + 1*a.
w*a.
h] = g;
195 a.
data[x2 + i*a.
w + 1*a.
w*a.
h] = g;
197 a.
data[x1 + i*a.
w + 2*a.
w*a.
h] = b;
198 a.
data[x2 + i*a.
w + 2*a.
w*a.
h] = b;
205 for(i = 0; i < w; ++i){
206 draw_box(a, x1+i, y1+i, x2-i, y2-i, r, g, b);
212 int left = (bbox.
x-bbox.
w/2)*a.
w;
213 int right = (bbox.
x+bbox.
w/2)*a.
w;
214 int top = (bbox.
y-bbox.
h/2)*a.
h;
215 int bot = (bbox.
y+bbox.
h/2)*a.
h;
218 for(i = 0; i < w; ++i){
219 draw_box(a, left+i, top+i, right-i, bot-i, r, g, b);
227 image **alphabets = calloc(nsize,
sizeof(
image));
228 for(j = 0; j < nsize; ++j){
229 alphabets[j] = calloc(128,
sizeof(
image));
230 for(i = 32; i < 127; ++i){
232 sprintf(buff,
"data/labels/%d_%d.png", i, j);
243 for(i = 0; i < num; ++i){
244 char labelstr[4096] = {0};
247 if (dets[i].prob[j] > thresh){
249 strcat(labelstr, names[j]);
252 strcat(labelstr,
", ");
253 strcat(labelstr, names[j]);
255 printf(
"%s: %.0f%%\n", names[j], dets[i].prob[j]*100);
259 int width = im.
h * .006;
269 int offset =
class*123457 %
classes;
271 float green =
get_color(1,offset,classes);
272 float blue =
get_color(0,offset,classes);
283 int left = (b.
x-b.
w/2.)*im.
w;
284 int right = (b.
x+b.
w/2.)*im.
w;
285 int top = (b.
y-b.
h/2.)*im.
h;
286 int bot = (b.
y+b.
h/2.)*im.
h;
288 if(left < 0) left = 0;
289 if(right > im.
w-1) right = im.
w-1;
291 if(bot > im.
h-1) bot = im.
h-1;
293 draw_box_width(im, left, top, right, bot, width, red, green, blue);
296 draw_label(im, top + width, left, label, rgb);
314 assert(im.
w == im.
h);
317 for(c = 0; c < im.
c; ++c){
318 for(n = 0; n < im.
w-1; ++n){
319 for(m = n + 1; m < im.
w; ++m){
320 float swap = im.
data[m + im.
w*(n + im.
h*c)];
321 im.
data[m + im.
w*(n + im.
h*c)] = im.
data[n + im.
w*(m + im.
h*c)];
322 im.
data[n + im.
w*(m + im.
h*c)] = swap;
330 assert(im.
w == im.
h);
331 times = (times + 400) % 4;
334 for(i = 0; i < times; ++i){
335 for(c = 0; c < im.
c; ++c){
336 for(x = 0; x < n/2; ++x){
337 for(y = 0; y < (n-1)/2 + 1; ++y){
338 float temp = im.
data[y + im.
w*(x + im.
h*c)];
339 im.
data[y + im.
w*(x + im.
h*c)] = im.
data[n-1-x + im.
w*(y + im.
h*c)];
340 im.
data[n-1-x + im.
w*(y + im.
h*c)] = im.
data[n-1-y + im.
w*(n-1-x + im.
h*c)];
341 im.
data[n-1-y + im.
w*(n-1-x + im.
h*c)] = im.
data[x + im.
w*(n-1-y + im.
h*c)];
342 im.
data[x + im.
w*(n-1-y + im.
h*c)] = temp;
352 for(k = 0; k < a.
c; ++k){
353 for(i = 0; i < a.
h; ++i){
354 for(j = 0; j < a.
w/2; ++j){
355 int index = j + a.
w*(i + a.
h*(k));
356 int flip = (a.
w - j - 1) + a.
w*(i + a.
h*(k));
357 float swap = a.
data[flip];
359 a.
data[index] = swap;
369 for(i = 0; i < a.
c; ++i){
370 for(j = 0; j < a.
h*a.
w; ++j){
374 for(j = 0; j < a.
h*a.
w; ++j){
383 float max_dist = sqrt((-source.
w/2. + .5)*(-source.
w/2. + .5));
384 for(k = 0; k < source.
c; ++k){
385 for(y = 0; y < source.
h; ++y){
386 for(x = 0; x < source.
w; ++x){
387 float dist = sqrt((x - source.
w/2. + .5)*(x - source.
w/2. + .5) + (y - source.
h/2. + .5)*(y - source.
h/2. + .5));
388 float alpha = (1 - dist/max_dist);
389 if(alpha < 0) alpha = 0;
390 float v1 = get_pixel(source, x,y,k);
391 float v2 = get_pixel(dest, dx+x,dy+y,k);
392 float val = alpha*v1 + (1-alpha)*v2;
393 set_pixel(dest, dx+x, dy+y, k, val);
402 for(k = 0; k < im.
c; ++k){
403 for(j = 0; j < im.
h; ++j){
404 for(i = 0; i < im.
w; ++i){
405 im.
data[i + im.
w*(j + im.
h*k)] = im.
data[i/s*s + im.
w*(j/s*s + im.
h*k)];
418 for(k = 0; k < im.
c; ++k){
419 for(j = dy; j < dy + h && j < im.
h; ++j){
420 for(i = dx; i < dx + w && i < im.
w; ++i){
421 im.
data[i + im.
w*(j + im.
h*k)] = im.
data[i/s*s + im.
w*(j/s*s + im.
h*k)];
431 for(k = 0; k < source.
c; ++k){
432 for(y = 0; y < source.
h; ++y){
433 for(x = 0; x < source.
w; ++x){
434 float val = get_pixel(source, x,y,k);
435 set_pixel(dest, dx+x, dy+y, k, val);
444 h = (h+border)*source.
c - border;
447 for(i = 0; i < source.
c; ++i){
449 int h_offset = i*(source.
h+border);
459 for(i = 0; i < im.
w*im.
h*im.
c; ++i){
471 for(i = 0; i < p.
h*p.
w*p.
c; ++i){
476 if(max - min < .000000001){
480 for(i = 0; i < p.
c*p.
w*p.
h; ++i){
481 p.
data[i] = (p.
data[i] - min)/(max-min);
487 float *min = calloc(p.
c,
sizeof(
float));
488 float *max = calloc(p.
c,
sizeof(
float));
490 for(i = 0; i < p.
c; ++i) min[i] = max[i] = p.
data[i*p.
h*p.
w];
492 for(j = 0; j < p.
c; ++j){
493 for(i = 0; i < p.
h*p.
w; ++i){
494 float v = p.
data[i+j*p.
h*p.
w];
495 if(v < min[j]) min[j] = v;
496 if(v > max[j]) max[j] = v;
499 for(i = 0; i < p.
c; ++i){
500 if(max[i] - min[i] < .000000001){
505 for(j = 0; j < p.
c; ++j){
506 for(i = 0; i < p.
w*p.
h; ++i){
507 p.
data[i+j*p.
h*p.
w] = (p.
data[i+j*p.
h*p.
w] - min[j])/(max[j]-min[j]);
516 memcpy(dest.
data, src.
data, src.
h*src.
w*src.
c*
sizeof(
float));
522 copy.
data = calloc(p.
h*p.
w*p.
c,
sizeof(
float));
523 memcpy(copy.
data, p.
data, p.
h*p.
w*p.
c*
sizeof(
float));
530 for(i = 0; i < im.
w*im.
h; ++i){
531 float swap = im.
data[i];
533 im.
data[i+im.
w*im.
h*2] = swap;
538 void show_image_cv(
image p,
const char *name, IplImage *disp)
546 sprintf(buff,
"%s", name);
548 int step = disp->widthStep;
549 cvNamedWindow(buff, CV_WINDOW_NORMAL);
552 for(y = 0; y < p.
h; ++y){
553 for(x = 0; x < p.
w; ++x){
554 for(k= 0; k < p.
c; ++k){
555 disp->imageData[y*step + x*p.
c + k] = (
unsigned char)(get_pixel(p,x,y,k)*255);
566 IplImage *buffer = disp;
567 disp = cvCreateImage(cvSize(w, h), buffer->depth, buffer->nChannels);
568 cvResize(buffer, disp, CV_INTER_LINEAR);
569 cvReleaseImage(&buffer);
571 cvShowImage(buff, disp);
578 IplImage *disp = cvCreateImage(cvSize(p.
w,p.
h), IPL_DEPTH_8U, p.
c);
581 show_image_cv(copy, name, disp);
583 cvReleaseImage(&disp);
584 int c = cvWaitKey(ms);
585 if (c != -1) c = c%256;
588 fprintf(stderr,
"Not compiled with OpenCV, saving to %s.png instead\n", name);
596 void ipl_into_image(IplImage* src,
image im)
598 unsigned char *
data = (
unsigned char *)src->imageData;
601 int c = src->nChannels;
602 int step = src->widthStep;
605 for(i = 0; i < h; ++i){
606 for(k= 0; k < c; ++k){
607 for(j = 0; j < w; ++j){
608 im.
data[k*w*h + i*w + j] = data[i*step + j*c + k]/255.;
614 image ipl_to_image(IplImage* src)
618 int c = src->nChannels;
620 ipl_into_image(src, out);
624 image load_image_cv(
char *filename,
int channels)
628 if (channels == 0) flag = -1;
629 else if (channels == 1) flag = 0;
630 else if (channels == 3) flag = 1;
632 fprintf(stderr,
"OpenCV can't force load with %d channels\n", channels);
635 if( (src = cvLoadImage(filename, flag)) == 0 )
637 fprintf(stderr,
"Cannot load image \"%s\"\n", filename);
639 sprintf(buff,
"echo %s >> bad.list", filename);
644 image out = ipl_to_image(src);
645 cvReleaseImage(&src);
650 void flush_stream_buffer(CvCapture *cap,
int n)
653 for(i = 0; i < n; ++i) {
658 image get_image_from_stream(CvCapture *cap)
660 IplImage* src = cvQueryFrame(cap);
662 image im = ipl_to_image(src);
667 int fill_image_from_stream(CvCapture *cap,
image im)
669 IplImage* src = cvQueryFrame(cap);
671 ipl_into_image(src, im);
676 void save_image_jpg(
image p,
const char *name)
683 sprintf(buff,
"%s.jpg", name);
685 IplImage *disp = cvCreateImage(cvSize(p.
w,p.
h), IPL_DEPTH_8U, p.
c);
686 int step = disp->widthStep;
687 for(y = 0; y < p.
h; ++y){
688 for(x = 0; x < p.
w; ++x){
689 for(k= 0; k < p.
c; ++k){
690 disp->imageData[y*step + x*p.
c + k] = (
unsigned char)(get_pixel(copy,x,y,k)*255);
694 cvSaveImage(buff, disp,0);
695 cvReleaseImage(&disp);
704 sprintf(buff,
"%s.png", name);
705 unsigned char *
data = calloc(im.
w*im.
h*im.
c,
sizeof(
char));
707 for(k = 0; k < im.
c; ++k){
708 for(i = 0; i < im.
w*im.
h; ++i){
709 data[i*im.
c+k] = (
unsigned char) (255*im.
data[i + k*im.
w*im.
h]);
714 if(!success) fprintf(stderr,
"Failed to write image %s\n", buff);
720 save_image_jpg(im, name);
731 for(i = 0; i < p.
c; ++i){
732 sprintf(buff,
"%s - Layer %d", name, i);
759 out.
data = calloc(h*w*c,
sizeof(
float));
766 out.
data = calloc(h*w*c,
sizeof(
float));
768 for(i = 0; i < w*h*c; ++i){
784 for(c = 0; c < im.
c; ++c){
785 for(y = 0; y < h; ++y){
786 for(x = 0; x < w; ++x){
787 float rx = ((float)x / w) * im.
w;
788 float ry = ((float)y / h) * im.
h;
789 float val = bilinear_interpolate(im, rx, ry, c);
790 set_pixel(canvas, x + dx, y + dy, c, val);
798 int m = (im.
w < im.
h) ? im.
w : im.
h;
811 for(c = 0; c < im.
c; ++c){
812 for(y = 0; y < h; ++y){
813 for(x = 0; x < w; ++x){
814 float rx = cos(rad)*((x - w/2.)/s*aspect + dx/s*aspect) - sin(rad)*((y - h/2.)/s + dy/s) + cx;
815 float ry = sin(rad)*((x - w/2.)/s*aspect + dx/s*aspect) + cos(rad)*((y - h/2.)/s + dy/s) + cy;
816 float val = bilinear_interpolate(im, rx, ry, c);
817 set_pixel(rot, x, y, c, val);
830 for(c = 0; c < im.
c; ++c){
831 for(y = 0; y < im.
h; ++y){
832 for(x = 0; x < im.
w; ++x){
833 float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx;
834 float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy;
835 float val = bilinear_interpolate(im, rx, ry, c);
836 set_pixel(rot, x, y, c, val);
846 for(i = 0; i < m.
h*m.
w*m.
c; ++i) m.
data[i] = s;
852 for(i = 0; i < m.
h*m.
w*m.
c; ++i) m.
data[i] += s;
858 for(i = 0; i < m.
h*m.
w*m.
c; ++i) m.
data[i] *= s;
865 for(k = 0; k < im.
c; ++k){
866 for(j = 0; j < h; ++j){
867 for(i = 0; i < w; ++i){
873 val = get_pixel(im, c, r, k);
874 set_pixel(cropped, i, j, k, val);
883 if(min == max)
return min;
884 int mid = floor((min + max) / 2.);
899 float best_distance = FLT_MAX;
900 for(i = min; i <= max; i += 2){
903 if(d < best_distance){
907 printf(
"%d %f\n", i, d);
915 if(!out) out =
"out";
930 printf(
"swapped, %d\n", shift);
933 printf(
"%d\n", shift);
938 for(i = 0; i < c.
w*c.
h; ++i){
942 save_image_jpg(c, out);
952 if (((
float)w/im.
w) < ((
float)h/im.
h)) {
954 new_h = (im.
h * w)/im.
w;
957 new_w = (im.
w * h)/im.
h;
960 embed_image(resized, boxed, (w-new_w)/2, (h-new_h)/2);
968 if (((
float)w/im.
w) < ((
float)h/im.
h)) {
970 new_h = (im.
h * w)/im.
w;
973 new_w = (im.
w * h)/im.
h;
980 embed_image(resized, boxed, (w-new_w)/2, (h-new_h)/2);
996 if(w == im.
w && h == im.
h)
return im;
1012 if(w == im.
w && h == im.
h)
return im;
1030 int min = (im.
h < im.
w*aspect) ? im.
h : im.
w*aspect;
1031 float scale = (
float)r / min;
1035 float dx = (im.
w*scale/aspect - w) / 2.;
1036 float dy = (im.
h*scale - w) / 2.;
1061 return (a > b) ? ( (a > c) ? a : c) : ( (b > c) ? b : c) ;
1066 return (a < b) ? ( (a < c) ? a : c) : ( (b < c) ? b : c) ;
1075 for(j = 0; j < im.
h; ++j){
1076 for(i = 0; i < im.
w; ++i){
1077 y = get_pixel(im, i , j, 0);
1078 u = get_pixel(im, i , j, 1);
1079 v = get_pixel(im, i , j, 2);
1082 g = y + -.39465*u + -.58060*v;
1085 set_pixel(im, i, j, 0, r);
1086 set_pixel(im, i, j, 1, g);
1087 set_pixel(im, i, j, 2, b);
1098 for(j = 0; j < im.
h; ++j){
1099 for(i = 0; i < im.
w; ++i){
1100 r = get_pixel(im, i , j, 0);
1101 g = get_pixel(im, i , j, 1);
1102 b = get_pixel(im, i , j, 2);
1104 y = .299*r + .587*g + .114*b;
1105 u = -.14713*r + -.28886*g + .436*b;
1106 v = .615*r + -.51499*g + -.10001*b;
1108 set_pixel(im, i, j, 0, y);
1109 set_pixel(im, i, j, 1, u);
1110 set_pixel(im, i, j, 2, v);
1122 for(j = 0; j < im.
h; ++j){
1123 for(i = 0; i < im.
w; ++i){
1124 r = get_pixel(im, i , j, 0);
1125 g = get_pixel(im, i , j, 1);
1126 b = get_pixel(im, i , j, 2);
1129 float delta = max - min;
1137 h = (g - b) / delta;
1138 }
else if (g == max) {
1139 h = 2 + (b -
r) / delta;
1141 h = 4 + (r - g) / delta;
1146 set_pixel(im, i, j, 0, h);
1147 set_pixel(im, i, j, 1, s);
1148 set_pixel(im, i, j, 2, v);
1160 for(j = 0; j < im.
h; ++j){
1161 for(i = 0; i < im.
w; ++i){
1162 h = 6 * get_pixel(im, i , j, 0);
1163 s = get_pixel(im, i , j, 1);
1164 v = get_pixel(im, i , j, 2);
1168 int index = floor(h);
1174 r = v; g =
t; b = p;
1175 }
else if(index == 1){
1176 r = q; g = v; b = p;
1177 }
else if(index == 2){
1178 r = p; g = v; b =
t;
1179 }
else if(index == 3){
1180 r = p; g = q; b = v;
1181 }
else if(index == 4){
1182 r =
t; g = p; b = v;
1184 r = v; g = p; b = q;
1187 set_pixel(im, i, j, 0, r);
1188 set_pixel(im, i, j, 1, g);
1189 set_pixel(im, i, j, 2, b);
1198 float scale[] = {0.299, 0.587, 0.114};
1199 for(j = 0; j < im.
h; ++j){
1200 for(i = 0; i < im.
w; ++i){
1202 for(k = 0; k < 3; ++k){
1203 val += scale[k]*get_pixel(im, i, j, k);
1205 im.
data[0*im.
h*im.
w + im.
w*j + i] = val;
1206 im.
data[1*im.
h*im.
w + im.
w*j + i] = val;
1207 im.
data[2*im.
h*im.
w + im.
w*j + i] = val;
1217 float scale[] = {0.299, 0.587, 0.114};
1218 for(k = 0; k < im.
c; ++k){
1219 for(j = 0; j < im.
h; ++j){
1220 for(i = 0; i < im.
w; ++i){
1221 gray.
data[i+im.
w*j] += scale[k]*get_pixel(im, i, j, k);
1232 for(i = 0; i < im.
w*im.
h*im.
c; ++i){
1233 t.
data[i] = im.
data[i]>thresh ? 1 : 0;
1240 assert(fore.
w == back.
w && fore.
h == back.
h && fore.
c == back.
c);
1243 for(k = 0; k < fore.
c; ++k){
1244 for(j = 0; j < fore.
h; ++j){
1245 for(i = 0; i < fore.
w; ++i){
1246 float val = alpha * get_pixel(fore, i, j, k) +
1247 (1 - alpha)* get_pixel(back, i, j, k);
1248 set_pixel(blend, i, j, k, val);
1258 for(j = 0; j < im.
h; ++j){
1259 for(i = 0; i < im.
w; ++i){
1260 float pix = get_pixel(im, i, j, c);
1262 set_pixel(im, i, j, c, pix);
1270 for(j = 0; j < im.
h; ++j){
1271 for(i = 0; i < im.
w; ++i){
1272 float pix = get_pixel(im, i, j, c);
1274 set_pixel(im, i, j, c, pix);
1283 for(i = 0; i < im.
w * im.
h * im.
c; ++i){
1302 for(i = 0; i < im.
w*im.
h; ++i){
1304 if (im.
data[i] > 1) im.
data[i] -= 1;
1305 if (im.
data[i] < 0) im.
data[i] += 1;
1325 for(i = 0; i < im.
w*im.
h; ++i){
1327 if (im.
data[i] > 1) im.
data[i] -= 1;
1328 if (im.
data[i] < 0) im.
data[i] += 1;
1356 float w_scale = (float)(im.
w - 1) / (w - 1);
1357 float h_scale = (float)(im.
h - 1) / (h - 1);
1358 for(k = 0; k < im.
c; ++k){
1359 for(r = 0; r < im.
h; ++
r){
1360 for(c = 0; c < w; ++c){
1362 if(c == w-1 || im.
w == 1){
1363 val = get_pixel(im, im.
w-1, r, k);
1365 float sx = c*w_scale;
1368 val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k);
1370 set_pixel(part, c, r, k, val);
1374 for(k = 0; k < im.
c; ++k){
1375 for(r = 0; r < h; ++
r){
1376 float sy = r*h_scale;
1379 for(c = 0; c < w; ++c){
1380 float val = (1-dy) * get_pixel(part, c, iy, k);
1381 set_pixel(resized, c, r, k, val);
1383 if(r == h-1 || im.
h == 1)
continue;
1384 for(c = 0; c < w; ++c){
1385 float val = dy * get_pixel(part, c, iy+1, k);
1386 add_pixel(resized, c, r, k, val);
1400 printf(
"L2 Norm: %f\n", mag);
1426 float exposure = 1.15;
1427 float saturation = 1.15;
1438 printf(
"%f %f %f\n", dhue, dsat, dexp);
1449 unsigned char *
data =
stbi_load(filename, &w, &h, &c, channels);
1451 fprintf(stderr,
"Cannot load image \"%s\"\nSTB Reason: %s\n", filename,
stbi_failure_reason());
1454 if(channels) c = channels;
1457 for(k = 0; k < c; ++k){
1458 for(j = 0; j < h; ++j){
1459 for(i = 0; i < w; ++i){
1460 int dst_index = i + w*j + w*h*k;
1461 int src_index = k + c*i + c*w*j;
1462 im.
data[dst_index] = (float)data[src_index]/255.;
1473 image out = load_image_cv(filename, c);
1478 if((h && w) && (h != out.
h || w != out.
w)){
1495 for(i = 0; i < m.
h*m.
w; ++i){
1503 for(i =0 ; i < m.
c; ++i){
1504 for(j =0 ; j < m.
h; ++j){
1505 for(k = 0; k < m.
w; ++k){
1506 printf(
"%.2lf, ", m.
data[i*m.
h*m.
w + j*m.
w + k]);
1523 h = (ims[0].
h + border) * n - border;
1525 if(c != 3 || !color){
1526 w = (w+border)*c - border;
1532 for(i = 0; i < n; ++i){
1533 int h_offset = i*(ims[0].
h+border);
1536 if(c == 3 && color){
1540 for(j = 0; j < copy.c; ++j){
1541 int w_offset = j*(ims[0].
w+border);
1557 int size = ims[0].
h;
1559 w = (ims[0].
w + border) * n - border;
1561 if(c != 3 || !color){
1562 h = (h+border)*c - border;
1568 for(i = 0; i < n; ++i){
1569 int w_offset = i*(size+border);
1572 if(c == 3 && color){
1576 for(j = 0; j < copy.c; ++j){
1577 int h_offset = j*(size+border);
void saturate_exposure_image(image im, float sat, float exposure)
void random_distort_image(image im, float hue, float saturation, float exposure)
void saturate_image(image im, float sat)
void rgb_to_yuv(image im)
void transpose_image(image im)
image resize_min(image im, int min)
image letterbox_image(image im, int w, int h)
void composite_image(image source, image dest, int dx, int dy)
float rand_scale(float s)
void constrain_image(image im)
STBIDEF const char * stbi_failure_reason(void)
image blend_image(image fore, image back, float alpha)
void normalize_image(image p)
image collapse_images_vert(image *ims, int n)
void print_image(image m)
float get_color(int c, int x, int max)
image get_image_layer(image m, int l)
image load_image(char *filename, int w, int h, int c)
image make_random_image(int w, int h, int c)
void draw_label(image a, int r, int c, image label, const float *rgb)
void rotate_image_cw(image im, int times)
void yuv_to_rgb(image im)
image mask_to_rgb(image mask)
void copy_image_into(image src, image dest)
void save_image_png(image im, const char *name)
image border_image(image a, int border)
image center_crop_image(image im, int w, int h)
image rotate_image(image im, float rad)
image tile_images(image a, image b, int dx)
image binarize_image(image im)
void show_images(image *ims, int n, char *window)
void ghost_image(image source, image dest, int dx, int dy)
void draw_bbox(image a, box bbox, int w, float r, float g, float b)
image random_crop_image(image im, int w, int h)
int constrain_int(int a, int min, int max)
void distort_image(image im, float hue, float sat, float val)
void fill_cpu(int N, float ALPHA, float *X, int INCX)
image grayscale_image(image im)
void test_resize(char *filename)
void normalize_image2(image p)
void rgb_to_hsv(image im)
image copy_image(image p)
image make_image(int w, int h, int c)
image rotate_crop_image(image im, float rad, float s, int w, int h, float dx, float dy, float aspect)
int best_3d_shift_r(image a, image b, int min, int max)
image get_label(image **characters, char *string, int size)
void fill_image(image m, float s)
float three_way_max(float a, float b, float c)
image image_distance(image a, image b)
void censor_image(image im, int dx, int dy, int w, int h)
void exposure_image(image im, float sat)
void hsv_to_rgb(image im)
image threshold_image(image im, float thresh)
void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b)
void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b)
image collapse_images_horz(image *ims, int n)
float dist_array(float *a, float *b, int n, int sub)
int show_image(image p, const char *name, int ms)
void translate_image(image m, float s)
void hue_image(image im, float hue)
STBIDEF stbi_uc * stbi_load(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels)
image float_to_image(int w, int h, int c, float *data)
void composite_3d(char *f1, char *f2, char *out, int delta)
image load_image_color(char *filename, int w, int h)
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
image resize_max(image im, int max)
void save_image(image im, const char *name)
int best_3d_shift(image a, image b, int min, int max)
image load_image_stb(char *filename, int channels)
void letterbox_image_into(image im, int w, int h, image boxed)
float three_way_min(float a, float b, float c)
void scale_image_channel(image im, int c, float v)
image resize_image(image im, int w, int h)
void translate_image_channel(image im, int c, float v)
void embed_image(image source, image dest, int dx, int dy)
void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
image collapse_image_layers(image source, int border)
void grayscale_image_3c(image im)
void show_image_layers(image p, char *name)
image random_augment_image(image im, float angle, float aspect, int low, int high, int w, int h)
float mag_array(float *a, int n)
int rand_int(int min, int max)
float rand_uniform(float min, float max)
image crop_image(image im, int dx, int dy, int w, int h)
void place_image(image im, int w, int h, int dx, int dy, image canvas)
void rgbgr_image(image im)
augment_args random_augment_args(image im, float angle, float aspect, int low, int high, int w, int h)
void scale_image(image m, float s)
void show_image_normalized(image im, const char *name)
void show_image_collapsed(image p, char *name)
void blocky_image(image im, int s)
image make_empty_image(int w, int h, int c)