ZBrushCentral

Custom Filter (ZScript and Tutorial added)

Hi ZBrushers,
i’m back…

MATRIX FILTER (Image Processing)

I briefly describe several useful convolution filters.
Unless otherwise noted, the kernels presented are normalized (that is, the kernel weights sum to 0).
This highlight is intended only as a very basic reference. Numerous texts on image processing provide more details and other filters.
You can use these matrix values with the “Custom Filter III” or “Custom Filter V” tool of ZBrush.
To apply the filter paint over image (use Dots, Freehand or DragRect as Stroke type)

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

GRADIENT DETECTION
Changes in value over 3 pixels can be detected using kernels called Gradient Masks or Prewitt Masks. The direction of the change from darker to lighter is described by one 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

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 (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: 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.
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

I hope to post some more infos and images in the next days.

Please post your result…

Happy ZBrushing

cameyo

Welcome back Cameyo !!! :smiley: :+1:
Interesting post!!! Tnx for sharing !! :smiley: :+1:

Hi Cameyo
Very studious return :slight_smile:
But where is this damned Custoom tools filter section of convolution ? I explore all menus but this convolution is hidden !
Where is there !!!??? In The 1.23 B ?
And did you Know this one from F Tomita and S Tsuji 1977 :smiley:
3 3 4 5 6
3 4 3 6 7
3 3 4 8 3
9 2 3 2 1
8 5 3 2 6
Pilou
:cool:

Hi Frenchy,
Tool Palette: CustomFilterIII and CustomFilterV…open MODIFIER and put values…paint over image…that’s all.
Try with Intensity = 1, AutoScale = ON, Additive = OFF.
Well… Some example:
Original Image:

Vertical Edge Detection with these values:
-5 0 0
0 0 0
0 0 5
Output Image:

And now the output image with Tomita and Tsuji values:

I think this is a blur filter.

Hope this helps.

cameyo

No I don’t found it !
May be because i have just the demo version 1.23b :slight_smile:
Pilou

Pilou, the FilterBrushes are some new tools that came with 1.5 :slight_smile:

cameyo: these are priceless tips! thank you for the thorough exploaration!!! :+1: :+1: :+1: :+1:

  • juandel

Nifty! I was wondering just what the heck that feature was for. Thanks for the education!

Great stuff! I haven’t been able to do anything with the filters except make a mess. Would be a cool function to create a script! hint hint!

A great contribution, Mr. C! Like Digits, I have a hard time wrapping my head around this particular tool, and would also really enjoy a script to lessen the brain murkiness… :smiley:

:sunglasses: :+1: :+1: :+1:

I remember a little problem about the matrix convolution : how found the inverted filter for refound the original image?
For exemple with the Cameyo Original-> out put -->original image !
I think it’s a brain teaser :slight_smile:
Just for the math lover :slight_smile:
Pilou

This one is going in my bookmarks, for sure, even though it’s going way over my head. I think I shall just try each of them separately to see what they do. Thanks so much for taking the mystery out of these!

so now I know why there is no Custom Filter I, II or IV … thanks for the detailed posting :slight_smile:

hi cameyo welcome back.
i never tryed the Filters yet.
if you made a zscript that would be Nice :+1:
i think this is how davey made the fire ant fire and smoke but im not sure

Hey EZ, I believe the smoke in the Fire Ant image was done with the ColorSpray brush, and the fire was done with the Highlighter 2 brush, which differs from the original highlighter brush in that it only highlights up to the RGB value you set… :wink:

Thanks Cameyo. Just to add that, since many members seem to have Paint Shop Pro, there is a good description of how these filters work in the PSP manual (certainly since version 5 onwards).

There is information about these custom filter brushes at this thread as well http://www.pixolator.com/zbc-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=007617

So that’s what highlighter 2 does! I did not know that. I tried it out, but it made everything so extremely white, apparently because I had my color set to white, which is as intense as you can get. Gotta try it over again now. Thanks, Miguel!

Thank you :warning: I also would welcome a zscript :warning: Excellent work :+1: :+1: :+1: :+1:

<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 :frowning: :(, 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:

  1. Select CustomFilter III Tool
  2. Open the Tool.Inventory palette
  3. Select a matrix and put the values on the slots (F00…F22))
  4. 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.

And for the math lover artist you have crazzy result when the filter is applied without temporary matrix.
The matrix function go pixol to the other pixol (pixel out Zbrush :slight_smile: in a sort of fractal procedure before the entiere filter will be finished on the nine slot !
It’s the same filters but with a sort of inverse retro-pedalling :slight_smile:
It’s not clear ? Yes :slight_smile: but it’s computer arts :slight_smile:
And in anotherway matrix apply is the Game of Life invent by John H Conway
You find the best free programm and start links for the fantastic Game of life here http://www.winlife32.com/ only for PC users
sorry for Apple people :frowning:
But here everybody can play as a “god creator” with a very speedy Applet !!! http://www.math.com/students/wonders/life/life.html
The Author of this crazzy programm is Alan Hensel and if you are interest how a modest genius make masterpiece of tricky speedy result go there http://hensel.lifepatterns.net/lifeapplet.html
But CAREFUL it’s more ADDICT than ZBRUSH !!!
If life interest you, all is on the Web !
Crazzy community too :slight_smile:
Have good matrix aventures
Pilou