How to?

Started by
4 comments, last by jimgeagea 18 years, 3 months ago
Hi, currently i am working on a project, an Image Processing project, i am using C Sharp language.. i dont know what the process or the technique is called, but i want to do the following: i have an image, the border of the image has a shape similar to a trapezoid. imagine i am taking a perspective picture of a rectangular plate, depending on the angle i am taking the image with, i will have a different shape every time, i want to take this shape and transform it to a perfect rectangle, with maintaining the information inside the image (binary colors: black and white). i hope i gave the correct image of what i want. what procedure should i use? 10x in advance
Advertisement
Well, the simplest approach is to simply take each line of pixels and scale it up to the same width as the widest row. That gives you a perfect rectangle. If your aim is to recreate then image on the 'plate,' then you'll need to apply some vertical stretch as well.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

is there any faster way?

i think it will take time to take each line of pixels and scale it up to the same width as the widest row, specially if the picture was big in size?
Well, if you're willing to create an image that is smaller than the widest row, then you can use a 'shading' approach.

You specify your desired resulting image width/height in pixels. Then, loop over each pixel, and 'sample' the original trapezeoid.

You'll need a function to convert perfect-rectangle coordinates to trapeseoid-coordinates; a simple interpolation approach will give you reasonable results, but you may want to build some kind of perspective correction into it.

The simple interpolation approach is to take the original coordinates as fractions of the target image dimensions (e.g. pixel (20, 20) in a 400x400 image gives you (0.05, 0.05)). Take the four vertices of the trapezeoid in the source image and use these coordinates to interpolate between them.

If you need really high performance, you might be able to adapt this technique to the GPU, though if the images are too large then you might run into problems.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

If I am following your question correctly, you have an image taken in perspective view and you want to transform it into an orthogonal view? If that is the case, applying the inverse perspective transformation function to the pixel location of the image should work. (Hard part is knowing what the various perspective parameters are for the image, but it is solvable given that you have some of the information present.) Then any "blank" pixels would have to get filled in based on an average neighbor search.
Quote:Original post by abso
If I am following your question correctly, you have an image taken in perspective view and you want to transform it into an orthogonal view? If that is the case, applying the inverse perspective transformation function to the pixel location of the image should work. (Hard part is knowing what the various perspective parameters are for the image, but it is solvable given that you have some of the information present.) Then any "blank" pixels would have to get filled in based on an average neighbor search.


i dont have any information about the coordinates of the image, i have it as a bmp

This topic is closed to new replies.

Advertisement