AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2010.02.08 10:47 "[Tiff] fftw and TIFF files", by
2010.02.08 16:48 "Re: [Tiff] fftw and TIFF files", by Bob Friesenhahn
2010.02.08 17:43 "[Tiff] OpenImageIO; was Re: fftw and TIFF files", by Larry Gritz
2010.02.09 07:58 "Re: [Tiff] OpenImageIO; was Re: fftw and TIFF files", by
2010.03.05 16:30 "Re: [Tiff] Tiffs", by Deborah
2010.02.08 21:39 "[Tiff] FFT on two TIFF images", by Richard Nolde
[...]

2010.02.08 17:43 "[Tiff] OpenImageIO; was Re: fftw and TIFF files", by Larry Gritz

I'll take this opportunity to point people to another open source project I'm administering: http://www.openimageio.org

OpenImageIO (OIIO for short) is a format-agnostic API for reading and writing image files. TIFF is among many image file formats supported (using libtiff underneath, of course). But even if you are only interested in TIFF, you may find that using OIIO's API's to read TIFF files is simpler and more straightforward than struggling with the raw libtiff calls. There are also a lot of other useful features of the library, including an image tile cache that lets you literally access hundreds of GB of image data without worrying about which parts are in memory or which files are opened, and a filtered texture system.

But the aspect of OIIO that is relevant to Debora's question is that the basic API for reading images automatically does format conversion and will read data into buffers with strides. For example, your basic issue is that you want to read data from a TIFF file (perhaps with arbitrary bit depth) into a buffer of double[2], but you want the pixel values to end up in every other buffer slot. Piece of cake. You can do it with about 7 lines of code:

ImageInput *in = ImageInput::create (filename);
ImageSpec spec;
in->open (filename, spec); /* res is now in spec.{width,height} */

        fftw_complex *img1 = fftw_malloc(sizeof(fftw_complex) * spec.width * spec.height);

        memset (img1, 0, sizeof(fftw_complex) * spec.width * spec.height);  // zero it out

in->read_image (TypeDesc::DOUBLE /* desired data format */,
                pixels /* buffer */,
                2*sizeof(double) /* optional: x stride */);
in->close ();
delete in;

This will work for scanline or tiled images, any bit depth with proper conversion to double, etc. (Though as I've written it, the code assumes a single data channel. To be robust, it should check spec.nchannels before proceeding with the read_image.) Also, if you had the need to read other file formats, this code would not need to be modified, as long as it's a file format that OIIO understands or can find a plugin for.

I hope you are using C++. If it's straight C, never mind.

-- lg

On Feb 8, 2010, at 8:48 AM, tiff-request@lists.maptools.org wrote:

> ----------------------------------------------------------------------
>

I'm trying to do the phase correlation of two TIFF images (a reference image and an image received via fax) to determine if they are similar and or have any offset.

For this I'm using LibTIFF and FFTW. In order to do this I need to load the Image data to the FFTW input arrays:

fftw_complex *img1 = ( fftw_complex* )fftw_malloc( sizeof( fftw_complex ) * width * height ); <- this is the input array (it's a double[2] composed of the real and imaginary parts of a complex number)

As I said, what I need to do is load the image data on that input array. I would like to do something like this:

for( i = 0; i < height ; i++ ) {

    for( j = 0 ; j < width ; j++) {

        img1[k][0] = <- here goes the image data

        img1[k][1] = 0.0;

    }

}

This kind of thing is what I've seen in an OpenCV example for reading TIFF images, but it doesn't seem to work so I decided to try with LibTIFF.

--
Larry Gritz
lg@larrygritz.com