The built-in ImageCrop function "effectively removes borders from image whose pixel value distribution is almost uniform" (emphasis mine). I need an efficient cropping function which removes borders whose pixel values are identical. What is the best way to do this in Mathematica? I don't need support for 3D images, but images with an alpha channel should be supported.
Here is an example of inconsistent behavior of ImageCrop (v. 9.0.1):
img = Rasterize[
Graphics[{Circle[{0, 0}, 1],
Text[Style[l, FontFamily -> "Times"], {1.2, 0}]}, Frame -> False,
PlotRange -> {{.9, 1.3}, All}], "Image", Background -> None];
Show[#, Frame -> True, FrameTicks -> False,
PlotRangePadding -> None] & /@ {img, ImageCrop[img],
ImagePad[img, -BorderDimensions[img, 0]]}

ImageCropis "smarter" than I need! – Alexey Popkov Mar 2 at 11:55SetOptions[ImageCrop, Tolerance -> 0.03]and get the "new" behavior. – Mr.Wizard♦ Mar 2 at 12:26