[5b3f5b]: bin / erect2mercator Maximize Restore History

Download this file

erect2mercator    75 lines (51 with data), 2.0 kB


use strict;
use warnings;
use File::Spec;
use Panotools::Script;
use Image::Size;

die "usage\n  $0 equirectangular.tif [...]" unless scalar @ARGV;

for my $img_erect (@ARGV)

my $pto_mercator = $img_erect;
$pto_mercator =~ s/\.([[:alnum:]]+)$/-mercator.pto/;

my ($width, $height) = imgsize ($img_erect);
my $height_m = int (0.6180339887 * $width);
my ($volume, $directories, $file) = File::Spec->splitpath ($img_erect);

my $mercator = new Panotools::Script;
if (-e $pto_mercator)
    $mercator->Read ($pto_mercator);
    $mercator->Panorama->Set (w => $width, h => $height_m);
    $mercator->Image->[0]->Set (w => $width, h => $height);
    $mercator->Panorama->Set (v => 360, f => 5, u => 0, w => $width, h => $height_m, n => '"TIFF"');
    $mercator->Image->[0] = new Panotools::Script::Line::Image;
    $mercator->Image->[0]->Set (w => $width, h => $height, v => 360, f => 4, r => 0, p => 0, y => 0, n => "\"$file\"");
$mercator->Write ($pto_mercator);



=head1 NAME

erect2mercator - Extract a mercator projection from an equirectangular image

=head1 Synopsis

  erect2mercator equirectangular.tif


Generates a suitably sized mercator .pto project from a 360 degree
equirectangular image.  Input is in any image format understood by hugin,
output is in TIFF format with an aspect ratio of 1.618:1 (a golden rectangle).

The output filename is derived automatically from the input filename with
'-mercator.pto' appended.  Existing .pto files will not be clobbered but
will be updated when input images change size.


=head1 License

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

=head1 See Also

L<perl>, L<Panotools::Script>

=head1 Author

Bruno Postle <bruno AT postle.net>