3 # img2gpiv - Converts an image frame "image_name", containing a PIV image
4 # pair, into a raw data frame "image_name.r" in order to
5 # analyse with gpiv's 'rr' program. Additional header info is
6 # saved in "image_name.h".
8 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
9 # Gerber van der Graaf <gerber_graaf@users.sourceforge.net
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software Foundation,
23 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #------------------------------------------------------------------
27 $VERSION = q
$Id: img2gpiv
.pl
,v
1.12 2008-04-28 12:09:30 gerber Exp
$;
28 $HELP = "Converts images into raw data (extension .r) format with belonging
29 ASCII header or hdf (extension .hdf) format. \n";
30 $USAGE = "gpiv_img2gpiv [-a|--auto] [-c|--cols ncolumns] [--combine] [-d|--depth]
31 [-h|--help] [-hdf] [-i|--inverse] [--suf_a]
32 [--suf_b] [--suf_num N] [-n] [--noclean] [-p] [-r|--rows nrows] [-t] [-v|--version]
36 -x|cross: double image for cross-correlation (default: single image
38 -c|cols ncolumns: the number of columns in the frame (default 1280)
39 --combine combinates two separate image frames to a single one for
40 cross-correlation. Also look at --suf_a/b and --suf_num
41 -d|depth depth: color depth (default 8)
43 -hdf: converts to (or from) hdf format (extension .hdf)
44 -i: inverse conversion; from raw 8-bit data to image format
45 --suf_a with --combine: suffix of first image (default: _a)
46 --suf_b with --combine: suffix of second image (default: _b)
47 --suf_num N with --combine: subsequent numbered images of which the
48 first one with number N and the second N+1. The converted
49 image will be named to file_base_name + N
50 -n: no execute, only print processes
51 -noclean: do not remove existing image
52 -r|rows rows: the number of rows in the frame of a SINGLE image
54 -p: prints process to stdout
55 -t: image type or format (default bmp)
59 #----------------- Default parameters ----------
76 $suf_num_next = -9999;
78 #------------------ Command line arguments handling ----------
81 GetOptions
("h|help", "i|inverse", "n|none", "p|print",
84 "t|type=s" => \
$format,
86 'c|cols=i' => \
$ncols,
90 'suf_num=i' => \
$suf_num,
91 'd|depth=i' => \
$depth,
92 'r|rows=i' => \
$nrows,
104 print ("$VERSION\n");
108 $file_base_name = shift (@ARGV);
112 printf ("\nUsage: $USAGE\n");
117 #------------------ Default variables ----------
146 if ($suf_num != -9999) {
147 $suf_num_next = $suf_num + 1;
148 if ($opt_p || $opt_n) {
149 print ("suf_num=$suf_num suf_num_next=$suf_num_next\n");
153 if ($suf_set == 1 && $suf_num != -9999) {
154 print ("error: a suffix is defined as well as a numbered filenames is used.");
158 if ($opt_p || $opt_n) {
159 print ("c=$ncols r=$nrows i=$opt_i t=$format f=$file_base_name\n");
163 if ($suf_num == -9999) {
164 $file_name_header = $file_base_name.".h";
166 $file_name_header = $file_base_name.$suf_num.".h";
169 if ($opt_combine) {$opt_x = 1;}
170 #------------------ Convert the entire frame to raw data
173 if ($suf_num == -9999) {
174 @args=("convert $file_base_name$suf_a.$format -depth $depth gray:$file_base_name$suf_a.r && \
175 convert $file_base_name$suf_b.$format -depth $depth gray:$file_base_name$suf_b.r");
177 @args=("convert $file_base_name$suf_num.$format -depth $depth gray:$file_base_name$suf_num.r && \
178 convert $file_base_name$suf_num_next.$format -depth $depth gray:$file_base_name$suf_num_next.r");
181 if ($suf_num == -9999) {
182 @args=("convert $file_base_name$suf_a.$format -depth $depth gray:$file_base_name$suf_a.r && rm $file_base_name$suf_a.$format && \
183 convert $file_base_name$suf_b.$format -depth $depth gray:$file_base_name$suf_b.r && rm $file_base_name$suf_b.$format");
185 @args=("convert $file_base_name$suf_num.$format -depth $depth gray:$file_base_name$suf_num.r && rm $file_base_name$suf_num.$format && \
186 convert $file_base_name$suf_num_next.$format -depth $depth gray:$file_base_name$suf_num_next.r && rm $file_base_name$suf_num_next.$format");
191 @args=("convert $file_base_name.$format -depth $depth gray:$file_base_name.r");
193 @args=("convert $file_base_name.$format -depth $depth gray:$file_base_name.r && rm $file_base_name.$format");
196 if ($opt_p || $opt_n) {printf ("@args \n");}
197 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
200 if ($suf_num == -9999) {
201 @args=("cat $file_base_name$suf_b.r >> $file_base_name$suf_a.r && mv $file_base_name$suf_a.r $file_base_name.r && rm $file_base_name$suf_b.r");
202 if ($opt_p || $opt_n) {printf ("@args \n");}
203 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
205 @args=("cat $file_base_name$suf_num_next.r >> $file_base_name$suf_num.r && rm $file_base_name$suf_num_next.r");
206 if ($opt_p || $opt_n) {printf ("@args \n");}
207 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
211 #------------------ Add header info
213 open (OUTH
,">$file_name_header") || die 'can\'t open $file_name_header';
214 printf(OUTH
"Ncolumns: $ncols\n");
215 printf(OUTH
"Nrows: %d\n", $nrows);
216 printf(OUTH
"X_corr: %d\n", $opt_x);
217 printf(OUTH
"Nbits: %d\n", $depth);
218 close (OUTH
) || die 'can\'t close $file_name_header';
220 printf("Ncolumns: $ncols\n");
221 printf("Nrows: %d\n", $nrows);
222 printf("X_corr: %d\n", $opt_x);
223 printf("Nbits: %d\n", $depth);
227 if ($opt_p || $opt_n) {
228 @args=("gpiv_piv2hdf -i -p -e $file_base_name");
230 @args=("gpiv_piv2hdf -i -e $file_base_name");
232 if ($opt_p || $opt_n) {printf ("@args \n");}
233 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
235 @args=("rm $file_base_name.r $file_base_name.h");
236 if ($opt_p || $opt_n) {printf ("@args \n");}
237 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
241 } else { # $opt_i; inverse conversion
243 if ($opt_p || $opt_n) {
244 @args=("hdf2piv -p -e $file_base_name");
246 @args=("hdf2piv -e $file_base_name");
248 if ($opt_p || $opt_n) {printf ("@args \n");}
249 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
252 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format",
255 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format && rm $file_base_name.r $file_base_name.hdf",
260 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format",
263 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format && rm $file_base_name.r $file_base_name.hdf",
270 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format",
273 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format && rm $file_base_name.r",
278 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format",
281 $CMD = sprintf("convert -size %dx%d -depth $depth gray:$file_base_name.r $file_base_name.$format && rm $file_base_name.r",
287 if ($opt_p || $opt_n) {printf ("@args \n");}
288 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
293 # ----------------- That's all folks.