View Source

h1. Session Aims

* Use the File Information Toolkit (FITS) to identify an files format
* Use FITS to validate that an image is well formed and valid
* Use OpenJPEG to create JPEG 2000 images.
* Use OpenJPEG to convert JP2Ks to TIFF images.
* Use the tiffcmp utility to on converted files to check that they're the same

h2. If There's Time

* Use ImageMagick compare to QA images for similarity
* Use ImageMagick to convert our source and result files to GIFs for QA comparison
* Use the imgcmp utility to on converted files to check that they're the same

h1. Session

h2. Installing imgcmp for Image Comparison

First we'll install the comparison tool as it's not on the vm

{code}

[email protected]:~$ sudo apt-get install libjasper-runtime

{code}

h2. Using FITS

The Harvard [FITS | http://code.google.com/p/fits/] toolkit wraps a set of Digital Preservation utilities. Let's see the help page and find out what version we're running:

{code}

[email protected]:~$ fits.sh -h

usage: fits
-h print this message
-i <arg> input file or directory
-o <arg> output file
-r process directories recursively when -i is a directory
-v print version information
-x convert FITS output to a standard metadata schema
-xc output using a standard metadata schema and include FITS xml

[email protected]:~/$ fits.sh -v

0.6.1

{code}

We'll now set up a small directory to allow us to experiment with a single image

{code}

[email protected]:~$ mkdir cli-exercise
[email protected]:~$ cd cli-exercise/
[email protected]:~/cli-exercise$ cp /home/bob/Samples/tiff/4.2.03.tiff ./original.tif

{code}

So we're going to use FITS to identify the format of files first:

{code}

[email protected]:~/cli-exercise$ fits.sh -i original.tif

{code}

So that's a LOT of information, let's see if we can get the format string alone, with the help of grep and a regualr expression, to get the format:

{code}

[email protected]:~/cli-exercise$ fits.sh -i original.tif | grep -i "\bformat"
<identity format="Tagged Image File Format" mimetype="image/tiff" toolname="FITS" toolversion="0.6.1">

{code}

So we can see that this is a tiff image, the following lines check for

{code}

[email protected]:~/cli-exercise$ fits.sh -i original.tif | grep -i "well"
<well-formed toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</well-formed>

[email protected]:~/cli-exercise$ fits.sh -i original.tif | grep -i "valid"
<valid toolname="Jhove" toolversion="1.5" status="SINGLE_RESULT">true</valid>

{code}

We now know that this is and uncompressed TIFF image that is "well-formed and valid", these terms are used by [JHOVE | http://jhove.sourceforge.net/index.html], one of the toolswrapped by FITS. JHOVE explains the terms as follows:

* A digital object is well-formed if it meets the purely syntactic requirements for its format.
* An object is valid if it is well-formed and it meets the higher-level semantic requirements for format validity.

Finally we'll use FITS to check for image compression, OpenJPEG, the tool we're using to convert, only works with uncompressed TIFFs.

{code}

[email protected]:~/cli-exercise$ fits.sh -i original.tif | grep -i "compress"
<compressionScheme toolname="Jhove" toolversion="1.5" status="CONFLICT">Uncompressed</compressionScheme>
<compressionScheme toolname="NLNZ Metadata Extractor" toolversion="3.4GA" status="CONFLICT">65536</compressionScheme>

{code}

Finally let's take a look at the image:

{code}

[email protected]:~/cli-exercise$ display original.tif

{code}

h2. Using OpenJPEG to convert to JPEG 2000

We're now going to look at the OpenJPEG compress tool that can be used to convert TIFF images to JPEG 2000, let's take a look at the manual first (press q to quit it).

{code}

[email protected]:~/cli-exercise$ man opj_compress

{code}

So to create a JPEG 2000 from our original

{code}

[email protected]:~/cli-exercise$ opj_compress -i original.tif -o original.tif.jp2

{code}

We're now going to use the Jpylyzer tool to ensure that our converted file is actually valid:

{code}

[email protected]:~/cli-exercise$ jpylyzer -h
usage: jpylyzer [-h] [-v] [--verbose] jp2In

JP2 image validator and properties extractor

positional arguments:
jp2In input JP2 image(s)

optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--verbose report test results in verbose format

[email protected]:~/cli-exercise$ jpylyzer -v
1.6.0

{code}

{code}

[email protected]:~/cli-exercise$ jpylyzer original.tif.jp2 | grep -i "valid"

{code}

Now, as a final check we'll convert back to TIFF and use a comparison tool to test the conversion.

{code}

[email protected]:~/cli-exercise$ opj_decompress -i original.tif.jp2 -o original.tif.jp2.tif

{code}

Which creates a TIFF from our copy, now we'll compare our original TIFF with our twice converted TIFF

{code}

[email protected]:~/cli-exercise$ tiffcmp original.tif original.tif.jp2.tif
SubFileType tag appears only in original.tif

{code}

This means that our image has converted successfully :), there's only a small difference in the image tags, but the image data is as it should be.

We can assess visually:

{code}
[email protected]:~/cli-exercise$ display original.tif &
[1] 2936
[email protected]:~/cli-exercise$ display original.tif.jp2 &
[1]+ Done display original.tif
[email protected]:~/cli-exercise$ display original.tif.jp2.tif &
[1] 2936

{code}