UOMOP

Add AWGN to image 본문

Wireless Comm./Python

Add AWGN to image

Happy PinGu 2023. 5. 24. 15:37
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
magnitude_fshift = np.log(np.abs(fshift) + 1)

ishift = np.fft.ifftshift(fshift)
img = np.abs(np.fft.ifft2(ishift))

plt.subplot(121),plt.imshow(img, cmap = 'gray')
plt.title('T-domain'), plt.xticks([]), plt.yticks([])

plt.subplot(122),plt.imshow(magnitude_fshift, cmap = 'gray')
plt.title('F-domain'), plt.xticks([]), plt.yticks([])

plt.show()

import acoustics

def add_AWGN_to_img(img, SNRdB) :
    height, width = img.shape

    noise = acoustics.generator.white(img.size).reshape(img.shape)
    SNR = 10.0**(SNRdB/10.0)
    current_SNR = np.mean(img) / np.std(noise)
    noise *= (current_SNR / SNR)

    return img + noise
img_SNR_1 = add_AWGN_to_img(img, 1)
plt.imshow(img_SNR_1, cmap = 'gray')

img_SNR_10 = add_AWGN_to_img(img, 10)
plt.imshow(img_SNR_10, cmap = 'gray')

img_SNR_100 = add_AWGN_to_img(img, 100)
plt.imshow(img_SNR_100, cmap = 'gray')

Comments