Why is my image not recombining properly after a DCT?

15 visualizaciones (últimos 30 días)
Alexander De-Ville
Alexander De-Ville el 20 de Abr. de 2015
Respondida: Ryan Brewes el 10 de Abr. de 2019
I am doing some image processing and have found that my code does not quite work, the image will not recombine properly after a DCT is applied. The relevant part of the code is below:
%Clear command window.
clc;
%Clear workspace.
clear;
%Load the image file, change to Lena, Airplane, or any other 512x512 file.
RGB = imread ('Lena.tiff');
%Display the result of the conversion.
figure, imshow(RGB), title('Original Image')
%Convert RGB image to YCbCr Components.
YCbCr = rgb2ycbcr(RGB);
%Isolate Y.
Y = YCbCr(:,:,1);
%Isolate Cb.
Cb = YCbCr(:,:,2);
%Isolate Cr.
Cr= YCbCr(:,:,3);
%Perform a 2D DCT operation on Y, Cb, and Cr, in blocks of 8x8 pixels.
YDCT = blkproc(Y,[8 8],@dct2);
CbDCT = blkproc(Cb,[8 8],@dct2);
CrDCT = blkproc(Cr,[8 8],@dct2);
%Perform an inverse DCT operation.
IDCTY = blkproc(YDCT,[8 8],@idct2);
IDCTCb = blkproc(CbDCT,[8 8],@idct2);
IDCTCr = blkproc(CrDCT,[8 8],@idct2);
%Recombine the YCbCr components.
Recombined = cat(3, IDCTY, IDCTCb, IDCTCr);
%Convert the recombined YCbCr matrix to RGB.
RecombinedIMG = ycbcr2rgb(Recombined);
%Display the recombined image.
figure, imshow(RecombinedIMG), title('Recombined')

Respuesta aceptada

Ryan Brewes
Ryan Brewes el 10 de Abr. de 2019
imread reads the original Image as a 512x512x3 uint8.
Both dct2 and idct2 produce a 512x512x3 double.
To display the image correctly, convert back uint8, for example by changing:
IDCTY = blkproc(YDCT,[8 8],@idct2);
IDCTCb = blkproc(CbDCT,[8 8],@idct2);
IDCTCr = blkproc(CrDCT,[8 8],@idct2);
to:
IDCTY = uint8(blkproc(YDCT,[8 8],@idct2));
IDCTCb = uint8(blkproc(CbDCT,[8 8],@idct2));
IDCTCr = uint8(blkproc(CrDCT,[8 8],@idct2));

Más respuestas (1)

Alexander De-Ville
Alexander De-Ville el 25 de Abr. de 2015
No one?

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by