Skip to content

shuvo-halder/image-processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🖼️ Image Processing Procedure (Step-by-Step)

This section explains the general steps followed in an image-processing workflow, regardless of the programming language or library.


📊 Image Processing Flowchart

               ┌────────────────────┐
               │   Start Program     │
               └─────────┬──────────┘
                         │
                         ▼
             ┌────────────────────────┐
             │ 1. Import Libraries     │
             └─────────┬──────────────┘
                       │
                       ▼
        ┌────────────────────────────┐
        │ 2. Load Input Image        │
        └──────────┬─────────────────┘
                   │
                   ▼
     ┌──────────────────────────────┐
     │ 3. Convert to Grayscale?     │
     │ (if required)                │
     └──────────┬───────────────────┘
                │
                ▼
    ┌───────────────────────────────┐
    │ 4. Pre-processing             │
    │ - Resize                      │
    │ - Noise Reduction (Blur)      │
    └──────────┬────────────────────┘
               │
               ▼
    ┌───────────────────────────────┐
    │ 5. Enhancement (Optional)     │
    │ - Sharpen                     │
    │ - Histogram Equalization      │
    └──────────┬────────────────────┘
               │
               ▼
   ┌────────────────────────────────┐
   │ 6. Image Processing / Analysis │
   │ - Edge Detection               │
   │ - Thresholding                 │
   │ - Contour Detection            │
   └──────────┬─────────────────────┘
              │
              ▼
     ┌──────────────────────────────┐
     │ 7. Post-processing (Optional)│
     │ - Dilation / Erosion         │
     │ - Smoothing                  │
     └──────────┬───────────────────┘
                │
                ▼
     ┌──────────────────────────────┐
     │ 8. Display Results           │
     └──────────┬───────────────────┘
                │
                ▼
     ┌──────────────────────────────┐
     │ 9. Save Output Image         │
     └──────────┬───────────────────┘
                │
                ▼
          ┌──────────────┐
          │     End       │
          └──────────────┘

1. Import Required Libraries

Before processing images, load the required Python libraries such as:

  • OpenCV (cv2)
  • NumPy
  • Pillow (optional)
import cv2
import numpy as np

2. Load the Image

Read the input image from the local directory or a URL.

image = cv2.imread("image.jpg")

3. Convert the Image to a Suitable Format (Optional)

Many operations need grayscale conversion:

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

4. Pre-processing

Prepare the image by applying filters or corrections.

Common steps:

a. Resize Image

resized = cv2.resize(image, (400, 400))

b. Noise Reduction (Smoothing / Blurring)

blur = cv2.GaussianBlur(gray, (5, 5), 0)

5. Image Enhancement (Optional)

Techniques to improve image quality:

a. Histogram Equalization

equalized = cv2.equalizeHist(gray)

b. Sharpening

kernel = np.array([[0, -1, 0],
                   [-1, 5,-1],
                   [0, -1, 0]])
sharpened = cv2.filter2D(image, -1, kernel)

6. Feature Extraction / Processing

Perform operations to extract useful information.

a. Edge Detection (e.g., Canny)

edges = cv2.Canny(gray, 100, 200)

b. Thresholding

_, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)

c. Contour Detection

contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

7. Post-processing (Optional)

Refine the processed image.

Examples:

  • Dilation
  • Erosion
  • Closing
  • Smoothing after detection
kernel = np.ones((3,3), np.uint8)
dilated = cv2.dilate(thresh, kernel, iterations=1)

8. Display the Results

Show the final or intermediate image:

cv2.imshow("Output", edges)
cv2.waitKey(0)
cv2.destroyAllWindows()

9. Save the Processed Image

cv2.imwrite("output.jpg", edges)