{"id":178922,"date":"2022-04-24T01:07:04","date_gmt":"2022-04-23T17:07:04","guid":{"rendered":"http:\/\/www.idc.net\/help\/178922\/"},"modified":"2022-04-24T01:07:04","modified_gmt":"2022-04-23T17:07:04","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/178922\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u5982\u4f55\u5904\u7406\u56fe\u7247"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/004\/5d859c76b2dd9248.jpg\" class=\"aligncenter\"><\/p>\n<p>\u4e00\u63d0\u5230\u6570\u5b57\u56fe\u50cf\u5904\u7406\uff0c\u53ef\u80fd\u5927\u591a\u6570\u4eba\u5c31\u4f1a\u60f3\u5230matlab\uff0c\u4f46matlab\u4e5f\u6709\u81ea\u8eab\u7684\u7f3a\u70b9\uff1a<\/p>\n<p>1\u3001\u4e0d\u5f00\u6e90\uff0c\u4ef7\u683c\u8d35<\/p>\n<p>2\u3001\u8f6f\u4ef6\u5bb9\u91cf\u5927\u3002\u4e00\u822c3G\u4ee5\u4e0a\uff0c\u9ad8\u7248\u672c\u751a\u81f3\u8fbe5G\u4ee5\u4e0a\u3002<\/p>\n<p>3\u3001\u53ea\u80fd\u505a\u7814\u7a76\uff0c\u4e0d\u6613\u8f6c\u5316\u6210\u8f6f\u4ef6\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u8fd9\u91cc\u4f7f\u7528python\u8fd9\u4e2a\u811a\u672c\u8bed\u8a00\u6765\u8fdb\u884c\u6570\u5b57\u56fe\u50cf\u5904\u7406\u3002<\/p>\n<p>\u8981\u4f7f\u7528python\uff0c\u5fc5\u987b\u5148\u5b89\u88c5python\uff0c\u4e00\u822c\u662f2.7\u7248\u672c\u4ee5\u4e0a\uff0c\u4e0d\u7ba1\u662f\u5728windows\u7cfb\u7edf\uff0c\u8fd8\u662flinux\u7cfb\u7edf\uff0c\u5b89\u88c5\u90fd\u662f\u975e\u5e38\u7b80\u5355\u7684\u3002<\/p>\n<p>\u8981\u4f7f\u7528python\u8fdb\u884c\u5404\u79cd\u5f00\u53d1\uff0c\u5c31\u5fc5\u987b\u5b89\u88c5\u5bf9\u5e94\u7684\u5e93\u3002\u8fd9\u548cmatlab\u975e\u5e38\u76f8\u4f3c\uff0c\u53ea\u662fmatlab\u91cc\u9762\u53eb\u5de5\u5177\u7bb1\uff08toolbox)\uff0c\u800cpython\u91cc\u9762\u53eb\u5e93\u6216\u5305\u3002\u5b89\u88c5\u8fd9\u4e9b\u5e93\uff0c\u4e00\u822c\u90fd\u662f\u4f7f\u7528pip\u6765\u5b89\u88c5\u3002<\/p>\n<p>\u4f7f\u7528python\u8fdb\u884c\u6570\u5b57\u56fe\u7247\u5904\u7406\uff0c\u8fd8\u5f97\u5b89\u88c5Pillow\u5305\u3002\u867d\u7136python\u91cc\u9762\u81ea\u5e26\u4e00\u4e2aPIL\uff08python images library), \u4f46\u8fd9\u4e2a\u5e93\u73b0\u5728\u5df2\u7ecf\u505c\u6b62\u66f4\u65b0\u4e86\uff0c\u6240\u4ee5\u4f7f\u7528Pillow, \u5b83\u662f\u7531PIL\u53d1\u5c55\u800c\u6765\u7684\u3002<\/p>\n<pre>pip&nbsp;install&nbsp;Pillow<\/pre>\n<p>\u4e00\u3001\u56fe\u7247\u7684\u6253\u5f00\u4e0e\u663e\u793a<\/p>\n<pre>from&nbsp;PIL&nbsp;import&nbsp;Image\nimg=Image.open('d:\/dog.png')\nimg.show()<\/pre>\n<p>\u867d\u7136\u4f7f\u7528\u7684\u662fPillow\uff0c\u4f46\u5b83\u662f\u7531PIL fork\u800c\u6765\uff0c\u56e0\u6b64\u8fd8\u662f\u8981\u4ecePIL\u4e2d\u8fdb\u884cimport. \u4f7f\u7528open()\u51fd\u6570\u6765\u6253\u5f00\u56fe\u7247\uff0c\u4f7f\u7528show()\u51fd\u6570\u6765\u663e\u793a\u56fe\u7247\u3002<\/p>\n<p>\u8fd9\u79cd\u56fe\u7247\u663e\u793a\u65b9\u5f0f\u662f\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u81ea\u5e26\u7684\u56fe\u7247\u6d4f\u89c8\u5668\u6765\u6253\u5f00\u56fe\u7247\uff0c\u6709\u4e9b\u65f6\u5019\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u592a\u65b9\u4fbf\uff0c\u56e0\u6b64\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u53e6\u4e0a\u4e00\u79cd\u65b9\u5f0f\uff0c\u8ba9\u7a0b\u5e8f\u6765\u7ed8\u5236\u56fe\u7247\u3002<\/p>\n<pre>from&nbsp;PIL&nbsp;import&nbsp;Imageimport&nbsp;matplotlib.pyplot&nbsp;as&nbsp;plt\nimg=Image.open('d:\/dog.png')\nplt.figure(\"dog\")\nplt.imshow(img)\nplt.show()<\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u590d\u6742\u4e86\u4e9b\uff0c\u4f46\u63a8\u8350\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u5b83\u4f7f\u7528\u4e00\u4e2amatplotlib\u7684\u5e93\u6765\u7ed8\u5236\u56fe\u7247\u8fdb\u884c\u663e\u793a\u3002matplotlib\u662f\u4e00\u4e2a\u4e13\u4e1a\u7ed8\u56fe\u7684\u5e93\uff0c\u76f8\u5f53\u4e8ematlab\u4e2d\u7684plot,\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2afigure,\u8bbe\u7f6efigure\u7684\u6807\u9898\uff0c\u751a\u81f3\u53ef\u4ee5\u4f7f\u7528subplot\u5728\u4e00\u4e2afigure\u4e2d\u663e\u793a\u591a\u5f20\u56fe\u7247\u3002matplotlib \u53ef\u4ee5\u76f4\u63a5\u5b89\u88c5\u3002<\/p>\n<p>figure\u9ed8\u8ba4\u662f\u5e26axis\u7684\uff0c\u5982\u679c\u6ca1\u6709\u9700\u8981\uff0c\u6211\u4eec\u53ef\u4ee5\u5173\u6389<\/p>\n<pre>plt.axis('off')<\/pre>\n<p>\u6253\u5f00\u56fe\u7247\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5c5e\u6027\u6765\u67e5\u770b\u56fe\u7247\u4fe1\u606f\uff0c\u5982<\/p>\n<pre>print&nbsp;img.size&nbsp;&nbsp;#\u56fe\u7247\u7684\u5c3a\u5bf8print&nbsp;img.mode&nbsp;&nbsp;#\u56fe\u7247\u7684\u6a21\u5f0fprint&nbsp;img.format&nbsp;&nbsp;#\u56fe\u7247\u7684\u683c\u5f0f<\/pre>\n<p>\u663e\u793a\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>(558, 450)<br \/>RGBA<br \/>PN<\/p>\n<p>\u4e8c\u3001\u56fe\u7247\u7684\u4fdd\u5b58<\/p>\n<pre>img.save('d:\/dog.jpg')<\/pre>\n<p>\u5c31\u4e00\u884c\u4ee3\u7801\uff0c\u975e\u5e38\u7b80\u5355\u3002\u8fd9\u884c\u4ee3\u7801\u4e0d\u4ec5\u80fd\u4fdd\u5b58\u56fe\u7247\uff0c\u8fd8\u662f\u8f6c\u6362\u683c\u5f0f\uff0c\u5982\u672c\u4f8b\u4e2d\uff0c\u5c31\u7531\u539f\u6765\u7684png\u56fe\u7247\u4fdd\u5b58\u4e3a\u4e86jpg\u56fe\u7247\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u63d0\u5230\u6570\u5b57\u56fe\u50cf\u5904\u7406\uff0c\u53ef\u80fd\u5927\u591a\u6570\u4eba\u5c31\u4f1a\u60f3\u5230matlab\uff0c\u4f46matlab\u4e5f\u6709\u81ea\u8eab\u7684\u7f3a\u70b9\uff1a 1\u3001\u4e0d\u5f00\u6e90\uff0c\u4ef7\u683c\u8d35 2\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":178923,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-178922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/178922","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=178922"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/178922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/178923"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=178922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=178922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=178922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}