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()
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.