{"id":328330,"date":"2022-10-24T00:15:45","date_gmt":"2022-10-23T16:15:45","guid":{"rendered":"https:\/\/www.idc.net\/help\/328330\/"},"modified":"2022-10-24T00:15:45","modified_gmt":"2022-10-23T16:15:45","slug":"%e5%9b%be%e5%83%8f%e6%95%b0%e6%8d%ae%e7%9a%84%e7%89%b9%e5%be%81%e5%b7%a5%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/328330\/","title":{"rendered":"\u56fe\u50cf\u6570\u636e\u7684\u7279\u5f81\u5de5\u7a0b"},"content":{"rendered":"<p>\u4e00\u63d0\u5230\u7279\u5f81\u5de5\u7a0b\uff0c\u6211\u4eec\u7acb\u5373\u60f3\u5230\u662f\u8868\u683c\u6570\u636e\u3002\u4f46\u662f\u6211\u4eec\u4e5f\u53ef\u4ee5\u5f97\u5230\u56fe\u50cf\u6570\u636e\u7684\u7279\u5f81\uff0c\u63d0\u53d6\u56fe\u50cf\u4e2d\u6700\u91cd\u8981\u7684\u65b9\u9762\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u627e\u5230\u6570\u636e\u548c\u76ee\u6807\u53d8\u91cf\u4e4b\u95f4\u7684\u6620\u5c04\u3002<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u4f7f\u7528\u66f4\u5c11\u7684\u6570\u636e\u548c\u8bad\u7ec3\u66f4\u5c0f\u7684\u6a21\u578b\u3002\u66f4\u5c0f\u7684\u6a21\u578b\u53ef\u4ee5\u51cf\u5c11\u9884\u6d4b\u6240\u9700\u7684\u65f6\u95f4\u3002\u8fd9\u5728\u90e8\u7f72\u5230\u8fb9\u7f18\u8bbe\u5907\u65f6\u7279\u522b\u6709\u7528\u3002\u53e6\u4e00\u4e2a\u597d\u5904\u662f\uff0c\u53ef\u4ee5\u66f4\u786e\u5b9a\u6a21\u578b\u4f7f\u7528\u4ec0\u4e48\u6765\u8fdb\u884c\u8fd9\u4e9b\u9884\u6d4b\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ecb\u7ecd\u4f7f\u7528Python\u8fdb\u884c\u56fe\u50cf\u7279\u5f81\u5de5\u7a0b\u7684\u4e00\u4e9b\u65b9\u6cd5:<\/p>\n<ul>\n<li>Cropping<\/li>\n<li>Grayscalling<\/li>\n<li>Selecting RGB channels<\/li>\n<li>Intensity thresholds<\/li>\n<li>Edge detection<\/li>\n<li>Colour filters (\u7ed9\u5b9a\u7684\u989c\u8272\u8303\u56f4\u5185\u63d0\u53d6\u50cf\u7d20)<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5c06\u5728\u81ea\u52a8\u9a7e\u9a76\u6c7d\u8f66\u4e0a\u8fdb\u884c\u6f14\u793a\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u8f68\u9053\u7684\u56fe\u50cf\u8bad\u7ec3\u4e00\u4e2a\u6a21\u578b\u3002\u7136\u540e\u8be5\u6a21\u578b\u5c06\u88ab\u7528\u6765\u505a\u51fa\u9884\u6d4b\uff0c\u6307\u5bfc\u6c7d\u8f66\u884c\u9a76\u3002\u672c\u6587\u7684\u6700\u540e\u6211\u4eec\u5c06\u8ba8\u8bba\u56fe\u50cf\u6570\u636e\u7279\u5f81\u5de5\u7a0b\u7684\u5c40\u9650\u6027\u3002<\/p>\n<p style=\"text-align:center\">\n<h3>\u7279\u6027\u5de5\u7a0b\u4e0e\u589e\u5f3a<\/h3>\n<p>\u5728\u6df1\u5165\u7814\u7a76\u4e4b\u524d\uff0c\u6709\u5fc5\u8981\u8ba8\u8bba\u4e00\u4e0b\u56fe\u50cf\u589e\u5f3a\u3002\u8be5\u65b9\u6cd5\u7684\u76ee\u6807\u4e0e\u7279\u5f81\u5de5\u7a0b\u76f8\u4f3c\u3002\u4f46\u662f\u5b83\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u5b9e\u73b0\u3002<\/p>\n<h4>\u4ec0\u4e48\u662f\u6570\u636e\u589e\u5f3a?<\/h4>\n<p>\u6570\u636e\u589e\u5f3a\u662f\u6307\u6211\u4eec\u4f7f\u7528\u4ee3\u7801\u7cfb\u7edf\u5730\u6216\u968f\u673a\u5730\u6539\u53d8\u6570\u636e\u3002\u5bf9\u4e8e\u56fe\u50cf\uff0c\u8fd9\u5305\u62ec\u7ffb\u8f6c\u3001\u8c03\u6574\u989c\u8272\u548c\u6dfb\u52a0\u968f\u673a\u566a\u58f0\u7b49\u65b9\u6cd5\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5141\u8bb8\u6211\u4eec\u4eba\u4e3a\u5730\u5f15\u5165\u566a\u58f0\u5e76\u589e\u52a0\u6570\u636e\u96c6\u7684\u5927\u5c0f\u3002<\/p>\n<p>\u5728\u751f\u4ea7\u4e2d\uff0c\u6a21\u578b\u9700\u8981\u5728\u4e0d\u540c\u7684\u6761\u4ef6\u4e0b\u6267\u884c\u3002\u8fd9\u4e9b\u6761\u4ef6\u662f\u7531\u7167\u660e\u3001\u76f8\u673a\u7684\u89d2\u5ea6\u3001\u623f\u95f4\u7684\u989c\u8272\u6216\u80cc\u666f\u4e2d\u7684\u7269\u4f53\u7b49\u53d8\u91cf\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u6570\u636e\u589e\u5f3a\u7684\u76ee\u6807\u662f\u521b\u5efa\u4e00\u4e2a\u5bf9\u8fd9\u4e9b\u6761\u4ef6\u7684\u53d8\u5316\u5177\u6709\u9c81\u68d2\u6027\u7684\u6a21\u578b\u3002\u5b83\u901a\u8fc7\u6dfb\u52a0\u6a21\u62df\u73b0\u5b9e\u4e16\u754c\u6761\u4ef6\u7684\u566a\u58f0\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4f8b\u5982\uff0c\u6539\u53d8\u56fe\u50cf\u7684\u4eae\u5ea6\u7c7b\u4f3c\u4e8e\u5728\u4e00\u5929\u7684\u4e0d\u540c\u65f6\u95f4\u6536\u96c6\u6570\u636e\u3002<\/p>\n<p>\u901a\u8fc7\u589e\u52a0\u6570\u636e\u96c6\u7684\u5927\u5c0f\uff0c\u589e\u5f3a\u8fd8\u5141\u8bb8\u6211\u4eec\u8bad\u7ec3\u66f4\u590d\u6742\u7684\u67b6\u6784\u3002\u6216\u8005\u8bf4\u5b83\u6709\u52a9\u4e8e\u6a21\u578b\u53c2\u6570\u6536\u655b\u3002<\/p>\n<h4>\u56fe\u50cf\u6570\u636e\u7279\u5f81\u5de5\u7a0b<\/h4>\n<p>\u7279\u5f81\u5de5\u7a0b\u7684\u76ee\u6807\u662f\u4e0e\u589e\u5f3a\u662f\u76f8\u4f3c\u7684\uff0c\u4e5f\u5c31\u662f\u60f3\u8981\u521b\u5efa\u4e00\u4e2a\u66f4\u5065\u58ee\u7684\u6a21\u578b\u3002\u4f46\u662f\u4e0d\u540c\u7684\u662f\uff0c\u5b83\u5220\u9664\u4e86\u4efb\u4f55\u5bf9\u51c6\u786e\u9884\u6d4b\u6ca1\u6709\u5fc5\u8981\u7684\u566a\u97f3\u3002\u4e5f\u5c31\u662f\u53bb\u6389\u4e86\u5728\u4e0d\u540c\u6761\u4ef6\u4e0b\u4f1a\u53d1\u751f\u53d8\u5316\u7684\u53d8\u91cf\uff08\u8fd9\u6b63\u597d\u4e0e\u589e\u5f3a\u76f8\u53cd\uff09\u3002<\/p>\n<p>\u901a\u8fc7\u63d0\u53d6\u56fe\u50cf\u4e2d\u6700\u91cd\u8981\u7684\u90e8\u5206\u7b80\u5316\u4e86\u95ee\u9898\u3002\u8fd9\u5141\u8bb8\u4f7f\u7528\u66f4\u7b80\u5355\u7684\u6a21\u578b\u67b6\u6784\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u66f4\u5c0f\u7684\u6570\u636e\u96c6\u6765\u627e\u5230\u8f93\u5165\u548c\u76ee\u6807\u4e4b\u95f4\u7684\u6620\u5c04\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u4e2a\u91cd\u8981\u7684\u533a\u522b\u662f\u5982\u4f55\u5728\u751f\u4ea7\u4e2d\u5904\u7406\u8fd9\u4e9b\u65b9\u6cd5\u3002\u4f60\u7684\u6a21\u578b\u4e0d\u4f1a\u5bf9\u589e\u5f3a\u56fe\u50cf\u505a\u51fa\u9884\u6d4b\u3002\u4f46\u662f\u4f7f\u7528\u7279\u5f81\u5de5\u7a0b\uff0c\u6a21\u578b\u5c06\u9700\u8981\u5728\u5b83\u8bad\u7ec3\u7684\u76f8\u540c\u7279\u5f81\u4e0a\u505a\u51fa\u9884\u6d4b\u3002\u8fd9\u610f\u5473\u7740\u5fc5\u987b\u80fd\u591f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fdb\u884c\u76f8\u540c\u7684\u7279\u6027\u5de5\u7a0b\u3002<\/p>\n<h3>\u4f7f\u7528Python\u8fdb\u884c\u56fe\u50cf\u7279\u5f81\u5de5\u7a0b<\/h3>\n<p>\u4e0b\u9762\u6211\u4eec\u5f00\u59cb\u8fdb\u5165\u6b63\u9898\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u8fdb\u884c\u7279\u6027\u5de5\u7a0b\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u6211\u4eec\u6709\u4e00\u4e9b\u6807\u51c6\u5305(\u7b2c2-3\u884c)\u3002Glob\u7528\u4e8e\u5904\u7406\u6587\u4ef6\u8def\u5f84(\u7b2c5\u884c)\u3002\u6211\u4eec\u4e5f\u6709\u4e00\u4e9b\u5305\u7528\u4e8e\u5904\u7406\u56fe\u50cf(\u7b2c7-8\u884c)\u3002<\/p>\n<pre><span style=\"color: #d73a49\">import<\/span> <span style=\"color: #005cc5\">numpy<\/span> <span style=\"color: #d73a49\">as<\/span> <span style=\"color: #005cc5\">np<\/span><br> <span style=\"color: #d73a49\">import<\/span> <span style=\"color: #005cc5\">matplotlib<\/span>.<span>pyplot<\/span> <span>as<\/span> <span>plt<\/span><br> <br> <span style=\"color: #d73a49\">import<\/span> <span style=\"color: #005cc5\">glob<\/span><br> <br> <span style=\"color: #d73a49\">from<\/span> <span>PIL<\/span> <span style=\"color: #d73a49\">import<\/span> <span style=\"color: #005cc5\">Image<\/span><br> <span style=\"color: #d73a49\">import<\/span> <span style=\"color: #005cc5\">cv2<\/span><\/pre>\n<p>\u6211\u4eec\u8fd9\u91cc\u5c06\u4f7f\u7528\u7528\u4e8e\u4e3a\u81ea\u52a8\u9a7e\u9a76\u6c7d\u8f66\u63d0\u4f9b\u65b9\u5411\u8def\u5f84\u7684\u56fe\u50cf\u3002\u4f60\u53ef\u4ee5\u5728Kaggle\u4e0a\u627e\u5230\u8fd9\u4e9b\u4f8b\u5b50\u3002\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u52a0\u8f7d\u5176\u4e2d\u4e00\u4e2a\u56fe\u50cf\u3002\u9996\u5148\u52a0\u8f7d\u6240\u6709\u56fe\u50cf\u7684\u6587\u4ef6\u8def\u5f84(\u7b2c2-3\u884c)\u3002\u7136\u540e\u52a0\u8f7d(\u7b2c8\u884c)\u5e76\u5728\u7b2c\u4e00\u4e2a\u8def\u5f84\u4e0a\u663e\u793a\u56fe\u50cf(\u7b2c9\u884c)\u3002\u53ef\u4ee5\u5728\u56fe1\u4e2d\u770b\u5230\u8fd9\u4e2a\u56fe\u50cf\u3002<\/p>\n<pre><span style=\"color: #005cc5\">#Load<\/span> <span>image<\/span> <span>paths<\/span><br> <span>read_path<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #690\">\"..\/..\/data\/direction\/\"<\/span><br> <span>img_paths<\/span> <span style=\"color: #d73a49\">=<\/span> <span>glob<\/span>.<span style=\"color: #005cc5\">glob<\/span>(<span>read_path<\/span> <span style=\"color: #d73a49\">+<\/span> <span style=\"color: #690\">\"*.jpg\"<\/span>)<br> <br> <span>fig<\/span> <span style=\"color: #d73a49\">=<\/span> <span>plt<\/span>.<span style=\"color: #005cc5\">figure<\/span>(<span>figsize<\/span><span style=\"color: #d73a49\">=<\/span>(<span style=\"color: #005cc5\">10<\/span>,<span style=\"color: #005cc5\">10<\/span>))<br> <br> <span style=\"color: #005cc5\">#Display<\/span> <span>image<\/span><br> <span>img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>Image<\/span>.<span style=\"color: #005cc5\">open<\/span>(<span>img_paths<\/span>[<span style=\"color: #005cc5\">0<\/span>])<br> <span>plt<\/span>.<span style=\"color: #005cc5\">imshow<\/span>(<span>img<\/span>)<\/pre>\n<p style=\"text-align:center\">\n<h4>Cropping<\/h4>\n<p>\u88c1\u526a\u56fe\u50cf\u4ee5\u53bb\u9664\u4e0d\u9700\u8981\u7684\u5916\u90e8\u533a\u57df\uff0c\u76ee\u7684\u662f\u53ea\u5220\u9664\u56fe\u50cf\u4e2d\u4e0d\u9700\u8981\u8fdb\u884c\u9884\u6d4b\u7684\u90e8\u5206\u3002\u5bf9\u4e8e\u81ea\u52a8\u9a7e\u9a76\u6c7d\u8f66\u53ef\u4ee5\u4ece\u80cc\u666f\u4e2d\u79fb\u9664\u50cf\u7d20\u3002<\/p>\n<p>\u52a0\u8f7d\u4e00\u5f20\u56fe\u50cf(\u7b2c2\u884c)\u3002\u7136\u540e\u5c06\u8fd9\u5f20\u56fe\u50cf\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6570\u7ec4(\u7b2c5\u884c)\u3002\u8fd9\u4e2a\u6570\u7ec4\u7684\u5c3a\u5bf8\u4e3a224 x 224 x 3\u3002\u56fe\u50cf\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u4e3a224\u50cf\u7d20\uff0c\u6bcf\u4e2a\u50cf\u7d20\u90fd\u6709\u4e00\u4e2aR G B\u901a\u9053\u3002\u4e3a\u4e86\u88c1\u526a\u56fe\u50cf\uff0c\u6211\u4eec\u53ea\u9009\u62e9y\u8f74\u4e0a\u4f4d\u7f6e25\u4ee5\u4e0a\u7684\u50cf\u7d20(\u7b2c8\u884c)\u3002\u7ed3\u679c\u5982\u56fe2\u6240\u793a\u3002<\/p>\n<pre><span style=\"color: #005cc5\">#Load<\/span> <span>image<\/span><br> <span>img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>Image<\/span>.<span style=\"color: #005cc5\">open<\/span>(<span>img_paths<\/span>[<span style=\"color: #005cc5\">609<\/span>])<br> <br> <span style=\"color: #005cc5\">#Covert<\/span> <span>to<\/span> <span>array<\/span><br> <span>img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>np<\/span>.<span style=\"color: #005cc5\">array<\/span>(<span>img<\/span>)<br> <br> <span style=\"color: #005cc5\">#Simple<\/span> <span>crop<\/span><br> <span>crop_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>img<\/span>[<span style=\"color: #005cc5\">25<\/span>:,]<\/pre>\n<p style=\"text-align:center\">\n<p>\u5982\u679c\u9700\u8981\u4fdd\u6301\u7eb5\u6a2a\u6bd4\u3002\u53ef\u4ee5\u901a\u8fc7\u5c06\u4e0d\u9700\u8981\u7684\u50cf\u7d20\u53d8\u4e3a\u9ed1\u8272(\u7b2c3\u884c\u4ee3\u7801)\u6765\u5b9e\u73b0\u7c7b\u4f3c\u7684\u7ed3\u679c\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u901a\u8fc7\u88c1\u526a\uff0c\u6211\u4eec\u5220\u9664\u4e86\u4e0d\u5fc5\u8981\u7684\u50cf\u7d20\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u6a21\u578b\u5bf9\u8bad\u7ec3\u6570\u636e\u7684\u8fc7\u5ea6\u62df\u5408\u3002\u4f8b\u5982\uff0c\u80cc\u666f\u4e2d\u7684\u6905\u5b50\u53ef\u80fd\u51fa\u73b0\u5728\u6240\u6709\u5de6\u8f6c\u5904\u3002\u8be5\u6a21\u578b\u6709\u53ef\u80fd\u5c06\u8fd9\u4e9b\u4e0e\u5de6\u8f6c\u9884\u6d4b\u8054\u7cfb\u8d77\u6765\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u56fe\u7247\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u6bd4\u5982\u53ef\u4ee5\u5728\u4e0d\u5220\u9664\u4efb\u4f55\u8f68\u9053\u7684\u60c5\u51b5\u4e0b\u88c1\u526a\u56fe\u50cf\u7684\u5de6\u4fa7\u3002\u4f46\u662f\u5728\u4e0b\u56fe\u4e2d\u6211\u4eec\u8981\u5220\u9664\u91cd\u8981\u7684\u8f68\u9053\u90e8\u5206\u3002<\/p>\n<pre><span>crop_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>np<\/span>.<span style=\"color: #005cc5\">array<\/span>(<span>img<\/span>)<br> <span>crop_img<\/span>[:<span style=\"color: #005cc5\">25<\/span>,] <span style=\"color: #d73a49\">=<\/span> [<span style=\"color: #005cc5\">0<\/span>,<span style=\"color: #005cc5\">0<\/span>,<span style=\"color: #005cc5\">0<\/span>]<br> <span>crop_img<\/span>[:,:<span style=\"color: #005cc5\">40<\/span>] <span style=\"color: #d73a49\">=<\/span> [<span style=\"color: #005cc5\">0<\/span>,<span style=\"color: #005cc5\">0<\/span>,<span style=\"color: #005cc5\">0<\/span>]<\/pre>\n<p style=\"text-align:center\">\n<p>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u505a\u5462\uff1f\u8fd9\u53c8\u56de\u5230\u4e86\u7279\u6027\u5de5\u7a0b\u9700\u8981\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u8fdb\u884c\u7684\u95ee\u9898\u4e0a\u3002\u4f60\u4e0d\u77e5\u9053\u4ec0\u4e48\u56fe\u50cf\u5c06\u5728\u4ec0\u4e48\u65f6\u95f4\u663e\u793a\u7ed9\u6a21\u578b\u3002\u8fd9\u610f\u5473\u7740\u9700\u8981\u5bf9\u6240\u6709\u56fe\u50cf\u5e94\u7528\u76f8\u540c\u7684\u88c1\u526a\u529f\u80fd\uff0c\u9700\u8981\u786e\u4fdd\u5b83\u6c38\u8fdc\u4e0d\u4f1a\u5220\u9664\u56fe\u50cf\u7684\u91cd\u8981\u90e8\u5206\uff0c\u4f46\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u624d\u9700\u8981\u6a21\u62df\u8fd9\u6837\u7684\u60c5\u51b5\u3002<\/p>\n<h4>Grayscale<\/h4>\n<pre><span>gray_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>cv2<\/span>.<span style=\"color: #005cc5\">cvtColor<\/span>(<span>img<\/span>,<span>cv2<\/span>.<span style=\"color: #005cc5\">COLOR_RGB2GRAY<\/span>)<\/pre>\n<p style=\"text-align:center\">\n<p>\u7070\u5ea6\u5316\u662f\u901a\u8fc7\u6355\u6349\u56fe\u50cf\u4e2d\u7684\u989c\u8272\u5f3a\u5ea6\u6765\u5b9e\u73b0\u7684\u3002\u5b83\u901a\u8fc7\u53d6RGB\u901a\u9053\u7684\u52a0\u6743\u5e73\u5747\u503c\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u6211\u4eec\u4f7f\u7528\u8fd9\u4e2a\u516c\u5f0f:<\/p>\n<p>Y = 0.299* r + 0.587* g + 0.114* b<\/p>\n<p>\u5982\u679c\u6211\u4eec\u4f7f\u7528\u6240\u6709\u7684RGB\u901a\u9053\uff0c\u5b83\u5c06\u7531150,528\u4e2a\u503c(224*224*3)\u7ec4\u6210\u3002\u5bf9\u4e8e\u7070\u5ea6\u56fe\u50cf\uff0c\u6211\u4eec\u73b0\u5728\u53ea\u670950,176\u4e2a\u503c(224*224)\u3002\u66f4\u7b80\u5355\u7684\u8f93\u5165\u610f\u5473\u7740\u9700\u8981\u66f4\u5c11\u7684\u6570\u636e\u548c\u66f4\u7b80\u5355\u7684\u6a21\u578b\u3002<\/p>\n<h4>RGB channels<\/h4>\n<p>RGB\u901a\u9053\u4e2d\uff0c\u4e00\u4e2a\u901a\u9053\u53ef\u80fd\u66f4\u91cd\u8981\u3002\u6211\u4eec\u53ef\u4ee5\u4e0d\u8fdb\u884c\u7070\u5ea6\u5316\uff0c\u800c\u662f\u76f4\u63a5\u53ea\u4f7f\u7528\u8be5\u901a\u9053\u3002\u4f8b\u5982\u4e0b\u9762\uff0c\u6211\u4eec\u9009\u62e9R(\u7b2c6\u884c)\u3001G(\u7b2c7\u884c)\u548cB(\u7b2c8\u884c)\u901a\u9053\u3002\u6bcf\u4e2a\u751f\u6210\u7684\u6570\u7ec4\u7684\u5c3a\u5bf8\u90fd\u662f224 x 224\u3002\u60a8\u53ef\u4ee5\u5728\u56fe6\u4e2d\u770b\u5230\u76f8\u5e94\u7684\u56fe\u50cf\u3002<\/p>\n<pre><span style=\"color: #005cc5\">#Load<\/span> <span>image<\/span><br> <span>img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>Image<\/span>.<span style=\"color: #005cc5\">open<\/span>(<span>img_paths<\/span>[<span style=\"color: #005cc5\">700<\/span>])<br> <span>img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>np<\/span>.<span style=\"color: #005cc5\">array<\/span>(<span>img<\/span>)<br> <br> <span style=\"color: #005cc5\">#Get<\/span> <span>rgb<\/span> <span>channels<\/span><br> <span>r_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>img<\/span>[:, :, <span style=\"color: #005cc5\">0<\/span>]<br> <span>g_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>img<\/span>[:, :, <span style=\"color: #005cc5\">1<\/span>]<br> <span>b_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>img<\/span>[:, :, <span style=\"color: #005cc5\">2<\/span>]<\/pre>\n<p style=\"text-align:center\">\n<p>\u8fd9\u91cc\u8fd8\u53ef\u4ee5\u4f7f\u7528channel_filter\u51fd\u6570\u3002\u901a\u9053\u53c2\u6570(c)\u7684\u503c\u4e3a0\u30011\u62162\uff0c\u8fd9\u53d6\u51b3\u4e8e\u4f60\u60f3\u8981\u54ea\u4e2a\u901a\u9053\u3002\u4f46\u662f\u6709\u4e00\u70b9\uff0c\u4e0d\u540c\u7684python\u5305\u5c06\u4ee5\u4e0d\u540c\u7684\u987a\u5e8f\u52a0\u8f7d\u901a\u9053\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u7684PIL\u662fRGB\u3002\u5982\u679c\u4f7f\u7528cv2.imread()\u52a0\u8f7d\u56fe\u50cf\uff0c\u901a\u9053\u5c06\u6309BGR\u987a\u5e8f\u6392\u5e8f\u3002<\/p>\n<pre><span>def<\/span> <span>channel_filter<\/span>(<span>img<\/span>,<span>c<\/span><span style=\"color: #d73a49\">=<\/span><span style=\"color: #005cc5\">0<\/span>):<\/pre>\n<p>\u4f7f\u7528\u7070\u5ea6\u6216\u8005RGB\u7684\u901a\u9053\u9009\u62e9\uff0c\u5c31\u9700\u8981\u8003\u8651\u662f\u5426\u8981\u4ece\u56fe\u50cf\u4e2d\u5220\u9664\u4e86\u91cd\u8981\u4fe1\u606f\u3002\u4f46\u662f\u5bf9\u4e8e\u672c\u6587\u4e2d\u7684\u8f68\u9053\u793a\u4f8b\uff0c\u8f68\u9053\u662f\u6a59\u8272\u7684\uff0c\u6240\u4ee5\u6ca1\u6709\u95ee\u9898\uff0c\u8f68\u8ff9\u7684\u989c\u8272\u6709\u52a9\u4e8e\u5c06\u5176\u4e0e\u56fe\u50cf\u7684\u5176\u4ed6\u90e8\u5206\u533a\u5206\u5f00\u6765\u3002\u8fd9\u4e5f\u662f\u5728\u5b9e\u9645\u5e94\u7528\u662f\u9700\u8981\u8003\u8651\u7684\u3002<\/p>\n<h4>Intensity threshold<\/h4>\n<p>\u4f7f\u7528\u7070\u5ea6\u5316\uff0c\u6bcf\u4e2a\u50cf\u7d20\u7684\u503c\u5c06\u57280\u5230255\u4e4b\u95f4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u503c\u6765\u8fdb\u4e00\u6b65\u7b80\u5316\u8f93\u5165\u3002\u5982\u679c\u7070\u5ea6\u503c\u9ad8\u4e8e\u4e00\u4e2a\u9608\u503c\uff0c\u50cf\u7d20\u503c\u4e3a1\uff0c\u5426\u5219\u4e3a0\u3002\u6211\u4eec\u79f0\u4e4b\u4e3a\u5f3a\u5ea6\u9608\u503c\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u51fd\u6570\u7528\u4e8e\u5e94\u7528\u8be5\u9608\u503c\u3002\u9996\u5148\u5bf9\u56fe\u50cf\u8fdb\u884c\u7070\u5ea6\u5316(\u7b2c5\u884c)\u3002\u5982\u679c\u50cf\u7d20\u9ad8\u4e8e\u9608\u503c\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u8bbe\u7f6e\u62101000(\u7b2c8\u884c)\u3002\u5982\u679c\u50cf\u7d20\u503c\u4f4e\u4e8e\u9608\u503c\u5c06\u88ab\u8bbe\u7f6e\u4e3a0(\u7b2c9\u884c)\u3002\u6700\u540e\u8fd8\u5c06\u518d\u6b21\u7f29\u653e\u6240\u6709\u50cf\u7d20\uff0c\u4f7f\u5b83\u4eec\u7684\u503c\u4e3a0\u62161(\u7b2c11\u884c)\u3002<\/p>\n<p>\u81ea\u52a8\u9a7e\u9a76\u6c7d\u8f66\u9879\u76ee\u7684\u4e00\u90e8\u5206\u662f\u4e3a\u4e86\u907f\u5f00\u969c\u788d\u7269\u3002\u5728\u56fe7\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u5982\u4f55\u5e94\u7528\u5f3a\u5ea6\u9608\u503c\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u9ed1\u8272\u7684\u7f50\u5934\u969c\u788d\u7269\u4ece\u56fe\u50cf\u4e2d\u5206\u9694\u79bb\u51fa\u6765\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u8fd9\u91cc\u7684\u622a\u65ad\u503c\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u8d85\u53c2\u6570\u3002\u66f4\u5927\u7684\u622a\u65ad\u610f\u5473\u7740\u6211\u4eec\u5305\u542b\u66f4\u5c11\u7684\u80cc\u666f\u566a\u58f0\u3002\u4f46\u662f\u7f3a\u70b9\u662f\u6211\u4eec\u6355\u83b7\u7684\u8303\u56f4\u66f4\u5c0f\u3002<\/p>\n<h4>Edge detection<\/h4>\n<p>\u5982\u679c\u60f3\u5206\u79bb\u8f68\u9053\uff0c\u53ef\u4ee5\u7528\u66f4\u7cbe\u7ec6\u8fb9\u7f18\u68c0\u6d4b\u65b9\u6cd5\u3002\u8fd9\u662f\u4e00\u79cd\u7528\u4e8e\u68c0\u6d4b\u56fe\u50cf\u8fb9\u7f18\u7684\u591a\u7ea7\u7b97\u6cd5\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528cv2.Canny()\u51fd\u6570\u5e94\u7528\u8be5\u7b97\u6cd5\u3002\u5176\u4e2dthreshold1\u548cthreshold2\u4e3a\u6ede\u56de\u8fc7\u7a0b\u53c2\u6570\u3002\u8fd9\u662f\u8fb9\u7f18\u68c0\u6d4b\u7b97\u6cd5\u7684\u6700\u540e\u4e00\u4e2a\u8fc7\u7a0b\uff0c\u7528\u4e8e\u786e\u5b9a\u54ea\u4e9b\u7ebf\u662f\u771f\u6b63\u7684\u8fb9\u3002<\/p>\n<pre><span style=\"color: #005cc5\">#Apply<\/span> <span>canny<\/span> <span>edge<\/span> <span>detection<\/span><br> <span>edge_img<\/span> <span style=\"color: #d73a49\">=<\/span> <span>cv2<\/span>.<span style=\"color: #005cc5\">Canny<\/span>(<span>img<\/span>,<span>threshold1<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">50<\/span>, <span>threshold2<\/span> <span style=\"color: #d73a49\">=<\/span> <span style=\"color: #005cc5\">80<\/span>)<\/pre>\n<p>\u5c31\u50cf\u5f3a\u5ea6\u9608\u503c\u4e00\u6837\uff0c\u6211\u4eec\u7559\u4e0b\u4e86\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6620\u5c04-\u767d\u8272\u8868\u793a\u8fb9\uff0c\u9ed1\u8272\u8868\u793a\u5176\u4ed6\u3002\u8fd9\u6761\u8f68\u8ff9\u73b0\u5728\u66f4\u5bb9\u6613\u4e0e\u56fe\u50cf\u7684\u5176\u4ed6\u90e8\u5206\u533a\u5206\u5f00\u6765\u3002\u4f46\u662f\u53ef\u4ee5\u770b\u5230\u80cc\u666f\u4e2d\u7684\u8fb9\u7f18\u4e5f\u88ab\u68c0\u6d4b\u5230\u4e86\u3002<\/p>\n<p style=\"text-align:center\">\n<h4>Colour filter<\/h4>\n<p>\u5982\u679c\u6211\u4eec\u7528\u50cf\u7d20\u989c\u8272\u6765\u9694\u79bb\u8f68\u8ff9\uff0c\u53ef\u80fd\u4f1a\u6709\u66f4\u597d\u7684\u7ed3\u679c\u3002\u4f7f\u7528\u4e0b\u9762\u7684pixel_filter\u51fd\u6570\u6765\u505a\u5230\u8fd9\u4e00\u70b9\u3002cv2.inRange()\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u6620\u5c04(\u7b2c10\u884c)\u3002\u8fd9\u4e2a\u51fd\u6570\u68c0\u67e5\u50cf\u7d20\u662f\u5426\u5728lower(\u7b2c5\u884c)\u548cupper(\u7b2c6\u884c)\u5217\u8868\u7ed9\u51fa\u7684\u8303\u56f4\u5185\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6bcf\u4e2aRGB\u901a\u9053\u5fc5\u987b\u5728\u5404\u81ea\u7684\u8303\u56f4\u5185(\u4f8b\u5982134-t\u2264R\u2264194+t)\u3002<\/p>\n<pre><span>def<\/span> <span>pixel_filter<\/span>(<span>img<\/span>, <span>t<\/span><span style=\"color: #d73a49\">=<\/span><span style=\"color: #005cc5\">0<\/span>):<\/pre>\n<p>\u7b80\u5355\u6765\u8bf4\uff0c\u8be5\u51fd\u6570\u786e\u5b9a\u50cf\u7d20\u989c\u8272\u662f\u5426\u4e0e\u8f68\u9053\u7684\u6a59\u8272\u8db3\u591f\u63a5\u8fd1\u3002\u53ef\u4ee5\u5728\u56fe9\u4e2d\u770b\u5230\u7ed3\u679c\u3002\u53c2\u6570t\u5f15\u5165\u4e86\u4e00\u4e9b\u7075\u6d3b\u6027\u3002\u4f7f\u7528\u66f4\u9ad8\u7684\u503c\u53ef\u4ee5\u6355\u83b7\u66f4\u591a\u7684\u8f68\u9053\uff0c\u4f46\u4f1a\u4fdd\u7559\u66f4\u591a\u7684\u566a\u97f3\u3002\u8fd9\u662f\u56e0\u4e3a\u80cc\u666f\u4e2d\u7684\u50cf\u7d20\u4e5f\u4f1a\u843d\u5728\u8fd9\u4e2a\u8303\u56f4\u5185\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u6211\u4eec\u4ece\u54ea\u91cc\u5f97\u5230\u4e0b\u754c\u548c\u4e0a\u754c\u5462\uff1f\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u600e\u4e48\u77e5\u9053\u4f1a\u843d\u5728[134,84,55]\u548c[192,121,101]\u4e4b\u95f4?\u5982\u679c\u4f60\u6709\u5174\u8da3\uff0c\u6211\u4eec\u5c06\u5728\u540e\u9762\u7684\u6587\u7ae0\u4e2d\u89e3\u91ca\u3002<\/p>\n<p>\u5728\u56fe10\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u6b63\u5728\u8fd0\u884c\u7684\u9009\u62e9\u5668\u3002\u4ece\u591a\u4e2a\u56fe\u50cf\u4e2d\u9009\u62e9\u50cf\u7d20\uff0c\u5e76\u5c1d\u8bd5\u5728\u8f68\u9053\u4e0a\u7684\u4e0d\u540c\u4f4d\u7f6e\u9009\u62e9\u5b83\u4eec\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u5728\u4e0d\u540c\u7684\u6761\u4ef6\u4e0b\u5f97\u5230\u5b8c\u6574\u7684\u50cf\u7d20\u503c\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u6211\u4eec\u4e00\u5171\u9009\u4e8660\u79cd\u989c\u8272\u3002\u53ef\u4ee5\u5728\u56fe11\u4e2d\u770b\u5230\u6240\u6709\u8fd9\u4e9b\u3002\u6240\u6709\u8fd9\u4e9b\u989c\u8272\u7684RGB\u901a\u9053\u5b58\u50a8\u5728\u4e00\u4e2a\u5217\u8868\u53d8\u91cf-\u201ccolours\u201d\u4e2d\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u6700\u540e\uff0c\u6211\u4eec\u4e3a\u6bcf\u4e2aRGB\u901a\u9053\u53d6\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002\u8fd9\u5c31\u7ed9\u51fa\u4e86\u4e0b\u754c\u548c\u4e0a\u754c\u3002<\/p>\n<pre> <span>lower<\/span> <span style=\"color: #d73a49\">=<\/span> [<span>min<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">0<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>),<br>              <span>min<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">1<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>),<br>              <span>min<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">2<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>)]<br> <br> <span>upper<\/span> <span style=\"color: #d73a49\">=<\/span> [<span>max<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">0<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>),<br>              <span>max<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">1<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>),<br>              <span>max<\/span>(<span>x<\/span>[<span style=\"color: #005cc5\">2<\/span>] <span style=\"color: #d73a49\">for<\/span> <span>x<\/span> <span style=\"color: #d73a49\">in<\/span> <span>colours<\/span>)]<\/pre>\n<h3>\u7279\u5f81\u5de5\u7a0b\u7684\u5c40\u9650\u6027<\/h3>\n<p>\u4e0a\u9762\u5c31\u662f\u5bf9\u4e8e\u56fe\u50cf\u6570\u636e\u57fa\u672c\u7684\u7279\u5f81\u5de5\u7a0b\uff0c\u4f46\u662f\u4f60\u53ef\u80fd\u89c9\u5f97\u8fd9\u4e9b\u65b9\u6cd5\u5e76\u4e0d\u90a3\u4e48\u592a\u597d\u7528\u3002\u8fd9\u662f\u56e0\u4e3a\u6df1\u5ea6\u5b66\u4e60\u7684\u4e00\u4e2a\u4e3b\u8981\u597d\u5904\u662f\u5b83\u53ef\u4ee5\u8bc6\u522b\u590d\u6742\u7684\u6a21\u5f0f\uff0c\u800c\u4e0d\u9700\u8981\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u3002\u4f60\u9700\u8981\u5f04\u6e05\u695a\u56fe\u50cf\u7684\u54ea\u4e9b\u65b9\u9762\u662f\u91cd\u8981\u7684\uff0c\u7136\u540e\u7f16\u5199\u4ee3\u7801\u6765\u63d0\u53d6\u8fd9\u4e9b\u65b9\u9762\uff0c\u8fd9\u5728\u795e\u7ecf\u738b\u7f57\u51fa\u73b0\u4ee5\u540e\u53d8\u5f97\u4e0d\u90a3\u4e48\u91cd\u8981\u4e86\u3002<\/p>\n<p>\u53e6\u5916\u5bf9\u4e8e\u4e00\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u65e0\u6cd5\u6d88\u9664\u6240\u6709\u7684\u566a\u58f0\u3002\u4f8b\u5982\uff0c\u9ed1\u8272\u80cc\u666f\u4e2d\u7684\u566a\u58f0\u548c\u5bf9\u8c61\u50cf\u7d20\u5177\u6709\u76f8\u540c\u7684\u503c\u3002\u8fd9\u4e9b\u90fd\u662f\u624b\u52a8\u7684\u7279\u5f81\u4e0d\u8db3\u4e4b\u5904\u3002<\/p>\n<p>\u4f46\u662f\u624b\u52a8\u63d0\u53d6\u7279\u5f81\u5728\u5904\u7406\u76f8\u5bf9\u7b80\u5355\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u95ee\u9898\u65f6\u65f6\u975e\u5e38\u6709\u7528\u7684\u3002\u4f8b\u5982\u8fd9\u4e2a\u65e0\u4eba\u9a7e\u9a76\u7684\u5c0f\u8f66\uff0c\u6211\u4eec\u7684\u8f68\u8ff9\u4ece\u672a\u6539\u53d8\uff0c\u7269\u4f53\u7684\u989c\u8272\u603b\u662f\u4e00\u6837\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u52a0\u5feb\u8fd0\u884c\u901f\u5ea6\u6838\u51c6\u786e\u6027\u3002\u800c\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u66f4\u591a\u7684\u6570\u636e\uff0c\u6216\u8005\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u7684\u65b9\u6cd5\u8fdb\u884c\u590d\u6742\u7684\u6a21\u5f0f\u8bc6\u522b\u3002<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u63d0\u5230\u7279\u5f81\u5de5\u7a0b\uff0c\u6211\u4eec\u7acb\u5373\u60f3\u5230\u662f\u8868\u683c\u6570\u636e\u3002\u4f46\u662f\u6211\u4eec\u4e5f\u53ef\u4ee5\u5f97\u5230\u56fe\u50cf\u6570\u636e\u7684\u7279\u5f81\uff0c\u63d0\u53d6\u56fe\u50cf\u4e2d\u6700\u91cd\u8981\u7684\u65b9\u9762\u3002\u8fd9\u6837\u505a\u53ef\u4ee5\u66f4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":328331,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-328330","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/328330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=328330"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/328330\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/328331"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=328330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=328330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=328330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}