Simple Auto-Levels

Just a quick note on auto-levels. You may know about that function in various graphics software like Photoshop. There was a simple question about how to implement auto-levels in Flash (especially AS3).

Therefore I googled around searching for an algorithm that fits my needs but I had no success. There was also no article in my beloved image-processign bible. What I found out is that the levels is about brightness, contrast and midtones. I am just using brightness and contrast here. You can find the whole source in /as3/ip/img/Image.as in my file-browser.

Now about the auto-levels with are not as good as the Photoshop results but it is a fast way to do it in Flash.

[as]
//– create an image
var img: Image = new Image( width, height );
img.setType( Image.IMAGE_GRAY );
img.loadBitmapData( bmp );

//– grayscale auto-levels
var a: int = img.getAvgValue();
img.adjustBrightness( Math.exp( (0×80 - a) / 0×80 ) * 0×10 );
img.adjustContrast( Math.exp( (0×80 - a) / 0×80 ) );
[/as]

Related Posts

2 Responses to “Simple Auto-Levels”


  1. 1 Shogo Yahagi

    I tried this with flex 2 final version. the methods getAvgValue() adjustBrightness() doesn’t seem to exist. I tried importing mx.controls.Image and mx.utils but I can’t compile.

  2. 2 joa

    I am sorry but I have deleted the old sources for my imageprocessing project. I found a much better and faster solution. You simply can not use mx.controls.Image because the class is somewhat like de.je2050.imageprocessing.core.Image

    You may also look here: http://blog.je2050.de/?p=70

Leave a Reply






Close
E-mail It