Reputation: 15910
I am working on a C# program to process images ( given as int[,] )..
I have a 2D array of pixels, and I need to rotate them around a point, then scale them down to fit the original array. I already found articles about using matrix to transform to a point and rotate then transform back. What remains is to scale the resultant image to fit an array of original size.
How that can be done? (preferably with 2 equations one for x and one for y )
Upvotes: 0
Views: 3490
Reputation: 5767
You need to find a transform from the resultant array to the original image. You then transform points in the destination to points in the source image and copy. Anti-aliasing via oversampling is also an option. Your rotation matrix can also apply a scaling - just multiply the matrix by the scale factor (this assumes a 2x2). If you're doing 3x3 matrix for rotation, scaling, and translation, then just multiply the upper left 2x2 by the scale factor.
Lastly, at the risk of some humility here is a link to some old TP6/asm DOS code I wrote for doing full screen roto-zooming. Strange the stuff that sticks around on the net: http://www.hornet.org/cgi-bin/scene-search.cgi?search=Paul%20H.%20Kahler
Upvotes: 1
Reputation: 75336
Everything you need to do can be done with Bitmap
images in GDI+ (using the System.Drawing...
namespaces). These classes are designed and optimized for doing exactly this sort of thing (image manipulation). Is there any particular reason you can't work with an actual Bitmap
instead of an int[,]
? You could even write a very simple routine to create a Bitmap
from an int[,]
, do whatever you need to to on the Bitmap
, and then convert it back to int[,]
at the end.
Upvotes: 0
Reputation: 12401
Have a look here. That should give you all the math behind doing coordinate rotations.
Upvotes: 1