What is an Image and How it is Stored on a Computer
Author: Bindeshwar Singh Kushwaha
Published by: Postnetwork Academy
πΈ Concept of an Image
An image can be thought of as a 2D function:
$$ f(x, y) $$
- Each point \( (x, y) \) in the function maps to an intensity or color value.
- A point in the image is called a pixel.
- In single-channel images (e.g., binary, grayscale), each pixel has one value.
- In color images (e.g., RGB), each pixel has three values:
$$ (r_{x,y}, g_{x,y}, b_{x,y}) $$
π» Digitalization of an Image
To process images on computers, they must be digitalized:
- Image sampling: Discretizes spatial coordinates \( (x, y) \)
- Gray-level quantization: Discretizes intensity/amplitude values
- Pixel values are typically:
- Integer: 0β255
- Float: 0.0β1.0
πΎ How Are Images Stored on a Computer?
Images are stored as files (e.g., .jpg, .png) that include:
- Metadata (e.g., resolution, color profile)
- Pixel data (in array format)
Typical formats:
- Grayscale image: 2D array β width Γ height
- RGB image: 3D array β width Γ height Γ 3
β« Black and White (Binary) Image
A binary image uses 1 bit per pixel:
- Pixel value is either 0 (black) or 1 (white)
- Represented as a 2D matrix of 0s and 1s
Example:
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Matrix: height Γ width
Values: 0β1
π«οΈ Grayscale Image
A grayscale image uses 8 bits per pixel, with intensity values from 0 to 255:
- 0 = black, 255 = white
- Stored as a 2D matrix of integers
Matrix: height Γ width
π RGB (Color) Image
An RGB image uses 3 channels:
- Red, Green, and Blue (each 8 bits)
- Each channel is a 2D array
- Combined into a 3D array: height Γ width Γ 3
Common in digital photos and web images
π§ What is Image Processing?
Image processing is the automatic manipulation and analysis of images using algorithms and code.
Applications include:
- Robotics and remote sensing
- Medical imaging and diagnostics
- Industrial quality control
- Photography and social media platforms (e.g., Instagram, Facebook)
π Reading, Saving, and Displaying an Image with Python (PIL)
Using Pythonβs Pillow (PIL) library:
from PIL import Image
im = Image.open("brown_val1.jpg") # read the image
print(im.width, im.height, im.mode, im.format, type(im))
im.show() # display the image
βοΈ Convert RGB to Grayscale with PIL
You can easily convert a color image to grayscale:
im_g = im.convert('L') # convert to grayscale
im_g.save('brown_val1.jpg') # save grayscale image
Image.open("brown_val1.jpg").show() # read & display
Video
π Connect with PostNetwork Academy

