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 has a somewhat 'quick-and-dirty' look and is not particularly user friendly; it runs in a command prompt ("DOS") window. It has been tested under Windows 7 and Windows 10 but should also work under Windows Vista, Windows 8.x and probably Windows XP. Note that starting from March 2020 you'll need a 64 bit version of Windows to run IMG2PNG. This was a necessary change to make it possible to convert extremely big files.
This utility should work for converting lots of different PDS files, e.g. MER, Pathfinder, Voyager, Galileo, Cassini, Stardust, various Mars orbiters and landers, Mariner 9/10 (!), Viking Orbiter, Viking Lander, Magellan, Clementine, Messenger, Phoenix, Venus Express, LRO, New Horizons, Dawn, Curiosity, Rosetta, Chang'e 3 etc. The current version does not support PDS4. Support for PDS4 will be added in the future.
Download and setup | How to use | Updates and changes |
IMG2PNG and associated files can be downloaded here (5.6 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 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, i.e. raw images (not derived products
like mosaics etc.). 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.
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 unless the input file contains exactly three bands (in that case the output is RGB). This means that if you convert a PDS file that contains several individual images (e.g. images at different wavelengths) you usually 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: |
(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 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 (14). |
(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 |
(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: |
(13) -allow_fneg If the input image contains floating point data and -fstretch is not used, by default IMG2PNG will produce a 16 bit image where the highest floating point value is mapped to 65535. If IMG2PNG detects that the input image is a DEM, the lowest floating point value is mapped to 0.0. If the input images is a normal image (not a DEM), the lowest floating point value is assumed to be 0.0 and that gets mapped to 0 (this does not apply if the highest value is less than 0.0 though). If -allow_fneg is used, the floating point value that really is the lowest values gets mapped to 0 instead if that value is less than 0.0. Usually you do not want this because in calibrated images it is fairly common to have a few values <0 in the black background space that is commonly visible in spacecraft images. |
(14) -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. |
(15) -force_hflip and -force_vflip -force_hflip and -force_vflip cause IMG2PNG to flip the input images horizontally and/or vertically, respectively, regardless of whether IMG2PNG "thinks" the images must be flipped or not. This is especially useful for images from very recent missions that IMG2PNG does not yet know how to handle. |
(15) -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. |
(16) -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. |
(17) -force_byteswap Forces IMG2PNG to byte swap 16 bit image data, regardless of whether it's needed or not according to data from the file header and/or detached LBL file. This can be used in rare cases, e.g. when the file header is erroneous (this has happened but is very rare) or if a bug prevents IMG2PNG from correctly determining if byte swapping is needed (this has also happened but is hopefully even more rare). |
(18) -force_nobyteswap Like -force_byteswap except that this forces IMG2PNG never to byte swap no matter what. |
(19) -force_dem Forces IMG2PNG to treat the input file(s) as a DEM if possible. For this to be possible the sample type in the input file(s) has to be signed. If this is the case, an appropriate constant is added to the data to get rid of negative values. For example, if the input samples are 16 bit signed integers, 32768 is added. |
(20) -metadata_table This can be used to write various interesting metadata (e.g. viewing geometry) from all of the converted images to a single output file, one row per image. If you use this, all of the images you want to convert should be from the same spacecraft. Currently, IMG2PNG can output three different types of metadata files; it automatically selects which one depending on the spacecraft/instruments. There is one type for Rosetta images, one for Mariner 9 and 10 images and one "generic" type for everything else; the last type is optimized for spacecraft with framing cameras, e.g. Cassini. More types will probably be added later, e.g. for landers. The filename can be selected by adding ":name", for example -metadata_table:test_file.txt will produce a file named test_file.txt. If ":name" is omitted a default name will be used. |
(21) -debayer, -debayer_ash and -debayer_exp This is
used to debayer color images and is applicable for images from e.g. Chang'e 3. The Bayer color filter arrangement can be specified, for example -debayer:RGGB (or debayer_ash:RGGB or debayer_exp:RGGB) for the color arrangement in the schematic image below. This is also the default if no color filter arrangement is specified; it is used by e.g. Chang'e 3. |
January 29, 2024 Corrected a bug that could result in IMG2PNG terminating (or even crashing) without converting all of the files it should convert. Fixed a bug that could occur in the conversion of a 16 bit VICAR formatted file when no detached LBL file is available. |
July 20, 2023 IMG2PNG can now convert files containing 64 bit floating point data. In earlier versions, floating point data could be converted only if it was 32 bits. |
July 30, 2020 Corrected a bug that occurred when converting multiband files containing floating point data if the number of bands was not 3. |
April 7, 2020 Corrected a bug that was caused by internal changes that had to be made when IMG2PNG became a 64 bit application last month. This bug affected the calibration of Cassini images and in special cases it could also mess up the conversion of images files containing floating point data. |
March 16, 2020 IMG2PNG is now a 64 bit program (earlier versions were 32 bit). This was a necessary change to make it possible to convert extremely large images, in particular 46080x23040 pixel LRO DEMs. Also fixed a bug that caused problems converting certain LROC images if the associated index files had a record length that may be inconsistent with the version number of the index file (I'm not completely sure if all index files that have the same version number should also have the same record length but at least IMG2PNG now correctly converts the images when this happens). |
April 4, 2018 Fixed a bug that could cause files containing floating point data to be incorrectly converted if they contained negative values that were real data and not 'special values' (this applies to e.g. DEMs). Also made a minor change to make the conversion of files containing JIRAM images slightly simpler (now you don't need to use -force_nobyteswap and -force_hflip to correctly convert JIRAM images). |
May 1, 2017 Added the -force_dem command line option. This forces IMG2PNG to treat the input file as a DEM if the input file's sample type makes this possible. |
October 8, 2016 IMG2PNG now correctly converts all images from India's Mars Orbiter Mission. |
March 15, 2016 Fixed a few bugs and added one new feature. (1) Fixed a bug which sometimes resulted in an incorrect arrangement of the framelets in LROC WAC images (in particular, in many cases they were not flipped vertically when doing so is necessary). Added support for the most recent version of the LROC index files (index.tab and cumindex.tab). In addition, IMG2PNG now reads these files even if they are corrupted, provided that they are not severly corrupted. At the time of this writing there are 77 corrupted lines in the most recent cumindex.tab file. IMG2PNG can now read this file with the exception of the 77 corrupted lines. (2) Fixed a bug which could cause the header to be missing from the metadata file that is created when -metadata_table is used. Also made some improvements to the metadata table and added a Chang'e 3-specific version of the metadata table. (3) Fixed a bug which could cause some of the Chang'e 3 images to be either incorrectly converted or not converted at all. (4) The automatic contrast stretch applied to thumbnails when using -t or -thumbn was usually far to severe, making many of the thumbnails almost useless. Color thumbnails also sometimes looked a bit strange. These bugs have now been fixed. (5) It is now possible to debayer (also known as demosaicking) the input images when applicable. See the description of the -debayer, -debayer_ash and debayer_exp command line options above. |
January 13, 2016 A relatively big update with several new command line options and a few relatively minor bug fixes. Fixed some bugs that affected how IMG2PNG handled Rosetta images, in particular they are now flipped correctly; IMG2PNG now never outputs mirror flipped Rosetta images. Fixed a bug that in rare cases caused IMG2PNG not to byte swap 16 bit input data that needs a byte swap. Changed how IMG2PNG maps values from floating point images to 16 bits (range 0 to 65535) when the lowest floating point value is less than 0 and the input image is a normal image and not e.g. a DEM. Crappy data near the top in Mariner 10 images now gets replaced with black when the images are converted. Added several new command line options: |
March 14, 2015 Fixed a bug which caused the output image to be completely black when converting MEx HRSC DTM files. IMG2PNG now correctly converts input files containing processed LROC images created from the original, raw data. An example is mosaics of LROC NAC images. Earlier versions of IMG2PNG confused these images with the raw images, resulting in strange (and incorrect) output images. Several minor internal improvements. |
May 3, 2014 Fixed several bugs and made some changes: (1) Fixed a bug which made it impossible to convert files unless you opened a command
prompt in the directory containing the files. Doing something like "img2png
c:\foo\*.img" from a different directory didn't work, you had to open the command
prompt in the c:\foo directory and then do "img2png *.img". The resulting PNG
files are written to the directory containing the original files so in the example above
they get written to the c:\foo directory. I'm a bit surprised that almost no one had
complained because of this bug which had been present for a long time. |
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). Fixed some Curiosity-related issues. 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. |
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. |
Back to main page.