LoginSignup
5
1
お題は不問!Qiita Engineer Festa 2024で記事投稿!
Qiita Engineer Festa20242024年7月17日まで開催中!

Evision を 0.2.3 に上げたら applyColorMap でエラーが発生したけど、すぐに対応してもらえた話

Last updated at Posted at 2024-06-21

はじめに

Evision が 0.2 まで上がっていたので、新しいバージョンで以前のコードが動くか検証していました

検証したのは以下の記事で使ったコード

その際、 Evision.applyColorMap でエラーが発生したのですが、 Issue に登録したらあっと言う間に対応してリリースまでしてもらえたので記事に残します

Evision のバージョン

  • エラー対応前: 0.2.3
  • エラー対応後: 0.2.4

エラーになったコード

エラーになったのは以下のコードです

mt_fuji_dem_color = Evision.applyColorMap(mt_fuji_dem_u8, Evision.Constant.cv_COLORMAP_JET())

グレースケール画像にカラーマップを適用し、色を付ける処理です

mt_fuji_gray.png

mt_fuji_jet.png

以下のようなエラーが発生していました

OpenCV(4.10.0) /work/3rd_party/opencv/opencv-4.10.0/modules/imgproc/src/colormap.cpp:842: error: (-215:Assertion failed) cv::LUT only supports tables of size 256. in function 'applyColorMap'

一時的な対処

とりあえず、以下のようにカラーマップをテンソルで指定することで対応は可能です

jet_colormap =
  [
    [0, 0, 131], [0, 0, 135], [0, 0, 139], [0, 0, 143], [0, 0, 147], [0, 0, 151], [0, 0, 155], [0, 0, 159], [0, 0, 163], [0, 0, 167],
    [0, 0, 171], [0, 0, 175], [0, 0, 179], [0, 0, 183], [0, 0, 187], [0, 0, 191], [0, 0, 195], [0, 0, 199], [0, 0, 203], [0, 0, 207],
    [0, 0, 211], [0, 0, 215], [0, 0, 219], [0, 0, 223], [0, 0, 227], [0, 0, 231], [0, 0, 235], [0, 0, 239], [0, 0, 243], [0, 0, 247],
    [0, 0, 251], [0, 0, 255], [0, 4, 255], [0, 8, 255], [0, 12, 255], [0, 16, 255], [0, 20, 255], [0, 24, 255], [0, 28, 255], [0, 32, 255],
    [0, 36, 255], [0, 40, 255], [0, 44, 255], [0, 48, 255], [0, 52, 255], [0, 56, 255], [0, 60, 255], [0, 64, 255], [0, 68, 255], [0, 72, 255],
    [0, 76, 255], [0, 80, 255], [0, 84, 255], [0, 88, 255], [0, 92, 255], [0, 96, 255], [0, 100, 255], [0, 104, 255], [0, 108, 255], [0, 112, 255],
    [0, 116, 255], [0, 120, 255], [0, 124, 255], [0, 128, 255], [0, 131, 255], [0, 135, 255], [0, 139, 255], [0, 143, 255], [0, 147, 255], [0, 151, 255],
    [0, 155, 255], [0, 159, 255], [0, 163, 255], [0, 167, 255], [0, 171, 255], [0, 175, 255], [0, 179, 255], [0, 183, 255], [0, 187, 255], [0, 191, 255],
    [0, 195, 255], [0, 199, 255], [0, 203, 255], [0, 207, 255], [0, 211, 255], [0, 215, 255], [0, 219, 255], [0, 223, 255], [0, 227, 255], [0, 231, 255],
    [0, 235, 255], [0, 239, 255], [0, 243, 255], [0, 247, 255], [0, 251, 255], [0, 255, 255], [4, 255, 251], [8, 255, 247], [12, 255, 243], [16, 255, 239],
    [20, 255, 235], [24, 255, 231], [28, 255, 227], [32, 255, 223], [36, 255, 219], [40, 255, 215], [44, 255, 211], [48, 255, 207], [52, 255, 203], [56, 255, 199],
    [60, 255, 195], [64, 255, 191], [68, 255, 187], [72, 255, 183], [76, 255, 179], [80, 255, 175], [84, 255, 171], [88, 255, 167], [92, 255, 163], [96, 255, 159],
    [100, 255, 155], [104, 255, 151], [108, 255, 147], [112, 255, 143], [116, 255, 139], [120, 255, 135], [124, 255, 131], [128, 255, 128], [131, 255, 124], [135, 255, 120],
    [139, 255, 116], [143, 255, 112], [147, 255, 108], [151, 255, 104], [155, 255, 100], [159, 255, 96], [163, 255, 92], [167, 255, 88], [171, 255, 84], [175, 255, 80],
    [179, 255, 76], [183, 255, 72], [187, 255, 68], [191, 255, 64], [195, 255, 60], [199, 255, 56], [203, 255, 52], [207, 255, 48], [211, 255, 44], [215, 255, 40],
    [219, 255, 36], [223, 255, 32], [227, 255, 28], [231, 255, 24], [235, 255, 20], [239, 255, 16], [243, 255, 12], [247, 255, 8], [251, 255, 4], [255, 255, 0],
    [255, 251, 0], [255, 247, 0], [255, 243, 0], [255, 239, 0], [255, 235, 0], [255, 231, 0], [255, 227, 0], [255, 223, 0], [255, 219, 0], [255, 215, 0],
    [255, 211, 0], [255, 207, 0], [255, 203, 0], [255, 199, 0], [255, 195, 0], [255, 191, 0], [255, 187, 0], [255, 183, 0], [255, 179, 0], [255, 175, 0],
    [255, 171, 0], [255, 167, 0], [255, 163, 0], [255, 159, 0], [255, 155, 0], [255, 151, 0], [255, 147, 0], [255, 143, 0], [255, 139, 0], [255, 135, 0],
    [255, 131, 0], [255, 128, 0], [255, 124, 0], [255, 120, 0], [255, 116, 0], [255, 112, 0], [255, 108, 0], [255, 104, 0], [255, 100, 0], [255, 96, 0],
    [255, 92, 0], [255, 88, 0], [255, 84, 0], [255, 80, 0], [255, 76, 0], [255, 72, 0], [255, 68, 0], [255, 64, 0], [255, 60, 0], [255, 56, 0],
    [255, 52, 0], [255, 48, 0], [255, 44, 0], [255, 40, 0], [255, 36, 0], [255, 32, 0], [255, 28, 0], [255, 24, 0], [255, 20, 0], [255, 16, 0],
    [255, 12, 0], [255, 8, 0], [255, 4, 0], [255, 0, 0], [251, 0, 0], [247, 0, 0], [243, 0, 0], [239, 0, 0], [235, 0, 0], [231, 0, 0],
    [227, 0, 0], [223, 0, 0], [219, 0, 0], [215, 0, 0], [211, 0, 0], [207, 0, 0], [203, 0, 0], [199, 0, 0], [195, 0, 0], [191, 0, 0],
    [187, 0, 0], [183, 0, 0], [179, 0, 0], [175, 0, 0], [171, 0, 0], [167, 0, 0], [163, 0, 0], [159, 0, 0], [155, 0, 0], [151, 0, 0],
    [147, 0, 0], [143, 0, 0], [139, 0, 0], [135, 0, 0], [131, 0, 0], [128, 0, 0]
  ]
  |> Enum.reverse()
  |> Nx.tensor()
  |> Nx.new_axis(1)
  |> Nx.as_type(:u8)

mt_fuji_dem_color = Evision.applyColorMap(mt_fuji_dem_u8, jet_colormap)

カラーマップの配列は ChatGPT に以下のように指示して生成しました

JET のカラーマップを 0 から 255 の RGB 整数で配列として表現してください

ただ、こんなコードは書きたくありません

バージョンアップ後のコード

冒頭で言ったとおり、あっという間に cocoa-xu さんが対応してくれました

(私は Issue を書いて寝てしまっていたので、コメントに気づかなかった)

今の最新版では、以下のように書くことでカラーマップが適用できます

mt_fuji_dem_color = Evision.applyColorMap(src: mt_fuji_dem_u8, colormap: Evision.Constant.cv_COLORMAP_JET())

差分(src:colormap: で指定するようにした)

-mt_fuji_dem_color = Evision.applyColorMap(mt_fuji_dem_u8, Evision.Constant.cv_COLORMAP_JET())
+mt_fuji_dem_color = Evision.applyColorMap(src: mt_fuji_dem_u8, colormap: Evision.Constant.cv_COLORMAP_JET())

まとめ

バグを見つけたらすぐに報告しましょう

また、報告する際には実行したコードも書きましょう

5
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
5
1