简体   繁体   中英

How do I get downscale and get B&W pixel values from an image in Python?

I am trying to create my own neutral network to see if an image is a number, and if it is, what number. I need to find a way to import an image a get an matrix of binary digits to indicate black or white. Im first trying out a 8*8 image but I may upscale that number.

import random
import math
def builder():
    startnnums = 64
    startnodes = []
    midnnums = 16
    midnodes = []
    endnnums = 9
    endnodes = []
    for i in range(startnnums):
        startnodes.append(0)
    for i in range(midnnums):
        midnodes.append([])
        for j in range(startnnums):
            midnodes[i].append(random.randint(0,100)/100)
    for i in range(endnnums):
        endnodes.append([])
        for j in range(midnnums):
            endnodes[i].append(random.randint(0,100)/100)
    print(startnodes,midnodes,endnodes)
def pfi(image):
    #code for get pixels from image

I have tried searching it on google but got no results, I also need a lot of bulk images for this project.

use the mNIST database here: https://deepai.org/dataset/mnist

docs here: https://www.askpython.com/python/examples/load-and-plot-mnist-dataset-in-python

The MNIST database (Modified National Institute of Standards and Technology database) is a large database of handwritten digits that is commonly used for training various image processing systems. The database is also widely used for training and testing in the field of machine learning. It was created by "re-mixing" the samples from NIST's original datasets. The creators felt that since NIST's training dataset was taken from American Census Bureau employees, while the testing dataset was taken from American high school students, it was not well-suited for machine learning experiments. Furthermore, the black and white images from NIST were normalized to fit into a 28x28 pixel bounding box and anti-aliased, which introduced grayscale levels.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM