python

时间:2018-03-31 07:11:57

标签: python opencv python-imaging-library pillow cv2

我使用python库PIL和OpenCV2学习图像处理,我想在黑色和图像上应用对数映射和指数映射。

我已编写此代码以应用对数映射:

import cv2
import numpy as np
import math
photo = cv2.imread('TurtleLuminance.jpg')
c = 255/math.log(1+255)
photoLogarithmic = c * cv2.log(1 + photo)
cv2.imshow('Logarithmic', photoLogarithmic)
cv2.waitKey(0)
cv2.destroyAllWindows()

公式为Logarithmic mapping但我在第7行photoLogarithmic = c * cv2.log(1 + photo)上有错误。

对于指数映射,我不知道如何配方 Exponential mapping

如果有人能向我解释如何做到这一点我会非常感激。

错误是:

OpenCV Error: Assertion failed (depth == 5 || depth == 6) in log, file /io/opencv/modules/core/src/mathfuncs.cpp, line 701
Traceback (most recent call last):
File "/home/rem/Desktop/Py/ImagesTre/tests/Logarithmic/Logarithmic.py", line 7, in <module>
photoLogarithmic = c * cv2.log(1 + photo)
cv2.error: /io/opencv/modules/core/src/mathfuncs.cpp:701: error: (-215) depth == 5 || depth == 6 in function log
import cv2
import numpy as np
import math
photo = cv2.imread('TurtleLuminance.jpg')
photo = photo.astype(float)
c = 255/math.log(1+250)
photoLogarithmic = c * (cv2.log(1 + photo))
cv2.imshow('Logarithmic', photoLogarithmic)
cv2.waitKey(0)
cv2.destroyAllWindows()

结果是enter image description here 知道为什么要这样做吗?

0 个答案:

没有答案