📄 jpegdoc.m
字号:
function b = jpeg(file);
A = imread('hulic1.bmp'); %reads file into a matrix
A = rgb2gray(A);
B = imfinfo('hulic1.bmp')
%convert to YCbCr
%if B.Format=='bmp'
% A=rgb2ycbcr(A)
width=B.Width
height=B.Height
%urcenie poctu matic 8x8 zaokruhlenim nahor
W=ceil(width/8);
H=ceil(height/8);
%create a matrix of zeros and add the image to it k naplneniu out the 8x8
%matrices (matrix will stay the same size if height and width are
%divisible by 8
I=zeros(H*8,W*8,'uint8');% uint8 vracia hodnoty z intervalu 0-255
I(1:height,1:width)=A(1:height,1:width);
imshow(I);
%rozdelenie cisel do WxH 8x8 matic
X=zeros(H,W,8,8);
for J=1:H
for K=1:W
for j=1:8
for k=1:8
X(J,K,j,k)=I((J-1)*8+j,(K-1)*8+k);
end
end
end
end
%definovanie kvantizacnej matice
Q=[...
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
b=[];
vprev=[];
vcurrent=[];
for J=1:H
for K=1:W
temp=zeros(8,8,'uint8');%vytvorenie docasnej matice
temp(:,:)=X(J,K,:,:); %pridenie hodnot z aktualneho 8x8 sektoru
temp=double(temp); %convertuje cisla to double formatu(floating point)
temp=temp-128; %posunutie na prostriedok okolo nuly
temp=dct2(temp); %vykonava 2-D cosinusovu transformacnu funkciu
temp=temp./Q; %delenie quantizacnou maticou
temp=round(temp); %zaokruhlenie quantizacnej matice
vcurrent= zigzag(temp);%convertovanie quantizacnej matice do 1-D vectoru
vcurrent=shorten(vcurrent);%remove extra zeros from vector
if J==1 && K==1
b=[b vecenc(vcurrent)];
else
vcurrent(1)=vcurrent(1) - vprev(1);%take difference of first value
b=[b vecenc(vcurrent)];
end
vprev=vcurrent;
end
end
%b=[head(Q) b 1 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1];%last two bytes:ff d9 denote EOF End of File
imshow(A);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -