[CT404]: Assignment 2 progress

This commit is contained in:
2024-11-04 00:41:03 +00:00
parent 316c5570ed
commit 418cd5b2a5
18 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# Task 1.2: Image Enhancement
import cv2
# read in chosen single-channel greyscale image
image = cv2.imread("./output/g_channel_greyscale.jpg", cv2.IMREAD_GRAYSCALE)
# apply histogram equalisation
equalised_image = cv2.equalizeHist(image)
equalised_image_contrast = equalised_image.std()
cv2.imwrite("./output/histogram_equalised.jpg", equalised_image)
# apply contrast stretching
stretched_image = cv2.normalize(image, None, 0, 255, cv2.NORM_MINMAX)
stretched_image_contrast = stretched_image.std()
cv2.imwrite("./output/contrast_stretched.jpg", stretched_image)
print("Histogram Equalisation Contrast: " + str(equalised_image_contrast))
print("Contrast Stretching Contrast: " + str(stretched_image_contrast))

View File

@ -0,0 +1,11 @@
# Task 1.3: Thresholding
import cv2
# read in chosen enhanced image
image = cv2.imread("./output/histogram_equalised.jpg", cv2.IMREAD_GRAYSCALE)
# perform otsu thresholding to find the optimal threshold
threshold_value, otsu_thresholded = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imwrite("./output/otsu.jpg", otsu_thresholded)
print("Threshold value used: " + str(threshold_value))

View File

@ -0,0 +1,14 @@
# Task 1.4: Noise Removal
import cv2
# read in thresholded image
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):
# define a disk-shaped structuring element
structuring_element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size))
# apply morphological opening to remove noise
opened_image = cv2.morphologyEx(image, cv2.MORPH_OPEN, structuring_element)
cv2.imwrite(f"./output/kernel_size_{kernel_size}.jpg", opened_image)

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB