Solved

(fast!) 2D rotation and scaling for grayscale bitmaps

Posted on 1998-05-07
11
575 Views
Last Modified: 2010-05-18
I need  source code (DELPHI or C) to implement a rather fast method to rotate a grayscale image about small angles (+-3 degrees) and scale it down using antialias. Have found nothing acceptable yet
0
Comment
Question by:arnoldu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 4

Expert Comment

by:jbrugman
ID: 1112620
a method to rotate an image on the web, i would use JavaScript. The images are rotated already with a tool like Photoshop.
Rotating can be done with the following script:
<SCRIPT LANGUAGE="JavaScript">

 if (document.images != null) {
     single0 = new Image();single0.src  = "images/aboutstar_0.gif";
     single1 = new Image();single1.src  = "images/aboutstar_1.gif";
     single2 = new Image();single2.src  = "images/aboutstar_2.gif";
     single3 = new Image();single3.src  = "images/aboutstar_3.gif";
     single4 = new Image();single4.src  = "images/aboutstar_4.gif";
     single5 = new Image();single5.src  = "images/aboutstar_5.gif";
     single6 = new Image();single6.src  = "images/aboutstar_6.gif";
     single7 = new Image();single7.src  = "images/aboutstar_7.gif";
     single8 = new Image();single8.src  = "images/aboutstar_8.gif";
     
     var singleI = 0, singleInTimeout = singleOutTimeout = null;
 }


 function fadeInabout() {
     if (document.images != null && singleI < 8) {
         document.images['single'].src = eval('single' + (++singleI) + ".src");
         singleInTimeout = setTimeout('fadeInabout()',60);
     }
 }

function thisfirst() {
   if (singleI >= 8) {
       singleI=0
   }
   clearTimeout(singleInTimeout);
}

</SCRIPT>
<BODY>

<IMG SRC="images/aboutstar_0.gif" NAME="single" BORDER="0">
<BR><BR>
<A HREF="pagina_01.html" TARGET="Right" onMouseover=thisfirst();fadeInabout()>  
About Star</A>

0
 

Author Comment

by:arnoldu
ID: 1112621
This is a wonderful idea - if rotating images on the web had been the actual question. I obtain images from the scanner and have to correct misalignments etc. and rotate them by small angles (e.g. 0.3 °)
0
 
LVL 4

Expert Comment

by:jbrugman
ID: 1112622
Why don't u use a tool like Photoshop or a shareware program like paintshop pro then?
0
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 

Author Comment

by:arnoldu
ID: 1112623
Because I dont have them statically ! My application scans images using a self-written twain interface and I need a kind of preprocessor within my own program to correct for smaller misalignment errrors.

0
 
LVL 4

Expert Comment

by:jbrugman
ID: 1112624
Perhaps it is an idea to post the question in another place then, like in programming C / C++
Good luck!
0
 
LVL 84

Expert Comment

by:ozo
ID: 1112625
how about composing sheer transforms?
0
 

Author Comment

by:arnoldu
ID: 1112626
Good idea - but how to implement them with interpolation?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1112627
I found this reference in
http://www.cis.ohio-state.edu/hypertext/faq/usenet/graphics/algorithms-faq/faq.html
Subject 3.01: How do I rotate a bitmap?

    The easiest way, according to the comp.graphics faq, is to take
    the rotation transformation and invert it. Then you just iterate
    over the destination image, apply this inverse transformation and
    find which source pixel to copy there.

    A much nicer way comes from the observation that the rotation
    matrix:

        R(T) = { { cos(T), -sin(T) }, { sin(T), cos(T) } }

    is formed my multiplying three matrices, namely:

        R(T) = M1(T) * M2(T) * M3(T)

    where

        M1(T) = { { 1, -tan(T/2) },
                  { 0, 1         } }
        M2(T) = { { 1,      0    },
                  { sin(T), 1    } }
        M3(T) = { { 1, -tan(T/2) },
                  { 0,         1 } }

    Each transformation can be performed in a separate pass, and
    because these transformations are either row-preserving or
    column-preserving, anti-aliasing is quite easy.

    Reference:

    Paeth, A. W., "A Fast Algorithm for General Raster Rotation",
    Proceedings Graphics Interface '89, Canadian Information
    Processing Society, 1986, 77-81
    [Note - e-mail copies of this paper are no longer available]

    [Gems I]
...
[Gems I]
    Graphics Gems,
    Andrew Glassner (ed.), Academic Press 1990, ISBN 0-12-286165-5

0
 
LVL 1

Expert Comment

by:mrausch
ID: 1112628
You could quite easily enlarge a "working window" on the
original picture, skew this according to the angle you want to
rotate and scale it down to the desired size. Antialiasing can
be done in this last step without problems.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1112629
I happen to have the Graphics Gems article with me now.
It's too long (and too copyrighted) to type in here, but for the next week or so (until the owner of the book wants it back)
I may be able to answer any furthur questions you have on it.
The article also compares a similar technique  that does a 2 pass simultaneous shear and scale.
A.R. Smith (1987) "Planar 2-Pass Texture Mapping and Warping"
ACM Computer Graphics (SIGGRAPH). 21(4), 263-272.
(A Fast Algorithm for General Raster Rotation)
0
 

Accepted Solution

by:
hlava earned 200 total points
ID: 1112630
try write for each pixel code like(in math):

xx=xb*cos(alfa)-yb*sin(alfa)
yy=xb*sin(alfa)+yb*cos(alfa)

xx-result x
yy-result y
xb-start x
yb-start y
alfa-angle

if you can use rotation about one point you must get this point to 0,0 and then rotate

shifting code(math):
xx=xb+xshift
yy=yb+yshift

good luck!!

                                 HEAD
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question