/*------------------------------------------------------------------------------------*/ /* NIGHTVISION.C */ /*------------------------------------------------------------------------------------*/ /* David A. Hess CS455 Assignment 1 */ /*------------------------------------------------------------------------------------*/ /* This program demonstrates a night camera visual system created by performing a */ /* probablelistic equalization (procedure 'equalize') on the histogram of a dark */ /* visual scene. The system is initialized in the normal, unequalized video mode */ /* and remains in that mode until the user makes a selection between test mode and */ /* night vision mode. Test mode freezes the image and performs and displays the */ /* unequalized histogram of the image. Then, when requested, performs an equalization */ /* on the frozen image and displays the histogram of the equalized image. Night */ /* vision mode performs a single equalization on the image and keeps the LUT at */ /* this level until requested to quit. Continuous equalize mode continuously loops */ /* through the image equalization routine until control-C is entered. */ /*------------------------------------------------------------------------------------*/ #include #define YES 1 #define NO 0 int harray[256]; int LUTarray[256]; main() { int scale = 255; char cmd; int j; do { VIS$OPEN(); VIS$INIT_FB(); setcamera(0); VIS$INIT_LUTS(); VIS$VIEW(); printf("%s%s","Enter command : n (continuous night vision)\n", "c (continuous equalize vision) t (test) e (exit program)"); cmd = getchar(); while(getchar() != '\n'); if (cmd != 'e') { switch (cmd) { case 'n' : /* begin continuous night vision */ { VIS$FREEZE(); VIS$CS455_HISTOGRAM(50,50,500,400,NO,harray,255); equalize(harray,LUTarray,scale); VIS$LOAD_LUT(0,1,LUTarray); VIS$SELECT_LUT(0,1); VIS$VIEW(); printf("%s","\nNight Vision Mode. Enter 'q' to quit.\n"); while(getchar() != 'q'); while(getchar() != '\n'); break; } case 't' : /*begin test */ { VIS$FREEZE(); VIS$HISTOGRAM(50,50,500,400,NO); printf("%s%s","Displaying unequalized histogram.\n", "Enter to view equalized histogram."); while (getchar() != '\n'); VIS$VIEW(); VIS$FREEZE(); VIS$CS455_HISTOGRAM(50,50,500,400,NO,harray,255); equalize(harray,LUTarray,scale); VIS$LOAD_LUT(0,1,LUTarray); VIS$SELECT_LUT(0,1); VIS$SET_MODE(1); VIS$HISTOGRAM(50,50,500,400,NO); printf("%s%s","Displaying equalized histogram.\n", "Enter to continue."); while (getchar() != '\n'); VIS$SET_MODE(0); break; } /* end test */ case 'c' : /* begin continuous equalize vision */ { printf("%s","\nContinuous Equalize Mode. Enter cntl-c to quit.\n"); VIS$VIEW(); while(1) { VIS$CS_HISTOGRAM(50,50,500,400,NO,harray,255); equalize(harray,LUTarray,scale); VIS$LOAD_LUT(1,0,LUTarray); VIS$LOAD_LUT(2,0,LUTarray); VIS$LOAD_LUT(3,0,LUTarray); } break; } /* end continuous equalize */ } /* end switch */ } /* end if */ } while (cmd != 'e'); } /* end main() */ equalize(harray,LUTarray,scale) int *harray,*LUTarray,scale; { int N,i,level = 0; float s = 0.0; N = harray[0]; for (i = 1;i <= scale;i++) N += harray[i]; /* total pixels */ for (i = 0;i <= scale;i++) { s += (float)harray[i]/(float)N; /* calc Sk */ while (((float)level/(float)scale) < s) level++; /* find scaling level */ LUTarray[i] = level; } } /* end equalize */ VIS$CS_HISTOGRAM(x1,y1,x2,y2,equalize,harray, color) int x1,y1,x2,y2, equalize, *harray, color; { int i,x; int values[641]; /* INITIALIZE ARRAYS */ for (i=0;i<=255;i++) { harray[i] = 0; } /* FILL HARRAY WITH READ_HORIZONTAL_LINE this is the histogram */ for (i=y1;i<=y2;i++) { rhline(x1,i,x2-x1,values); for (x=0;x