LoginSignup
0
2

More than 5 years have passed since last update.

ImageMagick | bash > 4枚の画像の重ね合わせ > overlay_image_171003_exec

Last updated at Posted at 2017-10-03
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)

関連

ImageMagick > 画像のoverlapping > composite -compose over LN.png background.png out.png

複数画像の合成

compositeによる合成は2つの画像までのようだ。

複数画像を合成する処理を実装してみた。

重ね合わせする元画像は以下で作成したもの。
ImageMagick | bash > white, blue, yellow, redの色を持つ4つのファイルを作成する > 同じサイズ | 異なるサイズ | 異なるサイズ+背景:透明

code v0.1

overlay_image_171003_exec
#!/usr/bin/env bash

files[0]="gray.png"
files[1]="blue.png"
files[2]="yellow.png"
files[3]="red.png"

LAST_IDX=3

for istart in $(seq 0 $((LAST_IDX-1)));do
  inext=$((istart+1))
  echo $istart $inext
  if [ $istart = 0 ];then
    composite -compose over ${files[istart]} ${files[inext]} out.png
  else
    composite -compose over wrk.png ${files[inext]} out.png  
  fi
  mv out.png wrk.png
done

qiita.png

code v0.2 > 実行時引数を使用

overlay_image_171003_exec
#!/usr/bin/env bash

#
# v0.2 Oct. 03, 2017
#   - take runtime parameters (inputs and output)
# v0.1 Oct. 03, 2017
#   - composite multiple images
#

if [ $# -le 4 ];then
    echo "Error:invalid parameter"
    echo
    echo "Usage:"
    echo "  $0 [in1] [in2] [in3] [in4] [out]"
    exit
fi

IN_FILES[0]=$1
IN_FILES[1]=$2
IN_FILES[2]=$3
IN_FILES[3]=$4
OUT_FILE=$5

LAST_IDX=3
STOP_IDX=$((LAST_IDX-1))

for istart in $(seq 0 $STOP_IDX);do
  inext=$((istart+1))
  #echo $istart $inext
  if [ $istart = 0 ];then
    composite -compose over ${IN_FILES[istart]} ${IN_FILES[inext]} out.png
  else
    composite -compose over $OUT_FILE ${IN_FILES[inext]} out.png  
  fi
  mv out.png $OUT_FILE
done

0
2
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
0
2