Why is my image not recombining properly after a DCT?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander De-Ville
am 20 Apr. 2015
Beantwortet: Ryan Brewes
am 10 Apr. 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')
0 Kommentare
Akzeptierte Antwort
Ryan Brewes
am 10 Apr. 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));
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!