You are here : matlabImage Processingimfilter

imfilter() - Image Processing

B = imfilter(A,h) filters
the multidimensional array A with the multidimensional
filter h. The array A can
be logical or a nonsparse numeric array of any
class and dimension. The result B has the same
size and class as A. imfilter computes each element of the output, B,
using double-precision floating point.  If A is
an integer or logical array, imfilter truncates
output elements that exceed the range of the given type, and rounds
fractional values. examplegpuarrayB = imfilter(gpuArrayA,h) performs
the operation on a GPU. gpuArrayA is a gpuArray
that contains a logical or a nonsparse numeric
array of any class and dimension. When used with a gpuArray, H must
be a vector or 2-D matrix. This syntax requires the Parallel Computing Toolbox™.example___= imfilter(___,options,...) performs
multidimensional filtering according to the specified options.Code Generation support:
Yes.MATLAB Function Block support:
Yes.


Syntax

B = imfilter(A,h) examplegpuarrayB = imfilter(gpuArrayA,h) example___= imfilter(___,options,...) example


Example

Create Filter and Apply ItOpen This Example
Read a color image into the workspace and display it.originalRGB = imread('peppers.png');
imshow(originalRGB)

Create a motion-blur filter using the fspecial function.h = fspecial('motion', 50, 45);
Apply the filter to the original image to create an image with motion blur. Note that imfilter is more memory efficient than some other filtering functions in that it outputs an array of the same data type as the input image array. In this example, the output is an array of uint8.filteredRGB = imfilter(originalRGB, h);
figure, imshow(filteredRGB)

Filter the image again, this time specifying the replicate boundary option.boundaryReplicateRGB = imfilter(originalRGB, h, 'replicate');
figure, imshow(boundaryReplicateRGB)

Create a Filter and Apply it on a GPURead a color image into the workspace as a gpuArray and
view it.originalRGB = gpuArray(imread('peppers.png'));
imshow(originalRGB)Original Image
Create a filter, h, that can be used
to approximate linear camera motion.h = fspecial('motion', 50, 45);Apply the filter, using imfilter, to
the image originalRGB to create a new image, filteredRGB.
The image is returned as a gpuArray.filteredRGB = imfilter(originalRGB, h);
figure, imshow(filteredRGB)Filtered Image
Note that imfilter is more memory efficient
than some other filtering operations in that it outputs an array of
the same data type as the input image array. In this example, the
output is an array of uint8.whos
Name               Size               Bytes  Class       Attributes

  filteredRGB      384x512x3              108  gpuArray              
  h                 37x37               10952  double                
  originalRGB      384x512x3              108  gpuArray                    Try the filtering operation again, this time specifying
the replicate boundary option.boundaryReplicateRGB = imfilter(originalRGB, h, 'replicate');
figure, imshow(boundaryReplicateRGB)Image with Replicate Boundary


Output / Return Value


Limitations


Alternatives / See Also


Reference