What is wrong with my 2D discrete cosine transform?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have to generalize the DCT transform for an image and have takeb the basic equation off of Wikipedia . To change it to 2D space and then compute its inverse i've followed the provided instructions. However, it seems that the output is wrong and cannot restore the image.
Direct Transform for DCT4 is provided here:
function [transformed] = TCD4Matrix(image)
[rows, columns] = size(image);
transformed = image;
for k1 = 0 : (rows - 1)
for k2 = 0 : (columns - 1)
summation = 0;
for m = 0 : (rows - 1)
for n = 0 : (columns - 1)
summation = summation + image(m + 1, n + 1) * cos ( (pi * (k1 + 0.5) * (m + 0.5))/rows ) * cos( (pi * (k2 + 0.5) * (n + 0.5))/columns );
end
end
transformed ( k1 + 1, k2 + 1) = summation;
end
end
end
DCT4-I is provided below:
function [restored] = iTCD4Matrix(image)
[rows, columns] = size(image);
restored = zeros(rows, columns);
for k1 = 0 : (rows - 1)
for k2 = 0 : (columns - 1)
summation = 0;
for m = 0 : (rows - 1)
for n = 0 : (columns - 1)
summation = summation + image(m + 1, n + 1) * cos ( (pi * (k1 + 0.5) * (m + 0.5))/rows ) * cos( (pi * (k2 + 0.5) * (n + 0.5))/columns );
end
end
restored ( k1 + 1, k2 + 1) = 4 * summation / (rows * columns);
end
end
end
I tried plotting both the result and a scaled version of it and there's no difference.
>> grayImage = rgb2gray(imread('logo.png'));
>> imageTransform = TCD4Matrix(grayImage);
>> imageRestore = iTCD4Matrix(imageTransform);
>> imshow(imageRestore, [0 255])
>> imshow(imageRestore)
Thanks.
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!