🖼️ Computer Vision में Image Preprocessing
जब हम किसी Deep Learning या Machine Learning model को images पर train करना चाहते हैं, तो हमें raw data को पहले preprocess करना पड़ता है। यह preprocessing step बहुत critical है क्योंकि इससे model की accuracy, efficiency और generalization improve होती है। इस ब्लॉग में हम step-by-step Image Preprocessing के concepts, techniques और Python implementations समझेंगे।
🔹 Why Image Preprocessing?
- Noise removal: images में मौजूद unwanted information हटाना।
- Normalization: pixel values को एक fixed scale में लाना (0–1 या -1 से +1)।
- Resizing: images को एक standard size में convert करना।
- Data augmentation: training data को बढ़ाना (rotation, flipping, cropping आदि)।
- Contrast और brightness adjustments: features को highlight करने के लिए।
🛠️ Image Preprocessing Techniques
1. Image Resizing
Different datasets में images के sizes अलग होते हैं। CNN models को fixed input size चाहिए होता है। इसलिए हम OpenCV या PIL का use करके images को resize करते हैं।
import cv2
# Load image
img = cv2.imread("sample.jpg")
# Resize to 224x224
resized_img = cv2.resize(img, (224,224))
print(resized_img.shape) # (224,224,3)
2. Normalization
Pixel values 0 से 255 तक होते हैं। Training stability के लिए इन्हें 0–1 scale में normalize किया जाता है।
import numpy as np
# Normalize
normalized_img = resized_img / 255.0
print(normalized_img.min(), normalized_img.max()) # 0.0 1.0
3. Grayscale Conversion
Color channels (RGB) हमेशा जरूरी नहीं होते। कई बार grayscale images sufficient होते हैं।
gray_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2GRAY)
print(gray_img.shape) # (224,224)
4. Noise Removal (Blurring & Filters)
Images में random noise को reduce करने के लिए filters जैसे Gaussian blur और Median filter use किए जाते हैं।
# Gaussian Blur
blurred_img = cv2.GaussianBlur(resized_img, (5,5), 0)
5. Data Augmentation
Deep Learning models को robust बनाने के लिए training images को artificially बढ़ाया जाता है।
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode="nearest"
)
📊 Importance of Preprocessing in CV Models
अगर preprocessing सही तरह से नहीं की जाए तो model overfit हो सकता है, generalize नहीं करेगा और training slow हो जाएगी। Image preprocessing हर Computer Vision pipeline की foundation है। चाहे आप Image Classification, Object Detection, या Segmentation कर रहे हों – preprocessing step जरूर apply करना चाहिए।
🚀 Real-World Applications
- Medical Imaging (X-rays, MRIs को normalize और enhance करना)।
- Self-driving cars (camera feeds को preprocess करके detection improve करना)।
- Face recognition systems।
- Satellite image analysis।
✅ Conclusion
Image preprocessing एक जरूरी step है जो Computer Vision models की accuracy और performance directly impact करता है। अगली blog में हम CNNs (Convolutional Neural Networks) के बारे में detail में जानेंगे।