Error while compressing the image using dct2()

2 visualizaciones (últimos 30 días)
anuja tidke
anuja tidke el 24 de Mzo. de 2020
Respondida: Sriram Tadavarty el 24 de Mzo. de 2020
Hi!
I am trying to compress image using DCT :
close all;
x=imread('image.jpeg');
figure,imshow(x);
F=dct2(x);
figure,imshow(F*0.01);
ff=idct2(F);
figure,imshow(ff/255);
[r,c]=size(x);
DF=zeros(r,c);
DFF=DF;
IDF=DF;
IDFF=DF;
depth=4;
N=8;
for i=1:N:r
for j=1:N:c
f=original(i:i+N-1,j:j+N-1);
df=dct2(f);
DF(i:i+N-1,j:j+N-1)=df;
dff=idct2(df);
DFF(i:i+N-1,j:j+N-1)=dff;
df(:,N:-1:depth+1)=0;
df(N:-1:depth+1,:)=0;
IDF(i:i+N-1,j:j+N-1)=df;
dff=idct2(df);
IDFF(i:i+N-1,j:j+N-1)=dff;
end
end
figure,imshow(DF/255);
figure,imshow(DFF);
A=DFF/255;
figure,imshow(A);
imwrite(A,'img.jpeg');
B=IDFF/255;
imwrite(B,'img_comp.jpeg');
figure,imshow(B);
Got this code from Online sources.
I am getting the following errors:
Matrix dimensions must agree.
Error in dct (line 76)
b = W .* fft(y);
Error in dct2 (line 50)
b = dct(dct(arg1).').';
Error in image_compression2 (line 4)
F=dct2(x);
Please help me resolve this Issue. Thanking you in Anticipation.
  4 comentarios
anuja tidke
anuja tidke el 24 de Mzo. de 2020
Thanks ! This helped :)
Sriram Tadavarty
Sriram Tadavarty el 24 de Mzo. de 2020
Glad that it helped. I will place this answer and it helps others too.

Iniciar sesión para comentar.

Respuesta aceptada

Sriram Tadavarty
Sriram Tadavarty el 24 de Mzo. de 2020
Hi Anuja,
This error can be solved by perfoming the RGB to gray conversion using rgb2gray function. To know the usage of dct2 with a example, look this page.
Hope this helps.
Regards,
Sriram

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by