IMG2PNG

This is a utility which can convert lots of different PDS files and FITS files to PNGs, including 16 bit PNGs when applicable. It's a 'quick-and-dirty' one so it isn't particularly user friendly; it runs in a command prompt ("DOS") window. It has been tested under Windows XP but should also work under Windows Vista, Windows 2000 and probably Windows ME and 98.


Download

IMG2PNG and associated files can be downloaded here (4.4 MB ZIP file). Unzip the ZIP file and put img2png.exe, cfitsio.dll and img2png.ini somewhere on your computer (they must be in the same directory). At this time, IMG2PNG.INI is only necessary if you want to calibrate Cassini images. Edit the INI file as described below. A standalone version of img2png.exe (724 KB ZIP file) can be donwnloaded here if you are upgrading and already have the associated files.

Put the mottlemap_hack.img into the calib\dustring directory (part of the data on the COISS_0011 volume) if you want to calibrate Cassini images.


Updates

New version January 25, 2010. New features and changes from the previous version:

IMG2PNG now correctly converts the MGS MOLA files. Please note that for the conversion to work you need to download the label files (.LBL) in addition to the image files. When converting, the constant 8208 is added to the data to get rid of negative values.


New version January 24, 2010. New features and changes from the previous version:

IMG2PNG now generates correct 16 bit PNG files if the source data is 32 bit floating point data that contains information on the valid minimum and maximum data values in an embedded label or a detached label. This means that the MRO HIRISE DEMs now get correctly converted, plus probably a lot of other 32 bit IMG files.


New version June 6, 2009. New features and changes from the previous version:

(1) Corrected a bug in the Cassini calibration code. The most obvious and commonly visible effect of this bug was that when doing RGB composites the blue images were too dark relative to the red and green images. This has now been fixed.

(2) Made minor changes based on CISSCAL on V2 of the Cassini calibration volume that became available earlier this year. If you are still using the old version of the Cassini calibration volume I strongly recommend "upgrading" to this new version. It can be found at http://pdsimg.jpl.nasa.gov/data/cassini/cassini_orbiter/ (the coiss_011_v2 files).

New version July 24, 2008. New features and changes from the previous version:

IMG2PNG should now properly convert calibrated Messenger images.

New version February 16, 2008. New features and changes from the previous version:

IMG2PNG can now convert FITS files to 16 bit PNG files. As each FITS file can contain multiple images and each image may consist of multiple planes the output filenames are of the form NAME_NN_planePP.PNG where NAME is the name of the input file (without the .FITS/.FIT extension), NN is the number of the image and PP is the plane number. If there is only one plane _planePP is omitted and if there is only one image in the input file _NN is omitted. An automatic contrast stretch is applied before writing data to the PNG file; the minimum intensity value becomes black and the maximum becomes white. The contrast stretch can be modified with the -ct command line option. Information on the conversion is written to a log file (img2png_fits.log).


New version November 13, 2007. New features and changes from the previous version:

Fixed lots of errors in the Cassini calibration code and made some modifications:

(1) Some files weren't getting closed after use. Because of this IMG2PNG eventually stopped working when calibrating/converting many files in one conversion run.
(2) In some cases IMG2PNG didn't find the flatfielding file even though it existed.
(3) In some cases IMG2PNG didn't find the effective wavelength 'database'  file. This was caused by an error in CISSCAL on which the IMG2PNG Cassini calibration code is largely based.
(4) When calibrating Cassini images, instead of displaying message boxes, most of IMG2PNG's errors/warnings are now written to a log file (img2png.log). If this file exists IMG2PNG appends it instead of recreating it. The most important stuff in the file is preceded by "Error:" so you can search the file for anything important. Really severe errors (out of memory, seriously corrupt input files etc.) still appear as message boxes.

New version May 26, 2007. Changes and new features from the previous version:

Fixed a bug which caused incorrect results when converting the 16 bit calibrated/geometrically corrected Voyager images, especially in dark areas, e.g. the background space. Changed the interpretation of the -s command line option so it can now be used regardless of whether you are using IMG2PNG to calibrate the input images when converting them. Previously this value was only used when calibrating. This is especially useful for 16 bit input images with an intensity range of 0-4095.

New version April 8, 2006. Changes and new features from the previous version:

Made several minor improvements to the code for reading PDS files. Also added two new command line switches:

(1) -l tells IMG2PNG to write the image labels to separate text files. The text files typically are named image.img.txt where "image.img" is the name of the original input file. Only a subset of the labels (some of the more "interesting" ones) are written to the text file.

(2) -n tells IMG2PNG not to create any PNG files. This can be used to check for bad input files or for creating thumbnails only.


New version November 13, 2005. Changes and new features from the previous version:

Fixed a bug which sometimes caused a crash when calibrating 256x256 pixel Cassini images. Also fixed a bug which caused a crash in rare cases when reading VICAR files. 512x512 and 256x256 pixel Cassini images now get multiplied by 0.25 and 0.0625, respectively when calibrating. This is to make their brightness identical to the brightness of 1024x1024 pixel images.

New version November 13, 2005. Changes and new features from the previous version:

16 bit Cassini images now get calibrated. Before this only 8 bit Cassini images got calibrated.

New version November 12, 2005. Changes and new features from the previous version:

IMG2PNG now always complains when a Cassini calibration file is missing. Before this it sometimes simply continued without complaining and skipped the relevant calibration step.

New version November 6, 2005. Changes and new features from the previous version:

(1) Fixed a crash which occurred when reading some of the Stardust images. In theory, this crash could also occur for files from various different spacecraft.

(2) It is now possible to calibrate Cassini images, including flatfielding etc. Please note that this feature is not completely implemented yet, for example dark current subtraction is not yet complete. Also the output 'units' are arbitary (not something like I/F) and the output is scaled using fudge factors I added to prevent the images from becoming too dark. To perform calibration you need to download everything from the CALIB directory on the COISS_0011 Cassini Imaging Science Subsystem data volume. This directory can be found here:

http://pds-rings.seti.org/cds/COISS_0011/CALIB/

Put this directory somewhere on your computer and then change the supplied img2png.ini file to include the name of the directory on your computer. For example, if the CALIB directory is at the root of your C:\ disk it should contain this line:

cassini_cal_dir=c:\calib

In addition, you must put the supplied mottlemap_hack.img file into the calib\dustring directory.

For calibration to work it is not sufficient to download only the IMG files. You must also download the associated LBL files since they contain information necessary for determining exactly how to perform the calibration for the corresponding image.

Finally, note that even if you do not download the CALIB directory you can perform 'partial calibration' since some of the calibration steps do not require data from this directory.


How to use

IMG2PNG is run by opening a command prompt window and typing something like

img2png *.img

which will create PNG files from all IMG files in the directory. This also works for more file types, e.g. Voyager (*.imq) and even Mariner 9/10.

There are five optional command line options. Please note that -r, -s and -l do not apply when converting FITS files:

(1) -t tells img2png to create thumbnail files in addition to full size files. Example:

img2png *.img -t

This will create thumbnail files in addition to the full size files. The thumbnails are 1/4 the size of the full size images and are automatically contrast stretched.

(2) -r tells img2png to perform radiometric correction (the default is not to do so). You will want to do this when working with RAD files from the Mars Exploration Rovers (MER) and also when converting Cassini images.

(3) -sNNNN where NNNN is a floating point number (e.g. -s12). The image is multiplied (scaled) by NNNN after radiometric correction. The reason for this is that the images are often very dark without this. The default value if -s is not used is 8 for MER and 1 for everything else. These values should work well in most cases.

(4) -l tells img2png to write the image labels to separate text files. The text files typically are named image.img.txt where "image.img" is the name of the original input file. Only a subset of the labels (some of the more "interesting" ones) are written to the text file.

(5) -n tells img2png not to create any PNG files. This can be used to check for bad input files or for creating thumbnails only.

(6) -ct specifies the name of a file containing contrast stretch parameters (e.g. -ctcontrast_stretch.txt). This applies only when converting FITS files. The contrast stretch file looks like this:

0 3800
0 25
0 32

This means that for image 1 in every FITS file, pixels with intensity <=0 will be set to black in the output file and pixels with intensity >=3800 will be set to white. The 0 and 25 parameters apply to image 2 in each FITS file and 0 and 32 to image 3. Any of the numbers in the file can be replaced with a "-" (without quotes), meaning use the minimum intensity value (if "-" is specified instead of a minimum value) to determine the contrast stretch. Replacing the maximum value with a "-" has a comparable effect. To determine applicable values for the contrast stretch parameters, first run IMG2PNG with the -n option. IMG2PNG will output the minimum and maximum intensity found for each image number.

Note that the resulting PNGs will often look very dark without the -s option, especially for MER images. The reason is that 16 bits yield an intensity range of 0-65535 but in all cases I have seen the maximum intensity is roughly 3000 or lower for MER images. An exception is RAD MER files, see (3) above.

This utility should work for lots of different PDS files, e.g. MER, Pathfinder, Voyager, Galileo, Cassini, Stardust, various Mars orbiters, Mariner 9/10 (!), Viking Orbiter, Viking Lander, Magellan, Clementine, Messenger, New Horizons etc.

Back to main page.