[英]How can I resize an image in python to gray scale low resolution like MNIST fashion data?
我從互聯網上下載了圖片,並嘗試將其轉換為與MNIST時尚數據集相似的低分辨率28 x 28灰度圖像,但是我無法正確調整其大小,因此我可以嘗試使用用於預測的圖像。 以下是圖像外觀及其大小的演示。 還附有圖片圖片。 這是我要轉換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()
以灰度模式加載圖像,而不是以RGB模式加載圖像。 imresize
只會更改寬度和高度。 不會將rgb圖像轉換為灰度圖像。 因此,只需將您的閱讀行更改為如下所示:
img = scipy.misc.imread("output.jpg", mode="L")
img = scipy.misc.imresize(img,(28,28))
print (img.shape)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.