CImage:FiltKernel
The FiltKernel method applies a user-defined kernel to an image. The filter is defined as a CMatrix.
bResult = CImage:FiltKernel( CMatrix class, cols, rows, CRect=nil ) |
CMatrix is the filter kernel in a CMatrix.
cols is the column length of the filter kernel.
rows is the row length of the filter kernel.
CRect is the rectangle defining the area to process. If omitted or passed as nil, the entire image is processed.
On success, this method returns true.
On failure, this method returns false.
This method applies a filter kernel defined as a CMatrix. No normalization is automatically applied, so the calling script is responsible for any normalization. If normalization is needed, use the CMatrix:Normalize method before calling FiltKernel.
Note that the filter CMatrix is defined as row major, that is, row index first and column index second. However, the arguments to FiltKernel are passed with the column dimension first (see Syntax).
The following table defines a 3x3 gradient filter at 45 degree angle:
3x3 Gradient Filter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This filter can be created as a CMatrix using the following script:
|
-- create a new CMatrix |
|
-- initialize 3x3 to all -1.0 |
|
|
|
|
|
|
|
-- central pixel |
Suppose an image is displayed in a CImageView named V. The following script creates a filter Kernel K as a 5x5 CMatrix of 0's. Next, the central pixel at index [3][3] is set to 100.0. The filter is then normalized to unit volume. With only the central pixel non-zero, this is a 5x5 identity filter which does a lot of math but simply returns the same image unchanged. The filter is applied to the region [100:300, 400:800]:
|
-- create a new CMatrix |
|
-- define a 5x5 matrix of 0's |
|
-- set the central matrix value |
|
-- normalize to a volume of 1.0 |
|
-- attach the current displayed image |
|
-- setup the rectangle to process |
|
-- apply the filter |
|
-- update the display after the scale |
|
-- if done with the CRect |
|
-- if done with the filter |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.