Betamoo
Betamoo

Reputation: 15910

2D pixel array rotation and scaling

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

Answers (4)

phkahler
phkahler

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

MusiGenesis
MusiGenesis

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

Jon Seigel
Jon Seigel

Reputation: 12401

Have a look here. That should give you all the math behind doing coordinate rotations.

Upvotes: 1

serhio
serhio

Reputation: 28586

In the Matrix class you have both functions Rotate(At) and Scale. What other would you find out?

Upvotes: 2

Related Questions