views:

323

answers:

5

Hi

  • I am working on C# program to process images ( given as int[,] )..
  • So I have 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 )

Thanks in advance

+1  A: 

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

serhio
A: 

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

Jon Seigel
he'll need a good interpolation algorithm though if he doesn't want his images to look a mess
banister
Yes, though he's also interested in doing scaling on the rotated image -- this will take care of the interpolation part of it.
Jon Seigel
A: 

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.

MusiGenesis
A: 

"Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions."

This may be a reason if you want image processing in a background service (without a GUI)

I'm lookin for a solution myself as well for this.

Shaddock
A: 

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

phkahler