Laporan Final Project
Laporan Final Project
Laporan Final Project
Disusun Oleh :
NIM. 180411100081
FAKULTAS TEKNIK
TAHUN 2021
1. Negative Images
Program :
#read image
img_src = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png
')
cv2_imshow(img)
histr = cv2.calcHist([img],
[i], None,
[256],
[0, 256])
plt.show()
cv2_imshow(img)
histr = cv2.calcHist([img],
[i], None,
[256],
[0, 256])
plt.show()
2. Log Transformation
Program :
#read image
image = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png')
cv2_imshow(image)
# Apply log transformation method
c = 255 / np.log(1 + np.max(image))
log_image = c * (np.log(image + 1))
3. Histogram Equalization
Program :
#read image
img_src = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png
')
cv2_imshow(img)
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * float(hist.max()) / cdf.max()
plt.plot(cdf_normalized, color = 'b')
plt.hist(img.flatten(),256,[0,256], color = 'r')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
plt.show()
4. Lowpass filtering
Program :
#read image
img_src = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png
')
cv2_imshow(img)
Program :
#read image
img = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png')
cv2_imshow(img)
# Convert to graycsale
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Blur the image for better edge detection
img_blur = cv2.GaussianBlur(img_gray, (3,3), 0)
cv2_imshow(img_blur)
# Sobel Edge Detection
sobelx = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=0, ksize
=5) # Sobel Edge Detection on the X axis
sobely = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=0, dy=1, ksize
=5) # Sobel Edge Detection on the Y axis
sobelxy = cv2.Sobel(src=img_blur, ddepth=cv2.CV_64F, dx=1, dy=1, ksiz
e=5) # Combined X and Y Sobel Edge Detection
cv2_imshow(sobelx)
cv2_imshow(sobely)
cv2_imshow(sobelxy)
# Canny Edge Detection
edges = cv2.Canny(image=img_blur, threshold1=100, threshold2=200) # C
anny Edge Detection
# Display Canny Edge Detection Image
cv2_imshow(edges)
6. Thressholding
Program :
#read image
img = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png', c
v2.IMREAD_GRAYSCALE)
cv2_imshow(img)
cv2_imshow(thresh1)
cv2_imshow(thresh2)
cv2_imshow(thresh3)
cv2_imshow(thresh4)
cv2_imshow(thresh5)
7. Boundary Detection – Morphological Image
Program :
#read image
img = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png', c
v2.IMREAD_GRAYSCALE)
cv2_imshow(img)
# Morphological Gradient
erode = cv2.erode(img,structure_element2,iterations = 1)
dilate = cv2.dilate(img,structure_element2,iterations = 1)
mg = np.subtract(dilate,erode)
cv2_imshow(mg)
8. Connected Component Labelling
Program :
#read image
img = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png', 0
)
cv2_imshow(img)
for i in range(8):
plt.subplot(2, 4, i+1), plt.imshow(images[i], 'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
9. Image Skeletonization
Program :
#read image
img = cv2.imread('/content/drives/MyDrive/Final Project/lenna.png', 0
)
cv2_imshow(img)
cv2_imshow(skel)