python上的阈值图像也是一个片段

python上的阈值图像也是一个片段,python,image,Python,Image,我想用上述代码将图像阈值设置为40%,但显示错误:- from PIL import Image import ImageOps im= Image.open("new.jpeg") imout=im.PIL.ImageOps.solarize(image, threshold=40) imout.show() 回溯(最近一次呼叫最后一次): 文件“C:\Users\Meraj\Desktop\script captcha\captchat.py”,第4行,在 imout=im.PIL.Im

我想用上述代码将图像阈值设置为40%,但显示错误:-

from PIL import Image
import  ImageOps
im= Image.open("new.jpeg")
imout=im.PIL.ImageOps.solarize(image, threshold=40)
imout.show()
回溯(最近一次呼叫最后一次):
文件“C:\Users\Meraj\Desktop\script captcha\captchat.py”,第4行,在
imout=im.PIL.ImageOps.solarize(图像,阈值=128)
文件“C:\Python27\lib\site packages\pillow-2.3.2-py2.7-win32.egg\PIL\Image.py”,第528行,位于\uu getattr__
提升属性错误(名称)
属性错误:PIL
我还会将孔图像分割为20。我该怎么做?你能给我完整的代码吗? 我是python新手,所以我无法找到如何做到这一点?我从一个星期开始发现。你能给我一个视频教程的链接吗

Traceback (most recent call last):
  File "C:\Users\Meraj\Desktop\script captcha\captchat.py", line 4, in <module>
    imout=im.PIL.ImageOps.solarize(image, threshold=128)
  File "C:\Python27\lib\site-packages\pillow-2.3.2-py2.7-win32.egg\PIL\Image.py", line 528, in __getattr__
    raise AttributeError(name)
AttributeError: PIL

这就是我找到的解决方案。更改thresh变量的值将更改阈值百分比

显然,
im
对象没有属性
PIL
。只需使用
PIL.ImageOps.solarize
“你能给我完整的代码吗?”不,问答网站也是如此,而不是代码编写服务。“你能给我一个视频教程的正确链接吗?”对不起,教程的推荐请求也脱离主题。PIL.ImageOps.solarize也不起作用:-文件“C:\Users\Meraj\Desktop\script captcha\captchat.py”,第4行,在imout=PIL.ImageOps.solarize(im,threshold=128)name错误:名称“PIL”未定义
import cv2

import Image


im_gray = cv2.imread('image.png', cv2.CV_LOAD_IMAGE_GRAYSCALE)

(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
thresh = 90
im_bw = cv2.threshold(im_gray, thresh, 255, cv2.THRESH_BINARY)[1]
cv2.imwrite('bw_image.png', im_bw)