본문 바로가기

프로그래밍

파이썬 이미지 RGB 색조 변경

반응형
import cv2
import numpy as np
import os

dirpath = "img/"
img_dir = os.listdir(dirpath)
i = 0
for img_name in img_dir:
    img = cv2.imread(dirpath + '/' + img_name,cv2.IMREAD_COLOR)
    b,g,r = cv2.split(img) # channel split
    img_color_ary = []
    img_color_ary.append( cv2.merge((r,g,b)) )
    img_color_ary.append( cv2.merge((g,b,r)) )
    img_color_ary.append( cv2.merge((b,g,r)) )

    for img_color in img_color_ary:
        cv2.imwrite( ('img/'+str(i) + '.png') , img_color)
        cv2.waitKey()
        cv2.destroyAllWindows()
        i+=1
반응형