0

Pythonで画像転送を行うためにcv2 LUTを使用しようとしています。LUT は、画像と同じ数のチャンネルを持つ必要があります。しかし、1 つのエラーを解決できません。

image1Transfered = cv2.LUT(image1, lut) cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/convert.cpp:1037: エラー: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.isContinuous() && (src.depth() == CV_8U || src.depth() == CV_8S) in function LUT

これがpythonコードです。画像を複数の単一チャンネルに分割し、それぞれLUTを適用できると思います。しかし、これは資源の無駄です。

    #!/usr/bin/python
    import sys
    import cv2
    import numpy as np

    image1 = cv2.imread("../pic1.jpg", 1)
    # apply look up table
    lut = np.arange(255, -1, -1, dtype = image1.dtype )
    lut = np.column_stack((lut, lut, lut))
    image1Converted = cv2.LUT(image1, lut)  # <-- this is where it fails

お時間をいただきありがとうございます。

4

2 に答える 2

0

ありがとう、アビッド、私はあなたのブログが好きです。Python CV の投稿を 1 つずつ見ていきます。Python opencv の学習に大いに役立ちます。とてもいい仕事をしてくれました。

これが私が最終的に得たものです:

lut3 = np.column_stack((lut, lut, lut))
lutIdxDot = np.array( [0, 1, 2], dtype=int)
lutIdx0 = np.zeros( image1.shape[0] * image1.shape[1], dtype=int)
lutIdx1 = np.ones( image1.shape[0] * image1.shape[1], dtype=int)
lutIdx2 = lutIdx1 * 2
lutIdx = np.column_stack((lutIdx0, lutIdx1, lutIdx2))
lutIdx.shape = image1.shape

image1Rev = lut3[image1, lutIdx] # numpy indexing will generate the expected LUT result. 

numpy インデックスを使用して結果を取得しました。cv LUT 機能は使用しませんでした。性能は不明です。

コードの最後の行は、最初は奇妙でした。インデックス作成は numpy の非常に興味深い機能です。コードが最後の行まで実行されると、lut3 は次のようになります。

ipdb> p lut3
array([[255, 255, 255],
       [254, 254, 254],
       [253, 253, 253],
       [252, 252, 252],
       ...
       [  2,   2,   2],
       [  1,   1,   1],
       [  0,   0,   0]], dtype=uint8)

ipdb> p lutIdx
array([[[0, 1, 2],
        [0, 1, 2],
        [0, 1, 2],
        ..., 
        ..., 
        [0, 1, 2],
        [0, 1, 2],
        [0, 1, 2]]])

lutIdx は image1 と同じ形をしています。lut3[image1, lutIdx] は、その形状が image1 および lutIdx と同じであるため、配列を要求しています。その値は lut3 からのものです。image1 の各項目について、lut[そのスポットの image1 の値、そのスポットの lutIdx の値] を使用して、その出力値を見つけます。(図が描けたらいいのに。)

于 2013-06-06T04:34:03.477 に答える