Skip to content

Instantly share code, notes, and snippets.

@cagbal
Created March 23, 2019 20:01
Show Gist options
  • Select an option

  • Save cagbal/9edcb4c1a60f28ad879bc30a0c976354 to your computer and use it in GitHub Desktop.

Select an option

Save cagbal/9edcb4c1a60f28ad879bc30a0c976354 to your computer and use it in GitHub Desktop.
!pip install opencv-python
!wget https://images.pexels.com/photos/860562/pexels-photo-860562.jpeg
import cv2
import numpy as np
import PIL
from IPython.display import display
#Resmi okuyalım
imge = cv2.imread("pexels-photo-860562.jpeg")
#Rengi BGR'den RGB'ye çevirelim
imge = cv2.cvtColor(imge, cv2.COLOR_BGR2RGB)
#Resmin boyutlarını normalize edelim
imge = cv2.resize(imge, (500, 500))
#Bastıralım
display(PIL.Image.fromarray(imge))
#Maskeyi oluşturalım, rastgele çizgiler ve bir kare çizip resmi bozalım
imge = imge.astype("uint8")
maske = np.ones((500, 500,3), dtype=imge.dtype)
maske[300:310,:,:] = 0
maske[400:405,:,:] = 0
maske[200:220,400:420,:] = 0
maske[:,100:103,:] = 0
#Bunu bitwise and gibi düşünebilirsiniz
imge = np.multiply(imge, maske)
# Bastıralım
display(PIL.Image.fromarray(imge))
#inpainting fonksiyonu bizim oluşturduğumuz maskenin tam tersini istiyor, o yüzden 1'den çıkarıyoruz bütün maskeyi
maske = 1-maske[:,:,0]
#CV'nin inpainting fonksiyonu
imge = cv2.inpaint(imge,maske,3,cv2.INPAINT_TELEA)
# Bastıralım
display(PIL.Image.fromarray(imge))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment