Why is my image not recombining properly after a DCT?

9 vues (au cours des 30 derniers jours)
Alexander De-Ville
Alexander De-Ville le 20 Avr 2015
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')

Réponse acceptée

Ryan Brewes
Ryan Brewes le 10 Avr 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));

Plus de réponses (1)

Alexander De-Ville
Alexander De-Ville le 25 Avr 2015
No one?

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by