Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-e.b-one.net (mx-e.one.com [91.198.169.52])
	by mail9.b-one.net (Postfix) with ESMTP id 0305140080A
	for <info@awaresystems.be>; Mon,  8 Feb 2010 18:45:06 +0100 (CET)
Received: by mx-e.b-one.net (Postfix, from userid 106)
	id ECC7294BFFF1; Mon,  8 Feb 2010 18:45:05 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=4 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144]) by
 mx-e.b-one.net (Postfix) with ESMTP id 2EB3894BFFFD for
 <info@awaresystems.be>; Mon,  8 Feb 2010 18:45:05 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id A71F81CEF2FE5; Mon,  8 Feb 2010
 12:44:31 -0500 (EST)
Received: from homiemail-a2.g.dreamhost.com (caiajhbdccac.dreamhost.com
 [208.97.132.202]) by lists.maptools.org (Postfix) with ESMTP id 669AB1CEF2FE1
 for <tiff@lists.maptools.org>; Mon,  8 Feb 2010 12:43:24 -0500 (EST)
Received: from [192.168.1.121] (adsl-75-42-129-102.dsl.pltn13.sbcglobal.net
 [75.42.129.102]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No
 client certificate requested) by homiemail-a2.g.dreamhost.com (Postfix) with
 ESMTP id DABB9D2717 for <tiff@lists.maptools.org>; Mon,  8 Feb 2010 09:43:23
 -0800 (PST)
Mime-Version: 1.0 (Apple Message framework v1077)
From: Larry Gritz <lg@larrygritz.com>
In-Reply-To: <mailman.104.1265647725.647.tiff@lists.maptools.org>
Date: Mon, 8 Feb 2010 09:43:23 -0800
Message-Id: <53B7FCEF-2339-43D5-8623-4BA87C788119@larrygritz.com>
References: <mailman.104.1265647725.647.tiff@lists.maptools.org>
To: tiff@lists.maptools.org
X-Mailer: Apple Mail (2.1077)
Subject: [Tiff] OpenImageIO; was Re: fftw and TIFF files
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

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:

> ----------------------------------------------------------------------
> 
> Date: Mon, 8 Feb 2010 11:47:27 +0100
> From: "Gil, Debora, VF-ES (dgilalv) STU" <debora.gil@vodafone.com>
> Subject: [Tiff] fftw and TIFF files
> To: <tiff@lists.maptools.org>
> 
> Hi,
> 
> 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. 
> 
> Thanks in advance,
> 
> Debora
> 

--
Larry Gritz
lg@larrygritz.com


_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
