GEGL (GEneric Graphics Library) は GIMP が内部で使っている画像処理エンジンで、gegl.exe はその コマンドライン版。フィルターやリサイズなどのオペレーション(ノード)をパイプラインでつなぐ形で処理します。
高さを指定して縮小
# 高さを1600pxで縮小
$gegl = "${HOME}/scoop/apps/gimp/current/bin/gegl.exe" # 環境に合わせる
$inDir = "."
$outDir = "./output"
$targetH = 1600
New-Item -ItemType Directory -Path $outDir -Force | Out-Null # エラー無視
# PNGファイルの一覧を取得し、繰り返し処理
Get-ChildItem $inDir -Filter *.png | ForEach-Object {
$in = ($_.FullName -replace '\\','/') # 入力ファイル。\を/に置き換え
$out = ((Join-Path $outDir ($_.BaseName + ".png")) -replace '\\','/') # 出力ファイル
# 画像の高さを取得しscaleを算出
$img = [System.Drawing.Image]::FromFile($_.FullName)
$scale = $targetH / $img.Height
$img.Dispose()
& $gegl -- `
gegl:load path="$in" `
gegl:scale-ratio x=$scale y=$scale sampler=nohalo `
gegl:save path="$out"
}
gegl.exeの処理内容
読み込み→画像加工処理→描き込みの流れになり、画像加工処理部分を複数の複数つなげる、パイプライン処理になっています。
1.gegle:load … 画像ファイルを読み込み
2.gegl:scale-ratio … 縮小処理、補完方法をNoHaloを指定
3.gegl:save … 画像ファイルを保存
色・レベル補正
8ビットグレースケール限定
# 色→レベル補正(8bitグレスケール限定)
function ToLinear($v255) {
$v = [double]$v255/255.0
if ($v -le 0.04045) { $v/12.92 } else { [math]::Pow( ($v+0.055)/1.055, 2.4 ) }
}
$gegl = "${HOME}/scoop/apps/gimp/current/bin/gegl.exe" # 環境に合わせる
$inDir = "."
$outDir = "./output"
$inL=ToLinear 59
$inH=ToLinear 176
$outL=0.0
$outH=1.0
echo $inL
echo $inH
New-Item -ItemType Directory -Path $outDir -Force | Out-Null # エラー無視
# PNGファイルの一覧を取得し、繰り返し処理
Get-ChildItem $inDir -Filter *.png | ForEach-Object {
$in = ($_.FullName -replace '\\','/') # 入力ファイル。\を/に置き換え
$out = ((Join-Path $outDir ($_.BaseName + ".png")) -replace '\\','/') # 出力ファイル
& $gegl -- `
gegl:load path="$in" `
gegl:levels in-low=$inL in-high=$inH out-low=$outL out-high=$outH `
gegl:convert-format format="Y' u8" `
gegl:png-save path="$out" bitdepth=8
}
最初gegl:levelsだけで実行しましたが、入力した画像が8ビットのグレースケール画像にたいし出力されるPNGファイルが64bitとなっていいて、gegl:convert-formatとgegl:png-save path="$out" bitdepth=8に変換しています。
また、ToLinearという関数を用意していますが、GIMPのレベルの値に近づけるための変換処理です。(何故か、GIMPで行ったLevelの数値をセットしても同じ結果にならない)
一応手元の環境で希望した通りの画像が出力されるようになりましたが、正しい処理とは思えないので様子見したいとお見ます。
色・レベル補正→高さを指定して縮小
# 色→レベル補正(8bitグレスケール限定)→縮小
function ToLinear($v255) {
$v = [double]$v255/255.0
if ($v -le 0.04045) { $v/12.92 } else { [math]::Pow( ($v+0.055)/1.055, 2.4 ) }
}
$gegl = "${HOME}/scoop/apps/gimp/current/bin/gegl.exe" # 環境に合わせる
$inDir = "."
$outDir = "./output"
$inL=ToLinear 59
$inH=ToLinear 176
$outL=0.0
$outH=1.0
$targetH = 1600
New-Item -ItemType Directory -Path $outDir -Force | Out-Null # エラー無視
# PNGファイルの一覧を取得し、繰り返し処理
Get-ChildItem $inDir -Filter *.png | ForEach-Object {
$in = ($_.FullName -replace '\\','/') # 入力ファイル。\を/に置き換え
$out = ((Join-Path $outDir ($_.BaseName + ".png")) -replace '\\','/') # 出力ファイル
# 画像の高さを取得しscaleを算出
$img = [System.Drawing.Image]::FromFile($_.FullName)
$scale = $targetH / $img.Height
$img.Dispose()
& $gegl -- `
gegl:load path="$in" `
gegl:levels in-low=$inL in-high=$inH out-low=$outL out-high=$outH `
gegl:scale-ratio x=$scale y=$scale sampler=nohalo `
gegl:convert-format format="Y' u8" `
gegl:png-save path="$out" bitdepth=8
}
help
PS J:\ps1> ~/scoop/apps/gimp/current/bin/gegl.exe --help
usage: C:\Users\karet\scoop\apps\gimp\current\bin\gegl.exe [options] <file | -- [op [op] ..]>
Options:
-h, --help this help information
--list-all list all known operations
--exists return 0 if the operation(s) exist
--info output information about the operation:
name, description, properties details.
-i, --file read xml from named file
-x, --xml use xml provided in next argument
-o, --output output generated image to named file, type based
on extension.
-p increment frame counters of various elements when
processing is done.
-s scale, --scale scale scale output dimensions by this factor.
-X output the XML that was read in
-v, --verbose print diagnostics while running
All parameters following -- are considered ops to be chained together
into a small composition instead of using an xml file, this allows for
easy testing of filters. After chaining a new op in properties can be set
with property=value pairs as subsequent arguments.
list-all
PS J:\ps1> ~/scoop/apps/gimp/current/bin/gegl.exe --list-all
gegl:absolute
gegl:aces-rrt
gegl:add
gegl:alien-map
gegl:alpha-clip
gegl:alpha-inpaint
gegl:antialias
gegl:apply-lens
gegl:average
gegl:band-tune
gegl:bayer-matrix
gegl:bevel
gegl:bilateral-filter
gegl:bilateral-filter-fast
gegl:blend-reflect
gegl:bloom
gegl:border-align
gegl:box-blur
gegl:boxblur
gegl:boxblur-1d
gegl:brightness-contrast
gegl:buffer-sink
gegl:buffer-source
gegl:bump-map
gegl:c2g
gegl:cache
gegl:cartoon
gegl:cast-format
gegl:cast-space
gegl:cell-noise
gegl:channel-mixer
gegl:checkerboard
gegl:clone
gegl:color
gegl:color-assimilation-grid
gegl:color-enhance
gegl:color-exchange
gegl:color-overlay
gegl:color-rotate
gegl:color-temperature
gegl:color-to-alpha
gegl:color-warp
gegl:component-extract
gegl:connected-components
gegl:contrast-curve
gegl:convert-format
gegl:convert-space
gegl:convolution-matrix
gegl:copy-buffer
gegl:crop
gegl:ctx-script
gegl:cubism
gegl:deinterlace
gegl:demosaic-bimedian
gegl:demosaic-simple
gegl:denoise-dct
gegl:difference-of-gaussians
gegl:diffraction-patterns
gegl:displace
gegl:display
gegl:distance-transform
gegl:dither
gegl:ditto
gegl:divide
gegl:domain-transform
gegl:dropshadow
gegl:edge
gegl:edge-laplace
gegl:edge-neon
gegl:edge-sobel
gegl:emboss
gegl:engrave
gegl:exp-combine
gegl:exposure
gegl:exr-load
gegl:exr-save
gegl:fattal02
gegl:fill-path
gegl:focus-blur
gegl:fractal-explorer
gegl:fractal-trace
gegl:gamma
gegl:gaussian-blur
gegl:gaussian-blur-selective
gegl:gblur-1d
gegl:gegl
gegl:gegl-buffer-load
gegl:gegl-buffer-save
gegl:gif-load
gegl:gradient-map
gegl:gray
gegl:gray-component-replacement
gegl:grid
gegl:high-pass
gegl:hue-chroma
gegl:icc-load
gegl:icc-save
gegl:illusion
gegl:image-compare
gegl:image-gradient
gegl:inner-glow
gegl:integral-image
gegl:introspect
gegl:invert-gamma
gegl:invert-linear
gegl:jp2-load
gegl:jpg-load
gegl:jpg-save
gegl:json:dropshadow2
gegl:json:grey2
gegl:layer
gegl:lcms-from-profile
gegl:lens-blur
gegl:lens-distortion
gegl:lens-flare
gegl:levels
gegl:line-profile
gegl:linear-gradient
gegl:linear-sinusoid
gegl:load
gegl:local-threshold
gegl:long-shadow
gegl:magick-load
gegl:mantiuk06
gegl:map-absolute
gegl:map-relative
gegl:matting-global
gegl:matting-levin
gegl:maze
gegl:mblur
gegl:mean-curvature-blur
gegl:median-blur
gegl:mirrors
gegl:mix
gegl:mono-mixer
gegl:mosaic
gegl:motion-blur-circular
gegl:motion-blur-linear
gegl:motion-blur-zoom
gegl:multiply
gegl:negation
gegl:negative-darkroom
gegl:newsprint
gegl:noise-cie-lch
gegl:noise-hsv
gegl:noise-hurl
gegl:noise-pick
gegl:noise-reduction
gegl:noise-rgb
gegl:noise-slur
gegl:noise-solid
gegl:noise-spread
gegl:nop
gegl:normal-map
gegl:npd
gegl:npy-save
gegl:oilify
gegl:opacity
gegl:open-buffer
gegl:pack
gegl:paint-select
gegl:panorama-projection
gegl:path
gegl:pdf-load
gegl:perlin-noise
gegl:photocopy
gegl:piecewise-blend
gegl:pixbuf
gegl:pixelize
gegl:plasma
gegl:png-load
gegl:png-save
gegl:polar-coordinates
gegl:posterize
gegl:ppm-load
gegl:ppm-save
gegl:radial-gradient
gegl:rawbayer-load
gegl:rectangle
gegl:recursive-transform
gegl:red-eye-removal
gegl:reflect
gegl:reinhard05
gegl:remap
gegl:reset-origin
gegl:rgb-clip
gegl:rgbe-load
gegl:rgbe-save
gegl:ripple
gegl:rotate
gegl:rotate-on-center
gegl:saturation
gegl:save
gegl:save-pixbuf
gegl:scale-ratio
gegl:scale-size
gegl:scale-size-keepaspect
gegl:sdl2-display
gegl:seamless-clone
gegl:seamless-clone-compose
gegl:segment-kmeans
gegl:selective-hue-saturation
gegl:sepia
gegl:shadows-highlights
gegl:shadows-highlights-correction
gegl:shear
gegl:shift
gegl:shuffle-search
gegl:simplex-noise
gegl:sinus
gegl:slic
gegl:snn-mean
gegl:soft-burn
gegl:soft-dodge
gegl:soft-light
gegl:softglow
gegl:spherize
gegl:spiral
gegl:stereographic-projection
gegl:stress
gegl:stretch-contrast
gegl:stretch-contrast-hsv
gegl:styles
gegl:subtract
gegl:subtractive
gegl:supernova
gegl:svg-huerotate
gegl:svg-load
gegl:svg-luminancetoalpha
gegl:svg-matrix
gegl:svg-saturate
gegl:text
gegl:texturize-canvas
gegl:threshold
gegl:tiff-load
gegl:tiff-save
gegl:tile
gegl:tile-glass
gegl:tile-paper
gegl:tile-seamless
gegl:transform
gegl:translate
gegl:unpremultiply
gegl:unsharp-mask
gegl:value-invert
gegl:value-propagate
gegl:variable-blur
gegl:vector-stroke
gegl:video-degradation
gegl:vignette
gegl:voronoi-diagram
gegl:warp
gegl:waterpixels
gegl:watershed-transform
gegl:wavelet-blur
gegl:wavelet-blur-1d
gegl:waves
gegl:webp-load
gegl:webp-save
gegl:weighted-blend
gegl:whirl-pinch
gegl:wind
gegl:write-buffer
svg:clear
svg:color-burn
svg:color-dodge
svg:darken
svg:difference
svg:dst
svg:dst-atop
svg:dst-in
svg:dst-out
svg:dst-over
svg:exclusion
svg:hard-light
svg:lighten
svg:overlay
svg:plus
svg:screen
svg:src
svg:src-atop
svg:src-in
svg:src-out
svg:src-over
svg:xor


コメント