I am trying to convert my array to image using OpenCV or PIL libraries, In both of libraries, I am getting the images with mixed up color.
This is the way I tried convert Numpy array to image using OpenCV :
for i in range(len(batch_tx)):
cls_pred = sess.run(y_pred_cls, feed_dict={x: batch_tx})
cls_true = sess.run(tf.argmax(batch_ty, 1))
img = cv2.resize(batch_tx[i], (FLAGS.img_size, FLAGS.img_size))
img = cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_BGR2RGB)
cv2.imwrite(
'./saveImage/img' + str(i) + ': ' + 'True: ' + str(cls_true[i]) + ', Pred:' +
str(cls_pred[i]) + '.JPEG', img)
The output is like below image for all my images (This is an image of a ship)
And I have tried PIL library as well and got the same output.
batch_tx[1] is an array of the first image in my dataset and the type is numpy.ndarray with the shape of (96,96,3)
Any Idea?
Thanks in advance.

img[:, :, ::-1].copy(). Or load it with PIL withImage.fromarray(img)img.astype(np.uint8)used in the cvtColor line may be needed in the imwrite one