1

I am attempting to separate red, green and blue components of an image and display the resulting images in separate subplots.

To do this, for each colour, I have created an array of zeros the same shape as the original image (using the function np.zeros), and copied one of the image colours across using slicing.

However, the output just appears to be a red square, therefore I don't think the code is working how I would expect it to. Does anyone have any idea where I'm going wrong?

red_image[:,:,0] = red_channel
image = plt.imread('archway.jpg')
plt.imshow(image)
red_channel = image[:,:,0]
red_image = np.zeros(image.shape)
red_image[:,:,0] = red_channel
plt.imshow(red_image)
petezurich
  • 9,280
  • 9
  • 43
  • 57
compscistudent
  • 107
  • 1
  • 2
  • 11
  • did you check out [this question](https://stackoverflow.com/questions/37431599/how-to-slice-an-image-into-red-green-and-blue-channels-with-misc-imread)? It seems to have what you need (look at second answer also, it has 2 ways, one only showing different images, one creating a copy for each channel) – freerafiki Feb 05 '20 at 11:01
  • Try `plt.imshow(red_image, cmap=plt.cm.gray)` – Mark Setchell Feb 05 '20 at 11:06
  • Also, remember that the 4th channel is alpha, if you set that to zeros, you'll always get a blank square. – dpwr Feb 05 '20 at 11:59

0 Answers0