본문으로 바로가기

Morphology

category AI/Computer Vision 2021. 3. 24. 14:10

Morphology

1) 개요

    - Morphology is a collection of image processing methods.

    - Usually it is applied to binary images. (each pixel takes only two values; 0 or 1)

    - Segmentate image and simplify, removal, adjustment, etc.

    - Useful for cheking object's structure.

 

2) 방식

    - By sliding structuring element (SE) on a image, compute logical operation. -> Doesn't change original image.

    - The origin of SE's pixel will be changed after the covolution.

    - There are various kind of SE.

 

Erosion (침식)

1) 개요

    - Shrinking object from the image. (reduce the size of object)

    - Effective for removal of a tiny object (noise).

 

2) 방식

출처 : http://www.kocw.net/home/search/kemView.do?kemId=1127905&ar=relateCourse

    - Erosion SE kernel is composed of binary data.

    - By moving the SE, if original image can cover the whole SE, the origin of SE will change the pixel to 1.

 

3) 코드 예시 (opencv)

 

# (src, kernel, anchor, iterations)
# anchor : structuring element 중심; default = (-1, -1)
# iterations : erosion 반복횟수

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
dst = cv2.erode(img, kernel, iterations = 3)

 

Dilation (팽창)

1) 개요

    - Expand the ojbect's  surroundings.

    - It fill a hole in the object and smoothen boundary.

 

2) 방식

출처 : http://www.kocw.net/home/search/kemView.do?kemId=1127905&ar=relateCourse

    - If the original image doesn't cover whole SE kernel, the origin of SE changes its image's pixel to 1.

 

3) 코드 예시 (opencv)

# (src, kernel, anchor, iterations)
# anchor : structuring element 중심 default = (-1, -1)
# iterations : dilation 반복횟수

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
dst = cv2.dilate(img, kernel, iterations = 3)

 

Opening & Closing

1) 개요

    - The combination of erosion and dilation.

 

2) Opening

    - Erosion -> Dilation (Remove noise + expand again)

    - Useful for removing noises that is brighter than the surroundings.

    - Seperate objects which are sticked each other.

 

3) Closing

    - Dilation -> Erosion (Fill a hole + reduce again)

    - Useful for removing noises that is darker than the surroundings.

    - Fill a hole or connect objects.

Image gradient = dilation - erosion -> can get contour pixels.
Top hat = original image - opening -> emphasize bright area.
Black hat = closing - original image -> emphasize dark area.

 

Code (Opencv)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
# kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
# kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(5,5))

erosion = cv2.erode(dotImage,kernel,iterations = 1)
dilation = cv2.dilate(holeImage,kernel,iterations = 1)

opening = cv2.morphologyEx(dotImage, cv2.MORPH_OPEN, kernel)
closing = cv2.morphologyEx(holeImage, cv2.MORPH_CLOSE,kernel)
gradient = cv2.morphologyEx(orig, cv2.MORPH_GRADIENT, kernel)
tophat = cv2.morphologyEx(orig, cv2.MORPH_TOPHAT, kernel)
blackhat = cv2.morphologyEx(orig, cv2.MORPH_BLACKHAT, kernel)

참고

swprog.tistory.com/entry/Mathematical-morphology-모폴로지-연산

bkshin.tistory.com/entry/OpenCV-19-모폴로지Morphology-연산-침식-팽창-열림-닫힘-그레디언트-탑햇-블랙햇

www.kocw.net/home/index.do

'AI > Computer Vision' 카테고리의 다른 글

SIFT (Scale invariant feature transform)  (0) 2021.03.26
Harris Corner Detector  (0) 2021.03.24
Image filtering (Detecting edges)  (0) 2021.03.24
Image filtering (Blurring images)  (0) 2021.03.23
Histogram equalization  (0) 2021.03.23