logo
Loading...

D3 作業問題:結果異常 - Cupoy

請問為何我將調整明亮/對比度的程式碼移動到for迴圈前產生的結果會不一樣?import cv2img...

D3 作業問題:結果異常

2019/11/27 11:48 AM
電腦視覺深度學習論壇
馮品儒
觀看數:0
回答數:1
收藏數:0

請問為何我將調整明亮/對比度的程式碼移動到for迴圈前產生的結果會不一樣?

import cv2
img = cv2.imread('lena.png',cv2.IMREAD_COLOR)
cv2.imshow('imput',img)
img_HSV=img
img_bgr=img
img_hsv=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2HSV)


for i in range (3):
    img_bgr[...,i]=cv2.equalizeHist(img_bgr[...,i])

cv2.imshow("case1_equalizeHist_BGR",img_bgr)
img_hsv[...,2]=cv2.equalizeHist(img_hsv[...,2])
img_out=cv2.cvtColor(img_hsv,cv2.COLOR_HSV2BGR)
cv2.imshow("case2_equalizeHist_HSV",img_out)

# 程式區1--------調整明亮/對比
contrast=cv2.convertScaleAbs(img_HSV,alpha=2,beta=0)
lightness=cv2.convertScaleAbs(img_HSV,alpha=1,beta=50)
cv2.imshow("contrast",contrast)
cv2.imshow('lightness',lightness)    
#---------

cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread('lena.png',cv2.IMREAD_COLOR)
cv2.imshow('imput',img)
img_HSV=img
img_bgr=img
img_hsv=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2HSV)

# 程式區1--------調整明亮/對比
contrast=cv2.convertScaleAbs(img_HSV,alpha=2,beta=0)
lightness=cv2.convertScaleAbs(img_HSV,alpha=1,beta=50)
cv2.imshow("contrast",contrast)
cv2.imshow('lightness',lightness)    
#---------

for i in range (3):
    img_bgr[...,i]=cv2.equalizeHist(img_bgr[...,i])

cv2.imshow("case1_equalizeHist_BGR",img_bgr)
img_hsv[...,2]=cv2.equalizeHist(img_hsv[...,2])
img_out=cv2.cvtColor(img_hsv,cv2.COLOR_HSV2BGR)
cv2.imshow("case2_equalizeHist_HSV",img_out)


cv2.waitKey(0)
cv2.destroyAllWindows()