Image Decompress Image Find Corners navigation bar

Table of Contents

Image Filter

Filters an image or portion of an image.

Library

QUARC Targets/Image Processing/Generic

Description

Image Filter

The Image Filter block filters an image or a portion of an image. To filter only a portion of the image, a rectangular region of interest is defined. The image may be filtered within the region of interest or outside the region of interest. The location of the region of interest may be specified via block dialog box parameters or by an external input, allowing the region of interest to be changed dynamically.

The Image Filter block supports both MATLAB RGB (HxWx3) and MATLAB grayscale (HxW) inputs.

Input Ports

image

The input may be an RGB image specified as a three-dimensional MxNx3 matrix where M is the image height and N is the image width. It contains the red, green and blue components for each pixel in the image.

It may also be a grayscale image specified as a two-dimensional MxN matrix. where M is the image height and N is the image width. It contains the luminance for each pixel in the image.

The interpretation of the data depends on the data type. Floating-point types should have elements in the range 0 to 1. Single floating-point types are supported. For integer types, only unsigned integer types are supported. The range of unsigned integer types should be the full range for the integer type.

The input is compatible with The MathWorks' Computer Vision System Toolbox.

Output Ports

image

The output data type and dimensions will match the image input signal.

Parameters and Dialog Box

Image Filter

Filter type

The type of filtering to apply. The filters currently supported are:

Filter Type

Description

Box

A simple box filter which blurs the image by averaging the pixels in the neighbourhood. The Mask size may be any dimension.

Depth hole-fill

A filter specifically designed for depth images from an RGBD camera that fills in holes where the RGBD camera could not determine the depth of a pixel. It treats a zero pixel as an unknown depth. This filter is typically applied after the Depth temporal low-pass filter so that it is operating on as much valid depth data as possible.

Depth temporal low-pass

A filter specifically designed for depth images from an RGBD camera that low-pass filters pixels of the depth image over time rather than spatially. It treats a zero pixel as an unknown depth. This filter can produce better quality depth images from stereoscopic cameras but can also introduce lag.

Gaussian

A Gaussian filter based on the specified kernel size and standard deviation which blurs the image. The kernel, G, is generated from the standard deviation using the formula:

G(i,j) = exp{-((K/2-i)2 + (K/2 - j)2) / (2 σ)}, i,j=0..K

where K is the Kernel size. The kernel size must be an odd number that is greater than or equal to three.

High-pass

A high-pass filter which accentuates edges. The high-pass filter approximates the derivative of the image. The high-pass filter uses the following kernels depending on the mask size specified:

-1 -1 -1
-1 8 -1
-1 -1 -1

or

-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

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Laplace

A Laplace filter highlights regions of rapid intensity change. It is an approximation of the second derivative of the image:

L(x,y) = ∂2I/∂x2 + ∂2I/∂y2

To avoid accentuating noise, a Gaussian smoothing filter is often applied first. The Laplace filter uses the following kernels depending on the mask size specified:

-1 -1 -1
-1 8 -1
-1 -1 -1

or

-1 -3 -4 -3 -1
-3 0 6 0 -3
-4 6 20 6 -4
-3 0 6 0 -3
-1 -3 -4 -3 -1

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Linear

The linear filter is a generic filter in which a custom kernel may be specified. While this filter is slower than the other filters, it does provide the most flexibility. The kernel may be any dimensions larger than a scalar, including a rectangular matrix.

Low-pass

A low-pass filter which smooths the image. The low-pass filter uses the following kernels depending on the mask size specified:

1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9

or

1/25 1/25 1/25 1/25 1/25
1/25 1/25 1/25 1/25 1/25
1/25 1/25 1/25 1/25 1/25
1/25 1/25 1/25 1/25 1/25
1/25 1/25 1/25 1/25 1/25

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Maximum

A maximum filter sets each pixel in the output to the maximum value of all source pixels in the neighbourhood of the input pixel. The Mask size may be any dimension.

Median

A median filter which removes isolated intensity spikes and can be used to reduce noise in an image. The filter sets each pixel in the output to the median value of all source pixels in the neighbourhood of the input pixel. The Mask size may be any dimension.

Minimum

A minimum filter sets each pixel in the output to the minimum value of all source pixels in the neighbourhood of the input pixel. The Mask size may be any dimension.

Sharpen

A filter which sharpens the image. The sharpening filter uses the following kernel:

-1/8 -1/8 -1/8
-1/8 16/8 -1/8
-1/8 -1/8 -1/8

The mask size must be [3 3]. No other sizes are supported for this filter because it is optimized for performance.

Sobel Horizontal

A filter which highlights horizontal edges in the image. The Sobel horizontal filter uses the following kernels depending on the mask size specified:

1 2 1
0 0 0
-1 -2 -1

or

1 4 6 4 1
2 8 12 8 2
0 0 0 0 0
-2 -8 -12 -8 -2
-1 -4 -6 -4 -1

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Sobel Vertical

A filter which highlights vertical edges in the image. The Sobel vertical filter uses the following kernels depending on the mask size specified:

-1 0 1
-2 0 2
-1 0 1

or

-1 -2 0 2 1
-4 -8 0 8 4
-6 -12 0 12 6
-4 -8 0 8 4
-1 -2 0 2 1

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Sobel

A filter which highlights horizontal and vertical edges in the image. The Sobel filter normalizes the Sobel horizontal and vertical operators using the selected norm:

Norm

Description

L1

Sum of absolute values

L2

Square root of the sum of squares

L-infinity

Maximum of absolute values

The mask size must be [3 3] or [5 5]. No other sizes are supported for this filter because it is optimized for performance.

Source of region of interest

Whether the region of interest is defined by an internal dialog parameter or by an external input port.

Region of interest style

The region of interest is specified as a 4-vector of coordinates. The style determines how these four coordinates are interpreted when defining the region of interest.

Region of interest (tunable online)

The region of interest as a 4-vector. The meaning of each element of the 4-vector is determined by the Region of interest style parameter.

Maximum region of interest size (tunable offline)

The maximum size of the region of interest. Set this parameter to an empty matrix to use the full size of the image. Otherwise, the maximum size of the region of interest may be specified to save memory.

Region of interest zone (tunable offline)

Whether to apply the filtering inside or outside the region of interest.

Border type (tunable offline)

How to handle pixels outside the border of the region of interest when filtering along the edge of the region of interest. The different border types are described below:

Replicate

When the border type is Replicate then pixels at the edge of the region of interest are replicated to supply pixel values beyond the region of interest when filtering the pixels at the edge. For example, consider the 4x4 region of interest shown in red below:

1 1 1 2 3 4 4 4
1 1 1 2 3 4 4 4
1 1 1 2 3 4 4 4
5 5 5 6 7 8 8 8
9 9 9 10 11 12 12 12
13 13 13 14 15 16 16 16
18 18 18 19 20 21 21 21
18 18 18 19 20 21 21 21
18 18 18 19 20 21 21 21

The green pixels illustrate how the pixels at the edge of the region of interest are replicated when using a 5x5 kernel to filter the image.

Mirror

When the border type is Mirror then pixels at the edge of the region of interest are mirrored to supply pixel values beyond the region of interest when filtering the pixels at the edge. For example, consider the 4x4 region of interest shown in red below:

11 10 9 10 11 12 11 10
7 6 5 6 7 8 7 6
3 2 1 2 3 4 3 2
7 6 5 6 7 8 7 6
11 10 9 10 11 12 11 10
15 14 13 14 15 16 15 14
20 19 18 19 20 21 20 19
15 14 13 14 15 16 15 14
11 10 9 10 11 12 11 10

The green pixels illustrate how the pixels at the edge of the region of interest are mirrored when using a 5x5 kernel to filter the image. Pick any pixel on the edge of the red region of interest and notice that the pixels to the left mirror the pixels to the right, and the pixels above mirror the pixels below. However, the pixel at the edge is not replicated.

Mirror with Replication

When the border type is Mirror with replication then pixels at the edge of the region of interest are mirrored to supply pixel values beyond the region of interest when filtering the pixels at the edge. The pixel at the edge is replicated, however, in this case. For example, consider the 4x4 region of interest shown in red below:

6 5 5 6 7 8 8 7
2 1 1 2 3 4 4 3
2 1 1 2 3 4 4 3
6 5 5 6 7 8 8 7
12 11 9 10 11 12 12 11
14 13 13 14 15 16 16 15
19 18 18 19 20 21 21 20
19 18 18 19 20 21 21 20
14 13 13 14 15 16 16 15

The green pixels illustrate how the pixels at the edge of the region of interest are mirrored when using a 5x5 kernel to filter the image. Pick any pixel on the edge of the red region of interest and notice that it is first replicated. Then the pixels to the left of the replicated pixel mirror the pixels to the right of the original pixel, and similarly for the pixels above and below.

Constant

When the border type is Constant then the Border value parameter determines the pixel values beyond the region of interest when filtering the pixels at the edge.For example, consider the 4x4 region of interest shown in red below:

V V V V V V V V
V V V V V V V V
V V 1 2 3 4 V V
V V 5 6 7 8 V V
V V 9 10 11 12 V V
V V 13 14 15 16 V V
V V 18 19 20 21 V V
V V V V V V V V
V V V V V V V V

The green pixels illustrate how the pixels at the edge of the region of interest are set the the Border value, V, when using a 5x5 kernel to filter the image.

Border value (tunable online)

This parameter is only used when the Border type is Constant. It supplies the pixel value to use for pixels that go beyond the edge of the region of interest when filtering the pixels at the edge.

Kernel size (tunable offline)

The size of the image kernel to use for filtering the image. The kernel size must be an odd number greater than or equal to 3.

This parameter is only visible for filters which require it.

Standard deviation (sigma) (tunable offline)

The standard deviation to use for generating the Gaussian kernel of the dimension specified by the Kernel size parameter. The elements of the Gaussian kernel are calculated using the formula:

G(i,j) = exp{-((K/2-i)2 + (K/2 - j)2) / (2 σ)}, i,j=0..K

where K is the Kernel size.

This parameter is only visible for filters which require it.

Mask size (tunable offline)

The dimensions of the mask to use for filtering the image. A vector for the form: [height, width] is expected.

This parameter is only visible for filters which require it.

Gap threshold (tunable online)

The maximum gap between valid depth pixels that the filter will fill. This threshold is typically small, such as 10-15, because larger gaps are assumed to differentiate between separate objects. Gaps larger than this threshold will not be filled.

This parameter is only visible for the Depth hole-fill filter.

Depth threshold (tunable online)

The maximum difference between valid depth pixels on either side of a gap that the filter will fill. This threshold is typically small (eg. 6% of the range for a pixel) because larger differences in depth are assumed to differentiate between separate objects. Gaps where the depth values on either side of the gap differ by more than this threshold will not be filled.

This parameter is only visible for the Depth hole-fill filter.

Iterations (tunable online)

The number of times to apply the algorithm. For efficiency, the depth hole-filling algorithm only makes a single pass over the image. Applying multiple passes can fill in more holes in the depth image. Two iterations, however, is usually enough to produce a reasonable image.

This parameter is only visible for the Depth hole-fill filter.

Threshold (tunable online)

The temporal low-pass filter will reset the filter for any pixel whose depth value changes by more than this threshold from one frame to the next. It is assumed that such a jump in depth indicates the presence of a new object at that pixel.

This parameter is only visible for the Depth temporal low-pass filter.

Weight, alpha (tunable online)

The weight to apply to the current pixel. It must be a real number between 0 and 1. The low-pass filter algorithm applied to each pixel is y[k] = alpha * u[k] + (1 - alpha) * y[k-1], where u[k] is the current pixel, y[k] is the new filtered pixel, and y[k-1] is the filtered pixel from the previous timestep.

This parameter is only visible for the Depth temporal low-pass filter.

Number of frames for persistence (tunable offline)

The temporal low-pass filter tracks how many frames contained valid depth values over time, for each pixel. The number of historical frames it tracks is determined by this parameter. The value of this parameter must be an integer between 1 and 8.

This parameter is only visible for the Depth temporal low-pass filter.

Number of valid frames for persistence (tunable offline)

The temporal low-pass filter tracks how many frames contained valid depth values over time, for each pixel. If the current pixel is zero, indicating an unknown depth, then the filter replaces the current pixel with the most recent filtered value if the number of valid historical frames is at least the number of frames specified by this parameter. The value of this parameter must be a non-negative number less than or equal to the Number of frames for persistence parameter.

This parameter is only visible for the Depth temporal low-pass filter.

Kernel (tunable offline)

The kernel to use for the linear filter. The data type of this kernel matrix is significant, and may be an int16, single or double matrix. To specify the data type of the kernel matrix, cast it using the standard MATLAB casting functions. The int16 data type is recommended, as it is generally fastest. For example:

int16([-1 -1 -1; -1 8 -1; -1 -1 -1])

defines a 3x3 int16 kernel which detects edges in the image. Note that this particular example is identical to the kernel used by the Laplace filter, so it is more efficient to use the Laplace filter.

Note that the divisor and offset parameters can be used with the int16 data type to implement rational factors in the image kernel, so the floating-point types are often unnecessary.

This parameter is only visible when the linear filter is selected.

Divisor (tunable offline)

The divisor is applied when the kernel data type is int16. After the output pixel has been calculated using the kernel, its value is divided by the divisor. The divisor must be an integer value. The offset is applied after the divisor.

This parameter is only visible when the linear filter is selected.

Offset (tunable offline)

The offset is applied when the kernel data type is int16. After the output pixel has been calculated using the kernel and its value has been scaled by the divisor, the offset is added to the signed result and the final pixel value stored in the output image. The offset must be an integer.

This parameter is only visible when the linear filter is selected.

Rounding mode (tunable offline)

For integral image data types, the rounding mode is used to round the result of applying the kernel to a pixel in the image. The rounding modes are defined as follows:

Rounding Mode

Description

To Zero

Round the result towards zero by truncating the fractional part.

Nearest

Round the result towards the nearest integer. When the fractional part is equal to 0.5, round to the nearest even integer.

Financial

Round the result towards the nearest integer. When the fractional part is equal to 0.5, then round up.

Accurate

Produce an accurate result. This mode is only supported for uint8 images.

This parameter is only visible when the linear filter is selected.

Algorithm hint (tunable offline)

The algorithm hint selects between optimizing for accuracy or performance. The hints are defined as follows:

Algorithm Hint

Description

None or Fast

The algorithm performs rounding according to the Rounding mode parameter but performance takes precedence over accuracy. Pixels values may differ by ±1 from the accurate result.

Accurate

The algorithm produces accurate pixel values. In this case, accuracy takes precedence over performance.

This parameter is only visible when the linear filter is selected.

Targets

Target Name

Compatible*

Model Referencing

Comments

QUARC Win32 Target

No

No

Not currently supported.

QUARC Win64 Target

Yes

Yes

QUARC Linux Nvidia Target

Yes

Yes

QUARC Linux QBot Platform Target

Yes

Yes

QUARC Linux QCar 2 Target

Yes

Yes

QUARC Linux QDrone 2 Target

Yes

Yes

QUARC Linux Raspberry Pi 3 Target

No

No

Currently only uint8 images are supported.

QUARC Linux Raspberry Pi 4 Target

Yes

Yes

QUARC Linux RT ARMv7 Target

No

No

Currently only uint8 images are supported.

QUARC Linux x64 Target

Yes

Yes

QUARC Linux DuoVero Target

No

No

Currently only uint8 images are supported.

QUARC Linux DuoVero 2016 Target

No

No

Currently only uint8 images are supported.

QUARC Linux Verdex Target

No

No

Not currently supported.

QUARC QNX x86 Target

No

No

Not currently supported.

Rapid Simulation (RSIM) Target

No

No

Not currently supported.

S-Function Target

No

N/A

Old technology. Use model referencing instead.

Normal simulation

Yes

Yes

* Compatible means that the block can be compiled for the target.

 

navigation bar