【第3回】Perlで画像処理 -スキュー-
スキュー
■結果
アフィン変換という行列を用いて
演算する方法があるので、次はそっちでちゃんとやってみる。
use strict;
use warnings;
use Imager;
use Image::Size;
use Math::Trig;
my $gain = 1.05;
my $angle = pi / $gain;
my $img = Imager->new;
$img->read(file => 'test.PNG') or die $img->errstr;
my ($max_width, $max_heigth) = imgsize('test.PNG');
my $set_img = Imager->new(xsize => $max_width, ysize => $max_heigth, channels => 4);
for (my $x = 0; $x < $max_width; $x++) {
for (my $y = 0; $y < $max_heigth; $y++) {
my $pixel = $img->getpixel(x => $x, y => $y);
my $tan = tan($angle);
my $x2 = $x;
my $y2 = $y + $tan * $x;
$set_img->setpixel(x => $x2, y => $y2, color => $pixel);
}
}
$set_img->write( file => 'save_test.png') or die $img->errstr;
__END__
■結果
アフィン変換という行列を用いて
演算する方法があるので、次はそっちでちゃんとやってみる。