1

I downloaded an image from the internet and I am trying to convert the image into a low resolution 28 x 28 grayscale image similar to the ones from MNIST fashion dataset but i'm not being able to resize it properly so that I can try using the image for prediction. Below is demo of what the images look like and their sizes. Also attached pictures of the image. This is the link to the image I'm trying to convert output.jpg

from PIL import Image
import scipy.misc
import numpy as np

img = scipy.misc.imread("output.jpg")
img = scipy.misc.imresize(img,(28,28))

print (f"my test image size: {img.shape}")
print (f"train image size: {test_images[0].shape}")

plt.figure(figsize=(10,10))
plt.subplot(2,2,1)
plt.imshow(img)
plt.title("my test image")

plt.subplot(2,2,2)
plt.imshow(test_images[0])
plt.title("my train imaage")

plt.show()

enter image description here

codeBarer
  • 2,238
  • 7
  • 44
  • 75
  • simply convert your image to grayscale. https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python – user8190410 Aug 25 '19 at 14:25
  • I did but when I resize it to 28 x 28 I don't get the same dimension as the train image of (28,28) instead I get (28,28,3) – codeBarer Aug 25 '19 at 14:27
  • change `img = scipy.misc.imread("output.jpg")` to `img = scipy.misc.imread("output.jpg", mode="L")` – user8190410 Aug 25 '19 at 14:32

1 Answers1

0

Load the image in grayscale mode instead of loading the image in RGB mode. imresize only changes width and height. It does not convert rgb image to grayscale image. So, simply change your imread line to as below:

img = scipy.misc.imread("output.jpg", mode="L")
img = scipy.misc.imresize(img,(28,28))
print (img.shape)
user8190410
  • 1,264
  • 2
  • 8
  • 15