{"id":6652,"date":"2019-04-08T11:22:45","date_gmt":"2019-04-08T02:22:45","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6652"},"modified":"2020-05-28T12:27:08","modified_gmt":"2020-05-28T03:27:08","slug":"python%ea%b3%bc-opencv-21-%ed%9e%88%ec%8a%a4%ed%86%a0%ea%b7%b8%eb%9e%a8histogram-2-4","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6652","title":{"rendered":"Python\uacfc OpenCV \u2013 21 : \ud788\uc2a4\ud1a0\uadf8\ub7a8(Histogram) 2\/4"},"content":{"rendered":"<p>\uc774 \uae00\uc758 \uc6d0\ubb38\uc740 https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_imgproc\/py_histograms\/py_histogram_equalization\/py_histogram_equalization.html#histogram-equalization \uc785\ub2c8\ub2e4.<\/p>\n<p>\ud788\uc2a4\ud1a0\uadf8\ub7a8\uc744 \ud65c\uc6a9\ud558\uc5ec \uc774\ubbf8\uc9c0\uc758 \ud488\uc9c8\uc744 \uac1c\uc120\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc774 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub4f1\ud654(Equalization)\uc785\ub2c8\ub2e4. \uc774\ud574\ub97c \ub3d5\uae30 \uc704\ud574 \uc544\ub798\uc758 \ucf54\ub4dc\ub97c \uc0b4\ud3b4\ubcf4\uba74..<\/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\/wiki.jpg', 0)\r\n\r\nhist,bins = np.histogram(img.flatten(),256,[0,256])\r\n\r\n#cdf = hist.cumsum()\r\n#cdf_m = np.ma.masked_equal(cdf,0)\r\n#cdf_m = (cdf_m - cdf_m.min())*255\/(cdf_m.max()-cdf_m.min())\r\n#cdf = np.ma.filled(cdf_m,0).astype('uint8')\r\n#img = cdf[img]\r\n\r\ncv2.imshow('img', img)\r\n\r\nplt.hist(img.flatten(),256,[0,256], color = 'r')\r\nplt.xlim([0,256])\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\/04\/histogram1.png\" alt=\"\" width=\"639\" height=\"543\" class=\"aligncenter size-full wp-image-6653\" \/><\/p>\n<p>\uc774\ubbf8\uc9c0\uc758 \ud654\uc18c\uac12\uc774 0-255\uc5d0 \uac78\uccd0 \uade0\ub4f1\ud558\uac8c \ubd84\ud3ec\ud558\uc9c0 \ubabb\ud558\uace0 120-210 \uc815\ub3c4 \uc0ac\uc774\uc5d0 \ubc00\uc9d1\ub418\uc5b4 \uc788\uc5b4 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \uc774\ubbf8\uc9c0\uc758 \ud488\uc9c8\uc744 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub3d9\ud654 \ubc29\ubc95\uc744 \uc774\uc6a9\ud574 \uac1c\uc120\ud574 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4. \uba3c\uc800 numpy\ub97c \uc774\uc6a9\ud55c \ucf54\ub4dc\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\/wiki.jpg', 0)\r\n\r\nhist,bins = np.histogram(img.flatten(),256,[0,256])\r\n\r\ncdf = hist.cumsum()\r\ncdf_m = np.ma.masked_equal(cdf,0)\r\ncdf_m = (cdf_m - cdf_m.min())*255\/(cdf_m.max()-cdf_m.min())\r\ncdf = np.ma.filled(cdf_m,0).astype('uint8')\r\nimg = cdf[img]\r\n\r\ncv2.imshow('img', img)\r\n\r\nplt.hist(img.flatten(),256,[0,256], color = 'r')\r\nplt.xlim([0,256])\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\/04\/histogram2.png\" alt=\"\" width=\"639\" height=\"544\" class=\"aligncenter size-full wp-image-6655\" \/><\/p>\n<p>\ubfcc\uc607\uac8c \ubcf4\uc600\ub358 \uc774\ubbf8\uc9c0\uac00 \uc880\ub354 \uba85\ud655\uc774 \ubcf4\uc774\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774\uc720\ub294 \uc704\uc758 \uc774\ubbf8\uc9c0\uc758 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uadf8\ub798\ud504\ucc98\ub7fc \ud654\uc18c\uac12\uc774 0-255 \uc0ac\uc774\uc5d0 \uace0\ub8e8\uac8c \ubd84\ud3ec\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>OpenCV\uc758 \ud568\uc218\ub97c \uc774\uc6a9\ud55c \ubc29\uc2dd\uc5d0 \ub300\ud55c \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\n\r\nimg = cv2.imread('.\/data\/tsukuba_l_clr.png',0)\r\nequ = cv2.equalizeHist(img)\r\nres = np.hstack((img,equ)) #stacking images side-by-side\r\n\r\ncv2.imshow('img', res)\r\ncv2.waitKey()\r\ncv2.destroyAllWindows()\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\/04\/histogram3.png\" alt=\"\" width=\"771\" height=\"321\" class=\"aligncenter size-full wp-image-6657\" \/><\/p>\n<p>\uc67c\ucabd\uc740 \uc6d0\ubcf8\uc774\uace0 \uc624\ub978\ucabd\uc774 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub4f1\ud654\ub97c \ud1b5\ud55c \uc774\ubbf8\uc9c0\uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uac00 \uba85\ud655\ud574\uc9c0\uae34\ud588\uc73c\ub098 \uc11d\uace0\uc0c1\uc758 \ubc1d\uae30\uac12\uc774 \ub108\ubb34 \ud07d\ub2c8\ub2e4. \uc774\ub294 \uc774\ubbf8\uc9c0\uac00 \uc804\uccb4\uc801\uc73c\ub85c \ube5b\uc774 \uace0\ub974\uac8c \ube44\uce58\uc9c0 \ubabb\ud558\uace0  \uc11d\uace0\uc0c1\uc5d0 \uc0c1\ub300\uc801\uc73c\ub85c \ub354 \ub9ce\uc740 \ube5b\uc774 \ube44\ucdb0\uc84c\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4. \uc774\ub97c \uc704\ud574\uc11c\ub294 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub4f1\ud654\ub97c \uc774\ubbf8\uc9c0 \uc804\uccb4\uc5d0 \ub300\ud574 \uc801\uc6a9\ud558\ub294\uac8c \uc544\ub2cc \uc77c\uc815\ud55c \uc601\uc5ed\uc744 \ubd84\ub9ac\ud558\uc5ec \ud574\ub2f9 \uc601\uc5ed\uc5d0 \ub300\ud55c \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub4f1\ud654 \uc5f0\uc0b0\uc744 \uc218\ud589\ud574 \uadf8 \uacb0\uacfc\ub97c \uc870\ud569\ud558\uba74 \ub429\ub2c8\ub2e4. \uc774\ub7ec\ud55c \uc54c\uace0\ub9ac\uc998\uc744 CLAHE(Contrast Limited Adaptive Histogram Equalization)\ub77c\uace0 \ud558\ub294\ub370, \ud574\ub2f9 \ucf54\ub4dc\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport cv2\r\nimport numpy as np\r\n\r\nimg = cv2.imread('.\/data\/tsukuba_l_clr.png',0)\r\n\r\nclahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))\r\ncl1 = clahe.apply(img)\r\n\r\nres = np.hstack((img,cl1)) #stacking images side-by-side\r\n\r\ncv2.imshow('img', res)\r\ncv2.waitKey()\r\ncv2.destroyAllWindows()\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\/04\/histogram4.png\" alt=\"\" width=\"771\" height=\"321\" class=\"aligncenter size-full wp-image-6659\" \/><\/p>\n<p>CLAHE \uc54c\uace0\ub9ac\uc998\uc744 \uad6c\ud604\ud55c cv2.createCLAHE \ud568\uc218\uc5d0\uc11c tileGridSize=(8,8)\uc774\ub77c\ub294 \uc758\ubbf8\ub294 8&#215;8 \uaca9\uc790 \ud06c\uae30\uc758 \uc601\uc5ed\uc744 \uc0ac\uc6a9\ud55c\ub2e4\ub294 \uac83\uc785\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_histograms\/py_histogram_equalization\/py_histogram_equalization.html#histogram-equalization \uc785\ub2c8\ub2e4. \ud788\uc2a4\ud1a0\uadf8\ub7a8\uc744 \ud65c\uc6a9\ud558\uc5ec \uc774\ubbf8\uc9c0\uc758 \ud488\uc9c8\uc744 \uac1c\uc120\ud558\uae30 \uc704\ud55c \ubc29\ubc95\uc774 \ud788\uc2a4\ud1a0\uadf8\ub7a8 \uade0\ub4f1\ud654(Equalization)\uc785\ub2c8\ub2e4. \uc774\ud574\ub97c \ub3d5\uae30 \uc704\ud574 \uc544\ub798\uc758 \ucf54\ub4dc\ub97c \uc0b4\ud3b4\ubcf4\uba74.. import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread(&#8216;.\/data\/wiki.jpg&#8217;, 0) hist,bins = np.histogram(img.flatten(),256,[0,256]) #cdf = hist.cumsum() #cdf_m = np.ma.masked_equal(cdf,0) #cdf_m = (cdf_m &#8211; cdf_m.min())*255\/(cdf_m.max()-cdf_m.min()) #cdf = np.ma.filled(cdf_m,0).astype(&#8216;uint8&#8217;) #img = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6652\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Python\uacfc OpenCV \u2013 21 : \ud788\uc2a4\ud1a0\uadf8\ub7a8(Histogram) 2\/4&#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-6652","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\/6652","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=6652"}],"version-history":[{"count":7,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6652\/revisions"}],"predecessor-version":[{"id":9461,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6652\/revisions\/9461"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6652"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}