其中i
和j
是像素的索引。随着频率的变化,生成的图像应如下所示:
其中显示了使用3个不同频率值构建的3个图像。但使用我的代码,我只能得到:
即使频率值不同,频率看起来也很小。我不能对这个问题全神贯注。我使用的代码是:
import numpy as np
import cv2 as cv
from math import pi, sin
a = np.random.rand(500, 500, 3)
f = 7000000000000
rows, cols , channel= a.shape
print(f'Rows are: {rows}')
print(f'Cols are: {cols}')
print(f'Channels are: {channel}')
OldMax = 1
OldMin = -1
NewMax = 1
NewMin = 0
# A function to normalize values b/w 0 and 1
def re_range(OldValue):
OldRange = (OldMax - OldMin)
NewRange = (NewMax - NewMin)
NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
return NewValue
for i in range(rows):
for j in range(cols):
a[i, j, :] = re_range(sin(2 * pi * f * (i + j)))
cv.imshow('image', a)
cv.waitKey(0)
cv.destroyAllWindows()
有人能解释出哪里出了问题吗
目前没有回答
相关问题 更多 >
编程相关推荐