{"id":1147786,"date":"2025-01-13T16:29:18","date_gmt":"2025-01-13T08:29:18","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1147786.html"},"modified":"2025-01-13T16:29:20","modified_gmt":"2025-01-13T08:29:20","slug":"python%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80jpj%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1147786.html","title":{"rendered":"python\u5982\u4f55\u6253\u5f00jpj\u56fe\u7247"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25165935\/16dbbdf0-e416-465b-9d05-6babd33b0f51.webp\" alt=\"python\u5982\u4f55\u6253\u5f00jpj\u56fe\u7247\" \/><\/p>\n<p><p> \u8981\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\uff0c\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u3001OpenCV\u5e93\u3001Matplotlib\u5e93\u7b49\u51e0\u79cd\u65b9\u6cd5\u3002<strong>Pillow\u5e93\u3001OpenCV\u5e93\u3001Matplotlib\u5e93<\/strong>\u662f\u5e38\u7528\u7684\u5904\u7406\u56fe\u50cf\u7684\u5e93\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u4f7f\u7528Pillow\u5e93\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><p>Pillow\u5e93\u662fPython Imaging Library\uff08PIL\uff09\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u662fPython\u56fe\u50cf\u5904\u7406\u5e93\u7684\u6807\u51c6\u5e93\u3002\u4f7f\u7528Pillow\u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u8bb8\u591a\u4e0d\u540c\u683c\u5f0f\u7684\u56fe\u50cf\u6587\u4ef6\u3002\u8981\u4f7f\u7528Pillow\u5e93\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6253\u5f00\u5e76\u663e\u793aJPJ\u56fe\u7247\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_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>\u4e0b\u9762\u5c06\u4ece\u591a\u4e2a\u65b9\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Pillow\u5e93<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528Pillow\u5e93\uff0c\u9996\u5148\u9700\u8981\u786e\u4fddPillow\u5e93\u5df2\u7ecf\u5b89\u88c5\u5728\u4f60\u7684Python\u73af\u5883\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pillow\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install Pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165Pillow\u5e93\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u62a5\u9519\uff0c\u8bf4\u660ePillow\u5e93\u5df2\u7ecf\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u6253\u5f00\u56fe\u7247\u6587\u4ef6<\/p>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u63a5\u53e3\u6765\u6253\u5f00\u548c\u5904\u7406\u56fe\u50cf\u3002\u8981\u6253\u5f00JPJ\u56fe\u7247\uff0c\u53ef\u4ee5\u4f7f\u7528Image\u7c7b\u7684open\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u7247<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>path_to_image.jpg<\/code>\u662f\u56fe\u7247\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u663e\u793a\u56fe\u7247<\/p>\n<\/p>\n<p><p>\u6253\u5f00\u56fe\u7247\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Image\u5bf9\u8c61\u7684show\u65b9\u6cd5\u663e\u793a\u56fe\u7247\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u663e\u793a\u56fe\u7247<\/p>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>show\u65b9\u6cd5\u4f1a\u8c03\u7528\u7cfb\u7edf\u9ed8\u8ba4\u7684\u56fe\u7247\u67e5\u770b\u5668\u6253\u5f00\u56fe\u7247\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u83b7\u53d6\u56fe\u7247\u4fe1\u606f<\/p>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u63d0\u4f9b\u4e86\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u83b7\u53d6\u56fe\u7247\u7684\u5927\u5c0f\u3001\u683c\u5f0f\u3001\u6a21\u5f0f\u7b49\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u56fe\u7247\u5927\u5c0f<\/p>\n<p>width, height = image.size<\/p>\n<p>print(&#39;\u56fe\u7247\u5927\u5c0f\uff1a&#39;, width, height)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u7247\u683c\u5f0f<\/strong><\/h2>\n<p>format = image.format<\/p>\n<p>print(&#39;\u56fe\u7247\u683c\u5f0f\uff1a&#39;, format)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u7247\u6a21\u5f0f<\/strong><\/h2>\n<p>mode = image.mode<\/p>\n<p>print(&#39;\u56fe\u7247\u6a21\u5f0f\uff1a&#39;, mode)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5904\u7406\u56fe\u7247<\/p>\n<\/p>\n<p><p>Pillow\u5e93\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u3001\u6ee4\u955c\u7b49\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u88c1\u526a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u7247<\/p>\n<p>box = (100, 100, 400, 400)<\/p>\n<p>cropped_image = image.crop(box)<\/p>\n<p>cropped_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>box<\/code>\u662f\u4e00\u4e2a\u5143\u7ec4\uff0c\u8868\u793a\u88c1\u526a\u533a\u57df\u7684\u5de6\u4e0a\u89d2\u548c\u53f3\u4e0b\u89d2\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u65cb\u8f6c\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u65cb\u8f6c\u56fe\u7247<\/p>\n<p>rotated_image = image.rotate(45)<\/p>\n<p>rotated_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>45<\/code>\u8868\u793a\u65cb\u8f6c\u7684\u89d2\u5ea6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u7f29\u653e\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u7f29\u653e\u56fe\u7247<\/p>\n<p>resized_image = image.resize((200, 200))<\/p>\n<p>resized_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>(200, 200)<\/code>\u8868\u793a\u7f29\u653e\u540e\u7684\u56fe\u7247\u5927\u5c0f\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5e94\u7528\u6ee4\u955c<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from PIL import ImageFilter<\/p>\n<h2><strong>\u5e94\u7528\u6a21\u7cca\u6ee4\u955c<\/strong><\/h2>\n<p>blurred_image = image.filter(ImageFilter.BLUR)<\/p>\n<p>blurred_image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u4fdd\u5b58\u56fe\u7247<\/p>\n<\/p>\n<p><p>\u5904\u7406\u5b8c\u56fe\u7247\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Image\u5bf9\u8c61\u7684save\u65b9\u6cd5\u5c06\u56fe\u7247\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u56fe\u7247<\/p>\n<p>image.save(&#39;output_image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>output_image.jpg<\/code>\u662f\u4fdd\u5b58\u7684\u6587\u4ef6\u8def\u5f84\u548c\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528OpenCV\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86Pillow\u5e93\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528OpenCV\u5e93\u6765\u6253\u5f00\u548c\u5904\u7406JPJ\u56fe\u7247\u3002OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5OpenCV\u5e93<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6253\u5f00\u5e76\u663e\u793a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u7247<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path_to_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<ol start=\"3\">\n<li><strong>\u83b7\u53d6\u56fe\u7247\u4fe1\u606f<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u56fe\u7247\u5927\u5c0f<\/p>\n<p>height, width, channels = image.shape<\/p>\n<p>print(&#39;\u56fe\u7247\u5927\u5c0f\uff1a&#39;, width, height)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u7247\u6a21\u5f0f<\/strong><\/h2>\n<p>mode = &#39;RGB&#39; if channels == 3 else &#39;Grayscale&#39;<\/p>\n<p>print(&#39;\u56fe\u7247\u6a21\u5f0f\uff1a&#39;, mode)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5904\u7406\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><p>OpenCV\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u3001\u6ee4\u955c\u7b49\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u88c1\u526a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u7247<\/p>\n<p>cropped_image = image[100:400, 100:400]<\/p>\n<p>cv2.imshow(&#39;Cropped Image&#39;, cropped_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u65cb\u8f6c\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u65cb\u8f6c\u56fe\u7247<\/p>\n<p>(h, w) = image.shape[:2]<\/p>\n<p>center = (w \/\/ 2, h \/\/ 2)<\/p>\n<p>M = cv2.getRotationMatrix2D(center, 45, 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<ol start=\"3\">\n<li><strong>\u7f29\u653e\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u7f29\u653e\u56fe\u7247<\/p>\n<p>resized_image = cv2.resize(image, (200, 200))<\/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<ol start=\"4\">\n<li><strong>\u5e94\u7528\u6ee4\u955c<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u5e94\u7528\u6a21\u7cca\u6ee4\u955c<\/p>\n<p>blurred_image = cv2.GaussianBlur(image, (15, 15), 0)<\/p>\n<p>cv2.imshow(&#39;Blurred Image&#39;, blurred_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li><strong>\u4fdd\u5b58\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u56fe\u7247<\/p>\n<p>cv2.imwrite(&#39;output_image.jpg&#39;, image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516b\u3001\u4f7f\u7528Matplotlib\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86Pillow\u5e93\u548cOpenCV\u5e93\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u6253\u5f00\u548c\u663e\u793aJPJ\u56fe\u7247\u3002Matplotlib\u662f\u4e00\u4e2a\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Matplotlib\u5e93<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6253\u5f00\u5e76\u663e\u793a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.image as mpimg<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u7247<\/strong><\/h2>\n<p>image = mpimg.imread(&#39;path_to_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u7247<\/strong><\/h2>\n<p>plt.imshow(image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u9690\u85cf\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u83b7\u53d6\u56fe\u7247\u4fe1\u606f<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u56fe\u7247\u5927\u5c0f<\/p>\n<p>height, width, channels = image.shape<\/p>\n<p>print(&#39;\u56fe\u7247\u5927\u5c0f\uff1a&#39;, width, height)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u7247\u6a21\u5f0f<\/strong><\/h2>\n<p>mode = &#39;RGB&#39; if channels == 3 else &#39;Grayscale&#39;<\/p>\n<p>print(&#39;\u56fe\u7247\u6a21\u5f0f\uff1a&#39;, mode)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5904\u7406\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><p>Matplotlib\u5e93\u4e3b\u8981\u7528\u4e8e\u7ed8\u56fe\uff0c\u4f46\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u88c1\u526a\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u7247<\/p>\n<p>cropped_image = image[100:400, 100:400]<\/p>\n<p>plt.imshow(cropped_image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u9690\u85cf\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u65cb\u8f6c\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u65cb\u8f6c\u56fe\u7247<\/strong><\/h2>\n<p>rotated_image = np.rot90(image)<\/p>\n<p>plt.imshow(rotated_image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u9690\u85cf\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u7f29\u653e\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from skimage.transform import resize<\/p>\n<h2><strong>\u7f29\u653e\u56fe\u7247<\/strong><\/h2>\n<p>resized_image = resize(image, (200, 200))<\/p>\n<p>plt.imshow(resized_image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u9690\u85cf\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5e94\u7528\u6ee4\u955c<\/strong><\/p>\n<p>Matplotlib\u5e93\u672c\u8eab\u6ca1\u6709\u63d0\u4f9b\u6ee4\u955c\u529f\u80fd\uff0c\u4f46\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u5e93\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528scipy\u5e93\u6765\u5e94\u7528\u6ee4\u955c\uff1a<\/li>\n<\/p>\n<\/ol>\n<p><pre><code class=\"language-python\">from scipy.ndimage import gaussian_filter<\/p>\n<h2><strong>\u5e94\u7528\u6a21\u7cca\u6ee4\u955c<\/strong><\/h2>\n<p>blurred_image = gaussian_filter(image, sigma=3)<\/p>\n<p>plt.imshow(blurred_image)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u9690\u85cf\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li><strong>\u4fdd\u5b58\u56fe\u7247<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u56fe\u7247<\/p>\n<p>plt.imsave(&#39;output_image.jpg&#39;, image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e5d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5e38\u7528\u7684\u5e93\u6709Pillow\u5e93\u3001OpenCV\u5e93\u3001Matplotlib\u5e93\u7b49\u3002\u6bcf\u4e2a\u5e93\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u9009\u62e9\u54ea\u79cd\u5e93\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u6765\u5b9a\u3002<strong>Pillow\u5e93\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u521d\u5b66\u8005\uff1bOpenCV\u5e93\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u5408\u9700\u8981\u590d\u6742\u56fe\u50cf\u5904\u7406\u7684\u573a\u666f\uff1bMatplotlib\u5e93\u4e3b\u8981\u7528\u4e8e\u7ed8\u56fe\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e9b\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5e76\u4e86\u89e3\u4e86\u5982\u4f55\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u4fdd\u5b58\u56fe\u7247\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5982\u679c\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u6b22\u8fce\u7559\u8a00\u8ba8\u8bba\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u6253\u5f00JPJ\u683c\u5f0f\u7684\u56fe\u7247\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86Pillow\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4 <code>pip install Pillow<\/code>\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">from PIL import Image\n\n# \u6253\u5f00JPJ\u56fe\u7247\nimage = Image.open(&#39;your_image.jpj&#39;)\nimage.show()  # \u663e\u793a\u56fe\u7247\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728Python\u4e2d\u8f7b\u677e\u6253\u5f00\u548c\u67e5\u770bJPJ\u683c\u5f0f\u7684\u56fe\u7247\u3002<\/p>\n<p><strong>JPJ\u56fe\u7247\u683c\u5f0f\u4e0e\u5176\u4ed6\u683c\u5f0f\u76f8\u6bd4\u6709\u4ec0\u4e48\u4f18\u52bf\uff1f<\/strong><br \/>JPJ\u683c\u5f0f\u901a\u5e38\u7528\u4e8e\u4fdd\u5b58\u9ad8\u8d28\u91cf\u7684\u56fe\u50cf\uff0c\u5c24\u5176\u5728\u6444\u5f71\u548c\u8bbe\u8ba1\u9886\u57df\u4e2d\u3002\u4e0eJPEG\u7b49\u683c\u5f0f\u76f8\u6bd4\uff0cJPJ\u6587\u4ef6\u53ef\u80fd\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\u63d0\u4f9b\u66f4\u597d\u7684\u538b\u7f29\u6548\u679c\u548c\u66f4\u5c11\u7684\u56fe\u50cf\u5931\u771f\u3002\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u9700\u8981\u9ad8\u5206\u8fa8\u7387\u7684\u56fe\u50cf\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5904\u7406JPJ\u56fe\u7247\u65f6\u6709\u54ea\u4e9b\u5e38\u89c1\u95ee\u9898\uff1f<\/strong><br \/>\u5904\u7406JPJ\u56fe\u7247\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\uff0c\u6bd4\u5982\u6587\u4ef6\u6253\u4e0d\u5f00\u6216\u663e\u793a\u9519\u8bef\u3002\u8fd9\u901a\u5e38\u4e0e\u6587\u4ef6\u8def\u5f84\u9519\u8bef\u6216\u7f3a\u5c11\u652f\u6301\u8be5\u683c\u5f0f\u7684\u5e93\u6709\u5173\u3002\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u5df2\u5b89\u88c5\u6240\u9700\u7684\u5e93\uff0c\u5982Pillow\u3002\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f6c\u6362\u4e3a\u5176\u4ed6\u5e38\u89c1\u683c\u5f0f\uff0c\u5982PNG\u6216JPEG\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u6253\u5f00JPJ\u56fe\u7247\uff0c\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u3001OpenCV\u5e93\u3001Matplotlib\u5e93\u7b49\u51e0\u79cd\u65b9\u6cd5\u3002P [&hellip;]","protected":false},"author":3,"featured_media":1147795,"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\/1147786"}],"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=1147786"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1147786\/revisions"}],"predecessor-version":[{"id":1147797,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1147786\/revisions\/1147797"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1147795"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1147786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1147786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1147786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}