{"id":1111978,"date":"2025-01-08T17:34:19","date_gmt":"2025-01-08T09:34:19","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1111978.html"},"modified":"2025-01-08T17:34:22","modified_gmt":"2025-01-08T09:34:22","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b0%e7%bb%84%e4%bf%9d%e5%ad%98%e4%b8%ba%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1111978.html","title":{"rendered":"python\u5982\u4f55\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25074217\/ad16e2cc-d865-434b-a616-2388646488e1.webp\" alt=\"python\u5982\u4f55\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u5e93\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528PIL\u5e93\u3001matplotlib\u5e93\u3001OpenCV\u5e93\u7b49\u3002<\/strong> \u5176\u4e2d\uff0cPIL\u5e93\u662f\u5904\u7406\u56fe\u50cf\u7684\u5e38\u7528\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u64cd\u4f5c\u529f\u80fd\uff1bmatplotlib\u5e93\u5219\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u6570\u636e\u53ef\u89c6\u5316\u9700\u6c42\uff1bOpenCV\u5e93\u4e3b\u8981\u7528\u4e8e\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u51fd\u6570\u3002<strong>\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u5c06\u5206\u522b\u4ecb\u7ecd\u6bcf\u79cd\u5e93\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5e76\u7ed9\u51fa\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528PIL\u5e93<\/h3>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u80fd\u591f\u8bfb\u53d6\u3001\u5904\u7406\u548c\u4fdd\u5b58\u591a\u79cd\u683c\u5f0f\u7684\u56fe\u50cf\u6587\u4ef6\u3002PIL\u5e93\u7684\u73b0\u4ee3\u7248\u672c\u88ab\u79f0\u4e3aPillow\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5Pillow<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Pillow\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528Pillow\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u56fe\u7247\u5e76\u4fdd\u5b58\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.random.rand(100, 100, 3) * 255<\/p>\n<p>array = array.astype(&#39;uint8&#39;)<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.fromarray(array)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u7247<\/strong><\/h2>\n<p>image.save(&#39;output_image.png&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u968f\u673a\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a8\u4f4d\u65e0\u7b26\u53f7\u6574\u578b\uff08uint8\uff09\uff0c\u7136\u540e\u4f7f\u7528<code>Image.fromarray<\/code>\u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u56fe\u7247\uff0c\u5e76\u6700\u7ec8\u4f7f\u7528<code>save<\/code>\u65b9\u6cd5\u5c06\u56fe\u7247\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>matplotlib\u662fPython\u4e2d\u5e38\u7528\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6570\u7ec4\u7ed8\u5236\u6210\u56fe\u50cf\u5e76\u4fdd\u5b58\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5matplotlib<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5matplotlib\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528matplotlib\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528matplotlib\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.random.rand(100, 100)<\/p>\n<h2><strong>\u4f7f\u7528matplotlib\u7ed8\u5236\u56fe\u50cf<\/strong><\/h2>\n<p>plt.imshow(array, cmap=&#39;gray&#39;)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u5173\u95ed\u5750\u6807\u8f74<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u7247<\/strong><\/h2>\n<p>plt.savefig(&#39;output_image.png&#39;, bbox_inches=&#39;tight&#39;, pad_inches=0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u968f\u673a\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528<code>imshow<\/code>\u65b9\u6cd5\u7ed8\u5236\u56fe\u50cf\u3002\u4e3a\u4e86\u53bb\u6389\u5750\u6807\u8f74\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>axis(&#39;off&#39;)<\/code>\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>savefig<\/code>\u65b9\u6cd5\u5c06\u56fe\u7247\u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528OpenCV\u5e93<\/h3>\n<\/p>\n<p><p>OpenCV\uff08Open Source Computer Vision Library\uff09\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5OpenCV<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5OpenCV\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528OpenCV\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528OpenCV\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.random.rand(100, 100, 3) * 255<\/p>\n<p>array = array.astype(&#39;uint8&#39;)<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/strong><\/h2>\n<p>cv2.imwrite(&#39;output_image.png&#39;, array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u968f\u673a\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a8\u4f4d\u65e0\u7b26\u53f7\u6574\u578b\uff08uint8\uff09\uff0c\u7136\u540e\u4f7f\u7528<code>imwrite<\/code>\u65b9\u6cd5\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u4e09\u79cd\u5e38\u7528\u65b9\u6cd5\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u3002\u4f8b\u5982\uff0c\u4f7f\u7528scipy\u5e93\u7684<code>imsave<\/code>\u65b9\u6cd5\uff0c\u6216\u4f7f\u7528skimage\u5e93\u7684<code>io.imsave<\/code>\u65b9\u6cd5\u3002\u8fd9\u4e9b\u65b9\u6cd5\u540c\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528scipy\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86scipy\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528scipy\u5e93\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.misc import imsave<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.random.rand(100, 100)<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/strong><\/h2>\n<p>imsave(&#39;output_image.png&#39;, array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cscipy\u5e93\u7684<code>imsave<\/code>\u65b9\u6cd5\u5728\u65b0\u7684\u7248\u672c\u4e2d\u5df2\u88ab\u5f03\u7528\uff0c\u56e0\u6b64\u5efa\u8bae\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528skimage\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86scikit-image\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scikit-image<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528skimage\u5e93\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from skimage import io<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.random.rand(100, 100)<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247<\/strong><\/h2>\n<p>io.imsave(&#39;output_image.png&#39;, array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528\u4e0d\u540c\u7684Python\u5e93\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\uff0c\u5305\u62ecPillow\u3001matplotlib\u3001OpenCV\u3001scipy\u548cskimage\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u8bfb\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p><strong>Pillow\u5e93<\/strong>\u9002\u7528\u4e8e\u5e38\u89c4\u7684\u56fe\u50cf\u5904\u7406\u9700\u6c42\uff0c<strong>matplotlib\u5e93<\/strong>\u9002\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\uff0c<strong>OpenCV\u5e93<\/strong>\u5219\u9002\u7528\u4e8e\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\u3002\u6b64\u5916\uff0c<strong>scipy\u548cskimage\u5e93<\/strong>\u4e5f\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u56fe\u50cf\u4fdd\u5b58\u529f\u80fd\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u7075\u6d3b\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u56fe\u7247\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u548cPillow\u5e93\uff08PIL\uff09\u6765\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u56fe\u50cf\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86\u8fd9\u4e24\u4e2a\u5e93\u3002\u7136\u540e\uff0c\u901a\u8fc7NumPy\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4\uff0c\u6700\u540e\u4f7f\u7528Pillow\u7684<code>Image.fromarray()<\/code>\u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\nfrom PIL import Image\n\n# \u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u7ec4\narray = np.random.rand(100, 100, 3) * 255\narray = array.astype(np.uint8)\n\n# \u8f6c\u6362\u4e3a\u56fe\u7247\u5e76\u4fdd\u5b58\nimage = Image.fromarray(array)\nimage.save(&#39;output_image.png&#39;)\n<\/code><\/pre>\n<p><strong>\u4fdd\u5b58\u56fe\u7247\u65f6\u652f\u6301\u54ea\u4e9b\u6587\u4ef6\u683c\u5f0f\uff1f<\/strong><br \/>Python\u4e2d\u7684Pillow\u5e93\u652f\u6301\u591a\u79cd\u56fe\u7247\u683c\u5f0f\uff0c\u5305\u62ecJPEG\u3001PNG\u3001BMP\u3001GIF\u7b49\u3002\u60a8\u53ef\u4ee5\u5728\u4fdd\u5b58\u6587\u4ef6\u65f6\u901a\u8fc7\u66f4\u6539\u6587\u4ef6\u6269\u5c55\u540d\u6765\u9009\u62e9\u6240\u9700\u7684\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u4f7f\u7528<code>.jpg<\/code>\u6269\u5c55\u540d\u4fdd\u5b58\u4e3aJPEG\u683c\u5f0f\uff0c\u6216\u8005\u4f7f\u7528<code>.gif<\/code>\u4fdd\u5b58\u4e3aGIF\u683c\u5f0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6570\u7ec4\u7684\u989c\u8272\u901a\u9053\uff1f<\/strong><br \/>\u5728\u5904\u7406\u56fe\u50cf\u65f6\uff0c\u4e86\u89e3\u989c\u8272\u901a\u9053\u7684\u987a\u5e8f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5bf9\u4e8eRGB\u56fe\u50cf\uff0c\u901a\u5e38\u4f7f\u7528\u4e09\u4e2a\u901a\u9053\uff1a\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\u3002\u786e\u4fdd\u6570\u7ec4\u7684\u5f62\u72b6\u4e3a<code>(\u9ad8\u5ea6, \u5bbd\u5ea6, 3)<\/code>\uff0c\u5176\u4e2d<code>3<\/code>\u4ee3\u8868\u989c\u8272\u901a\u9053\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u7070\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5355\u901a\u9053\u6570\u7ec4\uff0c\u5176\u5f62\u72b6\u4e3a<code>(\u9ad8\u5ea6, \u5bbd\u5ea6)<\/code>\uff0c\u5e76\u5728\u4fdd\u5b58\u65f6\u6307\u5b9a\u6a21\u5f0f\u4e3a<code>&#39;L&#39;<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u4ece\u6587\u4ef6\u8bfb\u53d6\u56fe\u7247\u5e76\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u8bfb\u53d6\u56fe\u7247\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\u3002\u901a\u8fc7<code>Image.open()<\/code>\u65b9\u6cd5\u6253\u5f00\u56fe\u7247\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528<code>np.array()<\/code>\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002\u4e0b\u9762\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">from PIL import Image\nimport numpy as np\n\n# \u6253\u5f00\u56fe\u7247\nimage = Image.open(&#39;input_image.png&#39;)\n\n# \u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\narray = np.array(image)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u5e93\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u56fe\u7247\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528PIL\u5e93\u3001matplotlib\u5e93\u3001OpenCV [&hellip;]","protected":false},"author":3,"featured_media":1111986,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111978"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1111978"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111978\/revisions"}],"predecessor-version":[{"id":1111989,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111978\/revisions\/1111989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1111986"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1111978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1111978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1111978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}