0% found this document useful (0 votes)
59 views7 pages

Image Noise Reduction Techniques

Uploaded by

rehan27tifanno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views7 pages

Image Noise Reduction Techniques

Uploaded by

rehan27tifanno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

pip install opencv-python

Requirement already satisfied: opencv-python in c:\python312\lib\site-


packages ([Link])
Requirement already satisfied: numpy>=1.21.2 in c:\python312\lib\site-
packages (from opencv-python) (2.1.3)
Note: you may need to restart the kernel to use updated packages.

[notice] A new release of pip is available: 24.0 -> 24.3.1


[notice] To update, run: [Link] -m pip install --upgrade pip

pip install pillow

Requirement already satisfied: pillow in c:\python312\lib\site-


packages (11.0.0)
Note: you may need to restart the kernel to use updated packages.

[notice] A new release of pip is available: 24.0 -> 24.3.1


[notice] To update, run: [Link] -m pip install --upgrade pip

!pip install matplotlib

Requirement already satisfied: matplotlib in c:\python312\lib\site-


packages (3.9.2)
Requirement already satisfied: contourpy>=1.0.1 in c:\python312\lib\
site-packages (from matplotlib) (1.3.1)
Requirement already satisfied: cycler>=0.10 in c:\python312\lib\site-
packages (from matplotlib) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in c:\python312\lib\
site-packages (from matplotlib) (4.55.0)
Requirement already satisfied: kiwisolver>=1.3.1 in c:\python312\lib\
site-packages (from matplotlib) (1.4.7)
Requirement already satisfied: numpy>=1.23 in c:\python312\lib\site-
packages (from matplotlib) (2.1.3)
Requirement already satisfied: packaging>=20.0 in c:\python312\lib\
site-packages (from matplotlib) (24.0)
Requirement already satisfied: pillow>=8 in c:\python312\lib\site-
packages (from matplotlib) (11.0.0)
Requirement already satisfied: pyparsing>=2.3.1 in c:\python312\lib\
site-packages (from matplotlib) (3.2.0)
Requirement already satisfied: python-dateutil>=2.7 in c:\python312\
lib\site-packages (from matplotlib) (2.9.0.post0)
Requirement already satisfied: six>=1.5 in c:\python312\lib\site-
packages (from python-dateutil>=2.7->matplotlib) (1.16.0)

[notice] A new release of pip is available: 24.0 -> 24.3.1


[notice] To update, run: [Link] -m pip install --upgrade pip
import cv2
import [Link] as plt
import numpy as np

a = [Link]('PCD/fig0503 (original_pattern).tif',0)
image = [Link](a,cv2.COLOR_BGR2RGB)

# gaussian
def gausian_noise(image, mean, std_dev):
noise = [Link](mean, std_dev, [Link])
output = image + noise
return output

# salt n papper
def salt_pepper_noise(image, prob):
output = [Link](image)
thres = 1-prob
for i in range([Link][0]):
for j in range([Link][1]):
rdn = [Link]()
if rdn < prob:
output[i][j] = 0
elif rdn > thres:
output[i][j] = 255
return output

# Poisson
PEAK = 150
noise_mask = [Link](image/255.0*PEAK)

[Link](figsize=(10,10))

# Original Image
[Link](221),[Link](image, cmap = 'gray'),[Link]('Original
Image')
[Link]([]),[Link]([])

# Gaussian Noise
noised_gaus = gausian_noise(a, 0, 50)
[Link](222),[Link](noised_gaus , cmap =
'gray'),[Link]('Gaussian Noise')
[Link]([]),[Link]([])

# Salt n Papper Noise


noised_im = salt_pepper_noise(a, 0.1)
[Link](223),[Link](noised_im , cmap = 'gray'),[Link]('Salt
n Pepper Noise')
[Link]([]),[Link]([])

# Poisson Noise
poissonimg2 = image + noise_mask
[Link](224),[Link](poissonimg2 , cmap =
'gray'),[Link]('Poisson Noise')
[Link]([]),[Link]([])

Clipping input data to the valid range for imshow with RGB data
([0..1] for floats or [0..255] for integers). Got range [0..419].

(([], []), ([], []))


# 2. Restorasi citra dengan Mean Filtering

figure_size = 3
mean = [Link](a,(figure_size, figure_size))
mean2 = [Link](noised_im, (figure_size, figure_size))

[Link](figsize=(15, 10))

[Link](131), [Link](mean, cmap='gray'),[Link]('Mean


Filtering Citra Original')
[Link]([]), [Link]([])

[Link](132), [Link](mean2, cmap='gray'),[Link]('Mean


Filtering Salt n Pepper Noise')
[Link]([]), [Link]([])

(([], []), ([], []))

# 3. Restorasi citra dengan Median Filtering

median = [Link](a,25)
median2 = [Link](noised_im, 25)

[Link](figsize=(15, 10))

[Link](131), [Link](median, cmap='gray'),[Link]('Median


Filtering Citra Original')
[Link]([]), [Link]([])

[Link](132), [Link](median2, cmap='gray'),[Link]('Median


Filtering Salt n Pepper Noise')
[Link]([]), [Link]([])

(([], []), ([], []))

!pip install scipy

Requirement already satisfied: scipy in c:\python312\lib\site-packages


(1.14.1)
Requirement already satisfied: numpy<2.3,>=1.23.5 in c:\python312\lib\
site-packages (from scipy) (2.1.3)

[notice] A new release of pip is available: 24.0 -> 24.3.1


[notice] To update, run: [Link] -m pip install --upgrade pip

# 4. Restorasi citra dengan Adaptive Filtering / Wiener Filtering

import cv2
import numpy as np
from [Link] import gaussian_filter
from [Link] import fft2, ifft2

def gaussian_kernel(kernel_size =3):


h = gaussian_filter([Link](kernel_size), kernel_size / 3)
h /= [Link](h)
return h

def wiener_filter(image, kernel, K):


kernel /= [Link](kernel)
dummy = [Link](image)
dummy = fft2(dummy)
kernel = fft2(kernel, shape = [Link])
kernel = [Link](kernel) / ([Link](kernel) ** 2 + K)
dummy = dummy * kernel
dummy = [Link](ifft2(dummy))
return dummy

blurred_img = [Link](image,(10,10))

kernel = gaussian_kernel(5)
filtered = wiener_filter(noised_im, kernel, K = 10)

[Link](figsize=(15,10))
[Link](121),[Link](filtered, cmap='gray'), [Link]('Wiener
Filtering Shape')
[Link]([]), [Link]([])

(([], []), ([], []))

You might also like