summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e9b7faa)
raw | patch | inline | side by side (parent: e9b7faa)
author | Rekhesh Mohan <reks@darkstar.Home> | |
Thu, 5 Jul 2012 20:02:44 +0000 (01:32 +0530) | ||
committer | Rekhesh Mohan <reks@darkstar.Home> | |
Thu, 5 Jul 2012 20:02:44 +0000 (01:32 +0530) |
configure.ac | patch | blob | history | |
src/fits2jpeg.c | patch | blob | history |
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
-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
--- a/src/fits2jpeg.c
+++ b/src/fits2jpeg.c
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
printf (" -h help \n");
printf (" -s <scale_type> \n");
printf (" scale for output image, where <scale_type> 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 <operation> \n");
- printf (" Image enhancements, where <operation> can be: \n");
printf (" normalize for linear histogram stretch \n");
printf (" equalize for histogram equalization \n");
printf (" Output will be written to <fits_file_root>.jpg. Wild card\n");
/*-------------------- 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 <min>:<max>
+ * set a flag. If this flag is on, do a 'reverse map'
+ * instead of search for datamin & datamax
+ */
break;
case 'h':
/*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)
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;
/* 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 */
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)
{
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 */