To sharpen a color image, you need to make the luma intensity transitions more acute, while preserving the color information of the image. To do this, you convert an R'G'B' image into the Y'CbCr color space and apply a highpass filter to the luma portion of the image only. Then, you transform the image back to the R'G'B' color space to view the results. To blur an image, you apply a lowpass filter to the luma portion of the image. This example shows how to use the 2-D FIR Filter block to sharpen an image. The prime notation indicates that the signals are gamma corrected.
Define an R'G'B' image in the MATLAB® workspace. To read in an R'G'B' image from a PNG file and cast it to the double-precision data type, at the MATLAB command prompt, type
I is a 384-by-512-by-3 array of double-precision
floating-point values. Each plane of this array represents the red,
green, or blue color values of the image.
The model provided with this example already includes this code
executes it prior to simulation.
To view the image this array represents, type this command at the MATLAB command prompt:
Now that you have defined your image, you can create your model.
Create a new Simulink® model, and add to it the blocks shown in the following table.
Image From Workspace
Computer Vision System Toolbox™ > Sources
Color Space Conversion
Computer Vision System Toolbox > Conversions
2-D FIR Filter
Computer Vision System Toolbox > Filtering
Computer Vision System Toolbox > Sinks
Use the Image From Workspace block to import the R'G'B' image from the MATLAB workspace. Set the parameters as follows:
Main pane, Value =
Main pane, Image
Separate color signals
The block outputs the R', G', and B' planes of the
at the output ports.
The first Color Space Conversion block
converts color information from the R'G'B' color space to the Y'CbCr
color space. Set the Image signal parameter to
Use the 2-D FIR Filter block to filter the luma portion of the image. Set the block parameters as follows:
Output size =
input port I
Padding options =
Filtering based on =
fspecial('unsharp') command creates two-dimensional
highpass filter coefficients suitable for correlation. This highpass
filter sharpens the image by removing the low frequency noise in it.
The second Color Space Conversion block converts the color information from the Y'CbCr color space to the R'G'B' color space. Set the block parameters as follows:
Image signal =
Use the Video Viewer block to automatically
display the new, sharper image in the Video Viewer window when you
run the model. Set the Image signal parameter
Separate color signals, by selecting File
> Image Signal.
Connect the blocks as shown in the following figure.
Set the configuration parameters. Open the Configuration dialog box by selecting Model Configuration Parameters from the Simulation menu. Set the parameters as follows:
Solver pane, Stop
Solver pane, Type =
Solver pane, Solver =
(no continuous states)
Run the model.
A sharper version of the original image appears in the Video Viewer window.
To blur the image, double-click the 2-D FIR Filter
block. Set Coefficients parameter to
15],7) and then click OK. The
15],7) command creates two-dimensional Gaussian lowpass
filter coefficients. This lowpass filter blurs the image by removing
the high frequency noise in it.
In this example, you used the Color Space Conversion and 2-D
FIR Filter blocks to sharpen an image. For more information, see the Color Space Conversion and 2-D FIR Filter, and