2017-09-19 24 views
0

私は画像をPythonで読み込みました。この画像にノイズとしていくつかの異なる正弦波のストライプを追加したいと思います。私は正弦波の周波数と回転度が完全にランダムであることを望みます。私はnumpyモジュールを試しましたが、私がここに必要なモデルではないかもしれません。pythonを使って画像にランダム正弦ストライプを生成する方法は?

誰も私に任意のpythonモジュールに画像にランダムサインカーブを追加するような機能があると教えてもらえますか?

結果、以下のこのイメージと少し似べき:

enter image description here

+0

あなたがこれを確認しましたhttps://stackoverflow.com/questions/22937589/how-to-add-noise-gaussian-salt-and-pepper-etc -to-image-in-python-with-opencv –

+0

あなたが試したことを表示する – eyllanesc

答えて

0

最後に私は、この使用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) 

次のような画像が表示されます。

enter image description here

enter image description here

enter image description here

関連する問題