UNIVERSITY OF RHODE ISLAND
Department of Electrical, Computer and Biomedical Engineering
BME 465
Medical Image Processing Laboratory
Fall 2025
Exercise 3 / week 3
Data Formats and Convolution (part 1)
Data Formats Okay, this first part will be boring but you should at least be aware of common
image data formats you may encounter in a medical setting. Since we are mostly concerned how
to process the image data, we are less concerned about how to store the image data.
The international standard specially designed for medical informatics is the Digital Imaging and
Communications in Medicine, or DICOM, standard. As the name suggests, DICOM is not a standard
for simply storing image data, but it also provides for organizing multiple sets of different types of
images, information describing how the images were acquired (the “modality”), and patient
specific data. On a computer CD, all of this information (“metadata”) is stored in a hierarchical
data structure in a file named DICOMDIR. The complete standard is available online [5], and a high
level description is given in [1, section 3.4].
GIF (Graphics Interchange Format) files can contain color or gray scale images, but these files are
limited to 256 colors or gray levels since the maximum bit depth is 8 bits. For color images, the
image data are pointers to an RGB value in a Look Up Table (LUT). The LUT is limited to 256
values, so this format makes real-life photographs look “washed out” (but the format works well
for internet memes). The image data are also compressed, making this format a poor choice for
medical images. It’s pronounced “jif” [6].
Portable Network Graphics (PNG) files use a lossless compression algorithm to reduce the file size.
The JPG (or JPEG — Joint Photographic Experts Group) files are compressed using a lossy
algorithm, meaning that image information is lost in the compression step. This format is popular
on the interwebs, however, since excellent compression can be achieved at the cost of image quality.
The TIFF, or TIF format, indicates the Tagged Image File Format, which is a standardized format
allowing for many possible data arrangements. The image may be gray scale, full color, or a
limited number of colors (e.g., via a LUT). The image data may be compressed. All of the
information is contained in the image “tags.” The TIFF standard is so expansive that most
applications do not process all the information contained in the tags.
Finally, the RAW data format contains all the image information as detected by the camera, the
scanner, or other imaging hardware. Because the data are not compressed, RAW image files can be
several tens of megabytes, making storage inconvenient. Expert photographers often save images
in RAW format because the data can be later manipulated to improve the color balance, contrast,
or saturation in the image [2].
Convolution of continuous time signals A signal x(t) input to a system with impulse
response h(t) will generate an output y(t) according to the convolution theorem:
Z t
y(t) = x(t) ∗ h(t) =
x(τ ) h(t − τ ) dτ
0
-1-
(1)
BME 465 - Exercise 3
Recall from ELE 313 that convolution is commutative: x(t) ∗ h(t) = h(t) ∗ x(t); in words:
convolving the signal with the impulse response is the same as convolving the impulse response
with the signal. A sort-of complicated example is worked in the appendix.
Convolution of discrete time signals Things are bit simpler here, but there are some rules
we need to follow. First: we assume the impulse response always has an odd number of
samples. Second: the “origin” of the impulse response is the center sample. (Later we will
cover why we need these rules.) Most of the following discussion is modified from [3, section 3.4,
pp 126-129] (an excellent reference).
We need to convolve the discrete input signal x[n] with the discrete impulse response (or kernel)
h[n]. The impulse response is often called the filter kernel (or simply the kernel) in the time
domain; in the frequency domain the impulse response is called the transfer function. Here we
are working in the time domain.
Assume the input signal has eight samples with the unit impulse (“Kronecker delta”) at n = 4:
x[n] = 0 0 0 1 0 0 0 0. The kernel (impulse response) is h[n] = 1 2 3 2 0. What is the
output y[n]? We can, of course, generate y[n] through convolution. Let’s look at x[n] ∗ h[n]
pseudo-graphically:
A.
0
0
input x[n]
0 1 0 0
0
0
kernel h[n]
1 2 3 2 0
h[−n] = h[n] reversed
0 2 3 2 1
B. Align the reversed kernel’s right-most sample with the x[n] origin:
x[n]:
0 0 0 1 0 0 0 0
h[−n]: 0 2 3 2 1
C. Add enough “zero padding” to x[n] to cover h[−n] (same padding on both ends):
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
h[−n]: 0 2 3 2 1
D. Multiply (column-wise) and sum, generate the output (0×0 + 0×2 + 0×3 + 0×2 + 0×1 = 0):
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
h[−n]: 0 2 3 2 1
output:
0
E. Shift the kernel right by one sample, multiply and sum, generate output:
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
h[−n]:
0 2 3 2 1
output:
0 0
F. (Skip a shift.) Shift kernel right, multiply and sum, generate output:
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
h[−n]:
0 2 3 2 1
output:
0 0 0 1
-2-
BME 465 - Exercise 3
G. Shift kernel right, multiply and sum, generate output:
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0
h[−n]:
0 2 3 2 1
output:
0 0 0 1 2
0
0
H. (Skip ahead to the last shift.) Multiply and sum, generate output:
x[n]: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
h[−n]:
0 2 3 2 1
output:
0 0 0 1 2 3 2 0 0 0 0 0
A few things to note:
• The final shift aligns the reversed kernel left-most sample with the right-most sample of the
original input signal (before the zero padding).
• In Matlab terminology, the full output (that we got above) includes output samples that
are computed using the zero padding samples; the same output is the same length as the
input signal; the valid output discards output samples computed using any zero padding.
conv(x,h,’full’): x[n] ∗ h[n] = 0 0 0 1 2 3 2 0 0 0 0 0
conv(x,h,’same’): x[n] ∗ h[n] =
0 1 2 3 2 0 0 0
conv(x,h,’valid’): x[n] ∗ h[n] =
2 3 2 0
• To execute the process in Matlab, we could use output = conv(x,h,’shape’), where
shape is one of full, same, or valid. The default is full.
• The conv() command requires the longer sequence (usually the signal x[n]) as the first
argument, and the shorter sequence (usually the kernel h[n]) as the second argument. This
is not mentioned in the Matlab documentation. So use conv(x,h); do not use conv(h,x).
• In the example above, the input signal has M = 8 samples and the kernel has N = 5
samples, so the full output has M + N − 1 = 12 samples. The same output has M = 8
samples (the same as x[n]), and the valid output has M − N + 1 = 4 samples. Another way
to view the valid output: it was computed only when the kernel was fully immersed in the
input signal [7], meaning that no zero padding samples were part of the computation; where
zero padding samples are part of the computation, the output is less reliable. (You will see
this in the full output you generate for your lab report.) We will discuss these “end effects”
(or “edge effects”) more in a later lab exercise.
• The odd-number-of-samples rule easily identifies the center sample of the kernel. The
“center sample is the origin” rule keeps the zero padding the same at both ends of the input
signal. (These reasons will become more important in 2D convolution.)
• In this particular example, the output is a delayed copy of the impulse response (not
surprising since the input is just a delayed impulse).
-3-
BME 465 - Exercise 3
Answer these questions in your lab report:
a. Use Equation 1 to calculate y(t) when x(t) = eat and h(t) = ebt , where a and b are unknown
constants.
b. Use the Matlab conv command to compute the full and valid results of the convolution of
these input signals:
x1 [n] =
0.0 −1.0 −2.0 −3.0 −4.0 −5.0 −6.0 −7.0
x2 [n] =
0.0
2.5
5.0
7.5
10.0
12.5
15.0 17.5
x3 [n] = −5.0 −9.4 −12.6 −15.4 −15.0 −13.4 −10.6 −6.6 −1.4 5.0 12.6
with the filter kernel:
h[n] =
0.5
0.0 −0.5
What function does this particular kernel provide? Hint: plot the input signals in one
figure, and the valid and full outputs each in different figure windows. Include
screenshots in your report. One way to plot the input signals in a single figure:
plot( 1:length(x1), x1, 1:length(x2), x2, 1:length(x3), x3 )
You could use the same approach for the outputs.
What happens to the output in the early (and late) samples of the full outputs?
Compare the valid outputs to the full outputs. Where are the outputs the same? Are there
any samples missing?
c. Matlab has seven data classes that will be important in this course:
double single uint8 uint16 int8 int16 logical
A Matlab variable of data class double is a “double-precision floating point” number that can
range (approximately) from −10308 to +10308 ; this variable requires 8 bytes to store in memory.
What is the name, range, and storage requirement for the other six data classes?
d. Suppose our input signal, stored in a int8 array, has the 12 samples:
x[n] = -128 -128 -128 -128 127 127 127 127 -128 -128 -128 -128
Use a “pencil and paper” approach to convolve this with the three sample, int8 kernel:
h[n] = 1 0 -1
What is the output signal? What data class is needed to store this output?
Suggestion: Compute what Matlab would call the valid output. 1. First determine the
number of samples in the output signal. 2. Compute each output sample. 3. Look at the
numerical range of the output samples: what are the maximum and minimum values? What
type of Matlab data class is needed to store these numbers? (Your answers to the previous
question will be helpful here.)
e. Suppose the signal x[n] has eight samples, and the kernel h[n] has three samples. Using
conv(x,h,’valid’) works as expected, but conv(h,x,’valid’) returns
1×0 empty double row vector
What went wrong? (Think about the length of the output. This was discussed earlier, above.)
-4-
BME 465 - Exercise 3
Appendix: Continuous Time Convolution Example Here’s a fun (IMHO) example
from [4, pp 223-227]: input signal: x(t) = t (a “ramp”), impulse response: h(t) = eat , where a is a
constant parameter. What is the output signal y(t)?
Z t
Z t
x(τ ) h(t − τ ) dτ =
τ ea(t−τ ) dτ
y(t) = x(t) ∗ h(t) =
0
at
Z t
τe
=e
−aτ
0
dτ
0
Since the integral is over τ , we can set aside eat . Recall integration by parts [8, section 10.1]:
Z
Z
u dv = u v − v du
1 −aτ
Let u = τ and dv = e−aτ dτ , so du = dτ and v = −a
e . Now plug-in everything and forge ahead
to integrate the term in brackets [let’s call this term g(t)]:
Z t
τe
g(t) =
0
−aτ
1 −aτ
dτ = τ
e
−
−a
Z
Z t
t
1 −aτ
1
=τ
e
−
−a
−a
1 −aτ
e dτ
−a
e−aτ dτ
0
0
t
1
1 −aτ
1
−aτ
τe
−
e
=
−a
−a −a
0
1
1 −at
1
−at
=
te − 2 e
− 0− 2
−a
a
a
1
1 −at 1
−at
=
−t e − e +
a
a
a
=
1 −at
−at
−at
e
−
e
+
1
a2
=
1 −at
1
−
e
(at
+
1)
a2
Now multiply by the eat that we set aside earlier:
y(t) = eat × g(t) =
1 at
e − at − 1
2
a
-5-
τ =t
τ =0
BME 465 - Exercise 3
References
[1] Wolfgang Birkfellner. Applied Medical Image Processing: A Basic Course. CRC Press/Taylor
& Francis, second edition, 2014.
[2] Anna Gay. RAW Image Format (Everything You Need to Know!). https://www.
lightroompresets.com/blogs/pretty-presets-blog/understanding-raw-file-format,
November 2019. [online; accessed 3-Jul-2020].
[3] Rafael C. Gonzalez, Richard E. Woods, and Steven L. Eddins. Digital Image Processing Using
Matlab. Gatesmark Publishing, third edition, 2020.
[4] Erwin Kreyzsig. Advanced Engineering Mathematics. Wiley, fourth edition, 1979.
[5] American College of Radiology (ACR) and National Electrical Manufacturers Association
(NEMA). DICOM Standard. https://www.dicomstandard.org/, January 2020. [online;
accessed 7-Jul-2020].
[6] Amy O’Leary. An Honor for the Creator of the GIF. https:
//bits.blogs.nytimes.com/2013/05/21/an-honor-for-the-creator-of-the-gif/, May
2013. [online; accessed 4-Jan-2021].
[7] Steven W. Smith. The Scientist and Engineer’s Guide to Digital Signal Processing. California
Technical Publishing, San Diego, CA, 1997.
[8] Earl W. Swokowski. Calculus With Analytic Geometry. Prindle, Weber, & Schmidt, second
edition, 1979.
-6-