Filter region of interest (ROI) in image
J = roifilt2(h, I, BW)
J = roifilt2(I, BW, fun)
J = roifilt2(h, I, BW) filters
the data in
I with the two-dimensional linear filter
a binary image the same size as
I that defines
an ROI used as a mask for filtering.
an image that consists of filtered values for pixels in locations
BW contains 1's, and unfiltered values for
pixels in locations where
BW contains 0's. For
implement the filter.
J = roifilt2(I, BW, fun) processes
the data in
I using the function
J contains computed values for pixels
in locations where
BW contains 1's, and the actual
I for pixels in locations where
fun must be a function handle. Parameterizing
Functions, in the MATLAB Mathematics documentation, explains how to
provide additional parameters to the function
For the syntax that includes a filter
the input image can be logical or numeric, and the output array
the same class as the input image. For the syntax that includes a
I can be of any class supported by
and the class of
J depends on the class of the
This example continues the
filtering the region of the image
I specified by
returns the filtered image
J, shown in the following
Read an image into the workspace.
I = imread('eight.tif');
Define the vertices of the mask polygon.
c = [222 272 300 270 221 194]; r = [21 21 75 121 121 75];
Create the binary mask image.
BW = roipoly(I,c,r);
Filter the region of the image
I specified by the mask
H = fspecial('unsharp'); J = roifilt2(H,I,BW);
Display the original image and the filtered image.