Why is my image not recombining properly after a DCT?
9 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
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));
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!