0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

紙に墨で書かれた絵の、紙の部分を透明にする

Posted at

これは何?

紙に黒で書かれた絵があって。
何も書かれていない部分→透明
黒い部分→不透明の黒
という変換をしたくなった。

墨が薄い部分は薄さに合わせた半透明にしたい。

この作業のために簡単な画像処理をしたので、その記録。

作戦

  1. 紙をスキャンして、グレースケール png にする。
  2. 紙のテクスチャが無くなり、墨のムラを減らすようにレベル調整する。
  3. png を HSL に変換し、L(輝度) だけの画像を得て、白黒反転する → 輝 と名付ける。
  4. 元画像と同じサイズの真っ黒な画像を用意する → 黒 と名付ける。
  5. 赤=「黒」, 緑=「黒」, 青=「黒」, 不透明度=「輝」 で一枚の画像にする。

レベル調整

こんなコマンドで:

convert scanned.png -fx "(u-0.3)/0.5" level.png

暗部3割と明部2割を捨てて残りの5割を活かすので、こんな計算になる。
0.30.5 はスキャンする素材やスキャナによって調整する。

png を HSL に変換し、L(輝度) だけの画像を得て、白黒反転する

こんなコマンドで:

convert level.png -colorspace HSL -separate -negate lumi.png

実行すると lumi-0.png, lumi-1.png, lumi-2.png の3つの画像ができてしまう。必要なのは lumi-2.png だけ。

元画像と同じサイズの真っ黒な画像を用意する

こんなコマンドで:

convert scanned.png -evaluate multiply 0 black.png

全画素に0を乗じれば真っ黒になる。

5. 赤=「黒」, 緑=「黒」, 青=「黒」, 不透明度=「輝」 で一枚の画像にする。

こんなコマンドで:

convert black.png black.png black.png lumi-2.png -combine alphapaper.png

各プレーンを結合できる。 convert 赤 緑 青 不透明度 -combine 結果 だと思う。

処理の例

段階 画像
スキャン画像 image.png
レベル調整後 image.png
反転した輝度プレーン image.png
出来上がった透過画像 image.png
透過画像との合成の例 image.png
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?