Skip to content

Instantly share code, notes, and snippets.

@juliensimon
Created April 14, 2017 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliensimon/c62742b200396b4eadd8229a22c4cf0b to your computer and use it in GitHub Desktop.
Save juliensimon/c62742b200396b4eadd8229a22c4cf0b to your computer and use it in GitHub Desktop.
Split image
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)
@roip
Copy link

roip commented Sep 26, 2017

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment