Last active
April 14, 2024 20:21
-
-
Save shivanandmn/36afaf6f07a5bda688e69bb2aa8b3ca2 to your computer and use it in GitHub Desktop.
Convert any image to 784(28*28) grayscale pixel dataframe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import cv2 | |
image_files = pd.DataFrame(columns=range(784)).add_prefix('pixels_') | |
for i in range(1, 6): | |
r_image = cv2.imread(f'images/{i}.JPG') | |
numpy_image = cv2.cvtColor(r_image, cv2.COLOR_BGR2GRAY) | |
image = cv2.resize(numpy_image, (28, 28)).astype(np.float32) | |
image = image.reshape(-1) | |
image_files.loc[f'image_{i}', 'pixels_0':] = image | |
print(image_files.head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!