Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:11:26+00:00 2026-06-14T18:11:26+00:00

==Question solved== This code will get you the dct2 output. I am working to

  • 0

==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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:11:27+00:00Added an answer on June 14, 2026 at 6:11 pm

    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:

    1. a and b need to be a function of n:

      if u==0
          a=sqrt(1/n);
      else
          a=sqrt(2/n);
      end
      
      if v==0
          b=sqrt(1/n);
      else
          b=sqrt(2/n);
      end
      
    2. You need to multiply your temp term by the image values (which you are not doing):

      temp = temp+(image(x+1,y+1))*(cos((((2*x)+1)*pi*u)/(2*m))*cos((((2*y)+1)*pi*v)/(2*n)));
      

    I haven’t addressed the performance problem, and you really should look into that on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

edit This question is solved! Having something weird. I'm using html { font-size: 100%
I'm trying to solve this problem, its not a homework question, its just code
This is an Amazon interview Question.I have solved this problem in O(n) using dynamic
I understand the problem that OSGI solved thanks to this question.... What does OSGi
I have asked this question before and the problem was half solved in the
My question is not about how to solve this error(I already solved it) but
This is not really a question because I just solved the problem, but I
Since my other bug got solved, I'm posting a new question for this bug.
Note: This question was marked as solved once, but it figured out that upgrading
I have previously solved a similar problem in this question , where I asked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.