python - Show rgb numpy array in matplotlib -
i have numpy array:
>> print(data[0].shape) (3, 5, 5) which corresponds 5x5 rgb image. when try plt.imshow(data[0]) typeerror: invalid dimensions image data. how show image?
this appears 3 dimensional matrix, not 5x5 image. 5x5 rgb image appears this: a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5 d1 d2 d3 d4 d5 e1 e2 e3 e4 e5
what showing, 3 dimensions matrix, in 3rd dimension not correspond volume (as in 3d images) either. hence invalid dimensions error. want incorporate n * m matrix rgb numbers want display, such x_{r:j}=rgb. can display matrix image.
example of image matrices:
from numpy.random import rand matplotlib.pyplot import imshow img = rand(5, 5) # creating 5x5 matrix of random numbers. # use bilinear interpolation (or displayed bicubic default). imshow(img, interpolation="nearest") show() displays:
of course numbers in matrix not correspond rgb colours, intensity, , displayed through default colourmap (jet). i'm sure idea.

Comments
Post a Comment