Reputation: 33
the below program splits an rgb image into separate color channels
import cv2
import numpy as np
img = cv2.imread('dog_backpack.jpg')
cv2.imshow('RGB COLOR',img)
cv2.waitKey(0)
B,G,R = cv2.split(img)
zero = np.zeros(img.shape[0:2],dtype="uint8")
cv2.imshow('RED',cv2.merge([zero,zero,R]))
cv2.waitKey(0)
cv2.imshow('GREEN',cv2.merge([zero,G,zero]))
cv2.waitKey(0)
cv2.imshow('BLUE',cv2.merge([B,zero,zero]))
cv2.waitKey(0)
cv2.destroyAllWindows()
on line 7 when i use np.zeros function with any int data type it throws an error but when i use it with uint8 it run properly. please explain
Upvotes: 3
Views: 42
Reputation: 13641
By default, cv2.imread
will load the image using np.uint8
, unless you change the flag.
You can also write like this:
np.zeros(img.shape[:2], dtype=img.dtype)
Upvotes: 1