Learn to plot the correct image idiot

main
Gasper Spagnolo 2022-10-21 14:51:40 +02:00
parent 8538bfac3d
commit a4aea8de7a
2 changed files with 28 additions and 22 deletions

BIN
assignment1/images/mask.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

View File

@ -388,7 +388,7 @@ def excercise_three() -> None:
three_a()
def three_a():
def three_a() -> None:
"""
We will perform two basic morphological operations on the image mask.png, erosion
and dilation. We will also experiment with combinations of both operations, named
@ -398,51 +398,57 @@ def three_a():
Answer: Opening = Erosion then dialation
Closing = Dialation then erosion
"""
img_orig = uz.imread_gray('./images/bird.jpg', uz.ImageType.float64)
img_orig = uz.imread_gray('./images/mask.png', uz.ImageType.float64)
img_er_dil = img_orig.copy()
img_dil_er = img_orig.copy()
img_comb = img_orig.copy()
img_er_dil_N = 5
SE = np.ones((img_er_dil_N, img_er_dil_N), np.float64)
SE_size = 2
SE = np.ones((SE_size, SE_size), np.float64)
fig, axs = plt.subplots(3, 4)
fig.suptitle("Image after N iterations of Opening, Closing and combination of opening and closing")
imgs = []
for im_ix in range(4):
SE = np.ones((SE_size, SE_size), np.float64)
img_er_dil = cv2.erode(img_er_dil, SE)
img_er_dil = cv2.dilate(img_er_dil, SE)
imgs.append(img_er_dil.copy())
axs[0, im_ix].imshow(img_er_dil.copy(), cmap='gray')
axs[0, im_ix].set(title=f"after {im_ix + 1} iterations of Opening, SE: {SE_size} x {SE_size}")
SE_size +=1
for im_ix in range(4):
axs[0, im_ix].imshow(imgs[im_ix], cmap='gray')
axs[0, im_ix].set(title=f"image after {im_ix + 1} iterations of opening")
imgs=[]
SE_size = 2
for im_ix in range(4):
img_dil_er = cv2.erode(img_dil_er, SE)
SE = np.ones((SE_size, SE_size), np.float64)
img_dil_er = cv2.dilate(img_dil_er, SE)
imgs.append(img_dil_er.copy())
img_dil_er = cv2.erode(img_dil_er, SE)
axs[1, im_ix].imshow(img_dil_er.copy(), cmap='gray')
axs[1, im_ix].set(title=f"after {im_ix + 1} iterations of Closing, SE: {SE_size} x {SE_size}")
SE_size +=1
for im_ix in range(4):
axs[1, im_ix].imshow(imgs[im_ix], cmap='gray')
axs[1, im_ix].set(title=f"Image after {im_ix + 1} iterations of Closing")
imgs = []
SE_size = 2
for im_ix in range(4):
img_comb = cv2.erode(img_comb, SE)
img_comb = cv2.dilate(img_comb, SE)
img_comb = cv2.dilate(img_comb, SE)
img_comb = cv2.erode(img_comb, SE)
imgs.append(img_comb)
axs[2, im_ix].imshow(img_comb.copy(), cmap='gray')
axs[2, im_ix].set(title=f"after {im_ix + 1} iterations of O+C, SE: {SE_size} x {SE_size}")
SE_size +=1
for im_ix in range(4):
axs[2, im_ix].imshow(imgs[im_ix], cmap='gray')
axs[2, im_ix].set(title=f"Image after {im_ix + 1} iterations of O + C")
plt.show()
def three_b() -> None:
"""
Try to clean up the mask of the image bird.jpg using morphological operations
as shown in the image. Experiment with different sizes of the structuring element.
You can also try different shapes, like cv2.getStructuringElement(cv2.MORPH_-
ELLIPSE,(n,n)).
"""
def main() -> None: