Prepare Images For CNN

How are images looked at by computers?

  • Matrices

  • Number in matrix represents darkness of image in that position (darker part → larger #)

How are coloured images looked at by computers?

  • Matrices, but with extra dimension (RGB)

    • Stack of 3 matrices

Reshaping Numpy Arrays

# images is a list of floats/integers that represent an image
images = np.array(images, dtype = 'float')  
  • We have a numpy array (images) of these dimensions: (x, )

    • Need 4D array for input shape whose product is xx

    • So we can take x\sqrt{x} and reshape as:

np.reshape(-1, sqrt(x), sqrt(x), 1) # 1 if the image is greyscaled

Plotting Images as Numpy Arrays

Creating Labels with Numpy Arrays

Last updated

Was this helpful?