2

I am trying to make my own dataset of handwritten images to test my hand written digit classifier. so to make it I wrote the images in a paint box and resized the images to 28x28 pixels same as the train test pixels. but when I loaded it to the python the image shape is (28,28,3) I know these are the RGB values. But I don't know how to get rid of them. should I change my image to gray scale to get an image of size (28,28). I don't know what it is called so the question title can be wrong. The code used to upload the image to environment

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img=mpimg.imread('0.png')
imgplot = plt.imshow(img)
Xts_n=img

can somebody give me a hint on how to get it done.

Bogorovich
  • 193
  • 2
  • 11

2 Answers2

1

if you have RGB image and you want to convert it to 1 channel (greyscale) - use can use this:

import cv2

img=cv2.imread('0.png')
img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

now its shape is (28,28)

yoram
  • 191
  • 1
  • 1
  • 13
1

python the image shape is (28,28,3)

If by this you meant that you used img.shape to get (28,28,3) then, just for the clarification - img.shape returns a tuple of number of rows, columns and channels (if image is color). So, you probably should first convert it to grayscale if you want (28,28) as your output.