Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Koristeći zašumljenu sliku iz prethodnog primera, ukloniti šum upotrebnom geometrijskog usrednjivača veličina:
- 3x3
- 5x5
- Koristeći PSNR odrediti koji filtar je dao objektivno najbolje otklanjanje.
- Za potrebe rešavanja zadatka napisati funkciju geometricMeanFilt koja implementira filtar geometrijski usrednjivač dat formulom:
- gde (s,t) predstavljaju prostorne koordinate regiona Sx,y posmatran oko centra pozicije (x,y) , g je ulazna slika a m,n predstavljaju dimenzije regiona koji se posmatra. Podrazumevati simetrično proširenje.
- '''
- import numpy as np
- import math
- def geometricMeanFilt(g, S_shape):
- f = np.zeros(g.shape)
- pad_rows = math.floor(S_shape[0]/2)
- pad_cols = math.floor(S_shape[1]/2)
- img_p = np.pad(g, ((pad_rows,),(pad_cols,)), mode='symmetric')
- for row in range(f.shape[0]):
- for col in range(f.shape[1]):
- region = img_p[row:row+S_shape[0], col:col+S_shape[1]]
- res = region.prod()**(1/np.prod(S_shape))
- f[row, col] = res
- return f
- # 3x3 geometrijski usrednjivac
- S_shape = (3,3)
- img_f = geometricMeanFilt(img_noisy, S_shape)
- fig = px.imshow(img_f, zmin=0, zmax=255, color_continuous_scale='gray')
- fig.show()
- psnr = 10*np.log10(255**2/((img - img_f)**2).mean())
- print("PSNR za geometrijski usrednjivac dimenzije {} je {}".format(S_shape, psnr))
- # 5x5 geometrijski usrednjivac
- S_shape = (5,5)
- img_f = geometricMeanFilt(img_noisy, S_shape)
- fig = px.imshow(img_f, zmin=0, zmax=255, color_continuous_scale='gray')
- fig.show()
- psnr = 10*np.log10(255**2/((img - img_f)**2).mean())
- print("PSNR za geometrijski usrednjivac dimenzije {} je {}".format(S_shape, psnr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement