> The mailing list has given me the sense that pdl would
 > be much better at masking and probably analysis than
 > what I have now. What is not clear is if pdl will have
 > the file handling (opening) functions I need. Writing
 > an efficient TIFF-stack opener is beyond me.

A work-around for the lack of direct support
for multi-image TIFF and PNM formats for the
current PDL image IO routines is to use the
readflex command to read the frames and
headers produced by a pipe from the tifftopnm
command.

The idea is to open the movie file via a pipe from the
tifftopnm command which converts the multi-image TIFF
data into a multi-image PNM file.  This file can be hand
read via the readflex command if you know the size of
the PNM headers in bytes.  For multi-image TIFFs the
headers for each frame should be identical.

For example, my test all.tif sequence is 420x300 byte
images so the header is "P5\n420 300\n255\n" which
works out to 15 bytes.  Then, use the header size and
the data dimensions and types to call readflex() for each
frame.  E.g.,

$perldl
perlDL shell v1.354
 PDL comes with ABSOLUTELY NO WARRANTY. For details, see the file
 'COPYING' in the PDL distribution. This is free software and you
 are welcome to redistribute it under certain conditions, see
 the same file for details.
ReadLines, NiceSlice, MultiLines  enabled
Reading /cygdrive/f/chm/.perldlrc...
Found docs database 
/cygdrive/f/perl/usr_lib/i686-cygwin-thread-multi-64int/PDL/pdldoc.db
Type 'help' for online help
Type 'demo' for online demos
Loaded PDL v2.4.9 (supports bad values)

pdl> $all = IO::File->new('tifftopnm all.tif 2>/dev/null|');

pdl> ($pnmhdr,$im) = readflex($all, [ { Type=>'byte', NDims=>1, Dims=>[15] }, { 
Type=>'byte', NDims=>2, Dims=>[420,300] } ]);

pdl> ?vars
PDL variables in package main::

Name         Type   Dimension       Flow  State          Mem
----------------------------------------------------------------
$im            Byte D [420,300]            P            0.12MB 
$Pi          Double D []                   P            0.01KB 
$pnmhdr        Byte D [15]                 P            0.01KB 

pdl> ($pnmhdr,$im) = readflex($all, [ { Type=>'byte', NDims=>1, Dims=>[15] }, { 
Type=>'byte', NDims=>2, Dims=>[420,300] } ]);
tifftopnm: writing PGM file

pdl> ?vars
PDL variables in package main::

Name         Type   Dimension       Flow  State          Mem
----------------------------------------------------------------
$im            Byte D [420,300]            P            0.12MB 
$Pi          Double D []                   P            0.01KB 
$pnmhdr        Byte D [15]                 P            0.01KB 

To provide a bit more generality, you could read the
header a line at a time to get the information needed
for the readflex call.  E.g.,

pdl> $all = IO::File->new('tifftopnm all.tif 2>/dev/null|');

pdl> $h1 = <$all>   # read line 1 of header

pdl> p $h1
P5

pdl> $h2 = <$all>  # read line 2 of header

pdl> p $h2
420 300

pdl> $h3 = <$all>  # read line 3 of header

pdl> p $h3
255

pdl> $im = readflex($all [ { Type=>'byte', NDims=>2, Dims=>[420,300] } ]);

and so forth.  A full implementation would need to take
care that you don't read into the binary data while
processing the header info for each frame but assuming
3 lines is probably ok for most cases with the expected
tifftopnm output.

Hope this helps and happy PDL-ing!

--Chris
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to