CombineZM Tutorials

5 Do Stack - Step by Step

I am going to explain how to perform all of the steps in the Do Stack macro one at a time by using menu commands.   This will bring several benifits, you will know what each step does so you will be in a better position to customize the macro.   You will become a little more familiar with the menu layout.   I will mention several new concepts like filtering and the Depth Map.   You will get an insight into how the process works so you can feed it with better data.

Be prepaired this is rather a lengthy page.

Select All - Remember the dotted rectangle from an earlier tutorial that was used to define an area to save, the same rectangle is used to tell other functions what area to work on.   We need to make sure the whole width and hight of the frames is used hence this command.   Pressing Escape will do the same thing.

Normal Filter Output - Here again a precaution to make sure the filter routines will produce predictable results.   The equivalent menu command is Normal on the Output submenu of the Filter menu.   From now on I will use an abbreviated form to refer to menu items etc. in this case Filter->Output->Normal.

Balance Colour and Brightness Global - Menu equivalent Stack->Balance Colour and Brightness->Global.

 

 

 

The first two pictures above are taken from a focus stack you can see the difference in brightness between them.   Imagine taking a piece from one and putting it into the other, the colour would not match and it would look out of place.   This is exactly what we are going to do so we must find a solution.   Suppose we make the darkest frame Active by displaying it on the screen then we click the menu item mentioned above we will get the second pair of pictures which more nearly match in colour but are dark.   Similarly selecting the lighter picture before Balancing will result in two lighter pictures as shown by the last pair.   This illustrates the importance of choosing the right Frame before using this function.   Some stacks may be better processed without this function, expecially if bright (or dark) areas disappear over the side of some frames due to size change when focusing, the function works on the average colour and brightness of the whole scene.

Align All Frames Automatically (Two pass) - Menu equivalent Stack->Size and Alignment->Automatic (Two Pass).   As with the last function the Automatic Size and Alignment functions are sensative to the choice of frame before they are started.   The Two pass function may be overkill in some cases, the Single pass function might be good enough and will be faster.   Both of these functions will not Rotate frames they will only move them from side to side and up and down and resize them to make them register properly.   There are manual methods to align which include rotation but they will be described elsewhere.   Automatic (Shift+Rotate) is rather slow in exicuting but can be sandwiched between two runs of the Single pass function to compensate for rotation, this is not 100% reliable though.   If you wish to do trial runs on a stack with various parameter settings it is worth removing alignment from this macro, run it from the menu or from a preprocessing macro once before doing all of your trials they will run faster then.

Find Detail(25) - Menu Equivalent Stack->Detail->Find Detail, enter 25 in the dialog.

 

 

The four pictures illustrate this function with four different parameters 10, 25, 50 and 100.   This function looks at each frame in turn to try and locate detail if it finds any it works out a score, e.g. a strong edge would score more than a slight colour variation.   At each pixel location a maximum score so far is stored and in the Depth Map the number of the Frame which gained that score.   So by the time the function finishes the depthmap has frame numbers wherever detail was found, what is more these numbers correspond to the highest scoring detail at each pixel position.   The scores are now discarded.   The frame numbers from the Depth Map are used to look up the actual pixel values which are put into the Picture.   When using this method to decide what should go into the stacked image note that there are holes that need filling where there was no detail in any frame and there may be errors where the program thinks there is detail this may be caused by noise in the frames or out of focus objects which spread into otherwise empty regions.

 

Above are shown pictorial representations of the Depth Maps produced with Find Detail(10) and Find Detail(50) you can see a Depth Map of this type by pressing the letter 'D'.   Bluer pixels represent pixels in the picture that come from frames near the bottom of the stack and greener ones those that come from nearer to the top of the stack.   The lower value 10 fills more holes in but produces more errors indicated by the freckled appearance towards the upper right.   The higher value leaves larger holes but fewer errors.   So the optimum value would find enough detail so that holes could be easily filled but not result in too many errors.

Remove Islands - Most of the noise in a picture results from random variations in the colour of individual pixels, these variations can be picked up by Find Detail and result in small isolated islands in the depthmap.   Remove islands eliminates these, in this case all islands below 5 pixels in size will be removed.   Below at the left is shown Find Detail(25) shown above followed by Remove Islands(5).

 

Fill Gaps - As its name implies examines the Depth Map and fills holes that were left by Find Detail/Remove Islands thus completeing the Map, above right, and enabling every pixel in the picture to be looked up and filled in.   The method used to fill the gaps looks at existing nearby known values and tries to fill the gap without any sudden steps in value, thus resulting in a smoothe looking depthmap.

We are now going to smoothe the Depth Map even more this will reduce certain artifacts at edges and further reduce the effects of noise.   This process involves creating a Filter.   CombineZM uses DFT (Discrete Fourier Transform) filters, they are not as quick as some methods but give good results with continuously variable settings.   In the diagrams below that show filters the upper left corner represents low frequencies these correspond to large scale properties of pictures and the lower right corner corresponds to small scale properties of a picture, high frequencies.   If part of a filter is light coloured it will emphasize corresponding parts of pictures to which the filter is applied.   Thus in the picture below the large scale features are exaggerated at the expense of the detail this results in blurring or softening or smoothing.   Note if the upper left corner ever closely approaches or reaches zero the whole of a filtered picture will vanish, hence the ZV= value mentioned below is useful to avoid this behaviour.

Notice my mistake above in the macro listing, a redundant Normal Filter Output

Create a Lowpass Filter(250,0) - Menu equivalent Filter->Create/Edit Filter->Lowpass.

Above is a pictorial representation of a Lowpass Filter(250,0).   Setting the parameters 250 and 0 in this case is a little unusual first notice the information on the title line

Starting at the left there is the filter name followed by the current settings in brackets (1000,0).   next the number 1 indicates that parameter 1 the left one= 1000 in this case can be changed.   Next in words is what this parameter is called 'Decay Width' in this case.  The last unfamiliar information ZV= 1.000 is the value of the zero frequency, the upper left pixel in the diagram above.   You can change the parameter to be altered to another one by pressing the Up and Down Arrow keys.   You can alter the actual value in small steps by pressing the Left and Right Arrow keys or in large steps by pressing 'M' and 'N'.   Finally you can set an exact numerical value by pressing 'V' and entering it in the dialog that appears.   Press 'Return' once to see the effect of the filter (you can still alter parameters at this stage), then Return again to accept these settings.

The above sounds complicated but is really quite easy here are the steps required to create our filter

1. Filter->Create/Edit Filter->Lowpass

2. Check '1' is showing on the title line, if not use Up or Down until it is

3. 'V' followed by 250 then OK

4. Press Return Twice.

A Low Pass Filter will blurr or smoothe something.

Filter and Replace Depthmap - It is necessary to issue two menu commands to do the same job, first  Filter->Input->Depth Map

Notice the different colour this is not a depthmap but a picture of one in Out.   Now Filter->Immediate->Last Output to Depth and the new Depthmap will take effect and the modified Picture will be drawn.

The special location Out is used extensively to hold the results and visualizations shown on the screen above, if you wish to keep something that is stored in this location save it or create a new frame from it using Frame->New from Visible, new frames created in this way are marked with an asterisk '*' which means they will not be used by most functions (most of the exceptions to this rule occur when they are sandwiched between two used frames).

 

Interpolated Output - Menu equivalent Stack->Interpolated Output.   Above I mentioned that the special location Picture contains pixels which come directly from the frames.   Sometimes when patches of pixels from two different frames are next to each other they do not look continuous i.e. you can see the joins, e.g. see the fragment of a picture on the left above.   This is one of the artifacts that smoothing the Depth Map is aimed at reducing.   The numbers stored in the Depth Map are actually not intagers, they can have fractional values.   Suppose at a given location a Depth Map value was 3.5 which frame should the output pixel be taken from?   In the Picture it will be either 3 or 4, but by using Interpolated Output the pixels from Frame 3 and Frame 4 will be bleended together as in the fragment on the right above which is the same part of the picture as that on the left.   The output from this function will go to Out.

Make a New Frame from Out - Equivalent make Out visible by pressing 'O' then Frame->New from Visible.   Remember Out is volatile so we must save it to somewhere more permanant.

Go to Top Frame - Whenever a new frame is created it is placed at the top of the stack, if you create it manually it will automatically be Active, but in a macro you must explicitly make it so.

When processing manually it is better to reverse the order of the next two steps.

Create a Highpass Filter(1000,750) - This is almost identical to creating the Lowpass filter above so I will just list the steps involved:

1. Filter->Create/Edit Filter->Highpass

2. Check '2' is showing on the title line, if not use Up or Down until it is

3. 'V' followed by 750 then OK

4. Press Return Twice.

A High Pass Filter will Sharpen a picture.   Interpolated Output above tends to soften edges this filter is intended to counteract this but goes too far for some peoples tastes.

Filter Active Frame - Equivalent to Filter->Input->Depth the filter created above is used immediately.   When processing manually it is better to do this step before the previous one.

Replace Frame with Out - Equivalent to making Out visible, by pressing 'O', then Frame->Replace with Visible.   This replaces the top frame of the stack with the contents of Out which in turn is the result of the last filtering step.

Adjust Contrast - Equivalent to Rectangle->Contrast then entiring 5 before pressing OK.   This is optional but I include it to compensate for any greying due to blending frames in the Interpolated Output step.

Replace Frame with Out - Equivalent to making Out visible, by pressing 'O', then Frame->Replace with Visible.   This replaces the top frame of the stack with the contents of Out which in turn is the result of the Contrast enhancement step.