{"id":1123666,"date":"2025-01-08T19:34:31","date_gmt":"2025-01-08T11:34:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1123666.html"},"modified":"2025-01-08T19:34:33","modified_gmt":"2025-01-08T11:34:33","slug":"%e5%9c%a8python%e4%b8%adimage%e5%a6%82%e4%bd%95%e7%94%a8%e6%9c%ac%e5%9c%b0%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1123666.html","title":{"rendered":"\u5728python\u4e2dimage\u5982\u4f55\u7528\u672c\u5730\u56fe\u7247"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085036\/6033115c-8d5c-40d3-87ef-4523bb354f07.webp\" alt=\"\u5728python\u4e2dimage\u5982\u4f55\u7528\u672c\u5730\u56fe\u7247\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u672c\u5730\u56fe\u7247\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u663e\u793a\u3002<strong>\u4f7f\u7528Pillow\u5e93\u3001\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528OpenCV\u5e93<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u4e3b\u8981\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Pillow\u5e93\u6765\u52a0\u8f7d\u548c\u663e\u793a\u672c\u5730\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><p><strong>Pillow\u5e93<\/strong>\u662fPython\u56fe\u50cf\u5904\u7406\u7684\u7ecf\u5178\u5e93\uff0c\u5b83\u80fd\u591f\u8f7b\u677e\u5730\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u56fe\u50cf\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Pillow\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\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><p>\u5728\u5b89\u88c5\u5b8cPillow\u5e93\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u52a0\u8f7d\u548c\u663e\u793a\u672c\u5730\u56fe\u7247\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\u672c\u5730\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_your_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u7247<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u5728Python\u4e2d\u4f7f\u7528\u672c\u5730\u56fe\u7247\u8fdb\u884c\u5404\u79cd\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5728Python\u4e2d\u4f7f\u7528\u672c\u5730\u56fe\u7247\u7684\u5176\u4ed6\u65b9\u6cd5\u548c\u66f4\u9ad8\u7ea7\u7684\u56fe\u50cf\u5904\u7406\u6280\u672f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Pillow\u5e93<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u662fPython\u56fe\u50cf\u5904\u7406\u7684\u6807\u51c6\u5e93\u4e4b\u4e00\uff0c\u5176\u524d\u8eab\u662fPython Imaging Library (PIL)\u3002Pillow\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u5305\u62ec\u56fe\u50cf\u6253\u5f00\u3001\u4fdd\u5b58\u3001\u526a\u5207\u3001\u6ee4\u955c\u3001\u8c03\u6574\u5927\u5c0f\u3001\u65cb\u8f6c\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u5e93\u52a0\u8f7d\u548c\u663e\u793a\u672c\u5730\u56fe\u7247\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u9700\u8981\u5bfc\u5165Image\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528Image.open()\u65b9\u6cd5\u52a0\u8f7d\u56fe\u7247\uff0c\u5e76\u4f7f\u7528show()\u65b9\u6cd5\u663e\u793a\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\u672c\u5730\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_your_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u7247<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u56fe\u50cf\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>Pillow\u5e93\u4e0d\u4ec5\u53ef\u4ee5\u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247\uff0c\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u57fa\u672c\u64cd\u4f5c\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p><strong>\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528resize()\u65b9\u6cd5\u8c03\u6574\u56fe\u50cf\u7684\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">resized_image = image.resize((width, height))<\/p>\n<p>resized_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528rotate()\u65b9\u6cd5\u65cb\u8f6c\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rotated_image = image.rotate(angle)<\/p>\n<p>rotated_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u526a\u5207\u56fe\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528crop()\u65b9\u6cd5\u526a\u5207\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cropped_image = image.crop((left, upper, right, lower))<\/p>\n<p>cropped_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>Matplotlib\u5e93\u662fPython\u7684\u4e00\u4e2a\u7ed8\u56fe\u5e93\uff0c\u7528\u4e8e\u751f\u6210\u5404\u79cd\u56fe\u8868\u548c\u56fe\u5f62\u3002\u9664\u4e86\u7ed8\u56fe\u529f\u80fd\u5916\uff0cMatplotlib\u8fd8\u53ef\u4ee5\u7528\u4e8e\u663e\u793a\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u5e93\u52a0\u8f7d\u548c\u663e\u793a\u672c\u5730\u56fe\u7247\u9700\u8981\u501f\u52a9Pillow\u5e93\u6765\u52a0\u8f7d\u56fe\u7247\uff0c\u7136\u540e\u4f7f\u7528imshow()\u65b9\u6cd5\u663e\u793a\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\u672c\u5730\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_your_image.jpg&#39;)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3anumpy\u6570\u7ec4<\/strong><\/h2>\n<p>image_np = np.array(image)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u7247<\/strong><\/h2>\n<p>plt.imshow(image_np)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u5173\u95ed\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u56fe\u50cf\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>Matplotlib\u5e93\u53ef\u4ee5\u4e0eNumPy\u5e93\u7ed3\u5408\u4f7f\u7528\uff0c\u5bf9\u56fe\u50cf\u8fdb\u884c\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p><strong>\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528resize()\u65b9\u6cd5\u8c03\u6574\u56fe\u50cf\u7684\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">resized_image = image.resize((width, height))<\/p>\n<p>resized_image_np = np.array(resized_image)<\/p>\n<p>plt.imshow(resized_image_np)<\/p>\n<p>plt.axis(&#39;off&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528rotate()\u65b9\u6cd5\u65cb\u8f6c\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rotated_image = image.rotate(angle)<\/p>\n<p>rotated_image_np = np.array(rotated_image)<\/p>\n<p>plt.imshow(rotated_image_np)<\/p>\n<p>plt.axis(&#39;off&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528OpenCV\u5e93<\/h3>\n<\/p>\n<p><p>OpenCV\u5e93\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u5e7f\u6cdb\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\u3002OpenCV\u5e93\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ecPython\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5OpenCV\u5e93<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5OpenCV\u5e93\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>3.2 \u52a0\u8f7d\u548c\u663e\u793a\u56fe\u7247<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528OpenCV\u5e93\u52a0\u8f7d\u548c\u663e\u793a\u672c\u5730\u56fe\u7247\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u9700\u8981\u5bfc\u5165cv2\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528cv2.imread()\u65b9\u6cd5\u52a0\u8f7d\u56fe\u7247\uff0c\u5e76\u4f7f\u7528cv2.imshow()\u65b9\u6cd5\u663e\u793a\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u52a0\u8f7d\u672c\u5730\u56fe\u7247<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path_to_your_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u7247<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image&#39;, image)<\/p>\n<p>cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.3 \u56fe\u50cf\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>OpenCV\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u57fa\u672c\u64cd\u4f5c\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p><strong>\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528resize()\u65b9\u6cd5\u8c03\u6574\u56fe\u50cf\u7684\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">resized_image = cv2.resize(image, (width, height))<\/p>\n<p>cv2.imshow(&#39;Resized Image&#39;, resized_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528rotate()\u65b9\u6cd5\u65cb\u8f6c\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">(h, w) = image.shape[:2]<\/p>\n<p>center = (w \/\/ 2, h \/\/ 2)<\/p>\n<p>M = cv2.getRotationMatrix2D(center, angle, 1.0)<\/p>\n<p>rotated_image = cv2.warpAffine(image, M, (w, h))<\/p>\n<p>cv2.imshow(&#39;Rotated Image&#39;, rotated_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u56fe\u50cf\u5904\u7406\u7684\u9ad8\u7ea7\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u57fa\u672c\u64cd\u4f5c\u5916\uff0cPillow\u3001Matplotlib\u548cOpenCV\u5e93\u8fd8\u652f\u6301\u66f4\u9ad8\u7ea7\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\uff0c\u5982\u56fe\u50cf\u6ee4\u955c\u3001\u56fe\u50cf\u589e\u5f3a\u3001\u56fe\u50cf\u5206\u5272\u7b49\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u56fe\u50cf\u6ee4\u955c<\/h4>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86ImageFilter\u6a21\u5757\uff0c\u53ef\u4ee5\u5e94\u7528\u5404\u79cd\u6ee4\u955c\u6548\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import ImageFilter<\/p>\n<p>blurred_image = image.filter(ImageFilter.BLUR)<\/p>\n<p>sharpened_image = image.filter(ImageFilter.SHARPEN)<\/p>\n<p>blurred_image.show()<\/p>\n<p>sharpened_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u56fe\u50cf\u589e\u5f3a<\/h4>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86ImageEnhance\u6a21\u5757\uff0c\u53ef\u4ee5\u5bf9\u56fe\u50cf\u7684\u4eae\u5ea6\u3001\u5bf9\u6bd4\u5ea6\u3001\u989c\u8272\u7b49\u8fdb\u884c\u589e\u5f3a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import ImageEnhance<\/p>\n<p>enhancer = ImageEnhance.Contrast(image)<\/p>\n<p>enhanced_image = enhancer.enhance(factor)<\/p>\n<p>enhanced_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.3 \u56fe\u50cf\u5206\u5272<\/h4>\n<\/p>\n<p><p>OpenCV\u5e93\u63d0\u4f9b\u4e86\u591a\u79cd\u56fe\u50cf\u5206\u5272\u7b97\u6cd5\uff0c\u5982\u9608\u503c\u5206\u5272\u3001\u8fb9\u7f18\u68c0\u6d4b\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf<\/p>\n<p>gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<\/p>\n<h2><strong>\u5e94\u7528\u9608\u503c\u5206\u5272<\/strong><\/h2>\n<p>_, thresholded_image = cv2.threshold(gray_image, 128, 255, cv2.THRESH_BINARY)<\/p>\n<p>cv2.imshow(&#39;Thresholded Image&#39;, thresholded_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u4f7f\u7528\u672c\u5730\u56fe\u7247\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u663e\u793a\u662f\u4e00\u4e2a\u975e\u5e38\u5e38\u89c1\u7684\u9700\u6c42\u3002<strong>\u4f7f\u7528Pillow\u5e93\u3001\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528OpenCV\u5e93<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u4e3b\u8981\u65b9\u6cd5\u3002Pillow\u5e93\u662fPython\u56fe\u50cf\u5904\u7406\u7684\u7ecf\u5178\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u57fa\u672c\u64cd\u4f5c\u529f\u80fd\uff1bMatplotlib\u5e93\u662fPython\u7684\u4e00\u4e2a\u7ed8\u56fe\u5e93\uff0c\u53ef\u4ee5\u4e0eNumPy\u5e93\u7ed3\u5408\u4f7f\u7528\uff0c\u5bf9\u56fe\u50cf\u8fdb\u884c\u57fa\u672c\u64cd\u4f5c\uff1bOpenCV\u5e93\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u5e7f\u6cdb\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u57fa\u672c\u64cd\u4f5c\u548c\u9ad8\u7ea7\u64cd\u4f5c\u529f\u80fd\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\u7684\u7ed3\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5404\u79cd\u56fe\u50cf\u5904\u7406\u548c\u663e\u793a\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u52a0\u8f7d\u672c\u5730\u56fe\u7247\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5e93\u6765\u52a0\u8f7d\u672c\u5730\u56fe\u7247\uff0c\u4f8b\u5982PIL\uff08Pillow\uff09\u3001OpenCV\u548cMatplotlib\u7b49\u3002\u4ee5Pillow\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u52a0\u8f7d\u5e76\u663e\u793a\u672c\u5730\u56fe\u7247\uff1a<\/p>\n<pre><code class=\"language-python\">from PIL import Image\nimport matplotlib.pyplot as plt\n\nimage_path = &#39;path\/to\/your\/image.jpg&#39;\nimage = Image.open(image_path)\nplt.imshow(image)\nplt.axis(&#39;off&#39;)  # \u5173\u95ed\u5750\u6807\u8f74\nplt.show()\n<\/code><\/pre>\n<p>\u786e\u4fdd\u5728\u8fd0\u884c\u4ee3\u7801\u524d\u5b89\u88c5\u4e86Pillow\u548cMatplotlib\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install Pillow matplotlib<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u672c\u5730\u56fe\u7247\uff1f<\/strong><br \/>\u5904\u7406\u672c\u5730\u56fe\u7247\u7684\u65b9\u5f0f\u591a\u79cd\u591a\u6837\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f7f\u7528\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Pillow\u65f6\uff0c\u53ef\u4ee5\u8fdb\u884c\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u8c03\u6574\u5927\u5c0f\u7b49\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u5904\u7406\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u7247\ncropped_image = image.crop((100, 100, 400, 400))\n# \u65cb\u8f6c\u56fe\u7247\nrotated_image = image.rotate(90)\n# \u8c03\u6574\u56fe\u7247\u5927\u5c0f\nresized_image = image.resize((200, 200))\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5bf9\u56fe\u7247\u8fdb\u884c\u81ea\u5b9a\u4e49\u5904\u7406\uff0c\u9002\u5e94\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u7247\uff1f<\/strong><br \/>\u5728\u5bf9\u672c\u5730\u56fe\u7247\u8fdb\u884c\u5904\u7406\u540e\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5c06\u4fee\u6539\u540e\u7684\u56fe\u7247\u4fdd\u5b58\u5230\u672c\u5730\u3002\u4f7f\u7528Pillow\u5e93\u7684<code>save<\/code>\u65b9\u6cd5\u53ef\u4ee5\u8f7b\u677e\u5b8c\u6210\u8fd9\u4e00\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-python\">modified_image_path = &#39;path\/to\/save\/modified_image.jpg&#39;\ncropped_image.save(modified_image_path)\n<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u9009\u62e9\u4fdd\u5b58\u4e3a\u4e0d\u540c\u7684\u683c\u5f0f\uff08\u5982JPEG\u3001PNG\u7b49\uff09\uff0c\u53ea\u9700\u76f8\u5e94\u5730\u66f4\u6539\u6587\u4ef6\u6269\u5c55\u540d\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u672c\u5730\u56fe\u7247\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u663e\u793a\u3002\u4f7f\u7528Pillow\u5e93\u3001\u4f7f\u7528Matplotlib\u5e93\u3001\u4f7f\u7528Op [&hellip;]","protected":false},"author":3,"featured_media":1123678,"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\/1123666"}],"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=1123666"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123666\/revisions"}],"predecessor-version":[{"id":1123682,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123666\/revisions\/1123682"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1123678"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1123666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1123666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1123666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}