From 6887371c62d57743a58397d4179bf287c9afcbaa Mon Sep 17 00:00:00 2001 From: Rekhesh Mohan Date: Fri, 6 Jul 2012 01:32:44 +0530 Subject: [PATCH] v2.0 Testing - Merged scale and enhancement operations to single block --- configure.ac | 2 +- src/fits2jpeg.c | 101 ++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 63 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index c63208d..4349060 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([CADS_fits2jpeg], [1.0], [cads@iiap.res.in]) +AC_INIT([CADS_fits2jpeg], [1.90], [cads@iiap.res.in]) AC_LANG_C AM_INIT_AUTOMAKE([-Wall -Werror]) AC_CONFIG_SRCDIR([config.h.in]) diff --git a/src/fits2jpeg.c b/src/fits2jpeg.c index b387ff0..58800fb 100644 --- a/src/fits2jpeg.c +++ b/src/fits2jpeg.c @@ -68,6 +68,15 @@ Reks 28 June 2012 1. rebranded to CADS/UVS + + Reks 05 July 2012 v2.0 plans + 1. Merged scale & operations to single flag + TODO + 1. New option to specify min-max for image + 2. specify output directory + 3. output filename for single input file + 4. Image resizing options + *-------------------------------------------------------------------------*/ #ifdef HAVE_CONFIG_H @@ -109,13 +118,11 @@ void usage() printf (" -h help \n"); printf (" -s \n"); printf (" scale for output image, where can be: \n"); - printf (" linear Linear scale, default \n\n"); + printf (" linear Linear scale, default \n"); printf (" sqroot for square root scale \n"); printf (" square for quadratic scale \n"); printf (" cubic for cubic scale \n"); printf (" log for log scale \n"); - printf (" -e \n"); - printf (" Image enhancements, where can be: \n"); printf (" normalize for linear histogram stretch \n"); printf (" equalize for histogram equalization \n"); printf (" Output will be written to .jpg. Wild card\n"); @@ -163,19 +170,29 @@ int main(int argc, char *argv[], char *envp[]) /*-------------------- Parse command line inputs ------------------------*/ if (argc < 2) usage(); /* People who don't give any arguments need help */ - while ( ( opt = my_getopt ( argc, argv, "s:e:h" ) ) != EOF ) + while ( ( opt = my_getopt ( argc, argv, "s:e:r:h" ) ) != EOF ) switch ( opt ) { case 's': - if (strcmp(optarg, "sqroot") ==0) scale = 1; - if (strcmp(optarg, "square") ==0) scale = 2; - if (strcmp(optarg, "cube") ==0) scale = 3; - if (strcmp(optarg, "log") ==0) scale = 4; + if (strcmp(optarg, "sqroot") ==0) scale = 1; + else if (strcmp(optarg, "square") ==0) scale = 2; + else if (strcmp(optarg, "cube") ==0) scale = 3; + else if (strcmp(optarg, "log") ==0) scale = 4; + else if (strcmp(optarg, "normalize")==0) scale = 5; + else if (strcmp(optarg, "equalize") ==0) scale = 6; + else + { + fprintf(stderr, "ERROR : Unrecognized option : %s\n", optarg); + exit(EXIT_FAILURE); + } break; - case 'e': - if (strcmp(optarg, "normalize")==0) process = 1; - if (strcmp(optarg, "equalize") ==0) process = 2; + case 'r': + /* + * read a string like : + * set a flag. If this flag is on, do a 'reverse map' + * instead of search for datamin & datamax + */ break; case 'h': @@ -231,7 +248,7 @@ int main(int argc, char *argv[], char *envp[]) /*Close data file*/ printf("INFO : data input from %s\n", fits_file_name); - /* find min & max in image */ + /* IF no range is provided, find min & max in image */ datamax = -1.0e9; datamin = +1.0e9; for (i = 0; i < npixels; ++i) @@ -240,6 +257,7 @@ int main(int argc, char *argv[], char *envp[]) if (data[i] < datamin) datamin = data[i]; } /*endfor*/ + /* Convert data into bytscaled values for jpeg file */ /* the dynamic range is reduced to 255 for jpeg */ scl_data = (datamax - datamin)/(float)JMAXVAL; @@ -256,6 +274,24 @@ int main(int argc, char *argv[], char *envp[]) /* Allocate image buffer */ image_buffer = (unsigned char *) malloc(sizeof(char) * npixels); scl_data = 1.0; + + + /* initialize image histogram. ensure all are zeroes in hist[] */ + /*-------------------------------------------------------------------*/ + for (i = 0; i <= JMAXVAL; ++i) hist[i] = 0; + + /* construct the image histogram */ + tmp = 1.0/(float)npixels; + for (i = 0; i <= npixels; ++i) + hist[(int)floor(data[i])] += tmp; + + /* And the cumulative histogram */ + cumhist[0] = hist[0]; + for (i = 1; i <= JMAXVAL; ++i) + cumhist[i] += cumhist[i - 1] + hist[i]; + /*-------------------------------------------------------------------*/ + + switch (scale) { case 1 : /* Square root */ @@ -286,35 +322,15 @@ int main(int argc, char *argv[], char *envp[]) image_buffer[i] = (int)((log(abs(data[i]) + 1.0))/scl_data); break; - default: /* Linear scale (min-max) */ - for (i = 0; i < npixels; ++i) - image_buffer[i] = (int)(data[i]); - break; - } - - /* initialize image histogram. ensure all are zeroes in hist[] */ - for (i = 0; i <= JMAXVAL; ++i) hist[i] = 0; - - /* construct the image histogram */ - tmp = 1.0/(float)npixels; - for (i = 0; i <= npixels; ++i) - hist[(int)floor(data[i])] += tmp; - - /* And the cumulative histogram */ - cumhist[0] = hist[0]; - for (i = 1; i <= JMAXVAL; ++i) - cumhist[i] += cumhist[i - 1] + hist[i]; - - switch (process) - { - case 1 : /* contrast stretch */ - printf("INFO : Performing contrast stretch (normalization) \n"); + case 5 : + /* contrast stretch */ + printf("INFO : Performing histogram stretch (normalization)\n"); datamax = (float)JMAXVAL; datamin = 0.0; /* We need to go through the cumulative histogram to pick the - appropriate values for datamin and datamax */ + * appropriate values for datamin and datamax */ i = 0; while (i < JMAXVAL) { @@ -343,18 +359,25 @@ int main(int argc, char *argv[], char *envp[]) else if (image_buffer[i] <= datamin) image_buffer[i] = 0; else - image_buffer[i]=(int)abs((image_buffer[i]-datamin)/scl_data); + image_buffer[i] = (int) abs((image_buffer[i] + - datamin)/scl_data); } break; - - case 2 : /* histogram equalization */ + case 6 : + /* histogram equalization */ printf("INFO : Performing Histogram Equalization\n"); for (i = 0; i < npixels; ++i) image_buffer[i] = cumhist[image_buffer[i]]*255; break; + + default: /* Linear scale (min-max) */ + for (i = 0; i < npixels; ++i) + image_buffer[i] = (int)(data[i]); + break; } + /*Write out data into JPEG file*/ cinfo.err = jpeg_std_error(&jerr); /* JPEG error handler */ jpeg_create_compress(&cinfo); /* JPEG initialization */ -- 2.12.1