Image-RGBA

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension Image::RGBA.

0.04  Sat Jan 04 2003
        - Moved files around so that make install actually does
          something

0.03  Fri Dec 29 2002
        - Changed the api so that pixels are now read/written with the
          Pixel() method, Sample() no longer exists.  An Image::Magick
          object can be retrieved at any time with Image().

0.02  Thu Oct 31 2002
        - Split into two modules; low level sampling in Image::RGBA
          and photo specific stuff in Image::Photo

0.01  Tue Sep 10 12:35:58 2002
	- original version; extracted kicking and screaming from
	  Image::Panorama

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    'NAME'		=> 'Image::RGBA',
    'VERSION_FROM'	=> 'lib/Image/RGBA.pm', # finds $VERSION
    'PREREQ_PM'		=> {Image::Magick}, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
      (ABSTRACT_FROM => 'lib/Image/RGBA.pm', # retrieve abstract from module
       AUTHOR     => 'Bruno Postle <bruno@postle.net>') : ()),
);

README  view on Meta::CPAN

   Blue information.

 - Uses spline16 pixel interpolated sampling for high quality results.

 - Radial brightness and barrel distortion correction.  Independent of
   image orientation and brightness, so each camera should have one set
   of values that work in all situations.  

DISADVANTAGES

 - Since it works at a lower level than the Image::Magick Get() method,
   it's not quite as flexible.

BUGS

 - Probably.

TODO

 - Make faster (rewrite in C, contributions welcome).

README  view on Meta::CPAN


To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES

This package depends on perl and the Image::Magick perl module.

These are available from CPAN, ActiveState, etc..

COPYRIGHT AND LICENCE

Copyright (C) 2002 Bruno Postle <bruno@postle.net> All Rights Reserved.
This module is Free Software. It may be used, redistributed and/or
modified under the same terms as Perl itself.

examples/correct.pl  view on Meta::CPAN


# A demonstration of Image::photo
#
# Image::Photo, samples images using high quality interpolation.  radial
# brightness and lens barrel correction can be applied at this sampling stage.
# 
# So you can use this script for batch correction of photographs.

use strict;
use warnings;
use Image::Magick;       # image stuff
use lib 'lib';
use Image::Photo;        # quality image sampling of photos

if ($#ARGV ne 5)
{
    die "Incorrect number of arguments\n" .
    "Usage $0 <a> <b> <c> <radlum> <infile> <outfile>\n" .
    "e.g.  $0 0.0 -0.02 0.0 10.0 input.jpg output.jpg\n";
}

my ($a, $b, $c, $radlum, $in_file, $out_file) = @ARGV;

# sort out inputImage::Magick object

my $in = new Image::Magick;
   $in->ReadImage ($in_file);

# we are going to have the same size for the output image

my $width = $in->Get ('width');
my $height = $in->Get ('height');

print STDERR "Image is $width"."x"."$height.\n";

# all this just creates a blank Image::Magick canvas

my $out = new Image::Magick (size => $width ."x". $height);
   $out->ReadImage ("NULL:Black");
   $out->Transparent (color => 'black');

# create objects for reading and writing

my $inphoto = new Image::Photo (image => $in,
                               radlum => $radlum,
                                    a => $a, b => $b, c => $c);

my $outrgba = new Image::Photo (image => $out);

examples/correct.pl  view on Meta::CPAN

    {
        if ($u >= 0 && $u < $width && $v >= 0 && $v < $height)
        {
            $outrgba->Pixel ($u, $v, $inphoto->Pixel ($u, $v));
        }
    }
    print STDERR "#";
}
print STDERR "\n";

# Convert from the RGBA blob back to an Image::Magick object

$outrgba->Image->Write ($out_file);

1;

examples/scale-magick.pl  view on Meta::CPAN

#!/usr/bin/perl

# This is an example script that does exactly the same job as the
# scale.pl script (except by using Image::Magick functions only).  Use
# it to scale an image by any factor.

use strict;
use warnings;
use Image::Magick;

if ($#ARGV ne 2)
{
    die "Incorrect number of arguments\n" .
    "Usage $0 <scale> <infile> <outfile>\n" .
    "e.g.  $0 1.618 input.jpg output.png\n";
}

my ($scale, $in_file, $out_file) = @ARGV;

# sort-out the input image

my $input = new Image::Magick;
   $input->Read ($in_file);

# the output image needs a size

my $width  = int ($scale * $input->Get ('width'));
my $height = int ($scale * $input->Get ('height'));

my $output = new Image::Magick (size => "$width" ."x". "$height");
   $output->Read ("NULL:Black");
   $output->Transparent (color => 'black');

# iterate through all the rows of the _output_ image

for my $v (0 .. $height - 1)
{
    for my $u (0 .. $width - 1)
    {
        my $pixel = $input->Get ('pixel['. int ($u/$scale) .','. int ($v/$scale) .']');

examples/scale-rgba.pl  view on Meta::CPAN

#!/usr/bin/perl

# This is an example script demonstrating Image::RGBA interpolation.
# Use it to scale an image by any factor.

use strict;
use warnings;
use Image::Magick;
use lib 'lib';
use Image::RGBA;

if ($#ARGV ne 3)
{
    die "Incorrect number of arguments\n" .
    "Usage $0 <scale> (simple|linear|spline16) <infile> <outfile>\n" .
    "e.g.  $0 1.618 spline16 input.jpg output.png\n";
}

my ($scale, $sample, $in_file, $out_file) = @ARGV;

# sort-out the input image

my $input = new Image::Magick;
   $input->Read ($in_file);

my $rgba = new Image::RGBA (image => $input, sample => $sample);

# the output image needs a size

my $width  = int ($scale * $input->Get ('width'));
my $height = int ($scale * $input->Get ('height'));

my $output = new Image::Magick (size => "$width" ."x". "$height");
   $output->Read ("NULL:black");
   $output->Transparent (color => 'black');

my $rgba_out = new Image::RGBA (image => $output);

# iterate through all the rows of the _output_ image

for my $v (0 .. $height - 1)
{
    for my $u (0 .. $width - 1)

examples/sphere-slicer.pl  view on Meta::CPAN

# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.

use strict;
use warnings;

use Image::Magick;             # image stuff
use Math::Trig;                # math stuff
use Math::Trig ':radial';      # more math stuff
use lib 'lib';                 # help, where are we?
use Image::RGBA;               # quality image sampling

if ($#ARGV ne 2)
{
    die "Incorrect number of arguments\n" .
    "Usage $0 <number of panels> <circumference> <filename>\n" .
    "e.g.  $0 16 1600 input.jpg\n";

examples/sphere-slicer.pl  view on Meta::CPAN

# output height, always half the circumference
my $out_height = int ($circumference / 2);

# output radius in pixels
my $rho = $out_height / pi;

# width of individual panels/segments
my $out_width = int (($circumference / pi) * tan (pi / $segments));

# open the input image
my $in = new Image::Magick;
   $in->ReadImage ($in_file);

my $in_width = $in->Get ('width');
my $in_height = $in->Get ('height');
print STDERR "Input image is ". $in_width ."x". $in_height .".\n";

# object to sample pixels from
my $rgba = new Image::RGBA (image => $in,
                           sample => 'spline16');

# do each panel/segment
for my $panel (0 .. $segments - 1)
{
    my $out = new Image::Magick (size => $out_width ."x". $out_height);
       $out->ReadImage ('NULL:black');
       $out->Transparent (color => 'black');

    my $rgba_out = new Image::RGBA (image => $out);

    # This is the angle to rotate the world for each panel

    my $theta_offset = (pi / $segments) * ($panel + 0.5) * 2;

    # do each row in the output image

lib/Image/Photo.pm  view on Meta::CPAN

images

Provided is optional radial luminance correction - Suitable for sampling
photographs where there is a known light falloff from the centre of the
image to the edges.

Also radial lens distortion can be corrected at the same time.

=head1 USAGE

You can start by creating an Image::Magick object:

    my $input = new Image::Magick;
    $input->Read ('input.jpg');

=cut

use strict;
use warnings;

use Image::RGBA;

use vars qw /@ISA/;
@ISA = qw /Image::RGBA/;

our $VERSION = '0.01';

=pod

Use an Image::Magick object as the basis of an Image::Photo
object:

    my $rgba = new Image::Photo (sample => 'linear',
                                 radlum => 0,
                                  image => $input,
                                      a => 0.0,
                                      b => -0.2,
                                      c => 0.0);

The parameters 'sample', 'radlum', 'a', 'b' and 'c' are quality settings

lib/Image/RGBA.pm  view on Meta::CPAN


 http://www.fh-furtwangen.de/~dersch/interpolator/interpolator.html

An RGBA image file is very simple, just each channel stored one after
the other with no delimiters for each pixel in turn.  There is no header
data, so you have to know the image dimensions to reconstruct an RGBA
image.

=head1 USAGE

You can start by creating an Image::Magick object:

    my $input = new Image::Magick;
    $input->Read ('input.jpg');

=cut

use strict;
use warnings;

use Image::Magick;

our $VERSION = '0.04';

=pod

Use an Image::Magick object as the basis of an Image::RGBA
object:

    my $rgba = new Image::RGBA (sample => 'linear',
                                 image => $input);

=cut

sub new
{
    my $class = shift;

lib/Image/RGBA.pm  view on Meta::CPAN

        return;
    };

    my ($r, $g, $b, $a) = $self->_sample ($m, $n);

    return $self->_pack ($r, $g, $b, $a);
}

=pod

You can access the image as an Image::Magick object at any time using the Image
method:

    $rgba->Image->Write ('filename.jpg');

=cut

sub Image
{
    my $self = shift;

lib/Image/RGBA.pm  view on Meta::CPAN


    elsif ($self->{sample} eq 'spline16')
        { ($r, $g, $b, $a) = $self->_spline16 ($m, $n) }

    return ($r, $g, $b, $a);
}

=pod

'simple' sampling is crude non-interpolated pixel sampling, equivalent
to the Image::Magick::Get ("pixel[$x,$y]") method.  Use this when speed
rather than quality is required.

=cut

sub _simple
{
    my $self = shift;

    my $m = shift;
    my $n = shift;

lib/Image/RGBA.pm  view on Meta::CPAN


sub _imagetoblob
{
    my $imagemagick = shift;

    $imagemagick->Set (magick => 'RGBA', depth => '8');
    \$imagemagick->ImageToBlob;
}

# used when we have an Image::RGBA object but we really need an
# Image::Magick object
# 
# FIXME should support other than 1 byte per pixel

sub _blobtoimage
{
    my $self = shift;

    my $imagemagick = new Image::Magick (magick => 'RGBA',
                                          depth => '8',
                                           size => $self->{width} ."x". $self->{height});

    $imagemagick->BlobToImage (${$self->{blob}});

    return $imagemagick;
}

=pod

t/000_Load_Modules.t  view on Meta::CPAN

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use lib './';
use Data::Dumper;

use Test;
BEGIN { plan tests => 8 };

use Image::Magick;
print "ok 1\n";

my $image = new Image::Magick;
print "ok 2\n";

$image->ReadImage ('t/data/Monument.jpg');
print "ok 3\n";

use Image::RGBA;
print "ok 4\n";

my $object = new Image::RGBA (image => $image,
                             sample => 'simple');

t/001_Load_Modules.t  view on Meta::CPAN

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use lib './';
use Data::Dumper;

use Test;
BEGIN { plan tests => 8 };

use Image::Magick;
print "ok 1\n";

my $image = new Image::Magick;
print "ok 2\n";

$image->ReadImage ('t/data/Monument.jpg');
print "ok 3\n";

use Image::Photo;
print "ok 4\n";

my $object = new Image::Photo (image => $image,
                              radlum => 10,



( run in 0.833 second using v1.01-cache-2.11-cpan-beeb90c9504 )