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.
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 in file>Model Properties>Model Properties>InitFcn, and executes it prior to simulation.
Now that you have defined your image, you can create your model.
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
Main pane, Value = I
Main pane, Image signal = Separate color signals
The block outputs the R', G', and B' planes of the I array at the output ports.
Coefficients = fspecial('unsharp')
Output size = Same as input port I
Padding options = Symmetric
Filtering based on = Correlation
The 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.
Conversion = Y'CbCr to R'G'B'
Image signal = Separate color signals
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 to Separate color signals, by selecting File > Image Signal.
Solver pane, Stop time = 0
Solver pane, Type = Fixed-step
Solver pane, Solver = Discrete (no continuous states)
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 fspecial('gaussian',[15 15],7) and then click OK. The fspecial('gaussian',[15 15],7) command creates two-dimensional Gaussian lowpass filter coefficients. This lowpass filter blurs the image by removing the high frequency noise in it.