After one click
How to automatically improve picture quality in Delphi.
Pictures downloaded on the net are often of poor quality : bad scans, video captures or too much JPEG compression. Using the mouse and a suitable brush, man can do the work to obtain a better image, but it's boring. The other way is to use a blur function on the whole picture, but this technique erases many details such as eyes or hair.
We have to blur large areas, but to save details (edges) of the picture. A simple function exists on all image processing programs : find edges. A mask is created using this function, and expanded with a blur function to have a larger action.
Image is first seriously blurred (gaussian blur, radius 3), and then the original pixels detected by the edge mask are copied from the original image to the blurred image in order to recover lost details.
Frequently, pictures scanned with an "old" scanner shows saturation in red areas, and darkness or patches of shadow in blue areas. Green areas are generally correct.
The idea is to mix about 12% (or more) of green values into red values and blue values. Result looks better, but of course with less color saturation. The saturation or contrast fonctions can restore color intensity.
The program offers the capability to restore a percentage of original (read) image, function which is very useful to adjust intensity of some actions.
The special Light+ function is better than Correction gamma to obtain bright images such as the background image of this page.
For more information about scanlines refer to the excellent efg's paper.
I use only pf24bit bitmaps because Jpg images are pf24bit. Instead of efg's arithmetic on scanlines pointers I store bitmap scanlines in arrays of scanlines (bitmaps limited to 2048 lines) to optimize the process when several lines are used to compute new pixel color values.
This Delphi 3 demo program (see below) is simple, but fully operational, and can be used as a basis for an image processing program . [efg's note: change messagebeep(-1) to messagebeep($ffffffff) in later versions of Delphi, like D6 and D7, to eliminate compiler error.]
A zoom show pixels details, save to and undo functions are provided, and a scroll box is used for large pictures. This demo is an extract of a complete image processing program called Estampe.exe. Unfortunately, design and comments are in French. Some original algorithms are used in this program : mix images, very rich text format (see the title above) with extruded letters, progressive shadow and see thru a background in letters), round text (for CD-Roms labels), gradients, select or fill region with tolerance on colors algorithm, etc...
Other interesting programs by Jean-Yves Quéinec:
since 18 Oct 2002