Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Napraviti demo sliku dimenzije 256x256 sa dva kvadrata u sredini (jedan u drugom) koji su sa nijansama 127 i 191. Postaviti pozadinu na 63. Prikazati njen histogram.
- Na ovu sliku dodati AWGN šum varijanse 100 i srednje vrednosti 0. Prikazati rezultat i histogram nove slike. Odrediti vršni odnost signal-šum.
- '''
- import plotly.graph_objects as go
- from plotly.subplots import make_subplots
- import numpy as np
- import plotly.express as px
- img = np.full((256, 256), fill_value=63)
- img[32:32+192,32:32+192] = 127
- img[64:64+128,64:64+128] = 191
- fig = px.imshow(img, color_continuous_scale='gray')
- fig.show()
- rng = np.random.default_rng()
- noise_im = rng.standard_normal(size=img.shape)
- fig = px.imshow(noise_im, color_continuous_scale='gray')
- fig.show()
- img_noisy = img + noise_im*np.sqrt(100) + 0 # varijansa i srednja vrednost
- img_noisy[img_noisy > 255] = 255
- img_noisy[img_noisy < 0] = 0
- fig = px.imshow(img_noisy, color_continuous_scale='gray')
- fig.show()
- import plotly.express as px
- rng = np.random.default_rng()
- noise_im = rng.standard_normal(size=img.shape)
- fig = px.imshow(noise_im, color_continuous_scale='gray')
- fig.show()
- img_noisy = img + noise_im*np.sqrt(100) + 0
- img_noisy[img_noisy > 255] = 255
- img_noisy[img_noisy < 0] = 0
- hist_n, bin_edges = np.histogram(img_noisy, bins = np.arange(257))
- fig = make_subplots(rows=1, cols=2)
- fig.add_trace(go.Image(z=np.stack((img_noisy, img_noisy, img_noisy), axis=2)), row=1, col=1)
- fig.add_trace(go.Scatter(x=np.arange(256), y=hist_n, mode='lines',name='hist_noisy', line=dict(color='blue')), row=1, col=2)
- fig.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement