Implement Basic Image Processing Operations (Feature Representation and Extraction)

Aim

To implement basic image processing operations for feature representation and extraction—specifically edge detection, blob detection, and corner detection—using Python and OpenCV.


Algorithm

  1. Image Loading: Read an input image and convert to grayscale if needed.

  2. Preprocessing: Optionally resize or smooth the image for noise reduction.

  3. Edge Detection: Apply the Canny edge detector to highlight boundaries.

  4. Blob Detection: Use Laplacian of Gaussian (LoG) via skimage’s blob_log.

  5. Corner Detection: Detect corners using the Harris method or Shi-Tomasi detector.

  6. Visualization: Display and interpret results for each operation.


Program (Python)

open cmd or terminal and then type "pip install numpy opencv-python matplotlib scikit-image" to install the required packages
import cv2 import numpy as np from matplotlib import pyplot as plt from skimage.feature import blob_log # Step 1: Load and preprocess the image img = cv2.imread('ex1.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (5, 5), 0) # Step 2: Edge Detection (Canny) edges = cv2.Canny(gray, 100, 200) # Step 3: Blob Detection (LoG) blobs = blob_log(gray, max_sigma=30, num_sigma=10, threshold=0.2) blob_img = img.copy() for y, x, r in blobs: cv2.circle(blob_img, (int(x), int(y)), int(r), (0,255,0), 2) # Step 4: Corner Detection (Harris) dst = cv2.cornerHarris(np.float32(gray), 2, 3, 0.04) corner_img = img.copy() corner_img[dst > 0.01 * dst.max()] = [0, 0, 255] # Step 5: Display Results plt.figure(figsize=(10,8)) plt.subplot(2,2,1), plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)), plt.title('Original') plt.subplot(2,2,2), plt.imshow(edges, cmap='gray'), plt.title('Edge Detection (Canny)') plt.subplot(2,2,3), plt.imshow(cv2.cvtColor(blob_img, cv2.COLOR_BGR2RGB)), plt.title('Blob Detection (LoG)') plt.subplot(2,2,4), plt.imshow(cv2.cvtColor(corner_img, cv2.COLOR_BGR2RGB)), plt.title('Corner Detection (Harris)') plt.tight_layout() plt.show()

Output



ex1 input image
ex1 output




Result

This lab exercise demonstrates the use of edge, blob, and corner detectors—each capturing different types of image features:

  • Edges delineate object boundaries, aiding in structure analysis.

  • Blobs detect prominent, homogeneous regions useful for segmentation or counting.

  • Corners identify repeatable interest points, crucial for matching, registration, and tracking.