[CT404]: Assignment 2 progress

This commit is contained in:
2024-11-08 01:05:27 +00:00
parent 353e078559
commit ca71d634e5
13 changed files with 104 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import cv2
image = cv2.imread("./output/otsu.jpg", cv2.IMREAD_GRAYSCALE)
# try several different sizes of structuring element (must be odd)
for kernel_size in range(1, 16, 2):
for kernel_size in range(1, 32, 2):
# define a disk-shaped structuring element
structuring_element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size))

View File

@ -0,0 +1,23 @@
# Task 1.5: Extraction of Binary Regions of Interest / Connected Components
import cv2
import numpy as np
# read in noise-reduced image
image = cv2.imread("./output/kernel_size_25.jpg", cv2.IMREAD_GRAYSCALE)
# Find connected components
num_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(image, connectivity=4)
# Create an output image (color) to label components
output_img = np.zeros((image.shape[0], image.shape[1], 3), dtype=np.uint8)
# Apply a single color (e.g., gray) to each component in the output image
for label in range(1, num_labels): # Skip background (label 0)
output_img[labels == label] = (200, 200, 200) # Light gray color for each component
# Overlay red text labels at component centroids
for i in range(1, num_labels): # Skip background (label 0)
x, y = int(centroids[i][0]), int(centroids[i][1])
cv2.putText(output_img, str(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) # Red color (BGR: (0, 0, 255))
cv2.imwrite("./output/region_of_interest.jpg", output_img)

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB