-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
49 lines (40 loc) · 1.47 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
close all;
clc;
clear all;
stddev = sqrt(.002);
cropped_pic = double(imread("noisy_cropped.png"));
user_input = input("gauss, anisotropic, tv, bilat, matnlm, nlm\nchoose filter: ");
switch user_input
case 'gauss'
% matlab's guassian filter
denoised_img = imgaussfilt(cropped_pic, 1);
case 'anisotropic'
% matlab's anisotropic filter
denoised_img = imdiffusefilt(cropped_pic, "GradientThreshold", [39 34 31 28 26]);
case 'tv'
% Magiera & Löndahl's matlab implementation of
% Total Variation minimization
denoised_img = rof_denoise(cropped_pic, 15);
case 'bilat'
% neighbourhood filtering instead of yaroslavsky
denoised_img = imbilatfilt(cropped_pic, 1);
case 'matnlm'
% matlab non-local means function for comparison
denoised_img = imnlmfilt(cropped_pic, "DegreeOfSmoothing", 10);
case 'nlm'
% my implementation of non-local means (img, swind, frame, sigma)
denoised_img = nl_means(cropped_pic, 5, 2, 10);
end
% method noise is the difference between noisy image and denoised image
diff = cropped_pic - denoised_img;
imwrite(mat2gray(cropped_pic), "output/original_img.png")
imwrite(mat2gray(denoised_img), "output/denoised_img.png")
imwrite(mat2gray(diff), "output/method_noise.png")
imshow(mat2gray(cropped_pic))
title("Original Image");
figure,
imshow(mat2gray(denoised_img))
title("Filtered Image");
figure,
imshow(mat2gray(diff));
title("Method Noise");