{"id":6485,"date":"2019-03-25T08:18:08","date_gmt":"2019-03-24T23:18:08","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6485"},"modified":"2020-05-28T12:35:23","modified_gmt":"2020-05-28T03:35:23","slug":"python%ea%b3%bc-opencv-8-image-thresholding-2-2","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6485","title":{"rendered":"Python\uacfc OpenCV \u2013 9 : Image Thresholding (2\/2)"},"content":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_thresholding\/py_thresholding.html#thresholding \uc785\ub2c8\ub2e4.<\/p>\n<p>\uc774\ubbf8\uc9c0\uc5d0 \ub300\ud55c Thresholding \uc5f0\uc0b0\uc744 \uc218\ud589\ud560 \ub54c, \uc784\uacc4\uce58 \uac12\uc744 \uac1c\ubc1c\uc790\uac00 \uc9c1\uc811 \uc9c0\uc815\ud574 \uc8fc\uc5c8\ub294\ub370 \uc774\ub97c \uc790\ub3d9\uc73c\ub85c \uacc4\uc0b0\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc774 \uc788\uc2b5\ub2c8\ub2e4. \ubc14\ub85c Otsu\uc758 \uc774\uc9c4\ud654(Binarization)\uc785\ub2c8\ub2e4.  Otsu\uc758 \uc774\uc9c4\ud654(Binarization)\uac00 \uac00\uc7a5 \ud6a8\uacfc\uc801\uc73c\ub85c \ubc1c\ud718\ub420 \uc218 \uc788\ub294 \uc774\ubbf8\uc9c0\ub294 Historam\uc758 \ud53c\ud06c(Peak)\uac00 2\uac1c \uc778 \uacbd\uc6b0\uc785\ub2c8\ub2e4. \ud53c\ud06c\uac00 2\uac1c\uac00 \uc544\ub2cc \uacbd\uc6b0 \uacb0\uacfc\ub294 \ubd80\uc815\ud655\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc758 \ud788\uc2a4\ud1a0\uadf8\ub7a8\uc5d0\uc11c \ud53c\ud06c\ub97c 2\uac1c \uac16\ub3c4\ub85d \ube14\ub7ec\ub9c1\uc744 \ud1b5\ud574 \uc7a1\uc74c\uc744 \uc81c\uac70\ud558\uae30\ub3c4 \ud569\ub2c8\ub2e4. \uc544\ub798\uc758 \uc608\uc81c\ub97c \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\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\/apple.jpg', 0)\r\n\r\n# \uc784\uacc4\uce58\ub97c 127\ub85c \uc9c0\uc815\ud55c \uacbd\uc6b0\r\nret1,th1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)\r\n\r\n# Otsu \ubc29\ubc95\uc73c\ub85c \uc784\uacc4\uce58\ub97c \ub0b4\ubd80\uc801\uc73c\ub85c \uacc4\uc0b0\ud558\uc5ec \uc9c0\uc815\ud55c \uacbd\uc6b0\r\nret2,th2 = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)\r\n\r\n# \uc7a1\uc74c \uac10\uc18c\ub97c \uc704\ud574 Gaussian filtering \uc5f0\uc0b0 \ud6c4 Otsu \ubc29\ubc95\uc73c\ub85c \uc784\uacc4\uce58\ub97c \uacc4\uc0b0\ud55c \uacbd\uc6b0\r\nblur = cv2.GaussianBlur(img, (5,5), 0)\r\nret3,th3 = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)\r\n\r\nprint(ret1, ret2, ret3)\r\n\r\n# plot all the images and their histograms\r\nimages = [img, 0, th1,\r\n          img, 0, th2,\r\n          blur, 0, th3]\r\n\r\ntitles = ['Original Noisy Image','Histogram','Global Thresholding (v=127)',\r\n          'Original Noisy Image','Histogram',\"Otsu's Thresholding\",\r\n          'Gaussian filtered Image','Histogram',\"Otsu's Thresholding\"]\r\n\r\nfor i in range(3):\r\n    plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray')\r\n    plt.title(titles[i*3]), plt.xticks([]), plt.yticks([])\r\n    plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256)\r\n    plt.title(titles[i*3+1]), plt.xticks([]), plt.yticks([])\r\n    plt.subplot(3,3,i*3+3),plt.imshow(images[i*3+2],'gray')\r\n    plt.title(titles[i*3+2]), plt.xticks([]), plt.yticks([])\r\n\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_OTSU.png\" alt=\"\" width=\"1055\" height=\"793\" class=\"aligncenter size-full wp-image-6486\" \/><\/p>\n<p>\ub3d9\uc77c\ud55c \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud574 3\ubc88\uc758 Thresholding \uc5f0\uc0b0\uc744 \uc218\ud589\ud55c \uacb0\uacfc\uc785\ub2c8\ub2e4. 8\ubc88 \ucf54\ub4dc\ub294 \uc784\uacc4\uce58\ub97c 127\ub85c \uba85\uc2dc\ud558\uc5ec Thresholding \uc5f0\uc0b0\uc744 \uc218\ud589\ud55c \uac83\uc774\uace0 11\ubc88 \ucf54\ub4dc\ub294 \uc784\uacc4\uce58\ub97c \ubbf8\uc9c0\uc815(0)\ud558\uace0 4\ubc88\uc9f8\uc5d0 cv2.THRESH_OTSU \uc635\uc158\uc744 \uc9c0\uc815\ud558\uc5ec \uc784\uacc4\uce58\ub97c \uc790\ub3d9\uc73c\ub85c \uacc4\uc0b0\ud558\ub3c4\ub85d \ud558\uc600\uc2b5\ub2c8\ub2e4. \uc774 \uacbd\uc6b0 v2.threshold \ud568\uc218\ub294 ret2 \ubcc0\uc218\uc5d0 \uacc4\uc0b0\ub41c \uc784\uacc4\uce58 \uac12\uc774 \ubc18\ud658\ub429\ub2c8\ub2e4. 15\ubc88 \ucf54\ub4dc\ub294 \uc774\ubbf8\uc9c0\ub97c \uba3c\uc800 \uac00\uc6b0\uc2dc\uc548 \ube14\ub7ec\ub9c1 \ucc98\ub9ac\ub97c \uc218\ud589\ud558\uace0 Othu \ubc29\uc2dd\uc758 Thresholding\uc744 \uc218\ud589\ud569\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc5d0 \uc7a1\uc74c\uc774 \ub9ce\uc740 \uacbd\uc6b0 \uc774 \ubc29\uc2dd\uc744 \ud1b5\ud574 Peak\uac00 2\uac1c\uc778 \ud788\uc2a4\ud1a0\uadf8\ub7a8\uc744 \uc0dd\uc131\ud569\ub2c8\ub2e4. \uc774\ubbf8 \uc6d0\ubcf8 \uc774\ubbf8\uc9c0\uc758 \ud788\uc2a4\ud1a0\uadf8\ub7a8\uc774 Peak\ub97c 2\uac1c \uac00\uc9c0\uace0 \uc788\uc73c\ubbc0\ub85c 3\uac1c\uc758 \uacb0\uacfc\uac00 \ud070 \ucc28\uc774\uac00 \uc5c6\uc9c0\ub9cc \uc7a1\uc74c\uc774 \ub9e4\uc6b0 \uc2ec\ud55c  \uc774\ubbf8\uc9c0\uc758 \uacbd\uc6b0 \uac00\uc6b0\uc2dc\uc548 \ube14\ub7ec\ub9c1 \ucc98\ub9ac\ub97c \uc218\ud589 \ud6c4 Othu \ubc29\uc2dd\uc758 Thresholding \uc5f0\uc0b0\uc740 \ud070 \uc758\ubbf8\uac00 \uc788\uc2b5\ub2c8\ub2e4.<\/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_thresholding\/py_thresholding.html#thresholding \uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc5d0 \ub300\ud55c Thresholding \uc5f0\uc0b0\uc744 \uc218\ud589\ud560 \ub54c, \uc784\uacc4\uce58 \uac12\uc744 \uac1c\ubc1c\uc790\uac00 \uc9c1\uc811 \uc9c0\uc815\ud574 \uc8fc\uc5c8\ub294\ub370 \uc774\ub97c \uc790\ub3d9\uc73c\ub85c \uacc4\uc0b0\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc774 \uc788\uc2b5\ub2c8\ub2e4. \ubc14\ub85c Otsu\uc758 \uc774\uc9c4\ud654(Binarization)\uc785\ub2c8\ub2e4. Otsu\uc758 \uc774\uc9c4\ud654(Binarization)\uac00 \uac00\uc7a5 \ud6a8\uacfc\uc801\uc73c\ub85c \ubc1c\ud718\ub420 \uc218 \uc788\ub294 \uc774\ubbf8\uc9c0\ub294 Historam\uc758 \ud53c\ud06c(Peak)\uac00 2\uac1c \uc778 \uacbd\uc6b0\uc785\ub2c8\ub2e4. \ud53c\ud06c\uac00 2\uac1c\uac00 \uc544\ub2cc \uacbd\uc6b0 \uacb0\uacfc\ub294 \ubd80\uc815\ud655\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc758 \ud788\uc2a4\ud1a0\uadf8\ub7a8\uc5d0\uc11c \ud53c\ud06c\ub97c 2\uac1c \uac16\ub3c4\ub85d \ube14\ub7ec\ub9c1\uc744 \ud1b5\ud574 \uc7a1\uc74c\uc744 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6485\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python\uacfc OpenCV \u2013 9 : Image Thresholding (2\/2)&#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-6485","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\/6485","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=6485"}],"version-history":[{"count":6,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6485\/revisions"}],"predecessor-version":[{"id":9481,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6485\/revisions\/9481"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6485"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}