简体   繁体   中英

Image processing with numpy

How to split the photo into green, blue and red part with numpy?

for example with this code I make 3 photos in a column red, green and blue but three photos how can I make the same but for 1 photo( upper part of the photo is red, middle part green and lower part blue):

from PIL import Image

import numpy as np

im = np.array(Image.open('NASA.jpg'))

im_R = im.copy()

im_R[:, :, (1, 2)] = 0

im_G = im.copy()

im_G[:, :, (0, 2)] = 0

im_B = im.copy()

im_B[:, :, (0, 1)] = 0

im_RGB = np.concatenate((im_R, im_G, im_B), axis=0)

Image.fromarray(im_RGB)

You may be looking for something like this?

from PIL import Image

import numpy as np

im = np.array(Image.open('NASA.jpg'))

# Zero out the green and blue components in the upper third of the image.
im[:int(im.shape[0]/3), :, 1] = 0

# Zero out the red and blue components in the middle third of the image.
im[int(im.shape[0]/3):int(2*im.shape[0]/3), :, 0] = 0

# Zero out the red and green components in the lower third of the image.
im[int(2*im.shape[0]/3):, :, 0] = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM