==Question solved==
This code will get you the dct2 output.
I am working to make improvement on my own codes
Thank you.
%Get the size of the input image
[m, n] = size(image);
output = zeros(m,n);
for u = 0:m-1
for v = 0:n-1
if u==0
a=sqrt(1/8);
else
a=sqrt(2/8);
end
if v==0
b=sqrt(1/8);
else
b=sqrt(2/8);
end
temp = 0;
for x = 0:m-1
for y = 0:n-1
temp = (cos((((2*x)+1)*pi*u)/(2*m))*cos((((2*y)+1)*pi*v)/(2*n)));
end
end
output(u+1,v+1) = a*b*temp;
end
end
There are two problems with your code if you are trying to compare it to the Matlab function
dct2. For the record, you can open and analyze the files to understand what Matlab is doing.In both case you are not following the formula:
a and b need to be a function of n:
You need to multiply your
tempterm by the image values (which you are not doing):I haven’t addressed the performance problem, and you really should look into that on your own.