Sunday, April 22, 2012

TIP | Blending Quicktime video layers to improve nightime videos

In my last video filter-processing tip, Blending Quicktime Video Layers to Penetrate Demon Cloaks, I provided a Quicktime video layer blending combination that will expose hidden and hard-to-see demons shot on video in darkly lit environments; however, the caveat is a loss of original color, in that any two colors that are similar have to be drastically changed in order to better distinguish between the two.
For example, 10% gray and 11% gray, which are virtually indistinguishable from each other, must be changed at least by 10% to be distinguishable, resulting in a wild-colored video. This is fine, if you're looking for otherwise impossible to see demons; but, if not, retaining the natural color of the video is far preferable.

The still frame below is a perfect example of an over-dark, over-saturated video. In the background, there is very little detail—the shelves on the cabinets blend together; the only distinction among them is there distance from each other. Also, my lips are way too red, and there is a color blotch on my cheek and lower eyelid; moreover, my skin is a blotchy and pinkish, and my lips are ruby-red.
Oversaturated in some places, shadow bleeding in others
Overly dark areas in a video are not just caused by dimly lit environments, but also over saturation, which is common is cheaper digital video cameras. To correct both, that is, to expose detail in dark areas of your video and correct the over-saturation, duplicate the video layer of your Quicktime move four times (for a total of 5 layers), and set the Graphics Mode to the following values:
Adjust only the blend layers (3 and 5) to reach the optimal contrast and saturation levels; set all others (1, 2, 4) as shown
Then, make adjustments to only layers 3 and 5—the blend layers—until you can see detail in the shadows, just like in the still frame below.
The change is subtle, but look closely at the following:
  • The objects in the shadows are sharper (look at the lampstand)

Before
After
  • The leaves are the correct color and so are the shadows; there is also more detail

Before
After

  • The lips and face are now a more natural color, and the splotchiness is reduced greatly

Before
After
For your reference
Transfer Modes
The term transfer mode may be considered as a generic term encompassing three different transfer mode types. Each has to do with the way source pixels interact with destination pixels during drawing, painting, erasing, filling, and copying operations. The three types of transfer mode are as follows:
  • Boolean Pattern Mode. Boolean pattern modes apply to line drawing, framing, painting, erasing, and filling operations. 
  • Boolean Source Mode. Boolean source modes apply to text drawing and copying operations. 
  • Arithmetic Source Mode. Arithmetic source modes apply to drawing (including text drawing), painting, and copying operations.


Boolean Source Modes
The Boolean source modes are the equivalent in text drawing and copying to the Boolean pattern mode used for non-text drawing, painting, filling, and erasing operations.
The relevant constants are srcCopy, srcOr, srcXor, srcBic, notSrcCopy, notSrcOr, notSrcXor, and notSrcBic. The additional non-standard mode grayishTextOr is useful for drawing text in deactivated or disabled user interface objects. (This mode is considered non-standard because it is not stored in pictures and printing with it is undefined.)
srcCopy
If the source is black, apply the foreground color to the destination; if the source is white, apply the background color; otherwise apply weighted portions of the foreground and background colors.
srcOr
If the source is black, apply the foreground color to the destination; if the source is white, do nothing; otherwise apply weighted portions of the foreground color.
srcXor
If the source is black, invert the destination (this operation is undefined for a colored destination). Otherwise, do nothing.
srcBic
If the source is black, apply the background color to the destination. If the source is white, do nothing. Otherwise, apply weighted portions of the background color.
notSrcCopy
If the source is white, apply the foreground color to the destination; if the source is black, apply the background color; otherwise apply weighted portions of the foreground and background colors.
notSrcOr
If the source is white, apply the foreground color to the destination; if the source is black, do nothing; otherwise apply weighted portions of the foreground color.
notSrcXor
If the source is white, invert the destination (this operation is undefined for a colored destination pixel). Otherwise, do nothing.
notSrcBic
If the source is white, apply the background color to the destination. If the source is black, do nothing. Otherwise, apply weighted portions of the background color.
Boolean Pattern Modes
Pattern modes may be set as pen transfer modes in the graphics port using the PenMode function. The modes are represented by eight constants, each of which relates to a specific Boolean operation (COPY, OR, XOR, and BIC (for bit clear)) and their inverse variants.
The effects of these modes are best explained assuming a 1-bit (black-and-white) environment in which the foreground colour is black and the background colour is white. The following lists the pattern modes and describes the effect of source pixels on destination pixels in such an environment.
Pattern Mode
Action On Destination Pixel
If source pixel is black
If source pixel is white
patCopy
Apply foreground colour.
Apply background colour.
patOr
Apply foreground colour.
Leave alone.
patXor
Invert.
Leave alone.
patBic
Apply background colour.
Leave alone.
notPatCopy
Apply background colour.
Apply foreground colour.
notPatOr
Leave alone.
Force black.
notPatXor
Leave alone.
Invert.
notPatBic
Leave alone.
Apply background colour.

These effects are illustrated at Fig 4. Note particularly that patCopy causes the destination pixels to be completely over-written. patCopy is the transfer mode initially set in the graphics port.

12image04.gif



Text dimming
grayishTextOr
Dim the destination. If in color, replace it with a blend of the foreground and background; if black-and-white, replace it with dithered black and white. This mode is used primarily for text.

Highlighting
Highlighting
hilite
Replace the background color with the highlight color.
hilitetransfermode
Replace the background color with the highlight color.

Arithmetic Source Modes
Arithmetic source modes may be set in the graphics port, and may be passed as parameters in QuickDraw functions for copying pixel images.
Arithmetic source modes perform arithmetic operations on the values of the red, green and blue components of the source and destination pixels. Because they work with RGB colours rather than colour table indexes, arithmetic transfer modes produce predictable results on indexed devices. The arithmetic source modes and their effects in a colour environment are as follows:

Constant
Value
Description
blend
32
Destination pixel is replaced with a blend of the source and destination pixel colours. Revert to srcCopy mode if the destination is a bitmap or 1-bit pixel image.
addPin
33
Destination pixel is replaced with the sum of the source and destination pixel colours up to a maximum allowable value. Revert to srcBic mode if the destination is a bitmap or 1-bit pixel image.
addOver
34
Destination pixel is replaced with the sum of the source and destination pixel colours, but if the value of the red, green or blue component exceeds 65,536, then subtract 65,536 from that value. Revert to srcXor mode if the destination is a bitmap or 1-bit pixel image.
subPin
35
Destination pixel is replaced with the difference of the source and destination pixel colours, but not less than a minimum allowable value. Revert to srcOr mode if the destination is a bitmap or 1-bit pixel image.
transparent
36
Source and destination pixel are replaced with the source pixel if the source pixel is not equal to the background colour.
addMax
37
Destination pixel is replaced with the colour containing the greater saturation of each of the RGB components of the source and destination pixels. Revert to srcBic mode if the destination is a bitmap or 1-bit pixel image.
subOver
38
Destination pixel is replaced with the difference of the source and destination pixel colours, but if the value of the red, green or blue is less than 0, add the negative result to 65,536. Revert to srcXor mode if the destination is a bitmap or 1-bit pixel image.
adMin
39
Destination pixel is replaced with the colour containing the lesser saturation of each of the RGB components of the source and destination pixels. Revert to srcOr mode if the destination is a bitmap or 1-bit pixel image.

Add Dithering to Transfer Modes
ditherCopy
Replace the destination with a dither mix of the source and destination.

Transparent mode
transparent
Replace the destination with the source if the source is not equal to the background.

Rerun