-
Notifications
You must be signed in to change notification settings - Fork 2
/
Code.Mat
81 lines (66 loc) · 3.09 KB
/
Code.Mat
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
input=datastore("dataset");
gaussian1 = fspecial('Gaussian', 10, 1.07);
gaussian2 = fspecial('Gaussian', 10, 1);
dog = gaussian1 - gaussian2;
sigma = 5;
scales = [15, 80, 250];
filt_size = 2 * ceil(3 * sigma) + 1;
Psnr_histo= 0;
Psnr_MSR=0;
Psnr_DoG=0;
SSIM_histo=0;
SSIM_MSR=0;
SSIM_DoG=0;
for i=1:length(input.Files)
img=input.read();
img=rgb2ycbcr(img);
img2=img;
GrayLevel=img(:,:,1);
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
%%%%%%%%%%%%% apply histogram%%%%%%%%%%%%%%%%%
HistImage=histeq(GrayLevel);
img(:,:,1)=HistImage;
imwrite(ycbcr2rgb(img),['Histogram/img' int2str(i) '.jpg']);
Psnr_histo=Psnr_histo+psnr(img,img2);
SSIM_histo=SSIM_histo+ssim(img,img2);
disp (['psnr for image ' int2str(i) ' after apply Histogram equalization equals to ' num2str(psnr(img,img2))]);
disp (['ssim for image ' int2str(i) ' after apply Histogram equalization equals to ' num2str(ssim(img,img2))]);
%%%%%%%%%%%%% apply DoG %%%%%%%%%%%%%%%%%%%%%%
DoGImage=conv2(double(GrayLevel), dog, 'same');
DoGImage=uint8(255*DoGImage);
img(:,:,1)=DoGImage;
imwrite(ycbcr2rgb(img),['DOG/img' int2str(i) '.jpg']);
Psnr_DoG=Psnr_DoG+psnr(img,img2);
SSIM_DoG=SSIM_DoG+ssim(img,img2);
disp (['psnr for image ' int2str(i) ' after apply DoG equals to ' num2str(psnr(img,img2))]);
disp (['ssim for image ' int2str(i) ' after apply DoG equals to ' num2str(ssim(img,img2))]);
%%%%%%%%%%%%% apply MSR %%%%%%%%%%%%%%%%%%%%%%
Img = double(GrayLevel);
enhanced = zeros(size(Img));
for j = 1:length(scales)
gaussian_filter = fspecial('gaussian', [filt_size, filt_size], sigma * scales(j));
blurred_image = imfilter(Img, gaussian_filter, 'conv');
retinex_component = log(Img + 1) - log(blurred_image + 1);
enhanced = enhanced + retinex_component;
end
enhanced = uint8( (enhanced - min(enhanced(:))) / (max(enhanced(:)) - min(enhanced(:))) * 255 );
img(:,:,1)=enhanced;
imwrite(ycbcr2rgb(img),['MSR/img' int2str(i) '.jpg']);
Psnr_MSR=Psnr_MSR+psnr(img,img2);
SSIM_MSR=SSIM_MSR+ssim(img,img2);
disp (['psnr for image ' int2str(i) ' after apply MSR equals to ' num2str(psnr(img,img2))]);
disp (['ssim for image ' int2str(i) ' after apply MSR equals to ' num2str(ssim(img,img2))]);
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
end
Psnr_MSR=Psnr_MSR/length(input.Files);
Psnr_DoG=Psnr_DoG/length(input.Files);
Psnr_histo=Psnr_histo/length(input.Files);
SSIM_MSR=SSIM_MSR/length(input.Files);
SSIM_DoG=SSIM_DoG/length(input.Files);
SSIM_histo=SSIM_histo/length(input.Files);
disp(['average Psnr for histogram equalization is ' num2str(Psnr_histo)]);
disp(['average Psnrfor MSR is ' num2str(Psnr_MSR)]);
disp(['average Psnr for DoG is ' num2str(Psnr_DoG)]);
disp(['average ssim for histogram equalization is ' num2str(SSIM_histo)]);
disp(['average ssim for MSR is ' num2str(SSIM_MSR)]);
disp(['average ssim for DoG is ' num2str(SSIM_DoG)]);