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

  • Home
  • SEARCH
  • 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 3947166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:13:09+00:00 2026-05-20T01:13:09+00:00

I’ve heard that it should be possible to do a lossless rotation on a

  • 0

I’ve heard that it should be possible to do a lossless rotation on a jpeg image. That means you do the rotation in the frequency domain without an IDCT. I’ve tried to google it but haven’t found anything. Could someone bring some light to this?

What I mean by lossless is that I don’t lose any additional information in the rotation. And of course that’s probably only possible when rotating multiples of 90 degrees.

  • 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-05-20T01:13:10+00:00Added an answer on May 20, 2026 at 1:13 am

    You do not need to IDCT an image to rotate it losslessly (note that lossless rotation for raster images is only possible for angles that are multiples of 90 degrees).

    The following steps achieve a transposition of the image, in the DCT domain:

    1. transpose the elements of each DCT block
    2. transpose the positions of each DCT block

    I’m going to assume you can already do the following:

    • Grab the raw DCT coefficients from the JPEG image (if not, see here)
    • Write the coefficients back to the file (if you want to save the rotated image)

    I can’t show you the full code, because it’s quite involved, but here’s the bit where I IDCT the image (note the IDCT is for display purposes only):

    Size s = coeff.size();
    Mat result = cv::Mat::zeros(s.height, s.width, CV_8UC1);
    
    for (int i = 0; i < s.height - DCTSIZE + 1; i += DCTSIZE)
    for (int j = 0; j < s.width  - DCTSIZE + 1; j += DCTSIZE)
    {
        Rect rect = Rect(j, i, DCTSIZE, DCTSIZE);
        Mat dct_block = cv::Mat::Mat(coeff, rect);
        idct_step(dct_block, i/DCTSIZE, j/DCTSIZE, result);
    }
    

    This is the image that is shown:

    Lenna

    Nothing fancy is happening here — this is just the original image.

    Now, here’s the code that implements both the transposition steps I mentioned above:

    Size s = coeff.size();
    Mat result = cv::Mat::zeros(s.height, s.width, CV_8UC1);
    
    for (int i = 0; i < s.height - DCTSIZE + 1; i += DCTSIZE)
    for (int j = 0; j < s.width  - DCTSIZE + 1; j += DCTSIZE)
    {
        Rect rect = Rect(j, i, DCTSIZE, DCTSIZE);
        Mat dct_block = cv::Mat::Mat(coeff, rect);
        Mat dct_bt(cv::Size(DCTSIZE, DCTSIZE), coeff.type());
        cv::transpose(dct_block, dct_bt);                // First transposition
        idct_step(dct_bt, j/DCTSIZE, i/DCTSIZE, result); // Second transposition, swap i and j
    }
    

    This is the resulting image:

    transposed

    You can see that the image is now transposed. To achieve proper rotation, you need to combine reflection with transposition.

    EDIT

    Sorry, I forgot that reflection is also not trivial. It also consists of two steps:

    1. Obviously, reflect the positions of each DCT block in the required axis
    2. Less obviously, invert (multiply by -1) each odd row OR column in each DCT block. If you’re flipping vertically, invert odd rows. If you’re flipping horizontally, invert odd columns.

    Here’s code that performs a vertical reflection after the transposition.

    for (int i = 0; i < s.height - DCTSIZE + 1; i += DCTSIZE)
    for (int j = 0; j < s.width  - DCTSIZE + 1; j += DCTSIZE)
    {
        Rect rect = Rect(j, i, DCTSIZE, DCTSIZE);
        Mat dct_block = cv::Mat::Mat(coeff, rect);
    
        Mat dct_bt(cv::Size(DCTSIZE, DCTSIZE), coeff.type());
        cv::transpose(dct_block, dct_bt);
    
        // This is the less obvious part of the reflection.
        Mat dct_flip = dct_bt.clone();
        for (int k = 1; k < DCTSIZE; k += 2)
        for (int l = 0; l < DCTSIZE; ++l)
            dct_flip.at<double>(k, l) *= -1;
    
        // This is the more obvious part of the reflection.
        idct_step(dct_flip, (s.width - j - DCTSIZE)/DCTSIZE, i/DCTSIZE, result);
    }
    

    Here’s the image you get:

    final

    You will note that this constitutes a rotation by 90 degrees counter-clockwise.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a text area in my form which accepts all possible characters from
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.