Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 회귀
- Computer Vision
- 프로세스
- 알고리즘
- Windows10
- 프로그래밍
- 쉘
- 시스템프로그래밍
- OpenCV
- 딥러닝
- Windows 10
- 백준알고리즘
- 코딩
- 공부
- shell
- 백준
- 턱걸이
- c
- TensorFlow
- C++
- 리눅스
- 운영체제
- 텐서플로우
- C언어
- python
- CV
- error
- linux
- 영상처리
- 학습
Archives
- Today
- Total
줘이리의 인생적기
CV - opencv(Python) Morphology 본문
728x90
Morphology에 대해 알아보겠습니다.
객체 외곽선을 부드럽게 하거나, 구멍을 메꾸거나, 작은 점을 지우는 기능.
이진 영상, 회색조 영상에도 수행 가능.
기본 Morphology 연산
-Dilation(팽창) : 각 픽셀의 structuring element를 적용하여 or연산 수행, 겹치면 형태 확장
-Erosion(침식) : 각 픽셀의 structuring element를 적용하여 and연산 수행, 겹치지 않으면 형태 축소
활용 Morphology 연산
-Opening : Erosion 후 Dilation 적용 (작은 돌기, 노이즈 제거)
-Closing : Dilation 후 Erosion 적용 (전체적인 윤곽 파악)
-Gradient : Dilation 이미지에서 Eriosion 이미지 빼는 연산(경계선 검출 방법)
Morphology
코드 원형 설명
#Dilation
def imageDilation(image, kernel, iterations):
return cv2.dilate(image, kernel=kernel, iterations=iterations)
#Erosion
def imageErosion(image, kernel, iterations):
return cv2.erode(image, kernel=kernel, iterations=iterations)
#Opening
def imageOpening(image, iterations = 1):
kernel = np.ones((3, 3), np.uint8)
erosion = imageErosion(image, kernel, iterations)
return imageDilation(erosion, kernel, iterations)
#Closing
def imageClosing(image, iterations = 1):
kernel = np.ones((3, 3), np.uint8)
dilation = imageDilation(image, kernel, iterations)
return imageErosion(dilation, kernel, iterations)
#Gradient
def imageMorphologicalGradient(image, iterations = 1):
kernel = np.ones((3, 3), np.uint8)
dilation = imageDilation(image, kernel, iterations)
erosion = imageErosion(image, kernel, iterations)
return dilation-erosion
코드 설명
더보기
from OpenCV_Functions import *
#이미지 설정
imagePath = "<이미지 경로>"
image = imageRead(imagePath, cv2.IMREAD_GRAYSCALE)
imageShow("image", image)
#morphology 설정
image_threshold = imageThreshold(image, 128, 255, cv2.THRESH_BINARY)
kernel = np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]], np.uint8)
image_Dilation = imageDilation(image_threshold, kernel, 1)
image_Erosion = imageErosion(image_threshold, kernel, 1)
image_Opening = imageOpening(image_threshold, 1)
image_Closing = imageClosing(image_threshold, 1)
image_Gradient = imageMorphologicalGradient(image_threshold)
#창 띄우기
imageShow("threshold", image_threshold)
imageShow("Dilation", image_Dilation)
imageShow("Erosion", image_Erosion)
imageShow("Opening", image_Opening)
imageShow("Closing", image_Closing)
imageShow("Gradient", image_Gradient)
cv2.destroyAllWindows()
'공부 > Computer Vision(py)' 카테고리의 다른 글
CV - opencv(Python) Hough Transform(설명필요) (0) | 2020.07.24 |
---|---|
CV - opencv(Python) Geometric Transform(설명필요) (0) | 2020.07.23 |
CV - opencv(Python) Canny Edge (0) | 2020.07.21 |
CV - opencv(Python) 경계선 검출(edge detection) (0) | 2020.07.20 |
CV - opencv(Python) Blur, GaussianBlur, MedianBlur (0) | 2020.07.17 |