Professional Documents
Culture Documents
The Image Processing Toolbox: Aims and Objectives
The Image Processing Toolbox: Aims and Objectives
Fig. 7.1 (a) A weight distribution motif; (b) the multifractal image. The weights are related to the
gray scale, for example, p1 D 1 would be white and p1 D 0 would be black on this scale
Move the cursor across the Image Tool window to see the pixel values of the 512
512 image Data. Check that the value of the pixel .500; 10/ is 1:54E 05.
You will note that the value of most pixels is close to zero, and this is why the
screen looks black. One may alter the contrast of the image by hitting the Adjust
contrast button. Click on Eliminate outliers, Apply and Adjust data to see an
image similar to that shown in Fig. 7.1b.
>> % Loading image files. Use the imread command.
>> % The image peppers.png is stored in an array named Image1.
>> Image1=imread(’peppers.png’);
A true color image, or RGB image, is an image in which each pixel is defined by
three numerical values for red, green, and blue (Fig. 7.2a). MATLAB stores true
color images as m n 3 matrices. A true color matrix can be of class uint8 and
uint16, single or double. See the MATLAB help pages for more information.
7.1 Image Processing and Matrices 141
Fig. 7.2 (a) The image peppers.png. (b) The red pixels
Note that the coordinate system used in the Image Processing Toolbox is ordered
from top to bottom and from left to right from the top left corner of the image. So
the pixel coordinate .500; 10/ refers to x D 500 (going left to right) and y D 10
(going top to bottom). Note that M.500; 10/ denotes the element in matrix M in row
500 and column 10. Check that the RGB value for the pixel coordinate .500; 10/ is
Œ61; 27; 63.
Suppose that one wanted to establish the number of red pixels in the image.
A simple program is listed below:
The next example demonstrates how one may obtain a binary image from a gray
scale image (Fig. 7.3).
>> % Load the image of rice, look at its properties and view
the image.
>> clear
>> I=imread(’rice.png’);
142 7 The Image Processing Toolbox
Fig. 7.3 (a) The image rice.png. (b) A binary image of rice.png.
>> whos I
>> imshow(I)
>> % Remove the rice grains using the strel function.
>> background=imopen(I,strel(’disk’,15));
>> % Subtract the background.
>> I2=imsubtract(I,background);
>> % Increase the image contrast.
>> I3=imadjust(I2);
>> % Convert the image to a binary image.
>> level=graythresh(I3);
>> bw=im2bw(I3,level);
>> imshow(bw)
>> whos
You can now perform some statistical analysis on the image. For example,
X
N
.n1/.k1/
Xk D tn !N ;
nD1
and
1 X
N
.n1/.k1/
xn D Xk !N ;
N
kD1
where
!N D e .2 i/=N ;
and each Xk is a complex number that encodes both amplitude and phase of a
sinusoidal component of function xn .
A fast Fourier transform, or FFT, is an algorithm to compute the discrete
Fourier transform. The FFT was first discovered by Gauss in 1805 but the modern
incarnation is attributed to Cooley and Tukey [3] in 1965. Computing a set of N data
144 7 The Image Processing Toolbox
a b
8 1
|Y(f)|
0.5
y
−2
−4
−6 0
0 10 20 30 40 50 0 100 200 300 400 500
time ms Frequency (Hz)
Fig. 7.4 (a) Signal corrupted with zero-mean random noise. (b) Single-sided amplitude spectrum
of y(t). You can read off the amplitude and frequencies
points using the discrete Fourier transform requires O N 2 arithmetic operations,
whilst an FFT can compute the same discrete Fourier transform in only O.N log N /
operations. Luckily for the reader, MATLAB has both the fft function and the ifft
function for computing the FFT and inverse FFT built in. The most well-known use
of the Cooley-Tukey algorithm is to divide the transform into two pieces of size
N=2 at each step and is therefore limited to power-of-two sizes, hence the use of
the nextpow2 command in Program 7a.
FFT is a powerful signal analysis tool, applicable to a wide variety
of fields including acoustics, applied mechanics, communications, digital
filtering, instrumentation, medical imaging, modal analysis, numerical analysis,
seismography, and spectral analysis. The following example is taken from the
MATLAB Help pages for the fft function.
Example 1. A common use of Fourier transforms is to find the frequency compo-
nents of a signal buried in a noisy time-domain signal. Consider data sampled at
1,000 Hz. Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and 120 Hz
sinusoid of amplitude 1 and corrupt it with some zero-mean random noise. Use
MATLAB to plot a graph of the signal and write a program that plots a single-sided
amplitude spectrum for the signal.
Solution. Figure 7.4a shows the sum of a 50 Hz sinusoid and a 120 Hz sinusoid
corrupted with zero-mean random noise and Fig. 7.4b displays the single-sided
amplitude spectrum of y.t /. The program for plotting the figures is listed below.
The main reason the amplitudes are not exactly at 0.7 and 1 is because of the
noise. Several executions of this code (including recomputation of y) will produce
different approximations to 0.7 and 1. The other reason for the error is due to
the finite length of the signal. Increasing L from 1,000 to 10,000 in the example
above will produce much better approximations on average.
The next example illustrates an application of FFT for finding the power spectra
of time series data. Interested readers should consult Melbourne and Gottwald [8],
who present results on the broadband nature of power spectra for diverse classes of
discrete dynamical systems. For many years, the power spectrum has been used
to distinguish periodic, quasiperiodic, and chaotic motions of certain dynamical
systems from a broad range of fields. The power spectrum plotted for a periodic or
quasiperiodic signal has discrete peaks at the harmonics and subharmonics, whilst
the chaotic signal has a broadband component in its power spectrum. In order to
illustrate these phenomena, consider the following simple example.
Example 2. Consider the two-dimensional discrete map defined by
where ˛ and ˇ are constants. Suppose that ˛ D 1, plot iterative plots and power
spectra for system (7.1) when (i) ˇ D 0:05, (ii) ˇ D 0:12, and (iii) ˇ D 0:3.
Solution. The MATLAB program for producing the plots in Fig. 7.5 is listed below.
a b
2 20
15
1
log(Power)
10
y
0
5
−1 0
−1 0 1 2 0 0.5 1
x Frequency (Hz)
c d
2 20
15
1
log(Power)
10
y
0
5
−1 0
−1 0 1 2 0 0.5 1
x Frequency (Hz)
e 2
f 20
15
1
log(Power)
10
y
0
5
−1 0
−1 0 1 2 0 0.5 1
x Frequency (Hz)
Fig. 7.5 Iterative plots and power spectra for system (7.1). (a) Periodic behavior when ˇ D 0:05.
(b) Power spectrum when ˇ D 0:05. (c) Quasiperiodic behavior when ˇ D 0:12. (d) Power
spectrum when ˇ D 0:12. (e) Chaotic behavior when ˇ D 0:3. (f) Power spectrum when ˇ D 0:3
y(n+1)=x(n);
end
plot(x(10:N),y(10:N),’.’,’MarkerSize’,1);
fsize=15;axis([-1 2 -1 2]);
set(gca,’XTick’,-1:1:2,’FontSize’,fsize)
7.3 The Fast Fourier Transform on Images 147
set(gca,’YTick’,-1:1:2,’FontSize’,fsize)
xlabel(’x’,’FontSize’,fsize)
ylabel(’y’,’FontSize’,fsize)
figure
% Power spectrum (Figure 7.5(f)).
f=-N/2+1:N/2;
freq=f*2/N;
Pow=abs(fft(x,N).^2);
plot(freq,log(Pow));
Pmax=20;axis([0 1 0 Pmax]);
set(gca,’XTick’,0:0.5:1,’FontSize’,fsize)
set(gca,’YTick’,0:5:20,’FontSize’,fsize)
xlabel(’Frequency (Hz)’);
ylabel(’log(Power)’);
Fig. 7.6 Low-pass filtering of the Lena image. (a) Lena.jpg, (b) fast Fourier transform, (c) a
circular low-pass filter, and (d) a compressed image of Lena. Use the MATLAB Help pages for
function definitions and syntax
7.4 Exercises
1. Use the matrix M D Œ0:1; 0:2I 0:2; 0:5 to produce a multifractal image up to
stage 8. Use the Image Processing toolbox to adjust the contrast to obtain a clear
figure.
2. Use the matrix M D Œ0:1; 0:2; 0:05I 0:2; 0:05; 0:01I 0:3; 0:04; 0:05 to produce
a multifractal image up to stage 5. Use the Image Processing Toolbox to adjust
the contrast to obtain a clear figure.
References 149
3. Edit Program 7b, to produce a binary image of the green pixels in peppers.png.
Determine an approximate number of green pixels.
4. Using the MATLAB Help pages, write a MATLAB program to detect the edges
of the rice grains for rice.png.
5. Compute the first 10,000 iterates of the logistic map
xnC1 D 4xn .1 xn /;
References
1. W. Birkfellner, Applied Medical Image Processing: A Basic Course, 2nd edn. (Taylor &
Francis, New York, 2014)
2. E. Brigham, Fast Fourier Transform and Its Applications (Prentice-Hall, New Jersey, 1988)
3. J.W. Cooley, J.W. Tukey, An algorithm for the machine calculation of complex Fourier series.
Math. Comput. 19, 297–301 (1965)
4. O. Demirkaya, M.H. Asyali, P.K. Sahoo, Image Processing with MATLAB: Applications in
Medicine and Biology (CRC Press, Florida, 2008)
5. Z. Elhadj, J.C. Sprott, A minimal 2-D quadratic map with quasiperiodic route to chaos. Int.
J. Bifurcat. Chaos 18, 1567–1577 (2008)
6. R.C. Gonzalez, R.E. Woods, S.L. Eddins, Digital Image Processing Using MATLAB, 2nd edn.
(Gatesmark Publishing, Aurora, 2009)
7. E.F. James, A Student’s Guide to Fourier Transforms: With Applications in Physics and
Engineering (Cambridge University Press, Cambridge, 2011)
150 7 The Image Processing Toolbox
8. I. Melbourne, G.A. Gottwald, Power spectra for deterministic chaotic dynamical systems.
Nonlinearity 21, 279–292 (2008)
9. J.L. Semmlow, Biosignal and Medical Image Processing: MATLAB-Based Applications, 2nd
edn. (CRC Press, Florida, 2008)
10. C. Solomon, T. Breckon, Fundamentals of Digital Image Processing: A Practical Approach
with Examples in Matlab (Wiley, New Jersey, 2011)