Matrix multiplication to rotate an image in C #

I need to write a program that uses matrix multiplication to rotate an image (simple square) based on the center of the square to a certain degree based on what I need. Any help on this would be greatly appreciated. I have almost no idea what I am doing because I have not done as much as looking at Calculus.

+2


source to share


3 answers


Take a look at http://www.aforgenet.com/framework/ . This is the complete C # image processing framework that I am using in the 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's an LGPL library, so if licensing is an issue, if you link to their binaries, you won't have a problem. There are other libraries as well.

If you decide to write it yourself, be careful with speed as C # makes the number crunching small. But there are ways to get around this.

+4


source


Here's a nice code project article discussing just what you want:



http://www.codeproject.com/KB/GDI-plus/matrix_transformation.aspx

+2


source


Rotation of a digital image in a plane is reduced to a set of 2X2 matrix multiplications. There is no calculus here! You don't need the entire imaging infrastructure to rotate a square image, unless it is very sensitive to image performance in terms of image quality and speed.

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

In a nutshell, state your origin (perhaps the center of the image if you want to rotate around), then compute in pixel space the coordinate of the pixel you want to rotate and multiply by your rotation matrix (see article.). After you do the multiplication, you get the new pixel coordinates in pixel space. Write that pixel to another image buffer and you will be off and spinning. Reiteration. Note that once you know your rotation angle, you only need to compute your rotation matrix!

Good luck,

Floor

+2


source







All Articles