From f047cfff99e00e28c02eb59b6d32386c122f9af6 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sun, 08 Mar 2015 18:31:12 +0000
Subject: [PATCH] renamed sigmoid to logistic
---
src/image.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 114 insertions(+), 5 deletions(-)
diff --git a/src/image.c b/src/image.c
index e2c451b..ee7a823 100644
--- a/src/image.c
+++ b/src/image.c
@@ -4,6 +4,86 @@
int windows = 0;
+float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} };
+
+float get_color(int c, int x, int max)
+{
+ float ratio = ((float)x/max)*5;
+ int i = floor(ratio);
+ int j = ceil(ratio);
+ ratio -= i;
+ float r = (1-ratio) * colors[i][c] + ratio*colors[j][c];
+ //printf("%f\n", r);
+ return r;
+}
+
+void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b)
+{
+ normalize_image(a);
+ int i;
+ if(x1 < 0) x1 = 0;
+ if(x1 >= a.w) x1 = a.w-1;
+ if(x2 < 0) x2 = 0;
+ if(x2 >= a.w) x2 = a.w-1;
+
+ if(y1 < 0) y1 = 0;
+ if(y1 >= a.h) y1 = a.h-1;
+ if(y2 < 0) y2 = 0;
+ if(y2 >= a.h) y2 = a.h-1;
+
+ for(i = x1; i < x2; ++i){
+ a.data[i + y1*a.w + 0*a.w*a.h] = b;
+ a.data[i + y2*a.w + 0*a.w*a.h] = b;
+
+ a.data[i + y1*a.w + 1*a.w*a.h] = g;
+ a.data[i + y2*a.w + 1*a.w*a.h] = g;
+
+ a.data[i + y1*a.w + 2*a.w*a.h] = r;
+ a.data[i + y2*a.w + 2*a.w*a.h] = r;
+ }
+ for(i = y1; i < y2; ++i){
+ a.data[x1 + i*a.w + 0*a.w*a.h] = b;
+ a.data[x2 + i*a.w + 0*a.w*a.h] = b;
+
+ a.data[x1 + i*a.w + 1*a.w*a.h] = g;
+ a.data[x2 + i*a.w + 1*a.w*a.h] = g;
+
+ a.data[x1 + i*a.w + 2*a.w*a.h] = r;
+ a.data[x2 + i*a.w + 2*a.w*a.h] = r;
+ }
+}
+
+void jitter_image(image a, int h, int w, int dh, int dw)
+{
+ int i,j,k;
+ for(k = 0; k < a.c; ++k){
+ for(i = 0; i < h; ++i){
+ for(j = 0; j < w; ++j){
+ int src = j + dw + (i+dh)*a.w + k*a.w*a.h;
+ int dst = j + i*w + k*w*h;
+ //printf("%d %d\n", src, dst);
+ a.data[dst] = a.data[src];
+ }
+ }
+ }
+}
+
+void flip_image(image a)
+{
+ int i,j,k;
+ for(k = 0; k < a.c; ++k){
+ for(i = 0; i < a.h; ++i){
+ for(j = 0; j < a.w/2; ++j){
+ int index = j + a.w*(i + a.h*(k));
+ int flip = (a.w - j - 1) + a.w*(i + a.h*(k));
+ float swap = a.data[flip];
+ a.data[flip] = a.data[index];
+ a.data[index] = swap;
+ }
+ }
+ }
+}
+
image image_distance(image a, image b)
{
int i,j;
@@ -138,7 +218,7 @@
}
free_image(copy);
if(disp->height < 500 || disp->width < 500 || disp->height > 1000){
- int w = 1500;
+ int w = 500;
int h = w*p.h/p.w;
if(h > 1000){
h = 1000;
@@ -369,7 +449,6 @@
// Will do a scaled image resize with the correct aspect ratio.
outImg = resizeImage(croppedImg, newHeight, newWidth, 0);
cvReleaseImage( &croppedImg );
-
}
else {
@@ -415,6 +494,25 @@
return out;
}
+image load_image_color(char *filename, int h, int w)
+{
+ IplImage* src = 0;
+ if( (src = cvLoadImage(filename, 1)) == 0 )
+ {
+ printf("Cannot load file image %s\n", filename);
+ exit(0);
+ }
+ if(h && w && (src->height != h || src->width != w)){
+ //printf("Resized!\n");
+ IplImage *resized = resizeImage(src, h, w, 0);
+ cvReleaseImage(&src);
+ src = resized;
+ }
+ image out = ipl_to_image(src);
+ cvReleaseImage(&src);
+ return out;
+}
+
image load_image(char *filename, int h, int w)
{
IplImage* src = 0;
@@ -424,7 +522,7 @@
exit(0);
}
if(h && w ){
- IplImage *resized = resizeImage(src, h, w, 1);
+ IplImage *resized = resizeImage(src, h, w, 0);
cvReleaseImage(&src);
src = resized;
}
@@ -642,10 +740,21 @@
void print_image(image m)
{
- int i;
- for(i =0 ; i < m.h*m.w*m.c; ++i) printf("%lf, ", m.data[i]);
+ int i, j, k;
+ for(i =0 ; i < m.c; ++i){
+ for(j =0 ; j < m.h; ++j){
+ for(k = 0; k < m.w; ++k){
+ printf("%.2lf, ", m.data[i*m.h*m.w + j*m.w + k]);
+ if(k > 30) break;
+ }
+ printf("\n");
+ if(j > 30) break;
+ }
+ printf("\n");
+ }
printf("\n");
}
+
image collapse_images_vert(image *ims, int n)
{
int color = 1;
--
Gitblit v1.10.0