Transformations

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Transformations

Postby Jetru » Mon Mar 24, 2008 1:15 pm

I'm working with transforming images(simple ones, like lines, circles,etc). I use a transformation matrix. Right now, I rotate a pixel by multiplying its coordinates with a transformation matrix and plotting the nearest resulting pixel. This results in a few pixels being 'lost'. After a number of successive transforms, all I'm left with is garbage... One possible way to circumvent this issue would be to rotate the 'operation' of drawing a line, that is, just the start and end point and draw the line again. But suppose I have a more arbitrary image...?
Task Throttling!

You can't conquer the game if you can't conquer yourself.
User avatar
Jetru
 
Posts: 751
Joined: Sat Oct 18, 2003 11:46 pm
Location: Bangalore,India

Postby Alvaro » Mon Mar 24, 2008 2:14 pm

I would work the other way around. For each pixel in the final image, find out which point it should come from (multiply by the inverse of the transformation matrix to do this), then find the closest pixel or interpolate several pixels to extract a color from the original image.

If you do several of these transformations you will always lose quality.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Jetru » Mon Mar 24, 2008 2:19 pm

But shouldn't this produce similar results to the previous method?

Interpolating would mean 'averaging the color' of the possible four source pixels(or so) based on their 'exposure' to the resulting transformed pixel
Task Throttling!

You can't conquer the game if you can't conquer yourself.
User avatar
Jetru
 
Posts: 751
Joined: Sat Oct 18, 2003 11:46 pm
Location: Bangalore,India

Postby Alvaro » Mon Mar 24, 2008 2:29 pm

Jetru wrote:But shouldn't this produce similar results to the previous method?

If your transformation is "scale everything up by a factor of 10", your method results in only one pixel in 100 being set in the destination image, while mine results in every pixel being set, although many pixels will be set to the same color.

Interpolating would mean 'averaging the color' of the possible four source pixels(or so) based on their 'exposure' to the resulting transformed pixel

Something like that. If the image you are dealing with is a photo, just finding the closest pixel will result in pixelization. You'll get much better results with some careful interpolation.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Jetru » Wed Apr 09, 2008 11:24 am

Ok I did what you suggested and the quality is significantly better. But I still need to improve it a bit more. Rotating an image some 5 times makes it totally waste!

So i was wondering about interpolation. I googled but found nothing really instructive. I have a pixel, I apply the transformation matrix and I get a pixel. I need to average the color of the destination pixel based on the source pixel. Do I take 9 pixels surrounding the source pixel? And just give my center pixel a 50% weight and add the rest to the pixel? What would be a particularly good technique?
Task Throttling!

You can't conquer the game if you can't conquer yourself.
User avatar
Jetru
 
Posts: 751
Joined: Sat Oct 18, 2003 11:46 pm
Location: Bangalore,India

Postby Alvaro » Wed Apr 09, 2008 11:34 am

What type of images are you manipulating? Photos? You can try with some bilinear interpolation (in the style of Gouraud shading).

I don't understand what you are trying to do but, could you just remember the chain of manipulations and the original image? That way you won't lose any precision when compounding these operations.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Jetru » Wed Apr 09, 2008 11:49 am

Not actually...I'm actually manipulating things like lines, circles, polygons and maybe just random scribbles. I'm working on a paint like program from scratch(no libraries for lines, etc etc)(Project...don't blame me).

Translating layers works fine as its just moving around pixels. Scaling them works a lot better and since there aren't many gradients, its pretty decent. But rotation is a pain! It looks terrible after a few rotates...
Task Throttling!

You can't conquer the game if you can't conquer yourself.
User avatar
Jetru
 
Posts: 751
Joined: Sat Oct 18, 2003 11:46 pm
Location: Bangalore,India

Postby Alvaro » Wed Apr 09, 2008 11:53 am

Can you store your scene as a list of primitives, apply the transformations on the primitives and then redraw? The way you are doing it now, I don't think there is a good solution.
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Jetru » Wed Apr 09, 2008 12:05 pm

Hmm :D Ok I should hit meself. This is wat my prof suggested...I thought it was stupid! I can do it, but it'll take a long time because my proggie isn't built that way...
Task Throttling!

You can't conquer the game if you can't conquer yourself.
User avatar
Jetru
 
Posts: 751
Joined: Sat Oct 18, 2003 11:46 pm
Location: Bangalore,India


Return to Games and Graphics

Who is online

Users browsing this forum: Google [Bot] and 1 guest