[CT404]: Assignment 2 progress
@ -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))
|
||||
|
||||
|
@ -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)
|
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 163 KiB |