What is an Image and How is it Stored on a Computer?

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
  • im.mode tells the image type (e.g., β€œRGB” or β€œL”)
  • show() opens the image in a viewer

βš™οΈ 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
  • 'L' stands for luminance (grayscale)
  • You can view the result with .show()

PDF

whatisimage

Video

πŸ”— Connect with PostNetwork Academy

πŸ™ Thank You for Reading!

We hope this gave you a better understanding of how images work and how they are processed on computers. Follow us for more educational content on image processing and computer vision!

 

Β©Postnetwork-All rights reserved. Β  Β