10 GetOptions('grey|gray|g'=>\$grey,
15 die "Only one of --grey or --pure can be used at a time\n";
18 my $left_name = shift;
19 my $right_name = shift;
23 my $left = Imager->new;
24 $left->read(file=>$left_name)
25 or die "Cannot load $left_name: ", $left->errstr, "\n";
27 my $right = Imager->new;
28 $right->read(file=>$right_name)
29 or die "Cannot load $right_name: ", $right->errstr, "\n";
31 $left->getwidth == $right->getwidth
32 && $left->getheight == $right->getheight
33 or die "Images must be the same width and height\n";
35 $left->getwidth == $right->getwidth
36 or die "Images must have the same number of channels\n";
40 $out = grey_anaglyph($left, $right);
43 $out = pure_anaglyph($left, $right, $green);
46 $out = anaglyph_images($left, $right);
49 $out->write(file=>$out_name, jpegquality => 100)
50 or die "Cannot write $out_name: ", $out->errstr, "\n";
54 Usage: $0 left_image right_image out_image
60 my ($left, $right) = @_;
62 my $expr = <<'EXPR'; # get red from $left, green, blue from $right
63 x y getp1 red x y getp2 !pix @pix green @pix blue rgb
65 my $out = Imager::transform2 ({ rpnexpr=>$expr, }, $left, $right)
66 or die Imager->errstr;
72 my ($left, $right) = @_;
74 $left = $left->convert(preset=>'grey');
75 $right = $right->convert(preset=>'grey');
78 x y getp1 red x y getp2 red !right @right @right rgb
81 return Imager::transform2({ rpnexpr=>$expr }, $left, $right);
85 my ($left, $right, $green) = @_;
87 $left = $left->convert(preset=>'grey');
88 $right = $right->convert(preset=>'grey');
92 # output is rgb(first channel of left, first channel of right, 0)
94 x y getp1 red x y getp2 red 0 rgb
98 # output is rgb(first channel of left, 0, first channel of right)
100 x y getp1 red 0 x y getp2 red rgb
104 return Imager::transform2({ rpnexpr=>$expr }, $left, $right);
109 =for stopwords anaglyph anaglyph.pl
111 anaglyph.pl - create a anaglyph from the source images
116 perl anaglyph.pl left_input right_input output
119 perl anaglyph.pl -g left_input right_input output
120 perl anaglyph.pl --grey left_input right_input output
121 perl anaglyph.pl --gray left_input right_input output
123 # pure anaglyph (blue)
124 perl anaglyph.pl -p left_input right_input output
125 perl anaglyph.pl --pure left_input right_input output
127 # pure anaglyph (green)
128 perl anaglyph.pl -p --green left_input right_input output
129 perl anaglyph.pl --pure --green left_input right_input output
134 See L<http://www.3dexpo.com/anaglyph.htm> for an example where this might
137 Implementation based on the description at
138 http://www.recordedlight.com/stereo/tutorials/ps/anaglyph/pstut04.htm
139 though obviously the interactive component is missing.
143 Using JPEG as the output format is not recommended.
147 Tony Cook <tonyc@cpan.org>
149 =for stopwords Oppenheim
151 Thanks to Dan Oppenheim, who provided the impetus for this sample.