Implement Basic Image Processing Operations (Feature Representation and Extraction)

Aim

To implement and demonstrate fundamental image processing operations for feature representation and extraction—including edge, blob, and corner detection—on a sample image using Python and OpenCV.

Algorithm

1. Load and preprocess the image (convert to grayscale, resize if needed).

2. Edge detection using the Canny edge detector.

3. Blob detection using the Laplacian of Gaussian (LoG) method.

4. Corner detection using the Harris Corner or Shi-Tomasi method.

5. Visualize and display outputs for each step.


Code (Python)

import cv2

import numpy as np

from matplotlib import pyplot as plt

from skimage.feature import blob_log


# Load and preprocess the image

img = cv2.imread('sample.jpg', cv2.IMREAD_GRAYSCALE)


# Edge Detection (Canny)

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


# Blob Detection (Laplacian of Gaussian)

blobs = blob_log(img, max_sigma=30, num_sigma=10, threshold=0.2)

img_blobs = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

for y, x, r in blobs:

    cv2.circle(img_blobs, (int(x), int(y)), int(r), (0, 255, 0), 2)


# Corner Detection (Harris)

img_float = np.float32(img)

harris = cv2.cornerHarris(img_float, 2, 3, 0.04)

img_corners = img.copy()

img_corners[harris > 0.01 * harris.max()] = 255


# Visualize outputs

plt.figure(figsize=(10,8))

plt.subplot(2,2,1), plt.imshow(img, cmap='gray'), 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(img_blobs, cv2.COLOR_BGR2RGB)), plt.title('Blob Detection (LoG)')

plt.subplot(2,2,4), plt.imshow(img_corners, cmap='gray'), plt.title('Corner Detection (Harris)')

plt.tight_layout()

plt.show()

```