3

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:

  1. Load an image at startup and display it in a picture box
  2. I should then be able to select four points (TopLeft, TopRight, BottomLeft, BottomRight) anywhere in the picture box.
  3. 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 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.

demonplus
  • 5,613
  • 12
  • 49
  • 68
over.drive
  • 287
  • 1
  • 6
  • 15

2 Answers2

3

I assume the answer to my question over here can help in your case, too.

Community
  • 1
  • 1
mafu
  • 31,798
  • 42
  • 154
  • 247
  • Well something similar. But the biggest difficulty is that i cannot simply stretch my transformed image. As I increase the size, a new image of bigger size tiled appropriately and which has the same perspective will have to be used. I just cannot think of a way to achieve that. Hope that makes sense. – over.drive Apr 20 '11 at 15:16
  • I'm not sure if I understand correctly. I think the solution over there does what you want. Did you have a look at the 3rd example image? – mafu Apr 20 '11 at 17:45
  • This is an image describing what I am trying to achieve: http://www.4shared.com/photo/DCp6oFjR/TiledImage.html – over.drive Apr 21 '11 at 03:41
  • That should be possible, too, by copying the original image several times with the correct coordinates - in this case, the copy destination won't be a rectangle but a trapezoid. You need to calculate the coordinates by the camera angles yourself, though, which requires some math, but should not be too difficult (if I estimate correctly). --- The image says "after transformation", what is the source? Could applying the source image rather than the transformed one be the easier option? – mafu Apr 21 '11 at 08:23
  • Yes, was working on the same idea. I am using the source image to tile it multiple times to generate a bigger image and then apply transformation on it and cut out the required area. But there are several cases where the image is so large that when I try to apply transformation I get the our of memory exception. Now I amm trying to limit the size of the generated image and shade the remaining portion in the final image. No other option I guess. Thank you mafutrct for the help. Much appreciated. – over.drive Apr 21 '11 at 11:05
1

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.

Doug S
  • 10,146
  • 3
  • 40
  • 45