{"id":6179,"date":"2019-09-28T09:21:55","date_gmt":"2019-09-28T00:21:55","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=6179"},"modified":"2020-05-28T10:14:47","modified_gmt":"2020-05-28T01:14:47","slug":"%eb%8f%84%ed%98%95%ec%97%90-%eb%8c%80%ed%95%9c-%ec%a3%bc%ec%b6%95-%ea%b5%ac%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=6179","title":{"rendered":"PCA\ub97c \uc774\uc6a9\ud55c \ub3c4\ud615\uc5d0 \ub300\ud55c \uc8fc\ucd95 \uad6c\ud558\uae30"},"content":{"rendered":"<p><P>PCA\ub294 \uc8fc\uc131\ubd84\ubd84\uc11d(Principal Component Analysis)\ub85c \ucc28\uc6d0\uac10\uc18c\uc5d0 \ud65c\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c\ub4e4\uc5b4 2\ucc28\uc6d0\uc5d0 \ubd84\ud3ec\ub41c \ub370\uc774\ud130\ub97c 1\ucc28\uc6d0\uc758 \uc5b4\ub5a4 \ucd95\uc5d0 \ub300\ud574 \ud22c\uc601\ud588\uc744\ub54c, \ud22c\uc601\ub418\uc5b4\uc9c4 \ub370\uc774\ud130\uc758 \ubd84\ud3ec(\ub370\uc774\ud130\uac04\uc758 \uac70\ub9ac)\uac00 \uac00\uc7a5 \ud070 \ucd95, \ubc14\ub85c \uc774 \ucd95\uc774 \uc8fc\uc131\ubd84\uc774\uba70, \uc774\ub97c \ucc3e\ub294 \ubc29\ubc95\uc785\ub2c8\ub2e4. GIS\uc5d0\uc11c\ub3c4 \uc774 PCA\ub97c \uc774\uc6a9\ud558\ub294 \uacbd\uc6b0\uac00 \uc788\ub294\ub370, \uc774\ud574\ub97c \uc704\ud574 Python \uc5b8\uc5b4\ub85c \uc124\uba85\ud574 \ubd05\ub2c8\ub2e4.<\/p>\n<p>Python \uc5b8\uc5b4\ub85c \uc815\uc758\ub41c \ub2e4\uc74c\uacfc \uac19\uc740 \uc88c\ud45c\uac00 \uc788\ub2e4.<\/P><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nX = np.array([\r\n    [150,  60, -30, -20, -120, -90],\r\n    [ 70, 180,  90,  50, -30,   70]\r\n], dtype=np.float64)\r\n\r\nX = X.transpose()\r\n<\/pre>\n<p>X\ucd95\uc5d0 \ub300\ud55c \uc88c\ud45c\uac12\uacfc Y\ucd95\uc5d0 \ub300\ud55c \uc88c\ud45c\uac12 \uac01\uac01\uc73c\ub85c \uad6c\uc131\ub418\ub2e4\uac00 \uc804\uce58\ub418\uc5b4 X, Y \uc88c\ud45c\uac00 \uc30d\uc744 \ub9fa\ub294 \ud615\ud0dc\uc774\ub2e4. \uc704\uc758 \uc88c\ud45c\ub97c \ud654\uba74\uc5d0 \ud45c\uc2dc\ud574 \ubcf4\uae30 \uc704\ud574 \uc774\ubbf8\uc9c0 \ubc84\ud37c\ub97c \uc0dd\uc131\ud558\uace0 \ud45c\uc2dc\ud55c\ub2e4. \uc544\ub798\ucc98\ub7fc..<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\ndst = np.full((512,512,3), (255, 255, 255), dtype= np.uint8)\r\n\r\nrows, cols, _ = dst.shape\r\ncenterX = cols \/\/ 2\r\ncenterY = rows \/\/ 2\r\n\r\ncv2.line(dst, (0,256), (cols-1, 256), (0, 0, 0))\r\ncv2.line(dst, (256,0), (256,rows), (0, 0, 0))\r\n\r\nFLIP_Y = lambda y: rows - 1 - y\r\n\r\nfor k in range(X.shape[0]):\r\n    x, y = X[k,:]\r\n    cx = int(x+centerX)\r\n    cy = int(y+centerY)\r\n    cy = FLIP_Y(cy)\r\n    cv2.circle(dst, (cx,cy), radius=5, color=(0,0,255), thickness=-1)\r\n    \r\ncv2.imshow('dst', dst)               \r\ncv2.waitKey()    \r\ncv2.destroyAllWindows()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/02\/major_axis_2.png\" alt=\"\" width=\"643\" height=\"681\" class=\"aligncenter size-full wp-image-6185\" \/><\/p>\n<p>1\ubc88 \ucf54\ub4dc\uc5d0\uc11c \uc88c\ud45c\uac12\uc744 \uace0\ub824\ud574\uc11c \ucda9\ubd84\ud55c \ud06c\uae30(512&#215;512)\uc758 \ubc84\ud37c\ub97c \uc900\ube44\ud55c\ub2e4. 7, 8\ubc88 \ucf54\ub4dc\ub294 \ud654\uba74\uc758 \uc815\uc911\uc559\uc744 \uc6d0\uc810\uc73c\ub85c XY\ucd95\uc744 \uadf8\ub824\uc8fc\ub294 \uac83\uc774\ub2e4. Y\ucd95\uc5d0 \ub300\ud574\uc11c\ub294 \uc218\ud559\uc801\uc778 \ucd95\ubc29\ud5a5\uacfc \ucef4\ud4e8\ud130 \uadf8\ub798\ud53d \ud654\uba74\uc758 \ucd95\ubc29\ud5a5\uc774 \ubc18\ub300\uc774\ubbc0\ub85c 10\ubc88 \ub78c\ub2e4 \ud568\uc218\uac00 \ud544\uc694\ud558\ub2e4. 12\ubc88 \ucf54\ub4dc\uc5d0 \ud45c\uc2dc\ub41c \ubc18\ubcf5\ubb38\uc744 \ud1b5\ud574 \uac01 \uc88c\ud45c\uc5d0 \ub300\ud574 \ube68\uac04\uc0c9 \uc6d0\uc73c\ub85c \ud45c\uc2dc\ud55c\ub2e4. (\uaf2d \ud544\uc694\ud55c \ubd80\ubd84\uc740 \uc544\ub2c8\uc9c0\ub9cc) \uc785\ub825 \ub370\uc774\ud130\ub97c \uc2dc\uac01\ud654\ud588\uc73c\ubbc0\ub85c \uc774\uc81c \uc8fc\ucd95\uc744 \uacc4\uc0b0\ud574\ubcf4\uc790.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\ncov, mean = cv2.calcCovarMatrix(X, mean=None, flags=cv2.COVAR_NORMAL+cv2.COVAR_ROWS)\r\nret, eVals, eVects = cv2.eigen(cov)\r\n\r\ndef ptsEigenVector(eVal, eVect):\r\n    scale = np.sqrt(eVal)\r\n    \r\n    x1 = scale*eVect[0]\r\n    y1 = scale*eVect[1]\r\n\r\n    x2, y2 = -x1, -y1\r\n\r\n    x1 += mean[0,0] + centerX\r\n    y1 += mean[0,1] + centerY\r\n    x2 += mean[0,0] + centerX\r\n    y2 += mean[0,1] + centerY\r\n    \r\n    y1 = FLIP_Y(y1)\r\n    y2 = FLIP_Y(y2)\r\n\r\n    return x1, y1, x2, y2\r\n<\/pre>\n<p>1\ubc88 \ucf54\ub4dc\uc758 cov, mean\uc740 \uac01\uac01 X\ucd95\uacfc Y\ucd95\uc744 \uad6c\uc131\ud558\ub294 \uac01\uac01\uc758 \uacf5\ubd84\uc0b0 \uadf8\ub9ac\uace0 \uc88c\ud45c\uac12\uc758 \ud3c9\uade0\uc774\ub2e4. 2\ubc88 \ucf54\ub4dc\uc758 eVals\uc640 eVects\ub294 \uacf5\ubd84\uc0b0 cov\uc5d0 \ub300\ud55c \uace0\uc720\uac12\uacfc \uace0\uc720\ubca1\ud130\uc774\ub2e4. \ud568\uc218 ptsEigenVector\ub294 \uc8fc\ucd95 \uacc4\uc0b0\uc744 \uc704\ud55c \ud568\uc218\uc774\ub2e4. \uc774 \ud568\uc218\uc758 \uc4f0\uc784\uc740 \uc544\ub798\uc640 \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nx1x, y1x, x2x, y2x = ptsEigenVector(eVals[0], eVects[0])\r\nx1y, y1y, x2y, y2y = ptsEigenVector(eVals[1], eVects[1])\r\n<\/pre>\n<p>x1x, y1x, x2x, y2x\ub294 X\ucd95\uc5d0 \ub300\ud55c \uc8fc\ucd95 \uc120\ubd84\uc758 \uc2dc\uc791\uc810\uacfc \ub05d\uc810\uc774\uace0, x1y, y1y, x2y, y2y\ub294 Y\ucd95\uc5d0 \ub300\ud55c \uc8fc\ucd95\uc758 \uc2dc\uc791\uc810\uacfc \ub05d\uc810\uc774\ub2e4. \uc774\uc81c \uacb0\uacfc\ub97c \uc2dc\uac01\ud654 \ud574\ubcf4\uc790.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\ncv2.line(dst, (x1x, y1x), (x2x, y2x), (255, 0, 0), 1)\r\ncv2.line(dst, (x1y, y1y), (x2y, y2y), (255, 0, 0), 1)\r\n\r\ncv2.imshow('dst', dst)               \r\ncv2.waitKey()    \r\ncv2.destroyAllWindows()\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/02\/major_axis_1.png\" alt=\"\" width=\"643\" height=\"681\" class=\"aligncenter size-full wp-image-6184\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PCA\ub294 \uc8fc\uc131\ubd84\ubd84\uc11d(Principal Component Analysis)\ub85c \ucc28\uc6d0\uac10\uc18c\uc5d0 \ud65c\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c\ub4e4\uc5b4 2\ucc28\uc6d0\uc5d0 \ubd84\ud3ec\ub41c \ub370\uc774\ud130\ub97c 1\ucc28\uc6d0\uc758 \uc5b4\ub5a4 \ucd95\uc5d0 \ub300\ud574 \ud22c\uc601\ud588\uc744\ub54c, \ud22c\uc601\ub418\uc5b4\uc9c4 \ub370\uc774\ud130\uc758 \ubd84\ud3ec(\ub370\uc774\ud130\uac04\uc758 \uac70\ub9ac)\uac00 \uac00\uc7a5 \ud070 \ucd95, \ubc14\ub85c \uc774 \ucd95\uc774 \uc8fc\uc131\ubd84\uc774\uba70, \uc774\ub97c \ucc3e\ub294 \ubc29\ubc95\uc785\ub2c8\ub2e4. GIS\uc5d0\uc11c\ub3c4 \uc774 PCA\ub97c \uc774\uc6a9\ud558\ub294 \uacbd\uc6b0\uac00 \uc788\ub294\ub370, \uc774\ud574\ub97c \uc704\ud574 Python \uc5b8\uc5b4\ub85c \uc124\uba85\ud574 \ubd05\ub2c8\ub2e4. Python \uc5b8\uc5b4\ub85c \uc815\uc758\ub41c \ub2e4\uc74c\uacfc \uac19\uc740 \uc88c\ud45c\uac00 \uc788\ub2e4. X = np.array([ [150, 60, -30, -20, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=6179\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;PCA\ub97c \uc774\uc6a9\ud55c \ub3c4\ud615\uc5d0 \ub300\ud55c \uc8fc\ucd95 \uad6c\ud558\uae30&#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":[8],"tags":[],"class_list":["post-6179","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6179","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=6179"}],"version-history":[{"count":9,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6179\/revisions"}],"predecessor-version":[{"id":9378,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/6179\/revisions\/9378"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6179"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}