2017-02-25 79 views
-1

opencv documentation我發現,將L 一個 b *顏色空間具有用於每個變量的限制值如下:讀取像素* A * b色空間圖像

0 < L < 100 
-127 < a < 127 
-127 < b < 127 

我寫了一個代碼,其讀取並將BGR類型的圖像轉換爲L a b *色彩空間。當我顯示L的值時,a和bi發現值超出範圍(所有這些值)

例如,在像素(y,x)中,b的值爲150,但是來自opencv 2.4.13文檔b必須是-127和127 的代碼之間如下:

#include <opencv2/core/core.hpp> 
    #include <opencv2/highgui/highgui.hpp> 
    #include "opencv2/imgproc/imgproc.hpp" 
    #include <iostream> 

    using namespace cv; 
    using namespace std; 


    int main(int argc, char** argv){ 

    Mat input, Lab_img; 

    input = imread("E:\\Walid\\Images\\b2.jpg"); 


    cvtColor(input, Lab_img, CV_BGR2Lab); 
    namedWindow("ORIGINAL", WINDOW_AUTOSIZE); 
    namedWindow("Lab", WINDOW_AUTOSIZE); 



    for (int y = 0; y < Lab_img.rows; y++) 
    { 
     for (int x = 0; x < Lab_img.cols; x++) 
     { 
      Vec3b intensity = Lab_img.at<Vec3b>(y, x); 
      double L = intensity.val[0]; 
      double a = intensity.val[1]; 
      double b = intensity.val[2]; 
      cout << b << std::endl; 
     } 
    } 


    imshow("ORIGINAL", input); 
    imshow("Lab", Lab_img); 

    waitKey(0); 
    return 0; 
    } 
+0

可以檢查源碼。 a和b被128分取消了。我發現我忘記了大部分細節。 – BlueWanderer

+0

添加鏈接到OP錯誤解釋(或讀取不夠)的相關文檔。 –

+0

@BarryMichaelDoyle每次編輯時請停止留下評論。你不需要通過評論來解釋你的編輯。 – meagar

回答

0

下面是參考cvtColor在第RGB < - > CIE的L * a * b *表,它說:

這輸出0 < = L < = 100,-127 < = a < = 127,-127 < = b < = 127。然後的 值被轉換爲目標數據類型:對於8位 圖像L = L * 255/10 A = A + 128,B = B + 128.

+0

Thnx很多,所以如果我有b = -50我必須通過將舊值加128來將其轉換爲b = 78。 –

+0

爲什麼不將'unsigned char'強制轉換爲'signed char',然後(隱式)轉換爲'double'? –