如何利用Python 图像库完成各种图像处理任务?
我们将使用这个图像文件,命名为:people.jpg。
img2 = Image.open('people.jpg')
plt.imshow(img2)
图像被读取。现在,我们调整图像大小。img2.thumbnail((50, 50), Image.ANTIALIAS) # resizes image in-place
imgplot = plt.imshow(img2)
imgplot1 = plt.imshow(img2, interpolation="nearest")
imgplot2 = plt.imshow(img2, interpolation="bicubic")
但是,为什么我们在图像处理中故意模糊图像?通常对于模式识别和计算机视觉算法,如果图像非常清晰,处理起来就会很困难。因此进行模糊处理以使图像平滑。模糊还可以使图像中的颜色过渡从一侧到另一侧更加平滑。现在,让我们验证我们之前处理过的汽车图像的尺寸。#some more interesting stuff
file='image1.jpg'
with Image.open(file) as image:
width, height = image.size
#Image width, height is be obtained
这些也是我们之前得到的维度。所以我们可以得出结论,图像是320*658。让我们也尝试旋转和转置图像。#Relative Path
img3 = Image.open("image1.jpg")
#Angle given
img_rot= img3.rotate(180)
#Saved in the same relative location
img_rot.save("rotated_picture.jpg")
这是旋转后的图像。#transposing image
transposed_img = img3.transpose(Image.FLIP_LEFT_RIGHT)
#Saved in the same relative location
transposed_img.save("transposed_img.jpg")
这是转置后的图像。尾注图像处理有各种重要的应用,随着时间的推移,方法和过程也会得到改进。

最新活动更多
-
3月27日立即报名>> 【工程师系列】汽车电子技术在线大会
-
4月1日立即下载>> 【村田汽车】汽车E/E架构革新中,新智能座舱挑战的解决方案
-
即日-4.22立即报名>> 【在线会议】汽车腐蚀及防护的多物理场仿真
-
4月23日立即报名>> 【在线会议】研华嵌入式核心优势,以Edge AI驱动机器视觉升级
-
4月25日立即报名>> 【线下论坛】新唐科技2025新品发布会
-
5月15日立即下载>> 【白皮书】精确和高效地表征3000V/20A功率器件应用指南
发表评论
请输入评论内容...
请输入评论/评论长度6~500个字
暂无评论
暂无评论