AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
February 2010

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2010.02.08 17:43 "OpenImageIO; was Re: fftw and TIFF files", by Larry Gritz
2010.02.09 07:58 "Re: OpenImageIO; was Re: fftw and TIFF files", by Debora Gil
2010.03.05 16:30 "Re: Tiffs", by <debita@gmail.com>
2010.03.05 18:50 "Re: Tiffs", by Larry Gritz

2010.03.05 18:50 "Re: Tiffs", by Larry Gritz

I'll answer your question in a separate email (and CC the OIIO dev list). 
No reason to have it on the TIFF list.

	-- lg


On Mar 5, 2010, at 8:30 AM, Deborah wrote:

> Hi Larry,
> 
> I don't remember if I thanked you for your comments on my problem.
> 
> As you adviced me I'm trying to use OpenImageIO. 
> 
> This is the code I have so far:
> 
> #include <imageio.h>
> using namespace OpenImageIO;
> #include <fftw3.h>
> 
> int main (int argc, char *argv[])
> {
>     ImageInput *Recibida = ImageInput::create (argv[1]);
>     ImageInput *Original = ImageInput::create (argv[2]);
> 
>     ImageSpec specRecibida;
>     ImageSpec specOriginal;
> 
>     Recibida->open (argv[1], specRecibida);
>     Original->open (argv[2], specOriginal);
> 
>     int width = specOriginal.width;
>     int height = specOriginal.height;
> 
>     fftw_complex *imgRecibida = ( fftw_complex*
>     )fftw_malloc(sizeof(fftw_complex) * width * height); 
>     fftw_complex *imgOriginal = ( fftw_complex*
>     )fftw_malloc(sizeof(fftw_complex) * width * height); 
>     fftw_complex *imgResultado = ( fftw_complex*
>     )fftw_malloc(sizeof(fftw_complex) * width * height);
> 
>     fftw_plan fft_imgRecibida = fftw_plan_dft_1d( width * height,
>     imgRecibida, imgRecibida, FFTW_FORWARD,  FFTW_ESTIMATE );
>     fftw_plan fft_imgOriginal = fftw_plan_dft_1d( width * height,
>     imgOriginal, imgOriginal, FFTW_FORWARD,  FFTW_ESTIMATE );
>     fftw_plan ifft_Resultado = fftw_plan_dft_1d( width * height,
>     imgResultado,  imgResultado,  FFTW_BACKWARD, FFTW_ESTIMATE );
> 
> unsigned char *pixelsRecibida, *pixelsOriginal;
>     Recibida->read_image (TypeDesc::DOUBLE, pixelsRecibida,
>     2*sizeof(double)); 
>     Original->read_image (TypeDesc::DOUBLE, pixelsOriginal,
>     2*sizeof(double));
> 
>   for(int k = 0 ; k < width * height ; k++ ) {
>         imgRecibida[k][0] = pixelsRecibida[k];            
>         imgRecibida[k][1] = 0.0;
>         
>         imgOriginal[k][0] = pixelsOriginal[k];
>         imgOriginal[k][1] = 0.0;
>     }
> 
> 
>     fftw_execute( fft_imgRecibida );
>     fftw_execute( fft_imgOriginal );
> 
>     return 0;
> }
> 
> I'm trying to do two autocorrelations, as you can see, of two images. One
> is an image received via Fax and the other one is the original image (the
> one that was sent). 
> 
> When I read the image with read_image, I want this image to be read into
> imgRecibida (and the other image in imgOriginal). They are pointers to 
>  typedef double fftw_complex[2];
> 
> I don't understand what is the x stride, or why in your example you said
> 2*sizeof(double), I tried reading the OpenImageIO documentation but still
> can't get the meaning... I suppose this is because I'm not really familiar
> with image processing and also because my native language isn't English,
> so maybe I'm missing some important point. Shouldn't it be
> specRecibida.nchannels * something, AutoStride ? or something like that?
> 
> Do you have any other comment that could help me? 
> 
> Thanks again and I'm sorry if I'm bothering you.
> 
> Deborah
> 
> ---------- Mensaje reenviado ----------
> From: "Larry Gritz" <lg@larrygritz.com>
> To: <tiff@lists.maptools.org>
> Date: Mon, 8 Feb 2010 18:43:23 +0100
> Subject: [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.
> 
>         -- 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/
> 
> 
> 
> ---------- Mensaje reenviado ----------
> From: "Bob Friesenhahn" <bfriesen@simple.dallas.tx.us>
> To: "Gil, Debora, VF-ES (dgilalv) STU" <debora.gil@vodafone.com>
> Date: Mon, 8 Feb 2010 17:48:31 +0100
> Subject: Re: [Tiff] fftw and TIFF files
> On Mon, 8 Feb 2010, Gil, Debora, VF-ES (dgilalv) STU 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.
> 
> Hi Debora,
> 
> Thanks for introducing yourself and the problem you want to solve.  We
> did receive your email.  Your email was not formulated as a simple
> question that any of us can answer.
> 
> Unless you are willing to perform a lot of libtiff-specific work to
> read images, then I suggest using an existing library on top of
> libtiff which simplifies the task for you, and allows using other
> image file formats as well.
> 
> It may be that OpenCV is the ideal library for you and that you will
> achieve more success from discussing the issue with OpenCV developers.
> 
> Bob
> --
> Bob Friesenhahn
> bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
> GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
> 
> 
> 
> 
> 
> -- 
> Déborah

--
Larry Gritz
lg@larrygritz.com