2

I'm writing an application for the windows store that uses Canny Edge Detection to find the borders of a document on an image. I need to be able to crop this image once the corners are found. I can use the WriteableBitmapExtension methods to crop a rectangle, but the problem is that it will rarely be a rectangle, but rather a quadrilateral.

I read about something called Aforge that may be able to do it, but it doesn't support Silverlight/WinRT it looks like. I know this should be possible with OpenGL, but it would most likely require I change a large portion of my application. Are there any alternatives?

1 Answers1

1

You could implement it with WriteableBitmapEx using Blit and n alpha mask for the region you want to crop. Just create the mask dynamically with the result from the Canny edge detection. Make sure all pixels you want to keep have an alpha value of 255 and the ones you want to crop have an alpha value of 0 in the mask bitmap. Then use the Blit method on the original image, supply the generated alpha mask bitmap as parameter and the BlendMode.Alpha as well. This won't really reduce the size of the original image but at least the unwanted pixels are gone. Before the alpha masking you could already crop rectangular using the min, max of x and y from your edge detection result. This way the size is also reduced and your alpha masking should be faster as a bonus.

Rene Schulte
  • 2,962
  • 1
  • 19
  • 26
  • Thank you for your answer, however, it sounds like by doing this it will only mask the unwanted pixels, but will not de-skew my resulting quadrilateral into a rectangle. Is this correct? If it WILL do this, then, is there and easier way to adjust the alpha values of each pixel other than iterating through the entire image and using SetPixel extension method? This method is extremely slow. Thanks again in advance. – Adam DeFranco Jul 23 '15 at 16:50