最後に私は、この使用numpyのモジュールのすべてを終了することができます見つける:
def sineimg(img, color='black', linewidth=1.5, linestyle="-"):
'''
frequency = X/random.uniform(10.0, 20.0)
amplitude = randint(35, 50)
phase = random.uniform(1.0, 16.0)
rotation = random.uniform(-pi/2, pi/2)
'''
#Random rotation angle
rot = random.randint(-90, 90)
x_ = img.shape[0]/np.cos(np.pi * rot/180)
X = np.linspace(-1 * x_, x_, 512)
axes = plt.subplot(111)
np.cos(np.pi * rot/180)
#Random amplitude
amp1 = random.randint(35, 50)
amp2 = random.randint(35, 50)
#Random frequency
frequency1 = X/random.uniform(10.0, 20.0)
frequency2 = X/random.uniform(10.0, 20.0)
#Random offset phase
phase1 = np.pi/random.uniform(1.0, 16.0) + np.pi/2
phase2 = np.pi/random.uniform(1.0, 16.0) + np.pi/3
#random distance between line cluster
distance = random.randint(90, 115)
#I need roughly 8 times of them
for i in range(8):
Y1 = amp1 * np.sin(frequency1 + phase1) - 450 + i * distance
Y2 = amp2 * np.sin(frequency2 + phase2) - 420 + i * distance
x1_trans = X * np.cos(np.pi * rot/180) - Y1* np.sin(np.pi * rot/180)
y1_trans = X * np.sin(np.pi * rot/180) + Y1* np.cos(np.pi * rot/180)
x2_trans = X * np.cos(np.pi * rot/180) - Y2* np.sin(np.pi * rot/180)
y2_trans = X * np.sin(np.pi * rot/180) + Y2* np.cos(np.pi * rot/180)
#Remove label
axes.set_xticks([])
axes.set_yticks([])
axes.spines['right'].set_color('none')
axes.spines['top'].set_color('none')
axes.spines['bottom'].set_color('none')
axes.spines['left'].set_color('none')
axes.plot(x1_trans, y1_trans, color = color, linewidth=linewidth, linestyle=linestyle)
axes.plot(x2_trans, y2_trans, color = color, linewidth=linewidth, linestyle=linestyle)
plt.imshow(img, zorder=0, extent=[148, -148, -225, 225])
ゼム:
img=mpimg.imread('me.jpg')
sineimg(img)
次のような画像が表示されます。
あなたがこれを確認しましたhttps://stackoverflow.com/questions/22937589/how-to-add-noise-gaussian-salt-and-pepper-etc -to-image-in-python-with-opencv –
あなたが試したことを表示する – eyllanesc