Home > Back-end >  Matlab image compression problem
Matlab image compression problem

Time:12-04

Code reprinted in https://blog.csdn.net/hesays/article/details/39499091, only learning with
When I met the problem is that Lena compression stripes appear intermittently, don't know what reason, solve o · bosses
I=imread (' Lena. BMP);
I1=im2double (I);
I1=I1 (:, :, 1);
T=DCTMTX (8);
B=blkproc (I1, 8 [8], 'P1 P2 * x *, T, T');
Mask=[16 November 10 16 to 24 40 51 61
12 12 of 14 19 26 58, 60 55
14 and 16 24 40 57 69 56
14 of 17 to 22 51, 87, 80, 62, 29
18 and 22 and 56 68 109 103 77
24 and 35 to 55, 64, 81, 104, 113, 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
Mask=mask./100;
B2=blkproc (B, 8 [8], 'P1 * x, mask);
I2=blkproc (B2, 8 [8], 'P1 P2 * x *' T ', T);
Subplot (1, 2, 1)
Imshow (I1)
The title (' original image)
figure;
Subplot (1,2,2)
Imshow (I2)
The title (' compressed images')
X1=imread (' Lena. BMP);
I=imread (' Lena. BMP);
X2=rgb2gray (I);
X1=double (x1);
X2=double (x2);
[m, n]=size (x1);
[m2, n2]=size (x2).
If the m2 ~=m | | n2 ~=n;
Error (' image selection error);
end;
msevalue=https://bbs.csdn.net/topics/0;
For I=1: m;
For j=1: n.
msevalue=https://bbs.csdn.net/topics/msevalue+ (x1 (I, j) - x2 (I, j)) ^ 2;
end;
end;
msevalue=https://bbs.csdn.net/topics/msevalue/(m * n);
Disp ([' input data of the mse is: ', num2str (msevalue)]);
psnrvalue=https://bbs.csdn.net/topics/255 ^ 2/msevalue;
psnrvalue=https://bbs.csdn.net/topics/10 * log10 (psnrvalue);
RGB=imread (' G: \ lena3 JPG);
Yuv=rgb2ycbcr (RGB);
Yuv=double (yuv);
Y=yuv (:, :, 1);
U=yuv (:, :, 2);
V=yuv (:, :, 3);
Eql=8;
T=DCTMTX (8);
Y_dct=blkproc (y, [8], 'P1 P2 * x *, T, T');
U_dct=blkproc (u, [8], 'P1 P2 * x *, T, T');
V_dct blkproc=(v, [8], 'P1 P2 * x *, T, T');
Y_dct=y_dct/eql;
U_dct=u_dct/eql;
V_dct=v_dct/eql;
Y_dct_c=fix (y_dct);
U_dct_c=fix (u_dct);
V_dct_c=fix (v_dct);
Y_dct_c=y_dct_c * eql;
U_dct_c=u_dct_c * eql;
V_dct_c=v_dct_c * eql;
Y_idct=blkproc (y_dct_c, [8], 'P1 P2 * x *, T ^ 1, (T') ^ - 1);
U_idct=blkproc (u_dct_c, [8], 'P1 P2 * x *, T ^ 1, (T') ^ - 1);
V_idct=blkproc (v_dct_c, [8], 'P1 P2 * x *, T ^ 1, (T') ^ - 1);
Yuv (:, :, 1)=y_idct;
Yuv (:, :, 2)=u_idct;
Yuv (:, :, 3)=v_idct;
Yuv=uint8 (yuv);
Rgb1=ycbcr2rgb (yuv);
For I=1: length (y_idct);
For j=1: length (u_idct);
Sum=0;
For k=1: length (v_idct);
Sum=sum + rgb1 (I, j, k)/3;
End
Rgb1 (I, j)=sum;
End
End
Imwrite (rgb1, 'JPG')
Subplot (121), imshow (RGB), title (' original image);
Subplot (122), imshow (rgb1), title (' processing after image ');

CodePudding user response:

  • Related