2010.02.08 10:47 "[Tiff] fftw and TIFF files", by

2010.02.09 07:58 "Re: [Tiff] OpenImageIO; was Re: fftw and TIFF files", by

Hi,

This OpenImageIO Project looks really good. I think I'll give it a try because I'm using C++. I'll let you know about the results.

Thanks and best regards,
Debora

-----Mensaje original-----

De: tiff-bounces@lists.maptools.org [mailto:tiff-bounces@lists.maptools.org] En nombre de Larry Gritz Enviado el: lunes, 08 de febrero de 2010 18:43 Para: tiff@lists.maptools.org

Asunto: [Tiff] OpenImageIO; was Re: fftw and TIFF files

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.

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.