JPEG compression with 16x16 DCT block

3 views (last 30 days)
Bilal Maskaleh
Bilal Maskaleh on 1 Jul 2015
Commented: Bilal Maskaleh on 2 Jul 2015
I'm trying to develop a JPEG encoder which use 16x16 DCT block instead of 8x8 but I faced some issue while I'm trying to show or read the image, i think the error is in the JFIF header, this is the method:
if true
function Entropycoding(dpcmseq,zigzagseq,row_aspect,col_aspect)
stream = [];
oldc = 2;
for m = 1:size(dpcmseq,2)
c = m*256;
stream = cat(2,stream,huffman_dc(dpcmseq(1,m)),huffman_ac(zigzagseq(1, oldc:c)));
oldc = c+2;
end
p=0;
G=size(stream,2);
for i=1:8:size(stream,2)
bit_val(1,1:8)=stream(1,i:i+7);
if strcmp(bit_val(1,1:8),'11111111')==1
tempbitstream = stream(1,i+8:G+p);
stream(1,i+8:i+15)='00000000';
p=p+8;
temp2_bitstream=stream(1,1:i+15);
stream(1,1:G+p)=cat(2,temp2_bitstream,tempbitstream);
end
end
numbytes=floor(length(stream)/8);
diff_stream=length(stream)-numbytes*8;
if diff_stream==0
matrix_code_decimal= zeros(numbytes+2,8);
else
matrix_code_decimal= zeros(numbytes+3,8);
end
s=0;
for count2=1:8:numbytes*8
s=s+1;
matrix_code_decimal(s,1)=bin2dec(stream(1,count2:count2+7));
end
if diff_stream~=0
s=s+1;
matrix_code_decimal(s,1)=bin2dec(stream(1,numbytes*8+1:length(stream)));
end
matrix_code_decimal(s+1,1)=255;
matrix_code_decimal(s+2,1)=217;
Header = [255 216 255 224 000 016 074 070 073 070 000 001 002 000 000 096 ...
000 096 000 000 255 219 001 003 000 016 008 007 007 007 007 006 ...
006 006 006 008 008 006 006 006 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 043 041 039 036 036 030 031 031 035 035 035 032 032 030 030 ...
028 035 035 040 044 044 034 034 032 032 039 042 046 047 047 047 ...
047 042 036 036 040 044 044 042 042 032 029 028 040 040 050 055 ...
041 041 044 044 048 048 048 048 048 046 048 047 047 047 053 053 ...
035 035 031 052 052 052 052 052 052 049 049 049 057 053 057 057 ...
057 054 045 045 045 039 052 057 060 061 056 056 057 056 053 055 ...
060 060 050 050 046 055 060 052 050 050 052 051 051 055 050 051 ...
054 052 052 051 051 051 050 050 050 255 219 001 003 000 017 009 ...
009 012 011 012 024 013 013 024 050 033 028 033 050 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 ...
001 001 001 001 001 001 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 050 ...
050 050 050 050 050 050 050 050 050 050 050 050 050 050 255 192 ...
000 011 008 000 000 000 000 001 001 034 000 255 196 000 031 000 ...
000 001 005 001 001 001 001 001 001 000 000 000 000 000 000 000 ...
000 001 002 003 004 005 006 007 008 009 010 011 255 196 000 181 ...
016 000 002 001 003 003 002 004 003 005 005 004 004 000 000 001 ...
125 001 002 003 000 004 017 005 018 033 049 065 006 019 081 097 ...
007 034 113 020 050 129 145 161 008 035 066 177 193 021 082 209 ...
240 036 051 098 114 130 009 010 022 023 024 025 026 037 038 039 ...
040 041 042 052 053 054 055 056 057 058 067 068 069 070 071 072 ...
073 074 083 084 085 086 087 088 089 090 099 100 101 102 103 104 ...
105 106 115 116 117 118 119 120 121 122 131 132 133 134 135 136 ...
137 138 146 147 148 149 150 151 152 153 154 162 163 164 165 166 ...
167 168 169 170 178 179 180 181 182 183 184 185 186 194 195 196 ...
197 198 199 200 201 202 210 211 212 213 214 215 216 217 218 225 ...
226 227 228 229 230 231 232 233 234 241 242 243 244 245 246 247 ...
248 249 250 255 218 000 008 001 001 000 000 063 000];
Y = dec2hex(row_aspect,4);
X = dec2hex(col_aspect,4);
Header(1,548) = hex2dec(Y(1,1:2));
Header(1,549) = hex2dec(Y(1,3:4));
Header(1,550) = hex2dec(X(1,1:2));
Header(1,551) = hex2dec(X(1,3:4));
JP_STREAM(1,1:size(Header,2)) = Header(1,1:size(Header,2));
for j=1:1:size(matrix_code_decimal,1)
JP_STREAM(1,size(Header,2)+j) = matrix_code_decimal(j,1);
end
JP_STREAM = JP_STREAM';
img_name = regexp('Stego image','\.','split');
img_name = img_name{1};
fid = fopen([img_name '.jpg'], 'wb');
if fid < 0
error('Failed to open data file for write');
end
fwrite(fid,JP_STREAM,'uint8');
fclose(fid);
end

Answers (1)

Walter Roberson
Walter Roberson on 2 Jul 2015
Your line
img_name = regexp('Stego image','\.','split');
attempts to split the literal string 'Stego image' at every literal period followed by literal space. That string does not have literal period followed by literal space so the output is going to be {'Stego image'} . Are you sure that is what you want?
  1 Comment
Bilal Maskaleh
Bilal Maskaleh on 2 Jul 2015
no, my issue is in the matrix which is called Header, and there is no error with the name of the file

Sign in to comment.

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!