【发布时间】:2020-03-19 07:47:34
【问题描述】:
我正在做一个增强图像对比度的问题。 请看下面这段代码
# 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/bokehCircular.jpg', 100) 这行代码调用预先编写的函数来加载图像,该函数在下面给出
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
当我运行代码时,以下行出现错误 image = image.astype(float) 错误如下所示
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:
我已经编写了增强图像对比度的代码,我已经通过相同的 LoadImage 函数加载图像来单独测试它,但在上述情况下,LoadImage 函数无法正常工作 请帮忙,如果有人可以,谢谢
【问题讨论】:
-
错误是
KeyboardInterrupt错误,这意味着您确实故意停止了脚本? -
我没有碰任何东西,我没有故意停止脚本,每次都会出现同样的错误
-
这个装饰器
@exit_after(4)是什么意思?它不会在 4 秒后停止吗?也许尝试提高它? -
不幸的是,这是一个测试单元,我无法编辑它,可能我必须创建另一个 ipynb
-
exit after也是一个被调用的函数
标签: python-3.x python-imaging-library loadimage