3
2

More than 3 years have passed since last update.

最高のランダムドットステレオグラム(RDS)を求めて。

Last updated at Posted at 2019-12-09

前回の記事でPythonを使ってオリジナルのランダムドットステレオグラムの作成に挑戦した。

無事に立体視をすることはできたのだが、単に丸印やテキストを立体視しただけで満足してしまった。今回はもう少しかっこいいものを作る。

色を変更する

前回はランダムドットステレオグラムをグレースケールで表示させていた。これがなんか昔のテレビの砂嵐みたいで怖い。

Matplotlibにはグレースケール以外にもいろいろなカラーマップがあるので変更してみた。

plt.imshow(stereogram, cmap='spring')

1207_1.png
貞子感がなくなってだいぶPOPになった。イイネ。

深み

前回は立体パターンの深度マップを2値で作成していた。これではいろんな意味で深みがない。
深度マップを連続的な数値にすることで立体の浮かび上がらせる程度を調整することができる。

ためしに下のようなパターンを準備した。

def make_depthmap(shape=(400, 600)):
    depthmap = np.zeros(shape, dtype=np.float)
    cv2.circle(depthmap, (200, 100), 50, (255 ,255, 255), -1)
    cv2.circle(depthmap, (400, 100), 50, (200 ,200, 200), -1)
    cv2.circle(depthmap, (300, 200), 50, (155 ,155, 155), -1)
    cv2.circle(depthmap, (200, 300), 50, (100 ,100, 100), -1)
    cv2.circle(depthmap, (400, 300), 50, (55 ,55, 55), -1)
    return depthmap

1207_2.png

左上からZ順に暗くなっていくパターン。これでRDSを作成してみる。

1207_3.png

すごいぞ。深度マップの暗さに応じて、飛び出し具合が変わっている。
こんなパターンでもやってみた。

def make_rectangle_depthmap(shape=(400, 600)):
    depthmap = np.zeros(shape, dtype=np.float)
    for i in range(16):
        c = 255 - i * 16
        cv2.rectangle(depthmap, (100+i*25, 100), (125+i*25, 300), (c, c, c), -1)
    return depthmap

1209_1.png

結果がこちら

1209_2.png

階段みたいに見える。イイネ。

おわり

次回は写真(2次元画像)から深度マップを作成して、普通の写真を立体視できるようにしたい。
ランダムドットステレオグラマーになりたい。

追記

続編を書きました。

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