-
Notifications
You must be signed in to change notification settings - Fork 7
/
Test_RGB_file.m
57 lines (55 loc) · 1.55 KB
/
Test_RGB_file.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
close all
clear all
clc
% constants
max_it=100;
iterations=(1:max_it);
lambda=0.000001;
alpha=3;
noise=1e-3;
conv_kernel=7;
%% Loading file and dividing channels
file=imread('figure.jpg');
file=im2single(file);
imshow(file)
red_part=file(:,:,1);
blue_part=file(:,:,2);
green_part=file(:,:,3);
clear file
%% Generating convolution core
a=fspecial('gaussian',conv_kernel,2);
%% Corrupting the channels
corrupted_red=conv2((red_part),a,'same');
corrupted_blue=conv2((blue_part),a,'same');
corrupted_green=conv2((green_part),a,'same');
%% Adding noise
corrupted_red=corrupted_red+randn(size(corrupted_red))*noise;
corrupted_blue=corrupted_blue+randn(size(corrupted_red))*noise;
corrupted_green=corrupted_green+randn(size(corrupted_red))*noise;
%% Showing result
figure
imshow(cat(3,(corrupted_red),(corrupted_blue),(corrupted_green)))
%% Loading in the GPU memory
a_gpu=gpuArray(a);
obj1_gpu=@(x) conv2(x,a_gpu,'same'); % Determine convolution operation
obj2_gpu=@(x) conv2(x,(a_gpu).','same');
%% DEconvolution
disp('GPU based algorithm started')
tic
disp('Red channel')
[red] = fista_gpu(gpuArray(corrupted_red),obj1_gpu,obj2_gpu,lambda,alpha,max_it);
toc;
red=gather(red);
tic
disp('Blue channel')
[blue] = fista_gpu(gpuArray(corrupted_blue),obj1_gpu,obj2_gpu,lambda,alpha,max_it);
toc
blue=gather(blue);
tic;
disp('Green channel')
[green] = fista_gpu(gpuArray(corrupted_green),obj1_gpu,obj2_gpu,lambda,alpha,max_it);
toc
green=gather(green);
%% Showing result
figure
imshow(cat(3,red,blue,green))