Вы не тасуете пиксели, вы тасуете все, когда используете потом np.ravel()
и np.shuffle()
.
Когда вы тасуете пиксели, вы должны убедиться, что цвет, RGB кортежи, оставайся таким же.
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
#Loads an arbitrary RGB image from the misc library
rgbImg = misc.face()
#Display out the original RGB image
plt.figure(1,figsize = (6, 4))
plt.imshow(rgbImg)
plt.show()
# doc on shuffle: multi-dimensional arrays are only shuffled along the first axis
# so let's make the image an array of (N,3) instead of (m,n,3)
rndImg2 = np.reshape(rgbImg, (rgbImg.shape[0] * rgbImg.shape[1], rgbImg.shape[2]))
# this like could also be written using -1 in the shape tuple
# this will calculate one dimension automatically
# rndImg2 = np.reshape(rgbImg, (-1, rgbImg.shape[2]))
#now shuffle
np.random.shuffle(rndImg2)
#and reshape to original shape
rdmImg = np.reshape(rndImg2, rgbImg.shape)
plt.imshow(rdmImg)
plt.show()
Это случайный енот, обратите внимание на цвета.Там нет красного или синего цвета.Только оригинальные, белые, серые, зеленые, черные.
![enter image description here](https://i.stack.imgur.com/bAAk4.png)
Есть некоторые другие проблемы с вашим кодом, который я удалил:
Не используйте вложенные циклы, медленно.
Предварительное выделение с np.zeros
не требуется (если оно вам когда-либо понадобится, просто введите rgbImg.shape
в качестве аргумента не нужно распаковывать отдельные значения)