{"id":6529,"date":"2019-03-26T10:43:07","date_gmt":"2019-03-26T01:43:07","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6529"},"modified":"2020-05-28T12:33:16","modified_gmt":"2020-05-28T03:33:16","slug":"python%ea%b3%bc-opencv-12-morphological-transformations","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6529","title":{"rendered":"Python\uacfc OpenCV \u2013 12 : Morphological Transformations"},"content":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_morphological_ops\/py_morphological_ops.html#morphological-ops \uc785\ub2c8\ub2e4.<\/p>\n<p>Morphological Transformations, \uc989 \ud615\ud0dc\ubcc0\ud658\uc740 \ud751\uacfc \ubc31\uc73c\ub85c \uad6c\uc131\ub41c \ubc14\uc774\ub108\ub9ac \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud574 \uc218\ud589\ub418\ub294 \uc5f0\uc0b0\uc73c\ub85c \uc774\ubbf8\uc9c0\uac00 \ub098\ud0c0\ub0b4\ub294 \ud615\ud0dc\uc5d0 \ub300\ud55c \ubcc0\ud658\uc744 \ubc1c\uc0dd\uc2dc\ud0b5\ub2c8\ub2e4. \ubcc0\ud658\uc758 \uc885\ub958\uc5d0\ub294 Erosion(\uce68\uc2dd), Dilation(\ud655\uc7a5), Opening, Closing \ub4f1\uc774 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ubcc0\ud658 \uc885\ub958\ubcc4\ub85c \ud558\ub098\uc529 \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uba3c\uc800 Erosion\uc5d0 \ub300\ud55c \uc608\uc81c\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/j.png', 0)\r\nkernel = np.ones((6,6), np.uint8)\r\nresult = cv2.erode(img,kernel, iterations=1)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_erosion.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6531\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Dilation\uc5d0 \ub300\ud55c \uc608\uc81c\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/j.png', 0)\r\nkernel = np.ones((7,7), np.uint8) \r\nresult = cv2.dilate(img,kernel, iterations=1)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_dilation.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6533\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Opening \uc5f0\uc0b0\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/opening.png', 0)\r\nkernel = np.ones((6,6), np.uint8) \r\nresult = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc740\ub370, \uce68\uc2dd \uc5f0\uc0b0\uc744 \uba3c\uc800 \uc218\ud589\ud558\uace0 \ub2e4\uc74c\uc5d0 \ud655\uc7a5 \uc5f0\uc0b0\uc744 \uc218\ud589\ud55c \uacb0\uacfc\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_opening.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6535\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Closing \uc5f0\uc0b0\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/closing.png', 0)\r\nkernel = np.ones((5,5), np.uint8) \r\nresult = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc740\ub370, \uba3c\uc800 \ud655\uc7a5 \uc5f0\uc0b0\uc744 \uc218\ud589\ud558\uace0 \ub2e4\uc74c\uc5d0 \uce68\uc2dd \uc5f0\uc0b0\uc744 \uc218\ud589\ud55c \uacb0\uacfc\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_closing.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6537\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Morphological Gradient \uc5f0\uc0b0\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/j.png', 0)\r\nkernel = np.ones((5,5), np.uint8) \r\nresult = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc740\ub370, \ud655\uc7a5 \uc5f0\uc0b0\uc758 \uacb0\uacfc\uc5d0\uc11c \uce68\uc2dd \uc5f0\uc0b0\uc758 \uacb0\uacfc\ub97c \ube7c\ub0b8 \uc774\ubbf8\uc9c0\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_gradient.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6539\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Top Hat \uc5f0\uc0b0\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/j.png', 0)\r\nkernel = np.ones((9,9), np.uint8) \r\nresult = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)\r\n\r\nplt.subplot(121),plt.imshow(img, cmap='gray'),plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122),plt.imshow(result, cmap='gray'),plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_top_hat.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6540\" \/><\/p>\n<p>\ub2e4\uc74c\uc740 Black Hat \uc5f0\uc0b0\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\nimg = cv2.imread('.\/data\/j.png', 0)\r\nkernel = np.ones((9,9), np.uint8) \r\nresult = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)\r\n\r\nplt.subplot(121), plt.imshow(img, cmap='gray'), plt.title('Original')\r\nplt.xticks([]), plt.yticks([])\r\nplt.subplot(122), plt.imshow(result, cmap='gray'), plt.title('Result')\r\nplt.xticks([]), plt.yticks([])\r\nplt.show()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/03\/opencv_black_hat.png\" alt=\"\" width=\"642\" height=\"546\" class=\"aligncenter size-full wp-image-6541\" \/><\/p>\n<p>\uc9c0\uae08\uae4c\uc9c0\uc758 \ud615\ud0dc\ubcc0\ud658\uc744 \uc218\ud589\ud560\ub54c \uc0ac\uc6a9\ud55c \ucee4\ub110 \ud589\ub82c \uc989, Structuring Element\ub294 numpy\uc758 \uc0ac\uac01\ud615 \ubaa8\uc591\uc758 \ub2e8\uc704 \ud589\ub82c\uc744 \uc0ac\uc6a9\ud588\ub294\ub370.. \ud544\uc694\uc5d0 \ub530\ub77c \uc6d0\uc774\ub098 \uc2ed\uc790\uac00, \ud0c0\uc6d0 \ubaa8\uc591\uc758 \ud589\ub82c\ub3c4 \uc0dd\uc131\ud558\uc5ec \ud615\ud0dc\ubcc0\ud658\uc744 \uc218\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc544\ub798\uc758 \uc608\uc81c\ub294 \uc774\ub7ec\ud55c \ub2e4\uc591\ud55c Structuring Element\ub97c \uc0dd\uc131\ud558\ub294 \uc608\uc81c\uc785\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\n\r\nprint(cv2.getStructuringElement(cv2.MORPH_RECT,(5,5)))\r\nprint()\r\n\r\nprint(cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5)))\r\nprint()\r\n\r\nprint(cv2.getStructuringElement(cv2.MORPH_CROSS,(5,5)))\r\n<\/pre>\n<p>\uc704\ub294 \ubaa8\ub450 5&#215;5 \ud589\ub82c 3\uac1c\ub97c \uc0dd\uc131\ud558\uace0 \uc788\ub294\ub370, \uac01\uac01\uc758 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><code><br \/>\n[[1 1 1 1 1]<br \/>\n [1 1 1 1 1]<br \/>\n [1 1 1 1 1]<br \/>\n [1 1 1 1 1]<br \/>\n [1 1 1 1 1]]<\/p>\n<p>[[0 0 1 0 0]<br \/>\n [1 1 1 1 1]<br \/>\n [1 1 1 1 1]<br \/>\n [1 1 1 1 1]<br \/>\n [0 0 1 0 0]]<\/p>\n<p>[[0 0 1 0 0]<br \/>\n [0 0 1 0 0]<br \/>\n [1 1 1 1 1]<br \/>\n [0 0 1 0 0]<br \/>\n [0 0 1 0 0]]<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_morphological_ops\/py_morphological_ops.html#morphological-ops \uc785\ub2c8\ub2e4. Morphological Transformations, \uc989 \ud615\ud0dc\ubcc0\ud658\uc740 \ud751\uacfc \ubc31\uc73c\ub85c \uad6c\uc131\ub41c \ubc14\uc774\ub108\ub9ac \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud574 \uc218\ud589\ub418\ub294 \uc5f0\uc0b0\uc73c\ub85c \uc774\ubbf8\uc9c0\uac00 \ub098\ud0c0\ub0b4\ub294 \ud615\ud0dc\uc5d0 \ub300\ud55c \ubcc0\ud658\uc744 \ubc1c\uc0dd\uc2dc\ud0b5\ub2c8\ub2e4. \ubcc0\ud658\uc758 \uc885\ub958\uc5d0\ub294 Erosion(\uce68\uc2dd), Dilation(\ud655\uc7a5), Opening, Closing \ub4f1\uc774 \uc788\uc2b5\ub2c8\ub2e4. \ubcc0\ud658 \uc885\ub958\ubcc4\ub85c \ud558\ub098\uc529 \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uba3c\uc800 Erosion\uc5d0 \ub300\ud55c \uc608\uc81c\uc785\ub2c8\ub2e4. import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread(&#8216;.\/data\/j.png&#8217;, 0) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6529\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python\uacfc OpenCV \u2013 12 : Morphological Transformations&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130,131],"tags":[],"class_list":["post-6529","post","type-post","status-publish","format-standard","hentry","category-opencv","category-python"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6529"}],"version-history":[{"count":7,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6529\/revisions"}],"predecessor-version":[{"id":9474,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6529\/revisions\/9474"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6529"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}