2017-10-10 275 views
0

我是opencv的新手,嘗試將RGB圖像轉換爲LAB色彩空間。我正在使用下面的代碼。如何在LAB中獲得LAB(l * a * b)色彩空間的a通道

data_path = 'D:/Images/' 
image_name= '1.png' 
img = cv2.imread(os.path.join(data_path, image_name),cv2.IMREAD_COLOR) # Reads image from disk 
img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) # changes RGB to LAB color space 

img = img [127.5, 1, 127.5] # This i was trying to get a-channel only but gives error 

現在我只想使用LAB圖像的a通道作爲1通道輸入饋入我的程序。我如何只能使用LAB色彩空間圖像的a通道?

+0

你的意思是你想管L聲道到一個單獨的程序 - 潛在的不同的語言? –

+0

@ Mark Setchell我想分離每個通道,並希望只使用a通道輸出。我已經完成了使用分割功能。謝謝 l_channel,a_channel,b_channel = cv2.split(img) – Kanvas

+0

爲什麼人們想降低一切?這是一個真正的問題。 – Kanvas

回答

0

我已經解決了下面的代碼行

l_channel, a_channel, b_channel = cv2.split(img) #splits the image into 3 channles l, a and b 

它的圖像爲L,a和我想的B信道分開我的問題。這很容易,但因爲我對opencv是陌生的,所以我不知道它。

0

我使用opencv2和Python來解決這個問題

import cv2 
    input = cv2.imread('path_to_image.png') 
    cv2.imshow('Hello World', input) 
    cv2.waitKey(0) 
    cv2.destroyAllWindows() 

    lab = cv2.cvtColor(input,cv2.COLOR_BGR2LAB) 
    cv2.imshow("l*a*b",lab) 

    L,A,B=cv2.split(lab) 
    cv2.imshow("L_Channel",L) # For L Channel 
    cv2.imshow("A_Channel",A) # For A Channel (Here's what You need) 
    cv2.imshow("B_Channel",B) # For B Channel 

    cv2.waitKey(0) 
    cv2.destroyAllWindows() 

希望這可以幫助你解決你的問題

相關問題