<a name=“filters”>TUTORIAL (and ZScript)
With this tutorial i’ll try to explain my experiment on Custom Filter tool. Sorry for any errors or wrong interpretation.
So what is a convolution filter ? Essentially, it’s a matrix, as follows:
0 0 0
0 1 0
0 0 0
The center cell in the matrix corresponds to the pixel that the filter will affect. The surrounding cells correspond to the pixels surrounding the target pixel.
The idea is that the pixel we are processing, and the eight that surround it, are each given a weight.
Convolution Matrix allow us to create simple custom filters. Convolution Matrix adds together the color values in the 3x3 (or 5x5) pixel box around each pixel, multiplying each pixel in the box by the corresponding value from the matrix.
The total value of the matrix is divided by a “FACTOR”, and optionally an “OFFSET” is added to the end value (I am unable to find these two values in ZBRUSH
:(, but,
with the AutoScale ON, the overall filter result will be factored to equal the specified Intensity value).
The matrix above is called an identity matrix, because the image is not changed by passing through it. Usually the “FACTOR” is the value derived from adding all the values in the matrix together, which ensures the end value will be in the range 0-255.
You can find more technical discussion of custom filter (User Defined Filter) in the PaintShopPro documentation, but here i want explain some rules of thumb instead of an equation.
To use a Custom Filter in ZBrush do the following:
- Select CustomFilter III Tool
- Open the Tool.Inventory palette
- Select a matrix and put the values on the slots (F00…F22))
- Paint over canvas
To apply the filter paint over image use Dots, Freehand or DragRect as Stroke type.
Try to modify the Intensity value, tha Autoscale and the Additive checkbox.
The filter depends from RGB Intensity value and DrawSize value too.
What we’ll normally want to do is make sure that the sum of the values in all the cells in the matrix equals 1. This will ensure that the overall brightness of the filtered image is the same as the brightness of the original image. If the sum is less than 1, the filtered image will be darker than the original. If the sum is greater than 1, the filtered image will be brighter. Sometimes we want to make a filter to brighten or darken images. But keep in mind that if we stray too far from 1, we’ll get a filter that turns an image either entirely black or entirely white!
Unless otherwise compensated for, keep the matrix sum at 1 to retain the brightness of the original image.
To brighten an image, make the matrix sum greater than 1.
To darken an image, make the matrix sum less than 1.
Note: In other package we can compensate the filter effect with the FACTOR and OFFSET values.
Example: Sample Blur
These are a Sample Blur filter values
1 1 1
1 1 1
1 1 1
Notice that here the sum of the matrix is 9: there are nine cells with values of 1, and adding together those nine 1’s gives us a sum of 9. This sum is greater than 1 by a factor of 9, and we can compensate for that by making use of the FACTOR. By specifying a FACTOR of 9, we divide the sum of 9 by 9, which gives us a result of 1. And 1 is just what we need if we want the brightness of the original image to be maintained in the filtered image.
To compensate for a sum that deviates from 1, we must use a FACTOR equal to that sum to maintain the image brightness of the original image.
This will work whether the sum (and corresponding FACTOR) is a positive value or a negative value. We can also use the FACTOR to help adjust the brightness of filtered image, by using a value that only partially compensates for the sum’s deviation from 1.
To compensate for a sum that deviates from 1, use a FACTOR equal to that sum to maintain the image brightness of the original image.
WHERE IS “FACTOR” AND “OFFSET” IN ZBRUSH ?!?!?! I don’t know.
The Sample Blur filter also shows us how in general to get a blurring filter:
For a Blur filter, use a positive center value and surround it with a symmetrical pattern of other positive values.
Lessen the effect of a filter by increasing the value in the center cell.
Example: Sharpen
With the blur filters, we add to the matrix positive peripheral cell values around a positive central value. For a sharpening filter, we also use a positive central value, but this time surround the central cell with negative values.
For a Sharpen filter, use a positive center value and surround it with a symmetrical pattern of negative values.
-1 -1 -1
-1 9 -1
-1 -1 -1
Remember that in general we maintain the overall brightness of original image by using values in the matrix that sum to 1.
Example: Edge
For edge filters, the central value is what’s negative, with positive surrounding values.
For an edge filter, use a negative center value and surround it with a symmetrical pattern of positive values.
1 1 1
1 -7 1
1 1 1
We can lessen the effect of a filter by increasing the value in the center cell.
Example: Embossing
For an Embossing filter, use a positive center value and surround it in a symmetrical pattern of negative values on one side and positive values on the other.
1 1 -1
1 1 -1
1 -1 -1
Again, we can lessen the effect of a filter by increasing the value in the center cell (but we must compensate to mantain brightness).
1 1 -1
1 3 -1
1 -1 -1
We can adjust the direction of the embossing by repositioning the positive and negative cells that surround the center cell. For example the following values emboos to top:
1 1 1
0 1 0
-1 -1 -1
Here is a small collection of Matrices to experiment with filter. They are mainly just to get you started. The way that the convolve works, is that it applies the matrix that you supply to every pixel in the image. The middle square represents the weight of the current pixel. The squares around it represent the weight of the surrounding pixels.
LINE DETECTION
Detection of one pixel wide lines can accomplished with the following filters;
Horizontal Edge
-1 -1 -1
2 2 2
-1 -1 -1
Vertical Edge
-1 2 -1
-1 2 -1
-1 2 -1
Left Diagonal Edge
2 -1 -1
-1 2 -1
-1 -1 2
Right Diagonal Edge
-1 -1 2
-1 2 -1
2 -1 -1
POINT DETECTION
The Point detecters detect discontinuities in the image… (non smooth areas)
-1 2 -1
-1 2 -1
-1 2 -1
GRADIENT DETECTION
Changes in value over 3 pixels can be detected using kernels called Gradient Masks or Prewitt Masks. these filters enhance the edges in various directions. The direction of the change from darker to lighter is described by the following matrixone of the points of the compass. The 3x3 kernels are as follows:
Embossing North
-1 -2 -1
0 0 0
1 2 1
Embossing West
-1 0 1
-2 0 2
-1 0 1
Embossing East
1 0 -1
2 0 -2
1 0 -1
Embossing South
1 2 1
0 0 0
-1 -2 -1
Embossing NorhtEast
0 -1 -2
1 0 -1
2 1 0
Embossing NorhtWest
-2 -1 0
-1 0 1
0 1 2
Embossing SudEst
2 1 0
1 0 -1
0 -1 -2
Embossing SudWest
0 1 2
-1 0 1
-2 -1 0
SMOOTHING AND BLURRING
Smoothing and blurring operations are low-pass spatial filters. They reduce or eliminate high-frequency aspects of an image.
Arithmetic Mean
The arithmetic mean simply takes an average of the pixels in the kernel. Each element in the filter is equal to 1 divided by the total number of elements in the filter. Thus the 3x3 arithmetic mean filter is:
1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9
Basic Smooth 3x3 (Blur) (not normalized)
1 2 1
2 4 2
1 2 1
Basic Smooth 5x5 (not normalized)
1 1 1 1 1
1 4 4 4 1
1 4 12 4 1
1 4 4 4 1
1 1 1 1 1
HIGH-PASS FILTERS
A high-pass filter enhances the high-frequency parts of an image. This type of filter is used to sharpen images.
Basic High-Pass Filter (Sharpen) 3x3
-1 -1 -1
-1 9 -1
-1 -1 -1
Basic High-Pass Filter: 5x5
0 -1 -1 -1 0
-1 2 -4 2 -1
-1 -4 13 -4 -1
-1 2 -4 2 -1
0 -1 -1 -1 0
LAPLACIAN FILTER
The Laplacian is used to enhance discontinuities (changes in the image).
The 3x3 kernel is:
0 -1 0
-1 4 -1
0 -1 0
The 5x5 kernel is:
1 1 1 1 1
1 1 1 1 1
1 1 24 1 1
1 1 1 1 1
1 1 1 1 1
SOBEL FILTER
The Sobel filter consists of two kernels which detect horizontal and vertical changes in an image. If both are applied to an image, the results can by used to compute the magnitude and direction of the edges in the image.
Horizontal Sobel
-1 -2 -1
0 0 0
1 2 1
Vertical Sobel
-1 0 -1
-2 0 2
-1 0 1
=============================================
Here is some more filters:
Edge Detection - Heavy
1 -2 1
-2 4 -2
1 -2 1
Edge Detection - Medium
-1 -1 -1
-1 8 -1
-1 -1 -1
Edge Detection - Light
0 1 0
1 4 1
0 1 0
Emboss Filter
-1 0 0
0 0 0
0 0 1
Enhance Detail
0 -1 0
-1 10 -1
0 -1 0
Enhance Edges
-1 -1 -1
-1 9 -1
-1 -1 -1
Enhance focus
-1 0 -1
0 7 0
-1 0 -1
Reduce jaggies
0 0 -1 0 0
0 0 3 0 0
-1 3 7 3 -1
0 0 3 0 0
0 0 -1 0 0
Soften Filter - Heavy
11 11 11
11 11 11
11 11 11
Soften Filter - Medium
10 10 10
10 20 10
10 10 10
Soften Filter - Light
6 12 6
12 25 12
6 12 6
Blur - Light
1 2 1
2 2 2
1 2 1
In the ZScript i have collected some more filters (see image): try it and experiment with your values.
ZScript: CustomFilter.TXT
Demo Image:

Happy ZBrushing
cameyo
p.s. Thank You Mentat7 to start the first topic on custom filter.