python上的阈值图像也是段

时间:2014-09-17 18:14:09

标签: python image

from PIL import Image
import  ImageOps
im= Image.open("new.jpeg")
imout=im.PIL.ImageOps.solarize(image, threshold=40)
imout.show()

我希望使用上面的代码将图像阈值设置为40%但显示错误: -

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

我还将洞图像分割为20.我将如何做到这一点?你能给我完整的代码吗? 我是python的新手所以我无法找到如何做到这一点?我发现一周后。你能给我一些关于视频教程的正确链接吗?

1 个答案:

答案 0 :(得分:0)

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)

这是我找到的股权图像解决方案。更改阈值变量的值将更改阈值百分比