How Neural Networks Process Images
Visualizing the process of "flattening" a 2D image grid into a 1D sequence of numbers to feed into Dense Layers.
Visualizing the process of "flattening" a 2D image grid into a 1D sequence of numbers to feed into Dense Layers.
Why and how we transform 2D grids of pixels into 1D lists for Neural Networks.
When you look at an image, you see a 2D grid of colors. However, standard Artificial Neural Networks (specifically Dense or Fully-Connected Layers) are structured to accept only a one-dimensional (1D) array or vector of numbers as input. Before a network can "look" at an image, the image must undergo Flattening.
Think of a digital image as a spreadsheet where each cell is a pixel holding a color value. "Flattening" is simply taking the first row of this spreadsheet, placing it down, taking the second row and appending it to the end of the first, and continuing until the whole grid forms a single, long line of numbers.
If the image is colored, it contains three channels: Red, Green, and Blue (RGB). The network needs separate input nodes for every color value of every pixel. The math for the total number of inputs is simple: Width × Height × Channels = Total Nodes.
Look at the right column. For a 16x16 RGB image, you'll see the 2D matrix labeled 16 x 16 x 3. This means there are 768 individual color values. Scroll the 1D Input Vector horizontally to see all 768 "nodes" laid out end-to-end!
Check the Convert to Grayscale box. Notice how the node count drops by exactly a factor of 3 (e.g., from 768 to 256). Grayscale images only have 1 channel (brightness) instead of 3 (RGB), making them much easier for simple neural networks to process.
Slide the Resolution to 32x32. Even for this tiny icon-sized image, an RGB format creates 3,072 nodes. This rapid growth in data is why modern deep learning requires powerful GPUs.
Switch to the Live Webcam tab. Try moving your hand. Watch how the 2D image changes and how those changes ripple through the 1D flattened array. Every movement changes hundreds of values simultaneously across the vector.
While flattening allows an MLP to process an image, it destroys spatial relationships. A pixel right above another pixel in 2D might be dozens of indices apart in the 1D array. Standard dense networks struggle to understand that these pixels were originally neighbors.
This exact problem led to the invention of Convolutional Neural Networks (CNNs), which process images in 2D first before flattening them at the very end!
Flattening is the bridge between raw image files and the mathematical matrix operations that power Artificial Intelligence.
When you look at an image, you see a 2D grid of colors. However, standard Artificial Neural Networks (specifically Dense or Fully-Connected Layers) are structured to accept only a one-dimensional (1D) array or vector of numbers as input. Before a network can "look" at an image, the image must undergo Flattening.