Sei sulla pagina 1di 7

HDR Images at different Exposures:

1. Size (210 KB (216,011 bytes)

2. Size 181 KB (186,083 bytes)

3. Size 156 KB (160,250 bytes)


Tone Mapping

Reinchard Tone mapping

m.file
function result = apply_reinhard_global_tonemap(hdr_map, a)
fprintf('== Applying Reinhard Global Tonemap (a = %.3f) ==\n', a);
[height, width, num_channels] = size(hdr_map);
num_pixels = height * width;
delta = 0.0001;
luminance_map = compute_luminance_map(hdr_map);
C = double(delta + luminance_map);
key = exp((1 / num_pixels) * sum(sum(log(C))));
scaled_luminance = (a / key) * luminance_map;
display_luminance = scaled_luminance ./ (1 + scaled_luminance);
result = apply_tonemap(hdr_map, luminance_map, display_luminance);
end

Tone Mapping Result:

After Tone Mapping..Size become as 111.799 KB


JPEG:

Now applying JPEG on this tone map output

M.file
function Anew=imgreader(x)
%reading the image
A=imread(x);

%get the number of pixels


[rows,columns] = size(A);
disp('No of pixels')
Number_Pixels = rows*columns;

%convert it to grayscale
%AS=rgb2gray(A);
AS=A;

%get the row and col size


rowSize=size(AS,1);
colSize=size(AS,2);

%subtract the bytes from the image


s=int16(AS)-128;
B=[];
Bq=[];
count=1;

blockSize=input('Enter 8 to encode using 8X8 or 16 to use 16X16 : ')


jump=0;
zzcount=0;
if blockSize==8
jump=7;
zzcount=64;
printLimit=8;
else
jump=15;
zzcount=256;
printLimit=16;
end

%encoding process
for i=1:blockSize:rowSize
for j=1:blockSize:colSize
%performing the DCT
B(i:i+jump,j:j+jump) = dct2(s(i:i+jump,j:j+jump));
%performing the quantization
Bq(i:i+jump,j:j+jump)=quantization(B(i:i+jump,j:j+jump),blockSize);
zigzag(count,1:zzcount)=zzag(Bq(i:i+jump,j:j+jump));
count=count+1;
end
end
disp('Original Image')
AS(1:printLimit,1:printLimit)
disp('After level shift')
s(1:printLimit,1:printLimit)
disp('After DCT')
B(1:printLimit,1:printLimit)
disp('After Quantization')
Bq(1:printLimit,1:printLimit)
zigzag(1,1:zzcount);
%for putting it into a file and compressing
save('compImg.mat','zigzag');
compImage=gzip('compImg.mat')

%for decompressing the file


gunzip('compImg.mat.gz')
%fid = fopen('magic5.bin', 'r');
%Bq=load('compImg.mat')

Bnew=[];
ASnew=[];
%decoding process
for i=1:blockSize:rowSize
for j=1:blockSize:colSize
%performing the dequantization

Bnew(i:i+jump,j:j+jump)=invQuantization(Bq(i:i+jump,j:j+jump),blockSize);
%performing the inverse DCT
ASnew(i:i+jump,j:j+jump) = round(idct2(Bnew(i:i+jump,j:j+jump)));
end
end
disp('dequantization')
%Bnew(1:printLimit,1:printLimit)
disp('Inverse DCT')
%ASnew(1:printLimit,1:printLimit)
Anew=ASnew+128;
Anew=uint8(Anew);
rgbImage = cat(3,Anew,Anew,Anew);

figure
imshow(A)
title('Original Image')
figure
imshow(Anew)
title('Compressed Image')

im1_stats = dir('new.jpg');
aw=im1_stats;
p=aw.bytes;
msgbox({sprintf('Original Image,%g (KB)',p/1000)});
im1_stats = dir('Compressed Image');
aw=im1_stats;
pp1=aw.bytes;
msgbox({sprintf('Compressed Image,%g (KB)',pp1/1000)});
end
Might be wrong…but achieve Compressed Image size become as 29.173KB

Potrebbero piacerti anche