IMG2PNG

This is a utility which can convert lots of different PDS files and FITS files to PNGs, including 16 bit PNGs when applicable. I originally wrote this solely for myself to use so it's somewhat 'quick-and-dirty' and not particularly user friendly; it runs in a command prompt ("DOS") window. It has been tested under Windows XP and Windows 7 but should also work under Windows Vista, Windows 2000 and possibly more versions of Windows.

This utility should work for converting 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, Phoenix, Venus Express, LRO, New Horizons, Dawn, Curiosity, Rosetta etc.

Download and setup How to use Updates and changes


Download and setup

IMG2PNG and associated files can be downloaded here (4.5 MB ZIP file). Unzip the ZIP file and put img2png.exe, cfitsio.dll, several files with names ending with .RSX and img2png.ini somewhere on your computer (they must be placed in the same directory). At this time, img2png.ini is only necessary if you want to calibrate Cassini images or if you want to convert LRO NAC images. A standalone version of img2png.exe (319 KB ZIP file) can be downloaded here if you are upgrading and already have the associated files. The mottlemap_hack.img file is only used if you want to calibrate Cassini images - see below.

The following steps are only necessary if you want to calibrate Cassini images and/or convert LRO NAC images:

(1) If you want to calibrate Cassini images. If you want to calibrate Cassini images you must start by downloading Cassini volume COISS_0011_V2 from http://pdsimg.jpl.nasa.gov/data/cassini/cassini_orbiter/ if you do not already have it on your computer. You must download everything in that volume. Note that if you download the volume by downloading the compressed tar.gz file and use WinZip to decompress it you must turn off the TAR file smart CR/LF conversion in the WinZip "Options/configuration/Miscellaneous/other" box. Otherwise the data doesn't get correctly decompressed.

Next you must tell img2png where to look for the calibration files you downloaded. Put the Cassini calibration stuff somewhere on your computer and then change the supplied img2png.ini file to include the name of the calibration directory on your computer. For example, if the CALIB directory is at the root of your C:\ disk img2png.ini should contain this line:

cassini_cal_dir=c:\calib

In addition, you must put the supplied mottlemap_hack.img file (it's included in img2png.zip) into the calib\dustring directory (part of the data on the COISS_0011_V2 Cassini calibration volume).

(2) If you want to convert LRO NAC images. To correctly convert LRO NAC images you must download the index file CUMINDEX.TAB from the most recent LROC volume or the INDEX.TAB file(s) for the volume(s) you are processing. Using old versions of these files (approximately prior to 2011) will not work. If you use CUMINDEX.TAB you must be careful to have a version of this file that is new enough to contain information on all of the images you want to convert. Once you have the index file(s) on your computer edit the supplied img2png.ini file (the line starting with "lroc_index_file=") to point to the index files on you machine. As an example, if the there is a file in the directory lro_index at the root of your C:\ disk img2png.ini should contain this line:

lroc_index_file=c:\lro_index\CUMINDEX.TAB

There can be multiple lines like this if you have many index files you want to use. For example like this:

lroc_index_file=c:\dir_1\INDEX.TAB
lroc_index_file=c:\dir_2\INDEX.TAB
lroc_index_file=c:\dir_3\CUMINDEX.TAB

Files at the top of the list take precedence which means that if two index files contain information on the same image the information from the file closer to the top of the list is used.


How to use

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

img2png *.img

Note that img2png must be run by opening a command prompt window and then typing something like the command above. Double clicking the img2png.exe file will not do what you want. If you don't know how to open a command prompt window you should read this.

The command above will create PNG files from all IMG files in the directory where the command prompt was opened. This also works for more file types, e.g. Voyager (*.imq) and even Mariner 9/10. Individual files can be converted by typing img2png followed by the name of the file you want to convert.

The filename can be followed by command line options. For example:

img2png *.img -thumbn -labels -s8 -destripe

The files output by img2png are always grayscale. This means that if you convert a PDS file that contains several individual images (e.g. images at different wavelengths) you get a 'tiled' output image. For example, this happens if you convert LCROSS and LRO WAC images.

When downloading the IMG files you want to convert you should always download the LBL files as well if they are present. In some cases the IMG files cannot be converted without the LBL files and in other cases certain features may not work properly without LBL files (in particular Cassini calibration).

In addition to normal images, various DEMs should be correctly converted to 16 bit PNGs. In particular this applies to the lunar LOLA DEM and the Mars MOLA DEM. To get rid of negative altitude values 32768 is added to the data. If the data is in meters this makes black=-32768 meters and white=+32767 meters. Please note that for LOLA the scaling factor is 0.5 so in that case black=-16384 meters and white=+16383.5 meters.

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

The command line options are:

(1) -tN or -thumbnN

Tells img2png to create thumbnail files in addition to full size files. N is an optional integer value that can be used to specify the thumbnail size. If N is not specified a value of 4 is used. The thumbnail images are automatically contrast stretched. Example:

img2png *.img -t8 (or img2png *.img -thumbn8)

This will create thumbnail files in addition to the full size files. In this example the thumbnails are 1/8 the size of the full size images.

(2) -r

This 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

Here NNNN is a floating point number (e.g. -s12). The image is multiplied (scaled) by NNNN after it is converted (or radiometrically corrected if -r is used). This is sometimes necessary since the images are often very dark without this. The default value if -s is not used is 8 for MER (when radiometric correction is used) and 1 for everything else. These values should work well in most cases. Note that the 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 most cases I have seen the maximum intensity is much lower than 65535. The main exception is RAD MER files.

(4) -l or -labels

This 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 or -none

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 (Contrast stretch Table) 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 in the image (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.

(7) -destripe

The black horizontal stripes that are sometimes present in Cassini and Voyager images can be removed using the command line option -destripe. They are removed using linear interpolation. Linear interpolation is not optimal; in a future version a better (and more complex) algorithm will probably be used.

(8) -resample

Images with non-square pixels can be resampled to square pixels using the -resample command line option. At present the NEAR MSI images are the only images that get resampled (this is because at present these are the only images I know of with non-square pixels).

(9) -fnamefilter and -fnameobs

The filter name(s) can be included in the output filename using the -fnamefilter command line option and the observation id using the -fnameobs command line options.

(10) -fnameflip

Adds _hflip and/or _vflip to the output filename if IMG2PNG has flipped the image horizontally and/or vertically. See also (13).

(11) -calib

Calibration files can be specified using the command line option -calib. This is implemented as suggested in machi's post at Unmanned Spaceflight: http://www.unmannedspaceflight.com/index.p...st&p=170463
So if you have a file named flat.txt (as in machi's example) use "-calibflat.txt". If this option is used the bias and darkframe are subtracted from the image and the result then divided by the flatfield. Individual calibration files are optional so you can for example omit bias correction by omitting the "b=" line (or commenting it out by prefixing the line with ; or #). If the input image is 8 bits it is converted to 16 bits before calibrating.

(12) -fstretchF1,F2

Here F1 and F2 are floating point numbers, for example "-fstretch0,0.1". This parameter is applicable when converting images containing floating point data and is used to specify how to map the floating point data to 2 byte integers in cases where IMG2PNG doesn't 'know' which parameters are applicable. If this is not used, IMG2PNG uses the actual range of the data when it isn't 'familiar' with the data and otherwise it uses built-in parameters that differ for different missions/targets.

-fstretch is also useful for forcing IMG2PNG to use the same parameters for many images which is necessary when doing color composites. To get a rough idea of which fstretch values might be good first run IMG2PNG without -fstretch and notice a line in the output that looks like this:

Floating point to 16 bit integer conversion: [-0.000023,0.059897] -> [0,65535]

This suggests that -fstretch0,0.06 might be good - or maybe -fstretch0,0.1 to avoid getting saturated areas for images where different and 'brighter' filters might have been used.

(13) -noflip

By default IMG2PNG flips images horizontally and/or vertically when necessary to get a correctly oriented output image. -noflip can be used to prevent this and get an output image with the same orientation as in the input file. Exception: IMG2PNG will always flip LRO images when needed, even if you use -noflip.

(14) -remres

Removes reseau marks if applicable. These are dark regularly spaced dots that appear in older images taken using 'pre-CCD' cameras. IMG2PNG can remove reseau marks from Voyager, Viking, Mariner 9 and Mariner 10 images.

(15) -loglevelNNN

Controls the amount of information written to the screen when converting images. NNN is a number from 0 to 100. Typical values to use are 0, 1, 10 and 100. The default value is 0.

 

Updates and change log:

December 19, 2013

Fixed a bug which caused 16 lines of garbage to appear at the top of the converted images and truncation of 16 lines at the bottom when converting certain images (in particular Curiosity Navcam RDRs).

August 19, 2013

It is now possible to point to many index files from img2png.ini when converting LRO NAC images. In earlier versions only one index file could be used. Img2png now correctly handles recent versions of these index files which are in a format that differs slightly from older versions (which img2png can also read).

Img2png now flips images from Dawn vertically instead of horizontally. Geometrically, this change is not significant (in effect the images are now rotated compared to the earlier version) but it is consistent with some of the labels in the Dawn files, e.g. NORTH_AZIMUTH. Flipping the images horizontally as in earlier versions wasn't consistent with these labels.

April 28, 2013

Fixed a bug which caused the resulting images to be incorrectly oriented (mirror-flipped up-down) in all cases if the input files were in FITS format. Changed the -t command line switch to make it possible for the user to specify the thumbnail size. Various minor bug fixes, the biggest of which involved the conversion of Clementine images.

December 16, 2012

Fixed a few fairly minor bugs and added several Dawn-related improvements. Added the ability to remove reseau marks from Voyager, Viking and Mariner 9 & 10 images (the -remres command line switch).

By default IMG2PNG now always flips the images horizontally and/or vertically if this is necessary to get a correctly oriented image and if IMG2PNG knows that this is necessary. This affects the conversion of Dawn and Rosetta images. This behavior can be disabled using the -noflip switch. -fnameflip can be used to add information on if/how it flips the image to the output filename.

March 11, 2012

Fixed a few bugs, most of which affected the conversion of input files containing floating point data. In particular, this new version has better support for the Messenger orbital data, Rosetta data and the LROC and HiRise DTMs. Also added the -fstretch command line option.

June 18, 2011

A complete rewrite of most of img2png. It is now easier to maintain and it also correctly handles a far larger number of PDS file 'variants' than earlier versions did. Several new features (command line options) have also been added (-destripe, -resample, -fnamefilter, -fnameobs, -calib, -loglevel) and some bugs/problems are now gone. In particular, LRO NAC images can now be flipped so the problem described when the previous version was released  is gone.

April 2, 2010

IMG2PNG now correctly converts the LRO images (LROC NAC and WAC). The WAC images look weird but this is normal because each image consists of a series of framelets. A future version will correctly account for this. Please note that converting LOLA files has not been tested yet and may not work correctly. Warning: The LRO narrow angle images come in pairs (RC and LC). One of the images from each pair must be mirror-flipped but neither the file headers nor the index.tab files contain enough information to make it possible to determine which image, RC or LC, must be mirror-flipped. Therefore you must manually determine which images to mirror-flip and mirror-flip them yourself. Future versions of the LRO data may contain more information, thus making it possible to do this automatically. SPICE kernels containing the information necessary to do this automatically will also be released in the future.

January 25, 2010

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.

January 24, 2010

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.

June 6, 2009

(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).

July 24, 2008

IMG2PNG should now properly convert calibrated Messenger images.

February 16, 2008

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).

November 13, 2007

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.

May 26, 2007

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 or not. Previously this value was only used when calibrating. This is especially useful for 16 bit input images with an intensity range of 0-4095.

April 8, 2006

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.

November 13, 2005

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.

November 13, 2005

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

November 12, 2005

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.

November 6, 2005

(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.

 

Back to main page.