Perspective Image Transformation with tiling
On the hunt of a good image processing library which can be used for a new application I plan to create. I will be using C#.NET (VS 2008)
My application needs to do the following:
- Load an image at startup and display it in a picture box
- I should then be able to select four points (TopLeft, TopRight, BottomLeft, BottomRight) anywhere in the picture box.
- I then need to transform the source image to the correct perspective using the 4 source and destination points.
Not just that, I need the final output image to be of a specified size. I want the application to be able to use the same perspective and return an image of the specified rectangular size (not the size of 4 points) I specify. I hope you understand what I mean. The source image needs to be tiled 开发者_JS百科and transformed to produce an output that fits the specified area completely.
I tried some libraries like Aforge.NET, ImageMagick, EMGU etc. Some are slow. Some can only produce a perspective image of small size. Some give memory errors. Can't find a proper solution.
I assume the answer to my question over here can help in your case, too.
You may want to take a look at this, as it may solve a portion of your problem, or lead you in the right direction: http://www.codeproject.com/KB/graphics/YLScsFreeTransform.aspx
It will take an image and distort it using 4 X/Y coordinates you provide.
Fast, free, simple code. Tested and it works beautifully. Simply download the code from the link, then use FreeTransform.cs like this:
using (System.Drawing.Bitmap sourceImg = new System.Drawing.Bitmap(@"c:\image.jpg"))
{
YLScsDrawing.Imaging.Filters.FreeTransform filter = new YLScsDrawing.Imaging.Filters.FreeTransform();
filter.Bitmap = sourceImg;
// assign FourCorners (the four X/Y coords) of the new perspective shape
filter.FourCorners = new System.Drawing.PointF[] { new System.Drawing.PointF(0, 0), new System.Drawing.PointF(300, 50), new System.Drawing.PointF(300, 411), new System.Drawing.PointF(0, 461)};
filter.IsBilinearInterpolation = true; // optional for higher quality
using (System.Drawing.Bitmap perspectiveImg = filter.Bitmap)
{
// perspectiveImg contains your completed image. save the image or do whatever.
}
}
FYI, I believe that .NET has a 2gb object memory limit, so if you're working with really large images, you may run into a memory error.
精彩评论