-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox1.m
99 lines (86 loc) · 2.9 KB
/
sandbox1.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% I = im2double(imread('images/ultrasound.jpg'));
% I = rgb2gray(I);
% figure, imshow(I)
% PSF = fspecial('motion', 10, 30);
% V = .5;
% WT = zeros(size(I));
% WT(5:end-4,5:end-4) = 1;
% J1 = deconvlucy(I,PSF);
% figure,imshow(J1);
% title('deconvlucy(A,PSF)');
% figure, imshow(WT), title('Weight')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = imread('images/ultrasound.jpg');
img = rgb2gray(img);
img = im2double(img)
figure, subplot(2, 2, 1)
imshow(img, []), title('Blurred image')
imgclear = imread('images/ultrasoundclear.jpg');
subplot(2, 2, 2)
imshow(imgclear, []), title('Desired image')
LEN = 10; THETA = 26; noise_var = 0.0001;
motion_noise = fspecial('motion', LEN, THETA);
signal_var = var(img(:));
wnr3 = deconvwnr(img, motion_noise, noise_var / signal_var);
figure, imshow(wnr3)
title('Restoration of Blurred, Noisy Image - Estimated NSR');
% LEN = 10; THETA = 26;
% motion_noise = fspecial('motion', LEN, THETA);
%
% wnr = deconvwnr(img, motion_noise, 0.01);
% luri = deconvlucy(img, motion_noise);
% subplot(2, 2, 3), imshow(wnr), title('Deblur using Wiener');
% subplot(2, 2, 4), imshow(luri), title('Deblur using Lucy-Richardson');
% figure, imshow(wnr)
% se1 = strel('square',3);
% img1 = imopen(luri, se1); % Remove the noise by opening
% img2 = imclose(img1, se1); % Connect back the image by closing
% figure, imshow(img2)
%%%%
% w = fspecial('laplacian', 0);
% I1 = imfilter(luri, w, 'replicate');
% figure, imshow(I1, [])
%
% I2 = im2double(luri);
% I3 = imfilter(I2, w, 'replicate');
% figure, imshow(I3, [])
%
% J = I2 - I3
% J = imadjust(J)
% figure, imshow(J, [])
% WEIGHT = edge(wnr,'sobel',.08);
%
% se = strel('disk',2);
% WEIGHT = 1-double(imdilate(WEIGHT,se));
%
% WEIGHT([1:3 end-(0:2)],:) = 0;
% WEIGHT(:,[1:3 end-(0:2)]) = 0;
% figure; imshow(WEIGHT); title('Weight array');
%
% PSF = fspecial('gaussian',7,10);
% UNDERPSF = ones(size(PSF)-4);
% OVERPSF = padarray(UNDERPSF,[4 4],'replicate','both');
% INITPSF = padarray(UNDERPSF,[2 2],'replicate','both');
%
% V = .5;
% WT = zeros(size(img));
% WT(5:end-4,5:end-4) = 1;
%
% [J, P] = deconvblind(img,PSF,30,[],WT);
% figure;imshow(J);title('Deblurred Image');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% noise_var = 0.001;
% estimated_nsr = noise_var / var(img(:));
% wnr3 = deconvwnr(img, motion_noise, estimated_nsr);
% figure, imshow(wnr3)
% title('Restoration of Blurred, Noisy Image Using Estimated NSR');
% % Simulate a motion blur image
% LEN = 10; THETA = 30;
% motion_noise = fspecial('motion', LEN, THETA);
% blurred = imfilter(img, motion_noise, 'conv', 'circular');
% figure, imshow(blurred), title('Blurred image')
% % Deblurring the image with Wiener filter
% uniform_quantization_var = (1/256)^2/12;
% signal_var = var(im2double(img(:)));
% wnr = deconvwnr(img, motion_noise, uniform_quantization_var/signal_var);
% figure, imshow(wnr), title('Restoration of Blurred Image')