summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 60d065b)
raw | patch | inline | side by side (parent: 60d065b)
author | Rekhesh Mohan <reks@iiap.res.in> | |
Thu, 12 Jul 2012 11:24:30 +0000 (16:54 +0530) | ||
committer | Rekhesh Mohan <reks@iiap.res.in> | |
Thu, 12 Jul 2012 11:24:30 +0000 (16:54 +0530) |
.gitignore | patch | blob | history | |
ChangeLog.txt | patch | blob | history | |
README.txt | patch | blob | history | |
configure.ac | patch | blob | history | |
src/fits2jpeg.c | patch | blob | history | |
src/fits2jpeg.h | patch | blob | history | |
src/image.c | patch | blob | history | |
src/messages.c | patch | blob | history |
diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
stamp-h1
*~
.*.swp
+.*swp
*.bak
*.lock
diff --git a/ChangeLog.txt b/ChangeLog.txt
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
------------------------------------------------------------------------
NOTE: This file records the changes made after the release of the stable
-version fits2jpeg-1.0
+version fits2jpeg-1.0
------------------------------------------------------------------------
+
+
+
+Updates in 2.0 Release
+----------------------
+
+ 1. Merged scale & operations to single flag
+ v1.0 had normalize/equalize handled by "-e" flag and rest of
+ image operations by "-s" flag. Both are merged into "-s" in
+ this release.
+
+ 2. New option to clip image min/max
+ You can limit the pixel-values in output image using the flag
+ "-r". For eg: -r 10:300 to generate jpegs with pixel values in
+ the range 10 to 300.
+
+ 3. New option to negate image option
+ A negative image can be generated using "-n" flag.
+
+ 4. New option to resize image
+ zoom or shrink output image using "-z <zoomfact>".
+
+ 5. New option to choose jpeg quality factor
+ You can choose the jpeg quality factor using "-q <quality>"
+ Quality factor was fixed at 100 in previous release.
+
diff --git a/README.txt b/README.txt
--- a/README.txt
+++ b/README.txt
0. FEATURES
-----------
-fits2jpeg is a tiny program to read FITS Images and convert them
-to jpeg, which is more popular. This software supports various
-type of intensity scaling and image enhancements. fits2jpeg do not
-support coordinate axes overlay. fits2jpeg supports batch mode
-operations - for instance, converting several fits files to jpeg
-at once.
+fits2jpeg is a tiny program to read FITS Images and convert them to jpeg, which
+is more popular. This software supports various type of intensity scaling and
+image enhancements. fits2jpeg do not support coordinate axes overlay. fits2jpeg
+supports batch mode operations - for instance, converting several fits files to
+jpeg at once.
1. BUILD/INSTALL
http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html
b) JPEGLIB
- jpeg library and headers. libjpeg is installed by default on most
- platforms, but we need the header files too. Once you have cfitsio
- and jpeglib installed, you may proceed with compiling jpeg2fits.
+ jpeg library and headers. libjpeg is installed by default on most platforms,
+ but we need the header files too. Once you have cfitsio and jpeglib
+ installed, you may proceed with compiling jpeg2fits.
+
Follow these 4 steps:
2. Type `make' to compile the package.
3. Type `make install' to install the programs and any data files and
- documentation. By default, the binary is copied to /usr/local/bin.
- You may change this destination by passing on the following
- argument to configure:
+ documentation. By default, the binary is copied to /usr/local/bin. You may
+ change this destination by passing on the following argument to configure:
--prefix=/your/chosen/destination
Which would result in the binary in /your/chosen/destination/bin
You may need to ensure that in $PATH to run the program.
- 4. You can remove the program binaries and object files from the
- source code directory by typing `make clean'.
+ 4. You can remove the program binaries and object files from the source code
+ directory by typing `make clean'.
-You may read more about configure script and others in the accompanying
-file named `INSTALL.txt'.
+You may read more about configure script and others in the accompanying file
+named `INSTALL.txt'.
2.USAGE
0.5 Shrink output to half of input
2.0 Magnify output to double the size
+ fits2jpeg uses a bilinear interpolation based algorithm
+ to scale the image. Allowed range: 0.01 to 4.0
+ NOTE: Anything outside the allowed range will be clipped
Output will be written to <fits_file_root>.jpg. For eg.,
writes output to jpeg file 30dor.jpg
- Wild card entries allowed in <fits_file>. For eg: *.fits,
- m31*.fits ngc???.fits etc.
+ Wild card entries allowed in <fits_file>. For eg: *.fits, m31*.fits
+ ngc???.fits etc.
More examples:
units.
+3.1. Sequence of operations
+---------------------------
+Here is the sequence of operations, after reading the fits file:
+
+ i. clip the image to user specified pixel limits, if it was requested
+ ii. Squeeze image pixel values to jpeg limits (0 - 255)
+ iii. image scaling function, default being linear pixel scale
+ iv. Negate the image, if requested
+ v. Image zoom - magnify or shrink the image
+ vi. Write out jpeg file
+
3. DOCUMENTATION
----------------
-An extensive coverage of how this program works along with line
-by line account of the happenings within the code, are dealt with
-in the user manual, which is yet to be written :(
+An extensive coverage of how this program works along with line by line account
+of the happenings within the code, are dealt with in the user manual, which is
+yet to be written :(
4. LICENSE: GPL [See the file COPYING.txt for details]
5. DISCLAIMER
-------------
-You may encounter bugs in this software. If you do, please
-report them. Your bug reports are valuable contributions,
-since they allow us to notice and fix problems on
-machines/platforms we don't have, and/or remained un-noticed.
+You may encounter bugs in this software. If you do, please report them. Your bug
+reports are valuable contributions, since they allow us to notice and fix
+problems on machines/platforms we don't have, and/or remained un-noticed.
6. REPORTING BUGS
Either way, please include as many details as possible.
+
-----------------------------------------------------------
Reks, 28 June 2012 <reks_at_iiap.res.in>
Last modified: 10 July 2012
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
# Checks for libraries.
# Checks for header files.
-AC_CHECK_HEADERS([stdio.h stdlib.h string.h math.h float.h ctype.h libgen.h dirent.h])
+AC_CHECK_HEADERS([string.h math.h float.h ctype.h libgen.h dirent.h])
# Checks for typedefs, structures, and compiler characteristics.
+
# Checks for library functions.
AC_FUNC_MALLOC
LIBS="$LIBS -L/usr/lib64 -L/usr/lib -lm -ljpeg -lcfitsio"
-CFLAGS="-ansi $CFLAGS -I/usr/include -I/usr/include/cfitsio"
+CFLAGS="-ansi -Wall $CFLAGS -I/usr/include -I/usr/include/cfitsio"
#---------------------------------------------------------------------#
# Now we check for cfitsio headers and library #
#---------------------------------------------------------------------#
diff --git a/src/fits2jpeg.c b/src/fits2jpeg.c
--- a/src/fits2jpeg.c
+++ b/src/fits2jpeg.c
4. negate image option
5. jpeg quality factor
6. pixel scaling operations moved to image.c
- 7. Image resizing works for reducing size. segfaults for zoom > 1 :(
+ 7. Image resizing
TODO
1. move fits read to image.c
2. specify output directory
- 3. Image resizing options
*---------------------------------------------------------------------------*/
#include "fits2jpeg.h"
{
fitsfile *fptr;
- int scale = 0, process = 0, status = 0, jpgqual = 100, nfound, anynull;
+ int scale = 0, status = 0, jpgqual = 100, nfound, anynull;
unsigned int i = 0, j = 0, usrclip = 0, usrnegt = 0, usrzoom = 0;
long xdim = 0, ydim = 0, naxes[2], row_stride;
unsigned long npixels = 0;
else if (strcmp(optarg, "normalize")==0) scale = 5;
else if (strcmp(optarg, "equalize") ==0) scale = 6;
else
+ printwarn(strcat(optarg, " -- Unrecognized option"));
scale = 0;
break;
sptr = strtok(tmpstr, ":");
datamin = atof(sptr);
}
- printinfo("User defined pixel range");
/* Remember.. now we have user specified range */
usrclip = 1;
/* Do something to scale image
*/
zoomfact = atof(optarg);
- if (zoomfact < 0.0) zoomfact = 1.0;
+ zoomfact = abs(zoomfact);
+ if (zoomfact < 0.01) zoomfact = 0.01;
+ if (zoomfact > 4.0) zoomfact = 4.0;
usrzoom = 1;
break;
/* Read in data */
npixels = naxes[0] * naxes[1];
- data = (float *) malloc(sizeof(float) * npixels);
+ data = malloc(sizeof(float) * npixels);
nullval = 0;
if (fits_read_img(fptr, TFLOAT, 1, npixels, &nullval, data, &anynull,
/* IF user has provided a range, fix them as min & max in image */
if (usrclip == 1)
{
+ printinfo("user defined pixel range");
for (i = 0; i < npixels; ++i)
{
if (data[i] > datamax) data[i] = datamax;
} /*endfor*/
}
- /* Allocate image buffer */
- image_buffer = (unsigned char *) malloc(sizeof(char) * npixels);
- scale_pixels(scale, npixels, data, image_buffer);
+ scale_pixels(scale, npixels, data, &image_buffer);
/* Before we write jpeg, check if there is any requirement to negate
* the image (usrnegt = 1) */
xdim = naxes[0];
ydim = naxes[1];
- if (usrzoom == 1) resize_image(&xdim, &ydim, zoomfact, image_buffer);
+ if (usrzoom == 1)
+ {
+ printf("INFO : Image zoom factor = %3.2f\n", zoomfact);
+ resize_image(&xdim, &ydim, zoomfact, &image_buffer);
+ }
/*Write out data into JPEG file*/
jpeg_file = fopen(jpeg_file_name, "wb");/* Open JPEG file for writing*/
diff --git a/src/fits2jpeg.h b/src/fits2jpeg.h
--- a/src/fits2jpeg.h
+++ b/src/fits2jpeg.h
#define PROGRAM "fits2jpeg"
#define r2d (90./atan2(1,0))
-#define MAX_TEXT 150
+#define MAX_TEXT 1024
int my_getopt(int, char * const *, const char *);
+void PRINT_BANNER(void);
+void usage(void);
void signals_handler(int);
void set_signals(void);
void printinfo(const char *);
void printwarn(const char *);
void printerro(const char *);
-void scale_pixels(int, unsigned int, float *, JSAMPLE *);
-void resize_image(long *, long *, float, JSAMPLE *);
+void scale_pixels(int, unsigned int, float *, JSAMPLE **);
+void resize_image(long *, long *, float, JSAMPLE **);
diff --git a/src/image.c b/src/image.c
--- a/src/image.c
+++ b/src/image.c
/*---------------------------------------------------------------------------*
* SCALE_PIXELS: Changes the pixel scale to linear/log/sqroot/etc..
*---------------------------------------------------------------------------*/
-void scale_pixels(int scale, unsigned int npixels,
- float *data, JSAMPLE *image_buffer)
+void scale_pixels(int scale, unsigned int npixels, float *data,
+ JSAMPLE ** image_buffer)
{
unsigned int i = 0;
int JMAXVAL = 255;
for (i = 1; i <= JMAXVAL; ++i)
cumhist[i] += cumhist[i - 1] + hist[i];
+ /* Allocate image buffer */
+ (*image_buffer) = malloc(sizeof(unsigned char) * npixels);
+
+
/* Linear scale (min-max) : This is the default scaling
* histo-eq will fail if we dont generate image_buffer here */
for (i = 0; i < npixels; ++i)
- image_buffer[i] = (int)(data[i]);
+ (*image_buffer)[i] = (int)(data[i]);
/*-----------------------------------------------------------------------*/
printinfo("Using square-root scale");
scl_data = sqrt((float)JMAXVAL)/(float)JMAXVAL;
for (i = 0; i < npixels; ++i)
- image_buffer[i] = (int)(sqrt(data[i])/scl_data);
+ (*image_buffer)[i] = (int)(sqrt(data[i])/scl_data);
break;
case 2 : /* Square */
printinfo("Using quadratic scale");
scl_data = pow((float)JMAXVAL,2)/(float)JMAXVAL;
for (i = 0; i < npixels; ++i)
- image_buffer[i] = (int)abs((pow(data[i],2) - 1.0)/scl_data);
+ (*image_buffer)[i] = (int)abs((pow(data[i],2) - 1.0)/scl_data);
break;
case 3 : /* Cubic */
printinfo("Using cubic scale");
scl_data = pow((float)JMAXVAL,3)/(float)JMAXVAL;
for (i = 0; i < npixels; ++i)
- image_buffer[i] = (int)abs((pow(data[i],3) - 1.0)/scl_data);
+ (*image_buffer)[i] = (int)abs((pow(data[i],3) - 1.0)/scl_data);
break;
case 4 : /* log */
printinfo("Using log scale");
scl_data = log(1.0 + (float)JMAXVAL)/(float)JMAXVAL;
for (i = 0; i < npixels; ++i)
- image_buffer[i] = (int)((log(abs(data[i]) + 1.0))/scl_data);
+ (*image_buffer)[i] = (int)((log(abs(data[i]) + 1.0))/scl_data);
break;
case 5 :
scl_data = (datamax - datamin)/(float)JMAXVAL;
for (i = 0; i < npixels; ++i)
{
- if (image_buffer[i] >= datamax)
- image_buffer[i] = JMAXVAL;
- else if (image_buffer[i] <= datamin)
- image_buffer[i] = 0;
+ if ((*image_buffer)[i] >= datamax)
+ (*image_buffer)[i] = JMAXVAL;
+ else if ((*image_buffer)[i] <= datamin)
+ (*image_buffer)[i] = 0;
else
- image_buffer[i] = (int) abs((image_buffer[i]
+ (*image_buffer)[i] = (int) abs(((*image_buffer)[i]
- datamin)/scl_data);
}
break;
/* histogram equalization */
printinfo("Performing Histogram Equalization");
for (i = 0; i < npixels; ++i)
- image_buffer[i] = cumhist[image_buffer[i]] * JMAXVAL;
+ (*image_buffer)[i] = cumhist[(*image_buffer)[i]] * JMAXVAL;
break;
default :
printinfo("Using linear scale");
break;
}
-
}
/*---------------------------------------------------------------------------*
- * RESIZE_IMAGE: Scales down/up the image_buffer
+ * RESIZE_IMAGE: Scales down/up the image_buffer using bilinear scaling
+ * Based on an article by "John" at
+ * http://tech-algorithm.com/articles/bilinear-image-scaling/
*---------------------------------------------------------------------------*/
-void resize_image(long *xdim, long *ydim, float zoomfact, JSAMPLE *image_buffer)
+void resize_image(long *xdim, long *ydim, float zoomfact,
+ JSAMPLE ** image_buffer)
{
int offset = 0, index = 0;
int A, B, C, D, x, y, gray;
@@ -186,8 +192,8 @@ void resize_image(long *xdim, long *ydim, float zoomfact, JSAMPLE *image_buffer)
xratio = ((float)(w - 1))/zxdim;
yratio = ((float)(h - 1))/zydim;
- /* allocate space for *buff */
- buff = (unsigned char *) malloc(sizeof(char) * zxdim * zydim);
+ /* allocate space for *buff */
+ buff = malloc(sizeof(unsigned char) * zxdim * zydim);
index = 0;
offset = 0;
@@ -203,10 +209,10 @@ void resize_image(long *xdim, long *ydim, float zoomfact, JSAMPLE *image_buffer)
xdiff = (xratio * j) - x;
index = y * w + x;
- A = image_buffer[index] & 0xff;
- B = image_buffer[index + 1] & 0xff;
- C = image_buffer[index + w] & 0xff;
- D = image_buffer[index + w + 1] & 0xff;
+ A = (*image_buffer)[index] & 0xff;
+ B = (*image_buffer)[index + 1] & 0xff;
+ C = (*image_buffer)[index + w] & 0xff;
+ D = (*image_buffer)[index + w + 1] & 0xff;
gray = (int)(A * (1 - xdiff) * (1 - ydiff)
+ B * (xdiff) * (1 - ydiff)
@@ -218,10 +224,8 @@ void resize_image(long *xdim, long *ydim, float zoomfact, JSAMPLE *image_buffer)
}
*xdim = zxdim;
*ydim = zydim;
- image_buffer = realloc(image_buffer, sizeof(char) * npixels);
- if (!image_buffer)
- printerro("Failed to allocate memory");
-
+ (*image_buffer) = realloc((*image_buffer), sizeof(unsigned char) * npixels);
for (i = 0; i < npixels; ++i)
- image_buffer[i] = buff[i];
+ (*image_buffer)[i] = buff[i];
+ free(buff);
}
diff --git a/src/messages.c b/src/messages.c
--- a/src/messages.c
+++ b/src/messages.c
printf (" Resize/Scale output image by <zoomfactor>. Eg: \n");
printf (" 0.5 Shrink output to half of input \n");
printf (" 2.0 Magnify output to double the size \n");
+ printf (" Allowed range: 0.01 to 4.0 \n");
+ printf (" NOTE: Zooming will be carried out after all other \n");
+ printf (" operations, before writing out jpeg image \n");
printf (" Output will be written to <fits_file_root>.jpg. Wild card\n");
printf (" entries allowed in <fits_file>; For eg: *.fits, m31*.fits\n");
printf (" ngc???.fits etc. \n");