Archive for the 'clevrlib' Category

Resizing Actionscript images with bicubic or bilinear interpolation

Thursday, July 10th, 2008

I’ve had a few people contact me to ask about how to use clevrlib to resize images with bicubic or bilinear interpolation in Flash or Flex, so I’ll give an overview of how to do this.

The InterpolatedBitmapData class adds the methods getPixelBicubic and getPixelBilinear to the BitmapData class, which allows you to fetch the colour of a point that’s not on a pixel boundary. We use this when reprojecting the source images in the CleVR Stitcher, but it can work just as well for resizing an image. Bear in mind that bicubic is a lot slower than bilinear, and the quality improvement isn’t usually worthwhile. However, you’re welcome to switch to getPixelBicubic if you need to.

The basic method I’m using here for resizing is to loop through the pixels of the output image, getting the equivalent pixels in the source image. As these are found by multiplying by the ratio between the source and output sizes, the coordinates probably won’t be integers. Using regular getPixel would require rounding, and therefore give a jagged (aliased) output. The getPixelXxx methods let you pass them a Number, which needn’t be an integer, giving a much smoother result.

The sample code below shows a way of resizing an image using this method. The InterpolatedBitmapData should be created in the same way as a BitmapData, such as by draw()ing a loader onto it. The example I’ve shown below is an Event.COMPLETE handler for a Loader. Code below the cut.

CleVR Actionscript libraries now on RIAForge

Thursday, September 6th, 2007

I’ve put up the CleVR AS3 libraries on RIAForge, where you can download them as a zip file, or use the svn repository.

The library includes a number of classes that we developed as part of the CleVR Stitcher. They include a set of matrix algebra classes, ported from the Java JAMA library. These let you do standard matrix algebra stuff, and includes support for singular value decomposition and QR decomposition.

There’s also some graphics classes. One is a subclass of BitmapData that adds bicubic and bilinear interpolation. Another is a class for calculating the histogram of an image, with methods to do histogram stretching. This gives results similar to “Auto levels” in Photoshop, or “Enhance” in iPhoto.

You will find them here. They’re released under the Creative Commons attribution licence, which basically lets you do anything with them, so long as you give credit somewhere. A link to would usually suffice. Let me know if you have any comments, patches, or if you’re using it.