As promised, here is the second half of my histogram code project. In this project, I’ll show you how to stretch a histogram, equalize individual channels, and – most useful of all – equalize an image’s overall luminance.
Today’s project demonstrates how to quickly and efficiently generate an image histogram. Histograms are invaluable for understanding and implementing a multitude of image processing techniques – including brightness, contrast, levels, curves, equalizing, and more – so it’s worth taking some time to experiment with them. As always, DIB sections are used to generate and render the histograms in real-time…
This little program demonstrates two key graphics programming principles: 1) simple “painting” code – basically, connecting a series of lines together as the user drags their mouse around, and 2) an implementation of the hard-to-find (and poorly documented) dll call for filling a contiguous region of an image. (Photoshop users should know this as the “paint bucket” tool.) As always, sample code and full documentation is provided…
Because the first draft of this project has become so popular, I’ve gone ahead and built a new and MUCH faster version. Updates include: DIB sections for flame drawing, look-up tables, optimized randomization, and custom flame coloring. On my old 1.6ghz laptop this version runs over 4x faster than version 1.0. Enjoy!
Whether working on an old-school RPG or a state-of-the-art FPS, every game programmer needs a fast, cool fire effect at some point in his/her career. In this example, I’ve opted for a straightforward and easy-to-understand method for generating real-time flames. No pre-built images or palettes are used, making the code quite small (only 11kb, including a demo exe) and very easy to reuse. Coloring and flame generation is done using only math and a little cleverness…
Real-time transparency has become so commonplace in modern games and PC applications that it’s almost taken for granted. However, the specific formula that performs this now-ubiquitous effect is worth understanding. Transparency is simply a weighted average between the color values of two pixels. As an example, consider the following two colors: Pure red, or RGB(255, [...]
Color shifting is a very fast, very simple effect that can greatly simplify the work of game artists. (Above is a demonstration using a classic StarCraft Siege Tank.) It is also extremely simple to implement – all we do is shift the red, green, and blue values of each pixel to the right or left. This allows us to generate two additional color variations on a source image without any extra work. (Read the rest of the article for details and sample code…)
Because gray-toned values have RGB values that are identical (or nearly identical), color shifting doesn’t change the appearance of gray pixels. This is pretty clear on the siege tanks above, as the color shifting merely adjusted the subtle hues of the gray regions…
This is one of my all-time favorite image effects – a simulated blacklight that looks GREAT on any image with people in it. I invented this algorithm myself, and the provided code will allow you to test the effect in real-time on any image below 2MB. (The sample image is Squall from FF8 – the greatest RPG ever made, btw…)
This is the first of its kind in VB: accurate, real-time image level adjustment. Image levels provide better control over luminance than strict brightness/contrast methods, but not quite as much control as a well-built Curves Dialog. Adjusting an image using input/output/midtone levels is useful for brightening or darkening an image without losing detail at either end of the luminance spectrum. I’ve included simple histogram drawing code (as the screenshot shows) so you can see the effect that adjusting levels has on an image’s histogram. The code is well-commented and fast – please post comments and/or requests for future VB graphics projects.
By request, here is the first of its kind in VB: a fast, accurate, real-time image curves dialog. (This should be familiar to any PhotoShop users out there :) Curves is similar in theory both “Image Levels” post and standard gamma correction, but it provides a much more powerful interface for adjusting the luminance of an image. This project provides results very similar to Photoshop’s, and it allows the creation of more spline knots (32 instead of 16). The code is well-commented and very fast – please post comments, requests for future Photoshop-related code, and many heaps of praise (as this was a complicated routine to sort out…)!