Morgan's Projects: Image Compression Demo

ImageCompressionDemo is a small Java desktop application built to demonstrate the use of the YCrCb colour model in lossy image compression algorithms. The application provides an easy to use front end where the user can load an image and see the effects of lossy compression by changing parameters governing the number of bits used to store the luminance and chrominance values.

ImageCompressionDemo also offers an indication of the compression ratio of the currently set parameters. It's quite surprising how much space such a simple algorithm can save!

The application was built using NetBeans 6.5 under Microsoft Windows and has been tested under both Windows and Linux environments. A bonus of the project is the creation of a small Java Bean class library 'ImagePreviewPanel' - a GUI component built on top of the Swing library that makes adding easy-to-manage image previews available to the masses.

More about ImagePreviewPanel

I aim to include information about the development of ImagePreviewPanel inline with this project, although it could be construed as a seperate entity. However, I'm doing this because I want to show how the Bean will incorporate into an existing, external application rather than provide a simple demo.

I have some nice ideas for ImagePreviewPanel including click and drag scrolling, mouse wheel zoom control and mouse gesture zoom. The panel will also make use of an overlay UI which can be used to more precisely set the zoom level.

Developer Blog

27th February 2009

I started developing libBitStream yesterday where it ran as a simple command line driven application. The base conversion and compression alogrithms are already in place and have been optimised for speed. I managed to reduce the time taken to load, convert, compress, decompress and save a 3264 x 2448 pixel .jpg image from just over 6 seconds to just over 3.5 seconds - nearly twice as fast!

So far the output results are acceptable but not optimal. The current method I've used for compressing the YCrCb values could be optimised to improve image quality whilst maintaining the same file size.

The screenshot below shows the application in its current state. At the moment, you can load an image and see the effects of changing the luminance and chrominance sliders (not yet labelled). The ImagePreviewPanel Bean is working but does not as yet offer zoom control.

I hope to have all elements of the GUI in place by the end of the day.

1st March 2009

Weekend Update. God I never thought I'd be doing this on a Sunday. Ok, so the application is nearly complete - the only thing missing is proper file filtering controls and a universal zoom for both the source and output images.

ImagePreviewPanel functions quite nicely - you'll notice the zoom in/out icons in the top-left hand corner of the output image. The panel fully supports zoom from 10% to 800% of the original image size along with click/drag scrolling. In fact, the only thing missing from ImagePreviewPanel is that the panel does not remain focused on the original area of interest. Should be fixed by tomorrow though!

The preview image shows a x3 zoom representing what I consider the least desirable image quality. In all honesty, I've had a re-think of the compression code and I know I can get much better quality - even at lower bit counts. After I've finished developing the GUI, I'll re-implement the compression code - promise!

Update!:Just to prove my point about a better compression algorithm: Here's another image using an adaptive compression just for luminance data. It allows me to store a higher quality image at a smaller size! The first image managed 25% (just of 232Kb) whilst the new algorithm achieves 18% (169Kb) with a smaller, more precise chrominance block size which would have increased the storage size using the original algorithm.

6th March 2009

The day before my wife's birthday and I have something else to celebrate! It's a bit cumbersome, but outside of a couple of bugs Image Compression Demo is complete. The only things I really need to do is add code to update the zoom combo box and link the viewports of the source and output images so that the they both display the same area of the image when either image is scrolled.

ImagePreviewPanel is, I'm happy to say, complete and solid. It's my first commericial library and is available to purchase from my online shop.

I've tidied the code up to more accurately reflect the compression levels that can be achieved (using relative YCrCb values) and the components are now fixed size so no more huge status and toolbars!

The screen shot below shows the released version of ImageCompressionDemo.jar, as you can see the scroll panels now fill their area correctly and the zoom icons have been replaced with a rounder, semi-transparent version.

10th March 2009

I've had chance to iron out a few of the wrinkles in ImagePreviewPanel which makes the whole user experience a lot better - both in terms of functionality and aesthetically. Icons can mow appear in any corner of an ImagePreviewPanel and are can be user defined rather than always being the default look and feel. Talking about the default look and feel - it's changed again to celebrate the new fade in/out transitions - I've recorded a video demo which can viewed below or downloaded from the downloads section at the end of this page.


As for a downloadable project - I'm looking into incorporating the library files directly into ImageCompressionDemo and obfuscating the code to make it harder for people to get access to the underlying libraries. I know that with some effort, it can still be re-engineered but I like people to get a real hands-on experience of my work rather than just look at pictures and videos.

Please check back soon as I hope it get something downloadable (it'll probably be a Java WebStart application) soon.

12th March 2009

Finally, I've managed to produce an executable obfucated JAR. NetBeans seems to have confused itself over the type of project I was making and wouldn't create an executable JAR to start with. Once I solved that little problem I ran into another accessing the icon images, but with a little hand-coding in my hand-dandy text editor all is good. You can download ImageCompressDemo using the link below. Before you can run the application you'll need a version of the J2SE Runtime Environment (JRE) installed. You can download it here.

Your Operating System may allow you to run the executable directly from your desktop by double-clicking the icon. If not, you can run ImageCompressionDemo by entering the command line and typing

java -jar ImageCompressionDemo.jar from the directory ImageCompressionDemo.jar is located in.

13th March 2009

Hopefully this will be the last update for this page, other than adding a link for the Web Start application. I've given the application another - fairly major - update in that the output image is produced on an secondary thread - rather than the Swing UI event thread - making the GUI as hell of a lot more responsive, especially for big images.

I was testing the code before on fairly large (6 Megapixel+) images and the sliders would respond probably once every second or two which was very ugly. Now they move instantly and the speed of the output generation doesn't seem to have been affected greatly. The download contains the newly updated code.

Downloads

Click here to download my demonstration video of ImageCompressionDemo in AVI (XVid) format. Click here to download my demonstration video of ImageCompressionDemo in OGG Video format. Click here to download ImageCompressionDemo executable (platform independent) Click here to run ImageCompressionDemo as a Java Webstart application (platform independent)

If you can have questions or want to report a bug with this project, please contact me using this email link