1
0

More than 5 years have passed since last update.

画像を平行移動してずらす

Last updated at Posted at 2015-07-04

Imagemagickでリサイズや拡大縮小する方法はよく見つかるけど、サイズや縮尺を変えずに画像をそのまま平行移動する方法は見つけるのに苦労したので、ここに書いとく。

紹介したAffine以外にもSRTという形式があるけど個人的にはAffineのほうが簡単だと思う。

例として「 A.png をx方向に3、y方向に−5だけ平行移動した画像を B.png に保存」するコマンドを考える。

Affine

$ convert A.png -distort Affine '10,10 3,5' B.png

'10,10 3,5' は(10,10)の位置にある点を(3,5)の位置に移すような変換を全体にかけろ、という命令。

注意

平行移動してくれるだけと思いきや、画素値も微妙に変わってしまうようです。
たぶんArea-Resamplingとかが関係していると思うけど、とくに深追いしていない。

確かめるために距離0で平行移動した画像を作って元画像とくらべてみる

$ convert A.png -distort Affine '10,10 10,10' A2.png
$ compare A.png A2.png compare.png

compare.pngには相違点が赤で表示されるので、そこそこ赤が出ているのがわかると思う。

参考

$ convert -version
Version: ImageMagick 6.9.0-10 Q16 x86_64 2015-03-09 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png xml zlib

Distorting -- IM v6 Examples
ImageMagick - 2枚の画像を比較! - mk-mode BLOG

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0