import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myImg\\opencv_logo.png',0) #흑백처리
blur = cv2.blur(img,(3,3)) # cv2.blur () 또는 cv2.boxFilter () 평균 필터
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(blur),plt.title('Blurred')
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myImg\\opencv_logo.png',0)
blur = cv2.GaussianBlur(img,(7,7),0) # 가우스 표준 편차값
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(blur),plt.title('Gaussian')
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myImg\\noise.jpg')
blur = cv2.medianBlur(img,(7)) # 중간값 표준 편차값
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(blur),plt.title('median')
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myImg\\noise.jpg')
blur = cv2.bilateralFilter(img,20,250,100) # 중간값 표준 편차값
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(blur),plt.title('bilateralFilter')
bilateralFilter ( src, d, sigmaColor, sigmaSpace) d
: 현재 픽셀의 이웃한 픽셀의 지름
비선형 필터를 구현할 때 사용, 밝기 변화가 심판 부분은 남겨두고 휘도 변화만 원만하게 만들어 준다.
cv2.erode()
: 수축 -> cv2.dilate()
팽창
cv2.morphologyEx(src,op, kernel[,dstp,anchor[,iterations[,borderType[,borderValue]]]]) -> ds
cv2.MORPH_CLOSE : 팽창한 다음에 수축
cv2.MORPH_OPEN : 수축한 다음 팽창한다.
cv2.MORPH_BLACKHAT : 입력한 이미지와 처리된 이미지의 차이를 표시
cv2.MORPH_GRADIENT : 외곽선
cv2.MORPH_TOPHAT : 9x9의 커널크기
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myimg\\letters.jpg',0)
#5x5
kernel = np.ones((5,5),np.uint8)
erosion = cv2.erode(img,kernel,iterations= 1)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(erosion),plt.title('erosion')
plt.show()
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myimg\\letters.jpg',0)
#5x5
kernel = np.ones((5,5),np.uint8)
dilates = cv2.dilate(img,kernel,iterations= 4)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(dilates),plt.title('dilates')
plt.show()
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('c:\\myImg\\letters.jpg')
#3x3
kernel = np.ones((7,7),np.uint8)
ret, img_th = cv2.threshold(img,110,255,cv2.THRESH_BINARY)
dilates = cv2.morphologyEx(img_th,cv2.MORPH_GRADIENT,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.subplot(122),plt.imshow(dilates),plt.title('morphology')
plt.show()