Created
April 14, 2017 21:56
-
-
Save juliensimon/c62742b200396b4eadd8229a22c4cf0b to your computer and use it in GitHub Desktop.
Split image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
def splitRGBImage(filename): | |
img = cv2.imread(filename) | |
red = np.copy(img) | |
red[:,:,0].fill(0) | |
red[:,:,1].fill(0) | |
red = cv2.resize(red, (224, 224,)) | |
cv2.imwrite("red_"+filename, red) | |
green = np.copy(img) | |
green[:,:,0].fill(0) | |
green[:,:,2].fill(0) | |
green = cv2.resize(green, (224, 224,)) | |
cv2.imwrite("green_"+filename, green) | |
blue = np.copy(img) | |
blue[:,:,1].fill(0) | |
blue[:,:,2].fill(0) | |
blue = cv2.resize(blue, (224, 224,)) | |
cv2.imwrite("blue_"+filename, blue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
may want to change the filename RGB prefixes to suffixes to support easy writing into other directory paths i.e. cv2.imwrite(filename+"_green") will allow a filename with path to save the file "/media/pic.jpg_blue"