I would like to apply DCT to each element in a matrix

조회 수: 2 (최근 30일)
Andrew
Andrew 2013년 2월 17일
I have a code where i take every 8*8 block of a 512*512 image and find its average, and subtract it away, storing the result into a new matrix(64*64).
n = 1;
for i = 1:bs:row;
m = 1;
for j = 1:bs:col;
ave = mean(mean(I(i:i+bs-1, j:j+bs-1)));
A(i:i+bs-1, j:j+bs-1) = I(i:i+bs-1, j:j+bs-1) - ave;
DC(n,m) = ave;
m = m + 1;
end
n = n + 1;
end
But i would like to apply DCT transform to each of the 8*8 blocks, without applying it to the entire image at once, and then store my results in a new matrix of the same size as the original image matrix. I am not sure how to continue from here. Can someone please guide me through this?

채택된 답변

Matt J
Matt J 2013년 2월 18일
I'll assume you have a dct function of some kind and also MAT2TILES from the File Exchange
Icell = mat2tiles(I,[8,8]);
ave=Icell;
for i=1:numel(Icell)
ave{i}=mean(Icell{i}(:));
Icell{i}=dct(Icell{i}-ave{i});
end
DC=cell2mat(ave);
result=cell2mat(Icell);
  댓글 수: 11
Andrew
Andrew 2013년 2월 18일
I am not sure how to do that.
Walter Roberson
Walter Roberson 2013년 2월 18일
Read the function you are using! It starts
%%LOSSY COMPRESSION-DECOMPRESSION USNIG DISCRETE COSINE TRANSFORM TECHNIQUE.
function[]=mydct(filename,n,m)
% "filename" is the string of characters including Image name and its
% extension.
% "n" denotes the number of bits per pixel.
% "m" denotes the number of most significant bits (MSB) of DCT Coefficients.
This documents that you must pass exactly 3 parameters to mydct(), the first of which must be a file name, and the other two must be scalars. But instead your code is passing in an array of data values as the first parameter, and you are not passing in the second or third parameter at all.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by