[EDIT: Fortunately, no one posted while I was working on the Avisynth script. It turned out be simplicity itself. I'll just re-edit this starting post to include all the info.]
I'll do this HSL Sources Recombination as a parallel demonstration. As each step is developed in the paint program, a parallel step will be implemented in Avisynth. Those new to one or both of these venues can see how things work and work through it themselves.
.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
COLOR TRANSFER BETWEEN MEDIA
This demonstration shows how to transfer the "color" of a colorized standard definition video to a B&W high definition video, creating a colorized hi-def video. This technique can also be generally use to transfer color between any two videos.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Create a new folder and put all the project resources in it (for the simplicity of not dealing with paths to files.
Get these SD (Standard Definition) and HD (High Definition) YouTube-video snapshots ..
SD: YouTube 480x360
http://i565.photobucket.com/albums/ss96/spaced_ranger/YTMO34thScolorizedSD360.jpg
and save this image in your work folder as
YTMO34thScolorizedSD360.jpg
HD: YouTube 1280x720
http://s8.postimg.org/gzpsk6ieb/YT_MO34th_S_B_W_HD720.jpg
and save this image in your work folder as
YT_MO34th_S_B_W_HD720.jpg
(sorry to use another picture service but PhotoBucket won't distribute this image full-sized)
Note: For an HSL split/recombination, the color part (Hue & Saturation) is not as critical as the resolution part (Luminance), for human perception. This has been known and used in both analog and digital processes for compression. So the smaller, fuzzier SD color image is just fine to use with the cleaner, more detailed HD resolution image.
.
PAINT PROGRAM
It's easy enough to view these images in a paint program.
.
AVISYNTH
How to do this in Avisynth? If you don't have it installed already, get Avisynth here ..
http://avisynth.nl/index.php/Main_Page
I'm running one a couple versions older but the core functions remain mostly the same. See it's documentation file for further info -- you'll be referring to it, allot, when writing a script or reading this one. :)
Avisynth is controlled by user scripts that tells it what to do. Throughout is demonstration will be sample script from sections of the full script that displays these assorted images as video in a media player.
NOTE: The full script is at the bottom of this post. When we arrive there, select and copy that entire text and paste it in a text file in your work folder. Name the file something like
HueSatLum transfer.avs
and see that the .avs extension is associated to Avisynth text scripts in your computer's Operating System. You can use any names you want -- I just used and tested the script with these.
##----------
## setup images path & name
##----------
clipSD = "YTMO34thScolorizedSD360.jpg" # insert your image names
clipHD = "YT_MO34th_S_B_W_HD720.jpg"
##----------
## get the images
##----------
vSD = ImageReader( clipSD ) # creates a still video
vHD = ImageReader( clipHD ) # creates a still video
The comment character "#" means "do not process anything hereafter on this line -- it is a comment". These can be used to add descriptions (as I do) of what's going on. They can also be used to make changes to the code without deleting other code for alternate actions. Here, I've "commented out" the video inputs lines because we're using still images (when loaded in, they become mini-videos for processing).
In this script, note that most line-statements starting names (of your choosing) are variables that take the form something = something else. However, when one of these variable names is on a line-statement by itself (usually the last line of a script), Avisynth takes that as the video to show.
##===============
## Display procedures ("uncomment" to use)
## uncomment only one statement at a time
##===============
##----------
## original sources
##----------
vSD
#vHD
When you right-click on this .avs text file and select Open With, choose your media player or Choose Program to find one. Your media player will then play Avisynth's processing of this script for several seconds (or forever, if you loop the videos in your player). Notice that this would show the SD image as a video -- it is not commented out as it the HD image. If the SD image is then commented out and the HD image is uncommented, the HD image would show ... in a 2nd player simultaneously. Avisynth keeps that previous version of the script in memory to run in the 1st player.
Avisynth is mostly non-interactive. After each change in script, be sure to "save" your .avs text file before viewing each new result in a new instance of your media player.
.
PAINT PROGRAM
To make this HSL split/recombine work well, the SD image must be resized and repositioned to exactly (or near enough) overlap the HD image. It's a hit-or-miss process with lots of adjusting.
In a paint program, a good guesstitmate can be had by zooming the SD-image window to come close to the full sized HD image. That will give the initial value for actually resizing the SD image.
For this one (and hopefully for the rest of the movie), we can start the resizing at 200%. So, copy the SD image into a layer of the HD image.
Initially, it is best to set the opacity of the SD image at 50% so we can see how it lines up with the underlying HD image. Later we can set back to 100% and, instead, click the visibility off-and-on for fine tuning.
Starting at the SD's 100% size ..
.. resize to a uniform 200%.
To quote a certain nerf-herder, "Here's where the fun begins."
It's best to find some point in a corner to make the first resizing adjustments vertical (or horizontal) to some opposite point. With that accomplished, then make horizontal (or vertical) adjustments to another opposite point. I usually make an adjustment, guesstimate a correction, step-back to 100%, then move forward with the new, total resize ... until it's right. Here's the short story:
width x height
100% x 100% -- start
200% x 200% -- window-zoom estimate (step-back to try ...)
200% x 218% -- vertical adjustment (looks good; step-back to try ...)
192% x 218% -- horizontal adjustment (needs both; step-back to try ...)
194% x 220% -- vert. & hori. re-adjustment (needs vert.; step-back to try ...)
194% x 221% -- vertical re-adjustment (bingo!)
.
AVISYNTH
The resizing and repositioning procedure in Avisynth is similar to that in the paint program. The masterful function that does all the hard work is Overlay() and it has extra options to do the final recombination in a single step. (I like this function!)
Instead of resizing by percentage, Avisynth goes by pixel count (although it could be done this way in the paint program, too). In this section of code, previous resizing code-lines are kept in the script, commented out for non-active reference. The last line is the active code for the final resize. Like with the paint program, the SD image is resized double to begin ("*2" means "times 2") and adjustment continues from there ..
##----------
## resize SD-image to fit HD-image
##
## these were the steps taken:
## vSD_siz = Lanczos4Resize( vSD, 480, 360 ) #original size
## vSD_siz = Lanczos4Resize( vSD, 480*2, 360*2 ) #guesstimate
## vSD_siz = Lanczos4Resize( vSD, (480*2)-24, (360*2)+78 ) #final resize
##----------
vSD_siz = Lanczos4Resize( vSD, (480*2)-24, (360*2)+78 )
At the same time, just like in the paint program, each newly resized SD image is repositioned to align to your selected anchor points. Opacity is reduced slightly to better see the alignment (like with the paint program) ..
##----------
## simultaneously to resizing, reposition SD-image to HD-image
##
## these were the steps taken:
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=0, y=0, mode="blend" ) #original size
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=180, y=-25, mode="blend" ) #guesstimate
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=194, y=-34, mode="blend" ) #final position
##----------
vHD_blnk = Levels( vHD, 0, 1.0, 255, 0, 0, coring=false ) #blank HD-mage for base
vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=194, y=-34, mode="blend" ) ## SD into base
The resize-reposition is then incorporated into an automatic on-and-off of the SD image in the video output to better see the alignment (set your media player to infinitely loop the video) ..
##----------
## for an assist,
## this joins the short video of orig. HD-image
## to the short video of SD-HD-overlay with transparency
## for alternating images
##----------
vSDHD_alternating = Overlay( vHD, vSD_siz_pos, mode="blend", opacity = 0.7 ) + vHD
With the SD and HD images aligned, there is one more step before the HSL split/recombination. In the paint program process, all the SD edging causes artifacts. It must be wiped away. It is handled differently in Avisynth and the result is no artifacts (but it wouldn't hurt to do a similar clean-up).
.
PAINT PROGRAM
In the paint program, on the SD layer, use the rectangular Selection Tool to select the acceptable image area right up to it's edges (this will entail losing the useless fading-out picture areas). Then choose Invert to reverse the selection. That will allow the painting of all the unacceptable image area with black (do that with your Paint Brush). Be sure you do not have anti-alias ticked for any of these operations ..
Deselect the image and it is complete, at full HD size. Copy-and-paste each of the two layers as individual images (in the paint program) for HSL processing.
For the SD image, perform a Split Channel > Split to HSL. Of the three resulting B&W splits, only Hue and Saturation will be used. Delete the Lightness split ..
Do the same thing for the HD image. Of the three resulting B&W splits, Hue and Saturation will be the ones deleted. Only the Lightness split will be used ..
The three remaining splits may now be recombined with Combine Channel > Combine from HSL ..
Done! Let's get a (full-sized) closer look, shall we? :)
.
AVISYNTH
As in the paint program, the garbage area of the now re-sized and re-positioned SD image will be wiped to black. Using Letterbox(), the coloring will be temporarily set to green while adjusting the new image-edge. Keep in mind that edges of the original image may have fading out or haloing -- those should go black, too.
##----------
## replace the "garabge" SD-image areas with black borders
## NOTE: Avisynth seems to do something similar internally in
## "recombination", but I don't know how that works.
## In the meantime, just doing this for completeness
## these were the steps taken:
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 0, 0, 0, 0, $00FF00 ) #start
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 2, 2, 200, 150, $00FF00 ) #guesstimate
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 2, 200, 150, $00FF00 ) #TOP fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 200, 150, $00FF00 ) #BOTTOM fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 150, $00FF00 ) #LEFT fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 168, $00FF00 ) #RIGHT fine tune
##----------
vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 168 ) #final black borders
Don't worry about the green showing in the above picture. I just wanted to show off the now-clean edges. Without specifying a color, as in the script, the default for this function is black.
Remember all that splitting and deleting and recombining in the paint program? Well, this one Avisynth statement does it all ..
##----------
## combine SD "color" media to HD "luminance" media
##----------
vSDHD = Overlay( vHD, vSD_siz_pos_lb, mode="chroma" )
The trick in not in the wrist ... it's in the mode. And it produces the finished colorized and high-definition video.
Here is listed the completed Avisynth script for this demonstration. I've noted all those lines that can be changed to make it work. The rest can be left alone. Also, I've tested all the various combination of uncommenting (to allow the script to do it's assorted tests). Feel free to play with it to understand it's functioning.
## HueSatLum transfer - source color to destination luminance
##====================
##===============
## Prepare media
## everything in the same folder helps during troubleshooting
##===============
##----------
## setup images path & name ("uncomment" to use) ...
##----------
###### v v v COMMENT/UN-COMMENT THESE STATEMENTS v v v
###### v v v UPDATE THESE VALUES v v v
clipSD = "YTMO34thScolorizedSD360.jpg" # insert your image names
clipHD = "YT_MO34th_S_B_W_HD720.jpg"
##----------
## ... or setup videos path & name ("uncomment" to use)
##----------
###### v v v COMMENT/UN-COMMENT THESE STATEMENTS v v v
###### v v v UPDATE THESE VALUES v v v
#clipSD = "YT_MO34thS_colriz_SD.mpg" # or insert your video names
#clipHD = "YT_MO34thS_BW_HD.mpg"
##===============
## Get media
##===============
##----------
## get the images ("uncomment" to use) ...
##----------
###### v v v COMMENT/UN-COMMENT THESE STATEMENTS v v v
vSD = ImageReader( clipSD ) # creates a still video
vHD = ImageReader( clipHD ) # creates a still video
vSD = vSD.Trim( 0, -10 ) ## use only 10 frames for processing
vHD = vHD.Trim( 0, -10 )
##----------
## ... or get the video ("uncomment" to use)
##----------
###### v v v COMMENT/UN-COMMENT THESE STATEMENTS v v v
#vSD = DirectShowSource( clipSD ) # for video
#vHD = DirectShowSource( clipHD ) # for video
##===============
## Process media
## optional - make the SD & HD look better
##===============
##===============
## Align media
##===============
##----------
## resize SD-image to fit HD-image
##
## these were the steps taken:
## vSD_siz = Lanczos4Resize( vSD, 480, 360 ) #original size
## vSD_siz = Lanczos4Resize( vSD, 480*2, 360*2 ) #guesstimate
## vSD_siz = Lanczos4Resize( vSD, (480*2)-24, (360*2)+78 ) #final resize
##----------
###### v v v UPDATE THESE VALUES v v v
vSD_siz = Lanczos4Resize( vSD, (480*2)-24, (360*2)+78 )
##----------
## simultaneously to resizing, reposition SD-image to HD-image
##
## these were the steps taken:
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=0, y=0, mode="blend" ) #original size
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=180, y=-25, mode="blend" ) #guesstimate
## vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=194, y=-34, mode="blend" ) #final position
##----------
vHD_blnk = Levels( vHD, 0, 1.0, 255, 0, 0, coring=false ) #blank HD-mage for base
###### v v v UPDATE THESE VALUES v v v
vSD_siz_pos = Overlay( vHD_blnk, vSD_siz, x=194, y=-34, mode="blend" ) ## SD into base
##----------
## for an assist,
## this joins the short video of orig. HD-image
## to the short video of SD-HD-overlay with transparency
## for alternating images
##----------
vSDHD_alternating = Overlay( vHD, vSD_siz_pos, mode="blend", opacity = 0.7 ) + vHD
##----------
## replace the "garabge" SD-image areas with black borders
## NOTE: Avisynth seems to do something similar internally in
## "recombination", but I don't know how that works.
## In the meantime, just doing this for completeness
## these were the steps taken:
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 0, 0, 0, 0, $00FF00 ) #start
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 2, 2, 200, 150, $00FF00 ) #guesstimate
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 2, 200, 150, $00FF00 ) #TOP fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 200, 150, $00FF00 ) #BOTTOM fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 150, $00FF00 ) #LEFT fine tune
## vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 168, $00FF00 ) #RIGHT fine tune
##----------
###### v v v UPDATE THESE VALUES v v v
vSD_siz_pos_lb = Letterbox( vSD_siz_pos, 13, 4, 216, 168 ) #final black borders
##----------
## combine SD "color" media to HD "luminance" media
##----------
vSDHD = Overlay( vHD, vSD_siz_pos_lb, mode="chroma" )
##===============
## Display procedures ("uncomment" to use)
## uncomment only one statement at a time
##===============
###### v v v COMMENT/UN-COMMENT THESE STATEMENTS v v v
##----------
## original sources
##----------
#vSD
#vHD
##----------
## fine-tuning assists
##----------
#vSDHD_alternating
#vSD_siz_pos_lb
##----------
## finished SD-color into HD-luminance recombination
##----------
vSDHD
##====================
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~