logo
Loading...

做直方圖均衡case2時,出現 ValueError: all the input arrays must have same number of dimensions錯誤 - Cupoy

做直方圖均衡case2時,出現 ValueError: all the input arrays m...

case, 每個, 組合經過直方圖均衡的每個, 組合圖片, 比較

做直方圖均衡case2時,出現 ValueError: all the input arrays must have same number of dimensions錯誤

2019/11/27 02:46 PM
電腦視覺深度學習論壇
LucaKao
觀看數:0
回答數:2
收藏數:0
case
每個
組合經過直方圖均衡的每個
組合圖片
比較

做直方圖均衡case2時,出現 ValueError: all the input arrays must have same number of dimensions,不太明白哪邊出錯了,謝謝!



```

import cv2

import numpy as np


img_path = '/lena.png'

img = cv2.imread(img_path, cv2.IMREAD_COLOR)

# case 1

# 每個 channel 個別做直方圖均衡

equalHist_by_channel_B = cv2.equalizeHist(img[...,0])

equalHist_by_channel_G = cv2.equalizeHist(img[...,1])

equalHist_by_channel_R = cv2.equalizeHist(img[...,2])


# 組合經過直方圖均衡的每個 channel

img_bgr_equal = np.hstack((equalHist_by_channel_B,equalHist_by_channel_G,equalHist_by_channel_R))

cv2.imshow("img_bgr_equal",img_bgr_equal)


#=======================================================================

# case 2 - 轉換 color space 後只對其中一個 channel 做直方圖均衡

img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

img_hsv_equal = cv2.equalizeHist(img_hsv[...,0])


# 組合圖片 + 顯示圖片

cv2.imshow("img_bgr_equal",img_bgr_equal)

cv2.imshow("img",img)

cv2.imshow("img_hsv_equal",img_hsv_equal)


img_bgr_equalHist = np.hstack((img, img_bgr_equal, img_hsv_equal))

while True:

# 比較 (原圖, BGR color space 對每個 channel 做直方圖均衡, HSV color space 對明度做直方圖均衡)

   cv2.imshow('bgr equal histogram', img_bgr_equalHist)

   k = cv2.waitKey(0)

if k == 27:

       cv2.destroyAllWindows()

break

```


```

ValueError                                

Traceback (most recent call last)  in     

 25 cv2.imshow("img_hsv_equal",img_hsv_equal)     

26--->

 27img_bgr_equalHist = np.hstack((img, img_bgr_equal, img_hsv_equal))     

28whileTrue:    

29# 比較 (原圖, BGR color space 對每個 channel 做直方圖均衡, HSV color space 對明度做直方圖均衡)

/anaconda3/lib/python3.7/site-packages/numpy/core/shape_base.py in hstack(tup)    

338    return _nx.concatenate(arrs,0)   

339else:--> 

340    return _nx.concatenate(arrs,1)    

341    

342 ValueError: all the input arrays must have same number of dimensions


```