画像ファイルの扱い

ビデオファイルの扱いメモ にも関連情報(主に ffmpeg )あり


imagemagick で eps file への変換 2021年7月24日

ファイルサイズが大きくなってしまった場合のワザ
eps2: または eps3: を出力ファイルの前に付け、フォーマットを指定する

$ convert ifile.png eps2:ofile.eps
$ convert ifile.jpg eps3:ofile.eps

最近の LaTeX では、画像ファイルが eps ファイルでなくてもコンパイルでき、 PDFファイルまで作れます。 なので、無理して eps ファイルに変換しなくてもOK。 しかし、GSView での閲覧でエラーが起きた場合、 eps ファイルにしておくとエラーが起きない。

参考:
https://slpr.sakura.ne.jp/qp/jpgpng2eps/
https://qiita.com/tdrk/items/5d92d6d9988aae636442
https://fatsumiyoshi.hatenablog.com/entry/2012/10/01/174354

imagemagick でサイズ変更 2020年5月25日

アスペクト比を変えずに変更

$ convert ifile.png -resize 640x ofile.png ← 幅を指定
$ convert ifile.png -resize x540 ofile.png ← 高さを指定
$ convert ifile.png -geometry 30% ofile.png

参考:https://imagemagick.biz/archives/93

imagemagick でトリミング(切り抜き)

単にトリミングするとき 2020年5月25日

$ convert ifile.png -crop 1920x1080+243+94 ofile.png ← (width) x (height) +(x) + (y) 

ペイントなどを利用して、どういう風に切るかの数字を見付ける

参考:https://imagemagick.biz/archives/550

trim オプションを使うと、周辺の単一色(または無色)の部分を削り取るので注意

$ convert ifile.png trim ofile.png

トリミングした画像ファイルを別途利用するとき 2020年5月25日

convert だけだとレイヤーが残る = キャンバスサイズが大きなままになる
キャンバスサイズやどのようにトリミングが行われたかなどは、identify で確認できる

$ identify trimmed.png
trimmed.png PNG 1500x925 1920x1080+243+94 8-bit sRGB 47909B 0.000u 0:00.000

これのような、キャンバスサイズが元のままで、再度 crop しようとするとヘンになる。
それを避けるためには、mogrify +repage をする。

$ mogrify +repage trimmed.png
$ identify trimmed.png
trimmed.png PNG 1500x925 1500x925+0+0 8-bit sRGB 47881B 0.000u 0:00.001

キャンバスサイズがトリミングした大きさに一致していることが、identify で確認できる

参考:https://qiita.com/yoya/items/62879e6e03d5a70eed09

コントラスト調整 2020年5月27日

$ convert ifile.png -normalize ofilen.png
$ convert ifile.png -linear-stretch 0x0.0001% ofilel.png
-normalize ←  to -contrast-stretch 2%x1% と同じ
-linear-stretch 0x0.0001%

どちらもコントラストを強める補正
オプションの -linear-stretch と -contrast-stretch は よく似ているが、-linear-stretch は the image colors are stretched mathematically で、 一方、-contrast-stretch は using the histogram bins との違いがある。 どっちが美しいのかよくわからないけれど、histogram bins を 使ってしまうと、結果的にガンマを触っていることになりそうなので、 ぼくらの仕事の分野ではよくないような気がする。
似たもので -auto-level があるが、これは real-life images には使わない(使えない)。外れ値があった場合、もろに影響されてしまうため。

※ -contrast-stretch の説明では、 -normalize は -contrast-stretch 0.15x0.05% と同じと書いてあり、矛盾がある

参考:
https://qiita.com/yoya/items/1da8e8e04881bab67015
https://imagemagick.org/script/command-line-options.php

ヒストグラム生成 2020年5月27日

$ convert ifile.png histogram:histo-ifile.png           ← カラー
$ convert histo-ifile.png -strip -separate histo-%d.png ← 3色分解したもの
$ convert ifile.png histogram:- | identify -format %c - ← 分布の数値がほしいとき

photoshop の作るヒストグラムと違いがないようです。

平均値など、まとめの数値がほしいときは、identify を使うしかなさそう。 沢山データが吐き出される(喜べ!)。

$ identify -verbose ifile.png 

参考:
https://www.imagemagick.org/Usage/files/
http://kyle-in-jp.blogspot.com/2008/02/imagemagick_26.html

Today:2Yesterday:0Total:1430 since 25 May 2020

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 24 Jul 2021 (土) 12:14:16 (1006d)