StevanovicMilan

8.2

Sep 18th, 2021
649
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. Koristeći zašumljenu sliku iz prethodnog primera, ukloniti šum upotrebom aritmetičkog usrednjivača veličina:
  3. 3x3
  4. 5x5
  5. 11x11
  6. Koristeći PSNR odrediti koji filtar je dao objektivno najbolje otklanjanje.
  7. '''
  8. import plotly.express as px
  9.  
  10. fig = px.imshow(img_noisy, zmin=0, zmax=255, color_continuous_scale='gray')
  11. fig.show()
  12.  
  13. from scipy import ndimage
  14. import plotly.graph_objects as go
  15. from plotly.subplots import make_subplots
  16.  
  17. # 3x3 aritmeticki usrednjivac
  18. kernel = np.ones((3,3))/9
  19.  
  20. img_f = ndimage.convolve(img_noisy.astype('float'), kernel, mode = 'mirror')
  21.  
  22. fig = px.imshow(img_f, zmin=0, zmax=255, color_continuous_scale='gray')
  23. fig.show()
  24.  
  25. psnr = 10*np.log10(255**2/((img - img_f)**2).mean())
  26. print("PSNR za box filtar dimenzije {} je {}".format(kernel.shape, psnr))
  27.  
  28. # 5x5 aritmeticki usrednjivac
  29. kernel = np.ones((5,5))/25
  30.  
  31. img_f = ndimage.convolve(img_noisy.astype('float'), kernel, mode = 'mirror')
  32.  
  33. fig = px.imshow(img_f, zmin=0, zmax=255, color_continuous_scale='gray')
  34. fig.show()
  35.  
  36. psnr = 10*np.log10(255**2/((img - img_f)**2).mean())
  37. print("PSNR za box filtar dimenzije {} je {}".format(kernel.shape, psnr))
  38.  
  39. # 11x11 aritmeticki usrednjivac
  40. kernel = np.ones((11,11))/121
  41.  
  42. img_f = ndimage.convolve(img_noisy.astype('float'), kernel, mode = 'mirror')
  43.  
  44. fig = px.imshow(img_f, zmin=0, zmax=255, color_continuous_scale='gray')
  45. fig.show()
  46.  
  47. psnr = 10*np.log10(255**2/((img - img_f)**2).mean())
  48. print("PSNR za box filtar dimenzije {} je {}".format(kernel.shape, psnr))
RAW Paste Data