-
Notifications
You must be signed in to change notification settings - Fork 7
/
PLOT_1.m
52 lines (45 loc) · 1.55 KB
/
PLOT_1.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
close all
clear all
tic
% constants
max_it=1000;
iterations=(1:max_it);
lambda=0.000001;
alpha=2;
noise=1e-3;
conv_kernel=7;
% Loading Image from file
file=imread('lena512.bmp');
file=im2double(file);
% Concatenating and increasing size
filegray1=cat(2,cat(1,file,file),cat(1,file,file));
filegray1=cat(2,cat(1,filegray1,filegray1),cat(1,filegray1,filegray1));
size(filegray1)
% Definition of the convolutional kernel
a=fspecial('gaussian',conv_kernel,2);
obj1=@(x) conv2(x,a,'same');
obj2=@(x) conv2(x,a.','same');
corrupted=conv2(filegray1,a,'same');
corrupted=corrupted+randn(size(corrupted))*noise;
% Definition of the convolutional kernel in GPU memory
a_gpu=gpuArray(a);
obj1_gpu=@(x) conv2(x,a_gpu,'same');
obj2_gpu=@(x) conv2(x,(a_gpu).','same');
corrupted_gpu=conv2(gpuArray(filegray1),a_gpu,'same');
corrupted_gpu=corrupted_gpu+gpuArray.randn(size(corrupted_gpu))*noise;
disp('CPU based algorithm started')
tic
[x,timeline_cpu] = fista_normal_time(corrupted,obj1,obj2,lambda,alpha,max_it);
toc
disp('Algorithm on GPU started')
tic
[x1,timeline_gpu] = fista_gpu_time(corrupted_gpu,obj1_gpu,obj2_gpu,lambda,alpha,max_it);
toc
%Plotting
semilogy(iterations,timeline_cpu,'b','LineWidth',2); hold on; grid on;
semilogy(iterations,timeline_gpu,'r','LineWidth',2); set(gca,'FontSize',14);
title('Ñêîðîñòü ðàáîòû ïî èòåðàöèÿì','FontSize',14);
xlabel('Èòåðàöèè','FontSize',14)
ylabel('Âðåìÿ ðàáîòû','FontSize',14)
hleg=legend(['Àëãîðèòì ðåàëèçîâàííûé íà CPU'],['Àëãîðèòì ðåàëèçîâàííûé íà GPU'])
set(hleg,'FontSize',14 )