我需要保存 x 和 y 尺寸的图像,我使用枕头来执行此操作,问题是它以默认尺寸保存,在我的情况下为 16x16,我尝试使用resize这样的:
new_image = image.resize((40, 40))
Run Code Online (Sandbox Code Playgroud)
但结果仍然相同,唯一的区别是在图像预览中它变小了,但它仍然是 16x16,有人有想法吗?
image_byte = b"image_bytes"
b = base64.b64decode(image_byte)
image = Image.open(io.BytesIO(b))
new_image = image.resize((40, 40))
new_image.save(icon_path)
Run Code Online (Sandbox Code Playgroud) 我有一个程序,使用 PIL 自动将一系列图像裁剪到某个区域。但是,当我使用不同尺寸显示器的屏幕截图运行程序时,裁剪的区域位于错误的位置。有没有办法使用 OpenCV 或 PIL 自动找到我想要裁剪的矩形(例如 Youtube 视频的主要观看者)并裁剪它,同时保留图像的颜色,然后将图像保存到新的文件夹?
我的裁剪图像代码:
import os, random
from PIL import Image
files = []
for x in os.listdir():
if '.jpg' in f'{x}' or '.png' in f'{x}' or '.jpeg' in f'{x}':
files.append(x)
else:
print(f'Passed by {x}! It is not an image!')
for x in files:
y = hex(random.randint(100000,500000))
image = Image.open(f'{x}')
newimage = image.crop((48,367,1626,1256))
newimage.save(f'newdir/{y}.png')
Run Code Online (Sandbox Code Playgroud)
来自另一台计算机的另一张图像需要裁剪到同一查看器:
我正在尝试使用 PIL 在 python 中旋转图像,但是当使用 PIL 旋转时,它会保留图像的原始尺寸。例如,如果我尝试旋转它,它的边缘就会被切断。解释这一点的最简单方法是向您展示:
有没有一种方法可以旋转图像,然后保存旋转后的版本,而无需使用 PIL 进行裁剪?或者,如果使用 PIL 无法做到这一点,您会推荐哪些其他方法。
我有以下图像:

我想去除该图像中的一些噪点。我已经尝试使用 OpenCV 和以下代码:
cv2.fastNlMeansDenoisingColored(image_sharp, None, 2, 10, 7, 20)
Run Code Online (Sandbox Code Playgroud)
然而,返回给我的图像看起来完全相同:

有没有人有什么建议?
我给一个网址作为例子:
http://ww4.sinaimg.cn/large/a7bf601fjw1f7jsbj34a1g20kc0bdnph.gif
Run Code Online (Sandbox Code Playgroud)
您可以在浏览器中看到它.
现在我想下载它.我试过了:
1.
urllib.urlretrieve(imgurl,filepath')
失败了,得到了一个"错误"的图片.
2.
wget.download(imgurl)
失败了,得到了一个"错误"的图片.
3.
r = requests.get(imgurl,stream=True)
img = PIL.Image.open(StringIO(r.content))
img.save(filepath)
失败,得到一张静态图片,我的意思是,只有一帧.
所以我该怎么做?
这是一张我要从中计算每种颜色的对象数的图表。什么是不使用opencv的简单方法?
[编辑2]: 我尝试过的方法如下:(1)有色物体计数
from PIL import Image
im = Image.open('./colored-polka-dots.png').getcolors()
im.sort(key=lambda k: (k[0]), reverse=True)
print('Top 5 colors: {}'.format((im[:5])))
# View non-background colors
color_values = []
for color in im[1:5]:
color_values.append(color[1])
arr = np.asarray(color[1]).reshape(1,1,4).astype(np.uint8)
plt.imshow(arr)
plt.show() # get top 4 frequent colors as green,blue,pink,ornage
# Create a dict of color names and their corressponding rgba values
color_dict = {}
for color_name,color_val in zip(['green','blue','pink','orange'],color_values):
color_dict[color_name] = color_val
# Make use of ndimage.measurement.labels from scipy
# to get the number …Run Code Online (Sandbox Code Playgroud) 当我从以下链接运行代码时:
我收到以下错误:
使用 TensorFlow 后端。找到属于 2 个类别的 2000 张图像。/home/nd/anaconda3/lib/python3.6/site-packages/PIL/TiffImagePlugin.py:692: UserWarning: 可能损坏 EXIF 数据。期望读取 80000 字节,但只得到 0。Skipping tag 64640 "Skipping tag %s" % (size, len(data), tag))
我正在使用 Ubuntu。
尝试的解决方案:将第 70 行和第 81 行中的“w”更改为“wb”。
提前谢谢
我想使用PIL.Image.open()读取图像,但是图像位于不同的路径。以下是我拥有python脚本的路径
"D:\YY_Aadhi\holy-edge-master\hed\test.py"
Run Code Online (Sandbox Code Playgroud)
以下是我拥有图像文件的路径。
"D:\YY_Aadhi\HED-BSDS\test\2018.jpg"
from PIL import Image
'''some code here'''
image = Image.open(????)
Run Code Online (Sandbox Code Playgroud)
如何填写问号以访问图像文件。
pip install pillow\nCollecting pillow\n Using cached Pillow-10.0.0.tar.gz (50.5 MB)\n Installing build dependencies ... done\n Getting requirements to build wheel ... done\n Preparing metadata (pyproject.toml) ... done\nBuilding wheels for collected packages: pillow\n Building wheel for pillow (pyproject.toml) ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 Building wheel for pillow (pyproject.toml) did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [198 lines of output]\n running bdist_wheel\n running build\n running build_py\n creating build\n creating build\\lib.mingw_x86_64-cpython-310\n creating build\\lib.mingw_x86_64-cpython-310\\PIL\n copying src\\PIL\\BdfFontFile.py -> …Run Code Online (Sandbox Code Playgroud) 我有两个图像,我想要一个响应(真或假)来知道它们是不同的.图像的大小不同.
我有一张显示皮肤的人体图像。假设我有另一种肤色并且假设我在身体图像中有一个暴露皮肤的面具,我该如何改变皮肤的颜色?
我花了几个小时试图解决这个问题.
我做以下事情:
sudo apt-get install python-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install libfreetype6 libfreetype6-dev
mkvirtualenv -p python2.7 --no-site-packages foobar
pip install PIL
Run Code Online (Sandbox Code Playgroud)
每当我尝试在django-cms网站上传图像时,都会收到错误消息.
python ×11
opencv ×4
image ×2
pip ×2
crop ×1
exif ×1
gif ×1
keras ×1
mingw ×1
pillow ×1
python-3.x ×1
scikit-image ×1
scipy ×1
ubuntu ×1
virtualenv ×1