views:

1156

answers:

3

I'm looking for a .Net library that will accept an image or filename and an aspect ratio, and crop the image to that aspect ratio. That's the easy part: I could do it myself. But I also want it to show a little intelligence in choosing exactly what content gets cropped, even if it's just picking which edge to slice.

This is for a personal project, and the pain isn't high enough to justify spending any money on it, but if you can recommend a for-pay tool go ahead. Maybe someone else will find the suggestion useful.

A: 

as in IT should pick the side or YOU will pick the side?

Sara Chipps
A: 

IT should pick the side. Or even the right amount of two or four sides, if it would improve the image. Basically, I want it to somehow evaluate the image and determine what part is fore-ground, and use that to crop the background down to fit the given aspect ratio. If there's no edge with just background, decide which part of the fore-ground is least important. There must be any number of algorithms for this, based on things like the most variation in color, etc.

Joel Coehoorn
Since answers could get out of order, it's better to update the original question so that it has this information.
Lou Franco
+1  A: 

Disclaimer: I work for a .NET Imaging vendor (Atalasoft)

It depends on what kind of image you are talking about. If you are talking about 1-bit document images (like faxes or scans) we can do this.

If you are talking about photographs, our product doesn't do this, but you might be looking for Seam carving. I wrote this application

http://www.atalasoft.com/cs/blogs/31appsin31days/archive/2008/05/26/simple-seam-carver.aspx

with our library that could be ported to just using the built-in .NET images with some work.

The idea of seam carving is to find connected paths in the image with the least interesting variation from the surrounding pixels. In the normal implementation, you would pick a continuous (but not necessarily vertical) path and remove it. If you wanted a crop, you could find the area with the least energy and remove it. My code shows how to calculate the energy of a pixel and path (how different it is from it's surrounding pixels)

If you look up seam carving, you will find some free implementations out there.

Lou Franco