0

The fashion mnist data included in Keras.datasets contained 2 sets of arrays (train and test) of shape (60000, 28, 28) and (10000, 28, 28) respectively. I want to fit the train dataset of shape (28, 28) to a pre-trained Keras model which requires input shape of (224, 224, 3). Instead of using sk.image.transform, I used OpenCV to resize arrays of shape (28, 28) to shape of (224, 224). The new images of size 224x224 were the same color composition to the original images of size 28x28 (black image/object on white background). As I'm new to OpenCV, I don't know whether it has a method to expand the dimensions of the ndarrays of (224, 224) to (224, 224, 3) so I used numpy to do that as per below

# x can be obtained by loading the fashion dataset included in Keras
x = np.stack((x, )*3, axis=-1)

Curiously, the expanded-dimension images flipped the color composition of image/object and background (that is, white image/object on black background) as shown in the example below (where the original image is on the left). Do you happen to know why? Thankyou! Flipped color of an image

Nemo
  • 1,124
  • 2
  • 16
  • 39
  • 2
    It might help to see the code. There no fewer than an infinite number of possibilities as to why this happened! – Mateen Ulhaq May 11 '19 at 04:30
  • Can you print the first few values of x (before and after) and check ? Also check the rendering utility, for ex OpenCV uses reverse ordering. – Prabindh May 11 '19 at 08:43
  • Hi Prabindh, x before and after are nday arrays of (28, 28) and (224, 224, 3) respectively so they can't be shown fully in Jupyternotebook. Can you please elaborate on what you meant by reverse ordering? – Nemo May 11 '19 at 10:55
  • 1
    I think Prabindh is referring to OpenCV's BGR ordering versus conventional RGB ordering as *"Reverse ordering"* I doubt that is the issue here as R=G=B in a grey image so the ordering is irrelevant since all components are identical. – Mark Setchell May 12 '19 at 09:42
  • Thanks for the explanation, Mark. I think you're right: if the component are identical, the order wouldn't affect the picture's colors. – Nemo May 13 '19 at 04:32

0 Answers0