[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20001007: stripping header information from PNG Satellite Imagery

>From: Larry Riddle <address@hidden>
>Organization: UCSD/Scripps
>Keywords: 200010072030.e97KUc410224 ldm-mcidas PNG


>This may have been mentioned and I missed it.  Since the imagery is now 
>coming down the pipe in PNG format, is there a way for those of us who do 
>not run McIdas to save this imagery as PNG's or GIF's?

The format of the compressed image allows one to strip off a header block
leaving a simple, PNG compressed image that may be viewed in web browsers,
ImageMagick, etc.  The length of the header block, however, is not fixed,
so one would have to write a simple routine that:

o opens the file
o determines the byte order of the values (big endian vs little endian)
o reads the appropriate word to see where the PNG compressed portion
o discards all header information up until the PNG compressed portion
o writes the PNG compressed portion out to a new file

This filter would easily be run as an LDM pqact.conf action, thus allowing
you to save the imagery in the form you want, where you want.

>We'd like to be able to use this imagery without having to use McIdas.  It 
>seems a waste to send it all to the bit bucket.

The uncompressed imagery does not require McIDAS in any way.  It is
being used in a variety of display/analysis packages such as
GEMPAK/GARP/NMAP, McIDAS, WXP, and at least one home grown system.

The PNG compressed file format I came up with was designed to be as
simple as possible:

             AREA file                  PNG file
       +--------------------+   +----------------------+
       |  area directory    |   |  area directory      |
       +--------------------+   +----------------------+
       +--------------------+   +----------------------+
       | navigation codicil |   |  navigation codicil  |
       +--------------------+   +----------------------+
       +--------------------+   +----------------------+
       | calibration codicil|   | calibration codicil  |
       +--------------------+   +----------------------+
       +--------------------+   +----------------------+
       |    aux block       |   |      aux block       |
       +--------------------+   +----------------------+
       +--------------------+   +----------------------+
       |                    |   |  AREA file comment   |
       |                    |   |       cards          |
       |    image lines     |   +----------------------+
       |                    |   +----------------------+
       |                    |   |                      |
       +--------------------+   |    PNG compressed    |
       +--------------------+   |       image          |
       | AREA file comment  |   |                      |
       |      cards         |   |                      |
       +--------------------+   +----------------------+

The area directory contains the byte offsets of where each of the other
directories/blocks begin.  Also, the word length of all words in the
non PNG compressed portion are 4-bytes.

The byte order of the file can be determined from the second word of
the file header which is always the number '4'.  If your application
opens the file and this number looks like a large negative number,
then the byte ordering of the 4-bytes words in the header portion are
opposite of the machine you are working on.

You should note that the calibration block, aux block, and comment
cards do not necessarily exist in the AREA file.  The UW imagery that
is being sent right now is pre-calibrated, so there is no calibration
block.  They also do not have aux blocks, but they do have comment
cards at the end (the comment cards record the McIDAS commands that had
been run on the original image to create the product).  Entries in the
area directory tell you this (by way of where they begin or where a
different block begins).

The PNG compression is only done on the image line portion of the
AREA file.  The comment cards, if they exist, are moved to just
after all of the other directories/codicils in the PNG compressed file.

A code snippit from pnga2area.c shows how to locate the beginning of
the PNG compressed image lines:

    ** Now figure out where the beginning of the PNG compressed image is.

    datoff = imgdir[33];
    datlen = datoff - nbytes;
    cmtlen = 80 * imgdir[63];

    udebug( "datoff: %d", datoff );
    udebug( "datlen: %d", datlen );
    udebug( "cmtlen: %d", cmtlen );

'datoff' (area directory word 33 (zero based)) would be the beginning
of the image lines in an AREA except that I move the comment cards to
that location so that the compressed image lines will be at the end of
the product.

'cmtlen' (area directory word 63 (zero based) is the number of bytes of
comment cards which will be located after all of the
directories/codicils and just before the PNG compressed image.  This
value could be zero.

The beginning of the PNG stuff will be at 'datoff+cmtlen' bytes from the
beginning of the file.  Once you know this, you can write a simple
filter that strips off the header stuff and writes the PNG compressed
image portion to a file of your choosing.

I hope that this helps.


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.