StevanovicMilan

8.4

Sep 18th, 2021
4,964
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. Napraviti demo sliku dimenzije 256x256 sa dva kvadrata u sredini (jedan u drugom)
  3. koji su sa nijansama 127 i 191. Postaviti pozadinu na 63. Prikazati njen histogram.
  4.  
  5. Na ovu sliku dodati impulsni:
  6.  
  7. so
  8. biber
  9. so i biber
  10. šum gustine 20%. Prikazati zašumljene slike i njihove histograme.
  11. '''
  12.  
  13. import plotly.graph_objects as go
  14. from plotly.subplots import make_subplots
  15. import numpy as np
  16. import plotly.express as px
  17.  
  18. img = np.full((256,256), fill_value=63)
  19. img[32:32+192,32:32+192] = 127
  20. img[64:64+128,64:64+128] = 191
  21. fig = px.imshow(img, color_continuous_scale='gray')
  22. fig.show()
  23.  
  24. # SO
  25.  
  26. rng = np.random.default_rng()
  27. p = rng.uniform(size=img.shape)
  28.  
  29. p0 = 0.2
  30.  
  31. img_so = img.copy()
  32. img_so[p<p0] = 255
  33. fig = px.imshow(img_so, color_continuous_scale='gray')
  34. fig.show()
  35.  
  36. # BIBER
  37.  
  38. img_biber = img.copy()
  39. img_biber[(rng.uniform(size=img.shape))<p0] = 0
  40. fig = px.imshow(img_biber, color_continuous_scale='gray')
  41. fig.show()
  42.  
  43. # SO I BIBER
  44.  
  45. img_sb = img.copy()
  46. p = rng.uniform(size=img.shape)
  47. img_sb[p<p0/2] = 0
  48. img_sb[(p0/2<=p) & (p<p0)] = 255
  49. fig = px.imshow(img_sb, color_continuous_scale='gray')
  50. fig.show()
RAW Paste Data