1. MATLAB
University of Lincoln School of Computer Science CMP3108M – Image Processing
Week-6: Sharpening Spatial Filters
In each section, there are a few new MATLAB built-in functions being used. To know more about these functions, you can Google the function name together with the keyword MATLAB to find the relevant MathWorks documentation, and read the instructions. For example: ‘rgb2gray MATLAB’.
2. Sharpening Spatial Filters
As we discussed in the lecture last week, image sharpening could be implemented through edge detector (e.g. Sobel, Laplace), or through unsharp masking.
2.1 Task
For a given sample image (e.g. pout.png), the task is to generate a new sharpening image using sharping filters (e.g. Sobel filter). You are required to write your own Matlab function to implement Sobel filter. The Sobel masks along x-and y- directions are shown below. Please also refer to last week’s lecture notes for the detail.
x-direction y-direction
By filtering using x-direction mask, you will obtain a vertical edge-emphasizing image Gx; whist filtering using y-direction mask, you will obtain a horizontal edge-emphasizing image Gy. The final
edge map (G) can be obtained by: G= Gy! + Gx!. Please use Matlab function (subplot) to display one figure which contains four images: original image, horizontal edge-emphasizing image Gy, vertical edge-emphasizing image Gx, and the final edge image G.
I=imread(filename); I_gray=rgb2gray(I);
C=im2double(I_gray);
I_out=zeros(size(C)); % create an empty image with the same size of
for i=2:size(C,1)-1
for j=2:size(C,2)-1
% please add code here
end end
2.2 Task
the input image
The built-in MATLAB IPT function H = fspecial (type) can be used to create a two-dimensional filter mask H of the specified type.
Please see the online help at http://www.mathworks.co.uk/help/images/ref/fspecial.html
The function B = imfilter(I, H) can then be used to filter an array (image) I with the filter mask H –
please refer to the MATLAB help or textbook for further details.
– Try the built-in functions (e.g. h = fspecial(‘sobel’) and imfilter) and compare this
with the results obtained from the Task 2.1. Please note that h = fspecial(‘sobel’) provides a horizontal edge-emphasizing filter; to obtain a vertical edge-emphasizing filter, you need to transpose the mask h, using: V= transpose(h)
– You can also compare different sharpening spatial filters, including Sobel and Laplace.
3. Unsharp masking
Write your own M-function for unsharp masking of a given image to produce a new output image (see lecture notes). Your function should apply the following steps:
• apply smoothing to produce a blurred version of the original image.
• subtract the blurred image from the original image to produce an edge image • add the edge image to the original image to produce a sharpened image.