Why is my image not recombining properly after a DCT?

조회 수: 9 (최근 30일)
Alexander De-Ville
Alexander De-Ville 2015년 4월 20일
답변: Ryan Brewes 2019년 4월 10일
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')

채택된 답변

Ryan Brewes
Ryan Brewes 2019년 4월 10일
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));

추가 답변 (1개)

Alexander De-Ville
Alexander De-Ville 2015년 4월 25일
No one?

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by