I am trying to slice an image into RGB and I have a problem with plotting these images. I obtain all images from a certain folder with this function:
def get_images(path, image_type):
image_list = []
for filename in glob.glob(path + '/*'+ image_type):
im=misc.imread(filename, mode='RGB')
image_list.append(im)
return image_list
This function creates 4d array (30, 1536, 2048, 3) and I am quite sure that the first value represents number of images, second and third are dimensions and third are RGB values.
After I obtained all the images, I stored them as a numpy array
image_list = get_images('C:\HDR\images', '.jpg')
temp = np.array(image_list)
After that I tried to use simple slicing on order to take specific colors from these images:
red_images = temp[:,:,:,0]
green_images = temp[:,:,:,1]
blue_images = temp[:,:,:,2]
When I print out the values, everything seems to be fine.
print(temp[11,125,311,:])
print(red_images[11,125,311])
print(green_images[11,125,311])
print(blue_images[11,125,311])
And I get the following:
[105 97 76]
105
97
76
So far, everything seems to be fine, but the problem arises when I try to display the image. I used matplotlib.pyplot.imshow
to display it and I get the image like:
Which is reasonable, because I choose red:
plt.imshow(temp[29,:,:,0])
But when I change it to different color channel, like this:
plt.imshow(temp[29,:,:,2])
I get the image like this:
My question is simple. What is happening here?