[CT404]: Assignment 2 progress
@ -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))
|
@ -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))
|
@ -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)
|
After Width: | Height: | Size: 168 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 308 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 277 KiB |
After Width: | Height: | Size: 216 KiB |
After Width: | Height: | Size: 168 KiB |
After Width: | Height: | Size: 115 KiB |
After Width: | Height: | Size: 310 KiB |