Sunteți pe pagina 1din 6

[PHYS356/452/953,

LAB ASSIGNMENT 5]

PHYS 356/452/953 - Medical Imaging Physics


Lab Assignment 5
(This lab assignment was designed and implemented by Mitra Safavi-Naeini in 2011-2014)

Introduction
The term spatial domain refers to the image plane itself, and methods in this category are based on
direct manipulation of the pixels in an image. In this laboratory class we will focus on two
important categories of spatial domain processing: intensity or gray-level transformations and
spatial filtering (sometimes referred to as neighbourhood processing or spatial convolution). We
will develop MATLAB scripts, using processing techniques in these two categories.
You will write two functions to perform spatial domain operations. Intxform_studentID.m
performs intensity transformations (mapping), and genlaplacian_studentID.m implements an n
n Laplacian filter in spatial domain (if attempting the bonus question, you will be a third function,
multixtran_StudentID.m)
Reference: Digital Image Processing - third edition (International edition), Rafael C.
Gonzalez Richard E Woods, Publisher, chapter 3.

Important Instruction
NEVER REMOVE BRACKETS! ANSWER WITHIN SQUARE BRACKETS.

Students should do the lab practical and report individually. You may never share data with
other students if not explicitly told to do so. However, you are most welcome to discuss with
each other;

Save all executed scripts (whenever applicable) in a single m-file, saved as


a5_StudentID.m.

Some questions require a short answer. Download and edit lab5.doc. Each answer must be
written between the square brackets on the Snn: -line provided for that question;

Your submission should include a lab report file (modified lab5.doc) and three M-files:
a5_StudentID.m, Intxform_StudentID.m,genlaplacian_StudentID.m (or four if the
bonus questions have been attempted , multixtran_StudentID.m).

The deadline to submit the final lab report is on Tuesday next week.

[PHYS356/452/953,

LAB ASSIGNMENT 5]

====================================================
Student Details and Statement of Originalilty
Name: [Your name]
Student Number: [Your student number]
E-mail: [Your email address]
Have discussed part or whole of this work with the following fellow students: [Yes/No]

====================================================

1. Background
As noted in your lecture notes, spatial domain operations work directly on the pixels of an image,
and are denoted by the following expression:
g(x, y) = T [f(x, y)]

(1)

where f(x,y) is the input image, g(x,y) is the output (processed) image, and T is an operator on f,
defined over a specified neighbourhood about point (x,y).
The simplest form of transformation T is when the neighbourhood is of size 1 1. In this case, the
value of g depends only on the intensity of f at that point, and T becomes an intensity or gray-level
transformation function:
s = T(r)

(2)

where r denotes the intensity of f and s the intensity of g, both at any corresponding (x,y) in the
images.
The remainder of this laboratory deals with various implementations of the preceding equation.
While conceptually simple, computational implementation in MATLAB requires careful attention
paid to data classes and value ranges.

1.1. Function imadjust


Function imadjust is the basic IPT tool for intensity transformations of gray-scale images. It has the
following syntax
G = imadjust (F, [LOW_IN HIGH_IN],[LOW_OUT HIGH_OUT], GAMMA)
This function maps the intensity values in image F to new values in G, such that values between
LOW_IN and HIGH_IN map to values between LOW_OUT and HIGH_OUT.
Note: The input image can be of class uint8, uint16, or double, and the output image has the same
class as the input.
Q1: What happens to pixels with values below LOW_IN and above HIGH_IN?
S01:[]

[PHYS356/452/953,

LAB ASSIGNMENT 5]

Q02: All inputs to the function imadjust, other than f, are specified as values between 0 and 1,
regardless of the class of f. How do you think imadjust determines the actual values to use for
mapping the pixel values?
S02: []
Q03: Download mammogram.pgm, and a5_studentID.m from the Moodle website. Using
imadjust and stretchlim functions, adjust the image contrast (use help to find out more about
stretchlim). Obtain and display the negative of the adjusted image, and corrected mammograms
for two values of (one less than 1, the other larger than 1).
Q04: How does varying change the outcome of the transformation?
S04: []

1.2. Logarithmic and Contrast Stretching Transformation


Logarithmic and contrast stretching transformations are implemented using the following
expression:
g = c log(1 + f)

(3)

Note: When performing a logarithmic transformation, the resulting compressed values are often
remapped to the full range of the display. For 8 bits, the easiest way to do this in MATLAB is with
statement:
gs=imunit 8 ( mat 2 gray ( g ) ) ;
Q05: Perform the log transformation on the mammogram and display the result. Try different values
for c. How does this change the resulting image?
S05: []
Contrast_Stretching transformation function has been extensively discussed in our lectures; it is
used to compress the input levels lower than a chosen lower boundary into a narrow band of dark
levels in the output image, and the values above an upper boundary into a narrow band of lighter
levels. The result is stretching the contrast of pixels with values between the upper and lower
boundaries. The function has the following form:
m/r

1+

(4)

1
s=T ( r )=

[PHYS356/452/953,

LAB ASSIGNMENT 5]

where r represents the intensities of the input image, s the corresponding intensity values in the
output image, and E controls the slope of the function.
Q06: Implement the above equation in MATLAB. Use it to enhance a region of your choice in the
mammogram. Experiment with different values of E and m, and comment on the results.
Hint: You might need to use eps to prevent overflow if the input image has any 0 pixel values.
S06: []
You will now start developing your function, intxtran_studentID.m. The function maps the
intensities of input image S using mapping function, MAP, whose values are assumed to be in the
range [0 1].
Note: Pay attention to how the map function is defined and the intxtran_StudentID is used to
square the input intensities of an input image in the Help section of the code.
Q07: Download inxtran_studentID.m and tofloat.m from the subject website (you need to
download the latter as it is used by inxtran_studentID.m). Begin by modifying its name, followed
by the main body of the function.
Q08: Download the fullbody.pgm from the subject website. Write a MATLAB script (in
a5_StudentID.m) that performs the following intensity mapping operation (transformations),
using your inxtran_studentID.m: negative, log, gamma and contrast_stretching.
Bonus Mark: Rewrite the above script into a function (multixtran_StudentID.m). Your function
must use inxtran_studentID.m, and taking the name of the transform as one of its input variables
performs the required transform on the input image.
Hint: You can use MATLABs varargin, switch/case functions to toggle between each method.

2. Spatial Filtering
There are two main types of filtering applied to images:

spatial domain filtering; and

frequency domain filtering.

In spatial domain filtering, we are performing filtering operations directly on the pixels of an image.
The latter makes use of the Fourier Transform, which will be covered next week.
Spatial filtering is a technique that uses a pixel and its neighbours to select a new value for the
pixel. The simplest type of spatial filtering is called linear filtering. It consists of multiplying each
pixel in the neighbourhood by a corresponding coefficient and summing the results to obtain the
response at each point (x, y). Linear filtering can be uses to smooth, blur, sharpen, or find the edges
of an image.

2.1. Convolution Filtering in Spatial Domain


4

[PHYS356/452/953,

LAB ASSIGNMENT 5]

Q09: Download and open myfilter.m from the subject website. Explain the operation that the two
for loops perform.
S09: []

Q10: Apply a filter of your choice to an image of your choice (remember to update your
a5_studentID.m). Comment on the resulting image. Does it match your expectation?
S10: []

2.2. Functions imfilter and fspecial


MATLABs IPT implements linear spatial filtering using function imfilter, which has the following
syntax:
G = IMFILTER(F, W, FILTERING_MODE, BOUNDARY_OPTIONS, SIZE_OPTIONS)
where F is the input image, W is the filter mask, G is the filtered result, FILTERING MODE
specifies whether to filter using correlations (corr) or convolution (conv). The
BOUNDARY_OPTIONS deal with the border padding issue, with the size of border being
determined by the size of filter. All parameters are listed within function documentation (see
MATLABs help to learn more about using imfilter).
Note: You need to make sure that the input image is of the type double. To typecast your image, you
can use MATLABs im2double function (see MATLABs help to learn more about using
im2double).
Q11: What is the difference between correlation and convolution? How can applying one in place of
the other change the output image? Which one is most commonly used in image processing?
S11: []
The toolbox supports a number of predefined 2-D linear spatial filters, obtained by using function
fspecial), which generates a filter mask, w, using the syntax:
W = FSPECIAL(TYPE, PARAMETERS);
where TYPE specifies the filter type, and PARAMETERS further defines the specified filter.
Q12: Using fspecial filter, create an averaging filter. Apply the filter to your image of choice, and
display the result. Try a couple of other filter types using fspecial, and display the resulting images
(see MATLABs help to learn more about using fspecial).
5

[PHYS356/452/953,

LAB ASSIGNMENT 5]

Q13: Compare the efficiency of myfilter to imfilter, using TIC, TOC, and an image of your choice
(choose one from the subject website) and update youre a5_studentID.m. Which method is more
efficient? Why?
S13: []
Q14: Create the following two Laplacian masks:
w4 = [ 1, 1, 1; 1 -4 1; 1, 1, 1];
w8 = [ 1, 1, 1; 1 -8 1; 1, 1, 1];
Apply the two filters to an image of your choice (choose one from the subject website). Comment
on the similarities and differences of the two resulting images.
S14: []

Q15: Write an M-function that generates a Laplacian mask of arbitrary odd size (download and
use genlaplacian_StudentID.m as your template). For example, the mask of size 5 5 would
consist of all 1s with a -24 in the centre location.
Q16: Download the image blurry_moon.pgm and compare the results obtained with masks of size
n n for n = 5, 9, 15, and 25 (add this to your script a5_StudentID.m. Explain the differences in
the resulting images.
S16: []

S-ar putea să vă placă și