views:

705

answers:

3

I need to write a program that uses matrix multiplication to rotate an image (a simple square), based on the center of the square, a certain amount of degree based on what I need. Any help on this would be greatly appreciated. I almost have no clue as to what I'm doing because I have not taken so much as a glance at Calculus.

+2  A: 

Here's a good code project article discussing just what you're wanting:

http://www.codeproject.com/KB/GDI-plus/matrix%5Ftransformation.aspx

James Kolpack
+4  A: 

Take a look at http://www.aforgenet.com/framework/. This is a complete image processing framework in C# that I'm using on a project. I just checked their help and they have a function that does what you want -

// create filter - rotate for 30 degrees keeping original image size
RotateBicubic filter = new RotateBicubic( 30, true );
// apply the filter
Bitmap newImage = filter.Apply( image );

It is an LGPL library, so if licensing is an issue, if you link against their binaries, you will have no issues. Their are also other libraries out there.

If you do decide to write it yourself, be careful about speed as C# doing number crunching is not great. But there are ways to work around it.

photo_tom
Thanks, this might be what I need. It is a small part of a very large school project so there are no issues :)
Cistoran
C# can be very effective at number crunching if done right. In numeric computational application's it's often the copying of vectors and matrices in C# that damage performance, not any underlying problem with C#.
Paul
A: 

Rotating an digital image in the plane boils down to a lot of 2X2 matrix multiplications. There's no calculus involved here! You don't need an entire image processing framework to rotate a square image - unless this is really performance sensitive in terms of image quality and speed.

Go and read the first half of Wikipedia's article on the rotation matrix and that should get you off to a good start.

In a nutshell, establish your origin (perhaps the center of the image if that's where you want to rotate around), then compute in pixel space the coordinate of a pixel you'd like to rotate, and multiply by your rotation matrix (see article.). Once you've done the multiply, you'll have your new coordinates of the pixel in pixel space. Write out that pixel in another image buffer and you'll be off and rotating. Repeat. Note that once you know your angle of rotation, you only need compute your rotation matrix once!

Have fun,

Paul

Paul