I am trying to split the RGB .jpg image into three channels:
imread = cv2.imread("picture.jpg")
blue = imread[:, :, 0]
green = imread[:, :, 1]
red = imread[:, :, 2]
cv2.imshow("preview", blue)
cv2.waitKey(0)
but the code will display grayscale image. The same is with the green and red arguments passed to the imshow function.
Is it possible to preview it only as a blue channel image?
Also, how would I loop through all the pixels of one channel, let's say: the blue one?
#Try imread[:, :, 1] = 0
that makes the blue pixel value to 0. In the same way you can modify the pixels. But while reading the image i am not sure either. But if you want to go through over each pixel then probably the best way is going through looping.
def slow():
img = imrerad.copy()
height, width, depth = img.shape
for i in range(0, height):
for j in range(0, width):
for k in range(0,depth):
img[i,j,k] = 0 # The value you want to modify with
return img
def fast():
img = imread.copy()
height, width, depth = img.shape
img[0:height, 0:width, 0:depth] = 0 # The value you want to modify with if every value is same..
return img
or if you have anything better regarding your algorithm then we can look for a better solution. Depending on your need. That first one is very slow where as the second one is a quite faster than the previous one.
#I cannot answer this question from my account but somehow i thought this would help you