Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用PIL模块加载图像_Python 3.x_Python Imaging Library_Loadimage - Fatal编程技术网

Python 3.x 使用PIL模块加载图像

Python 3.x 使用PIL模块加载图像,python-3.x,python-imaging-library,loadimage,Python 3.x,Python Imaging Library,Loadimage,我在做一个增强图像对比度的问题。 请看一下下面的代码 # this is a test cell @exit_after(4) def testContrastSharpening(): # load an image i0 = loadImage('Data/bokehCircular.jpg', 100) # run student code s0 = contrastSharpen(i0, 3, 0.5) # collect test data

我在做一个增强图像对比度的问题。 请看一下下面的代码

# this is a test cell
@exit_after(4)
def testContrastSharpening():
    # load an image
    i0 = loadImage('Data/bokehCircular.jpg', 100)

    # run student code
    s0 = contrastSharpen(i0, 3, 0.5)

    # collect test data
    rTest = s0[:, int(i0.shape[1]/2), 0]
    gTest = s0[:, int(i0.shape[1]/4), 1]
    bTest = s0[int(i0.shape[0]/5), :, 2]

    # load and compare to reference result
    l0 = load('Data/t0.npz')

    return allclose(rTest, l0['r']) and allclose(gTest, l0['g']) and allclose(bTest, l0['b'])

try:
    assert(testContrastSharpening())
    print('Contrast sharpening seems to work!')
except:
    raise Exception("Contrast sharpening is not working... please try again...")
i0=loadImage('Data/bokehccircular.jpg',100) 这行代码调用预先编写的fffunction来加载图像,该函数如下所示

def loadImage(path, scale):
    image = Image.open(path, mode = 'r')
    image = image.resize((int(image.width * scale / 100), int(image.height * scale / 100)), resample=Image.LANCZOS)
    image = array(image.getdata()).reshape(image.size[1], image.size[0], 3)
    image = image.astype(float)
    image = image / max(image)

    return image
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-8-bf381c328e33> in <module>
     20 try:
---> 21     assert(testContrastSharpening())
     22     print('Contrast sharpening seems to work!')

<ipython-input-1-4c3172e491d3> in inner(*args, **kwargs)
     44             try:
---> 45                 result = fn(*args, **kwargs)
     46             finally:

<ipython-input-8-bf381c328e33> in testContrastSharpening()
      4     # load an image
----> 5     i0 = loadImage('Data/bokehCircular.jpg', 100)
      6 

<ipython-input-3-545d6e0c0f38> in loadImage(path, scale)
      5     image = array(image.getdata()).reshape(image.size[1], image.size[0], 3)
----> 6     image = image.astype(float)
      7     image = image / max(image)

KeyboardInterrupt:
当我运行代码时,我在下面的行中得到错误 image=image.astype(浮点) 错误如下所示

def loadImage(path, scale):
    image = Image.open(path, mode = 'r')
    image = image.resize((int(image.width * scale / 100), int(image.height * scale / 100)), resample=Image.LANCZOS)
    image = array(image.getdata()).reshape(image.size[1], image.size[0], 3)
    image = image.astype(float)
    image = image / max(image)

    return image
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-8-bf381c328e33> in <module>
     20 try:
---> 21     assert(testContrastSharpening())
     22     print('Contrast sharpening seems to work!')

<ipython-input-1-4c3172e491d3> in inner(*args, **kwargs)
     44             try:
---> 45                 result = fn(*args, **kwargs)
     46             finally:

<ipython-input-8-bf381c328e33> in testContrastSharpening()
      4     # load an image
----> 5     i0 = loadImage('Data/bokehCircular.jpg', 100)
      6 

<ipython-input-3-545d6e0c0f38> in loadImage(path, scale)
      5     image = array(image.getdata()).reshape(image.size[1], image.size[0], 3)
----> 6     image = image.astype(float)
      7     image = image / max(image)

KeyboardInterrupt:
键盘中断回溯(最近一次调用)
在里面
20试试:
--->21断言(testcontrasting())
22打印(“对比度锐化似乎有效!”)
在内部(*args,**kwargs)
44尝试:
--->45结果=fn(*args,**kwargs)
46.最后:
在测试中,锐化()
4#加载图像
---->5 i0=loadImage('Data/bokehccircular.jpg',100)
6.
在loadImage中(路径、比例)
5 image=array(image.getdata())。重塑(image.size[1],image.size[0],3)
---->6 image=image.astype(浮点)
7图像=图像/最大值(图像)
键盘中断:
我已经编写了增强图像对比度的代码,并通过相同的LoadImage函数加载ana图像对其进行了单独测试,但在上述情况下,LoadImage函数无法正常工作
请帮助,如果有人可以,谢谢

我想这是因为你的装饰师
@exit\u在(4)
之后。事实上,在(4)之后使用
@exit_
4秒后,您的测试单元将被
键盘中断
错误停止

从源代码

有两种解决方案:

  • 修改测试:让您的测试更宽容并提高该数字?e、 g.
    @exit_在(10)
    之后,查看此操作是否有效
  • 修改脚本:使函数更快,以便在4秒的限制下工作。您可以先将函数设置为几乎为空,然后检查它是否有效

错误是一个
键盘中断
错误,这意味着您是故意停止脚本的?我没有碰任何东西,我不是故意停止脚本的,每次都会出现相同的错误(4)之后这个装饰程序
@exit\u打算做什么?4秒后它不会停止吗?也许试着提高它?不幸的是,这是一个测试单元,我无法编辑它,可能我必须创建另一个ipynbexit,因为它也是一个正在调用的函数