Image Processing Toolbox | ![]() ![]() |
Filtering a Region
You can use the roifilt2
function to process a region of interest. When you call roifilt2
, you specify an intensity image, a binary mask, and a filter. roifilt2
filters the input image and returns an image that consists of filtered values for pixels where the binary mask contains 1's, and unfiltered values for pixels where the binary mask contains 0's. This type of operation is called masked filtering.
This example uses the mask created in the example in Selecting a Polygon to increase the contrast of the logo on the girl's coat.
Figure 11-3: An Image Before and After Using an Unsharp Filter on the Region of Interest.
roifilt2
also enables you to specify your own function to operate on the region of interest. In the example below, the imadjust
function is used to lighten parts of an image. The mask in the example is a binary image containing text. The resulting image has the text imprinted on it.
BW = imread('text.tif'); I = imread('cameraman.tif'); f = inline('imadjust(x,[],[],0.3)'); I2 = roifilt2(I,BW,f); imshow(I2)
Figure 11-4: An Image Brightened Using a Binary Mask Containing Text
Note that roifilt2
is best suited to operations that return data in the same range as in the original image because the output image takes some of its data directly from the input image. Certain filtering operations can result in values outside the normal image data range (i.e., [0,1] for images of class double
, [0,255] for images of class uint8
, [0,65535] for images of class uint16
). For more information, see the reference page for roifilt2
.
![]() | Other Selection Methods | Filling a Region | ![]() |