LIVRO A Practical Guide To Biospeckle Laser Analysis
LIVRO A Practical Guide To Biospeckle Laser Analysis
LIVRO A Practical Guide To Biospeckle Laser Analysis
A Practical Guide
to
Biospeckle Laser Analysis
Theory and Software
Lavras - 2016
Roberto Alves Braga Júnior
Fernando Pujaico Rivera
Junio Moreira
A Practical Guide
to
Biospeckle Laser Analysis
Theory and Software
Lavras - 2016
© 2016 by Roberto Alves Braga Júnior, Fernando Pujaico Rivera and Junio Moreira
Nenhuma parte desta publicação pode ser reproduzida, por qualquer meio ou forma, sem a
autorização escrita e prévia dos detentores do copyright.
Direitos de publicação reservados à Editora UFLA.
Impresso no Brasil – ISBN: 9-788581-270517
Editora UFLA
Campus UFLA - Pavilhão 5
Caixa Postal 3037 – 37200-000 – Lavras – MG
Tel: (35) 3829-1532 – Fax: (35) 3829-1551
E-mail: [email protected]
Homepage: www.editora.ufla.br
Diretoria Executiva: Marco Aurélio Carbone Carneiro (Diretor) e Nilton Curi (Vice-Diretor)
Conselho Editorial: Marco Aurélio Carbone Carneiro (Presidente), Nilton Curi, Francisval de
Melo Carvalho, Alberto Colombo, João Domingos Scalon, Wilson Magela Gonçalves.
Administração: Flávio Monteiro de Oliveira
Secretária: Késia Portela de Assis
Comercial/Financeiro: Damiana Joana Geraldo Souza
Revisão de Texto em Inglês: Heloisa Helena Nogueira Chaves
Referências Bibliográficas: Editora UFLA
Editoração Eletrônica: Fernando Pujaico Rivera, Roberto Alves Braga Júnior
Capa: Fernando Pujaico Rivera
Bibliografia.
CDD – 621.366
To my wife Vanessa and sons Matheus and Lucas.
Roberto
Amicum lege feliciter, vivas, gaudeas, floreas in Deo.
Fernando
I dedicate this work to my family, particularly to my mother Iraci, and friends
for all the support, understanding and assistance they have given me.
Junio
This book was only possible because of the support of
UFLA, Fapemig, Capes, CNPq and Finep during the last
20 years.
A foreword to “A Practical Guide to Biospeckle Laser Analysis”
This book is an offshoot of a meeting with Roberto and me, when he visited the UK in 2011 as
part of a UK-Brazil collaborative research program. We have been involved in the development of
laser based instrumentation for more than 15 years and shared similar thoughts, but, in different
parts of the world. Since then, we had several face-to- face and online meetings and discussions on
Laser Biospeckle and image processing. Through this book, Roberto and his co-authors address
some of the common practical issues in the area of Laser Biospeckle.
Laser Speckle is a random intensity pattern produced by many light waves of different phase
and amplitude but with the same frequency. During the initial stages of laser development and
imaging, this was considered to be a noise as it produces grainy or glittery type images. The famous
saying “All that glitters is not Gold” was fitting properly with the Laser Speckle phenomena. But,
later on, these “glitters” were found to be carrying “golden” information about the surface and
near-surfaces and lead to the emergence of various non-destructive type imaging applications. This
book is an outgrowth of two decades of research and teaching by the authors on the development of
laser speckle based systems. Again, various technical presentations and discussions with applied
researchers, including me, have opened-up the avenue for this practical guide on Biospeckle Laser.
The objective of this guide is to introduce fundamental concepts of laser speckle from applications
specific to Biosystems and to develop a basic understanding on the relevant software and image
processing techniques, smoothly.
In this book, which is mostly based on case studies and experiments with a flavour of theory,
the authors have tried to cover most of the practical difficulties experienced in the application
of the method and keep the theoretical data to a minimum. In most of the cases the authors use
examples to illustrate specific points, especially where data or software interpretation are involved.
For those who are new to biospeckle systems, will find little difficulty in keeping up-to- date in
the field as many developments emerge regularly. The authors have made an attempt to keep the
literature/developments up-to- date.
This is a very useful book for those who are working in the areas of biospeckle and their
applications. It is well structured, providing experimental and theoretical details needed to under-
stand and develop laser based biospeckle systems. The first part of the guide provides a step-by-
step approach for setting-up the systems along with the details on the software interface for data
collection and analysis. In the second part, a detailed list of library software tools provides the
various data analysing functions and their effects with realistic examples. This will help the user to
develop or carryout user specific modifications based on their experimental needs. The BSL tool
library reference manual helps to get a quick insight into these functions. The high quality pictures
and figures, mostly based on practical examples, provide better understanding and easy learning.
Overall, this book provides a guide for developing biospeckle laser systems with a practical touch.
Radhakrishna Prabhu
Dy. Director for Northern Research Partnership MedTech JRI and Lecturer in School of
Engineering, Robert Gordon University Aberdeen, UK.
Contents
I Part 1: Theory
1 Experimental Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.1 Introduction 25
1.2 Biospeckle Laser System 27
1.3 Optical Setup - Hardware 28
1.4 On-line Adjustments 31
1.5 Quality Tests 31
1.5.1 Saturation and Under-exposition Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.5.2 Contrast Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.5.3 Homogeneity Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.6 Methods of Data Analysis - On-line Methods 37
1.6.1 MHI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.7 Methods of Data Analysis - Off-line Methods 40
1.7.1 Graphic Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.7.2 Numerical Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.7.3 Frequency Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.8 Frequently Asked Questions - FAQ 52
1.8.1 How Should I Mount my Experiment? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
1.8.2 How Should I Analyze my Data? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
1.9 Exercises 53
II Part 2: BSL Tool Library User Manual
2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.1 Overview of BSL Tool Library 57
2.2 News 57
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Books 157
Sites 159
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
List of Figures
6.1 Datapack of a 3D matrix created by grouping NTIMES matrices with NLIN lines and
NCOL columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.2 Time history speckle pattern construction. Evolution on time of a set of M points
in the speckle image. Thus, this set of points will be represented in the lines of a T HSP
matrix, and the column represents the evolution on time . . . . . . . . . . . . . . . . . . . . 116
6.3 Time history speckle pattern of a line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
6.4 Co-occurrence matrix of a T HSP patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
6.5 Impulse response function h[n]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
6.6 Decomposition scheme according to the used mode. . . . . . . . . . . . . . . . . . 143
6.7 Quadrature mirror filter in synthesis mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
6.8 Synthesis of a path in a filter bank. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
6.9 Datapack DATA obtained at the end of a path SEQ=[0 1 1]. . . . . . . . . . . . . . 146
6.10 Frequency response of D(Z). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
List of Tables
AD - Average Difference
GD - Generalized Difference
IM - Inertia Moment
1 Experimental Guidelines . . . . . . . . . . . . . 25
1.1 Introduction
1.2 Biospeckle Laser System
1.3 Optical Setup - Hardware
1.4 On-line Adjustments
1.5 Quality Tests
1.6 Methods of Data Analysis - On-line Methods
1.7 Methods of Data Analysis - Off-line Methods
1.8 Frequently Asked Questions - FAQ
1.9 Exercises
1. Experimental Guidelines
1.1 Introduction
The Biospeckle Laser (BSL) is an interferometric phenomenon, which has been observed as a
sensitive way to monitor faint changes in the biological samples, and thus it has been adopted as a
reliable tool that can be applied in many areas, from medicine to agriculture. The main advantage
regarding its use is linked to the simplicity of the apparatus necessary to address the outcomes,
associated to the fact that it is a Non-Destructive Test (NDT ) which is relevant in biological
applications.
The multitude of applications demanded the appearing of a range of methods to illuminate,
to assemble the images and to provide their analysis. The absence of a standard, and even of a
commercial equipment to create some common approaches can be considered the main limit to the
biospeckle accessibility as a technology to measure biological activity.
The static appearance of a speckle pattern is expressed in Figure 1.1 and its evolution in time
is named dynamic laser speckle, a general term applied to biological and non-biological samples.
Therefore, the term bio preceding the word speckle represents the applications of the phenomenon
in biological material. In Figure 1.1, we have the image of a round seed on a table illuminated by
a laser beam and the grains represent the interference pattern in a static way. If you continue to
observe the image in time, if the seed is alive and in an adequate moisture, you will see a boiling
effect happening on it, i.e. the speckle pattern changing the shape and the grain illumination, whilst
on the table the speckle pattern stands still without changes in its grains.
The term biospeckle was at first adopted by Asakura (1988) when presenting a feasible applica-
tion to blood flow monitoring, a similar application presented by J. Briers (1975) and Fujii et al.
(1985). Once the technique showed its viability, many accounts appeared in order to present new
approaches to analyze the signal and to provide new applications in other areas of science.
26 Chapter 1. Experimental Guidelines
The analysis of the dynamic laser speckle as a source of information about the activity of
a biological or even of a non-biological material demands a lot of image processing associated
to mathematical and statistical approaches; these analysis were limited by the low capacity of
computers and cameras in the earlier applications.
However, the development of digital electronics and laser sources opened new doors regarding
the biospeckle laser phenomenon. New cameras, computers and lasers did a revolution in the
applications as well as in the field of image and signal analysis. Thus, the complexity of the
biospeckle adoption became related to the data processing rather than to the hardware itself.
In this book we would like to offer to new users, or even to experts, a collection of information
related to hardware and particularly to software in order to create a guide, integrating all the
developments we have done in the field of biospeckle laser applied to biosystems so far.
The software we have developed to analyze the biospeckle laser is presented here to OCTAVE
and MATLAB environments, with additional suggestion of free executable procedures. The
advantages of the software in OCTAVE or MATLAB versions compared to executable procedures
are the facility to change and to tailor the instructions to your particular case, as well as to know
exactly what you are doing. In this way, we presented a thorough documentation of the software in
order to help you use the best approach to analyze your data. The free software as a collection of
procedures is named here Biospeckle Laser Tool Library (BSLT L).
The book is divided into three parts and built as an onion (Figure 1.2). The external part of the
onion is the Part I, this part which you are reading now, and it has the aim to introduce you all the
main concepts regarding the use of biospeckle laser, from how to build your apparatus to what you
need to run the right procedure to get the information you want. The middle layer is Part II, or User
Guide of the software, with all the procedures you need to run and analyze your data. Finally, in
the core of the onion you will find the Reference Guide with all the details you need to understand
the procedures you are planning to use. Thus, it is a complete guide which intends to help you to
peel the onion easily, without crying.
The biospeckle theory will not be the main aim here, since it can be obtained on the book
Dynamic laser speckle and applications by Rabal; Braga (2008). Therefore, the focus is to guide you
1.2 Biospeckle Laser System 27
through the biospeckle laser application, tutoring you to chose the best experimental configuration
(Part I), and the best way to analyze the data (Parts I to III) by means of the BSLT L. In addition,
we have uploaded reference data in a repository (BRAGA, 2015), so you will be able to test the
procedures presented in this guide using an actual data of a maize and of a coffee seed illuminated
by a HeNe laser. The maize seed data has a collection of one hundred frames of a speckle pattern
over time, and the first image can be seen in Figure 1.3.
these classifications is plotted in Figure 1.4 where you can see the suggestion of previous steps
before the data analysis.
The forward-scattering setup presents less sensitivity if compared to the backscattering one
(RABAL; BRAGA, 2008, p. 21), and it is limited to applications restricted to the samples that are
transparent enough to let the light pass through them. In turn, the analysis of transparent samples
can be accomplished by the back-scattering with higher sensitivity than the forward arrangement as
well as it is the way we analyze the opaque samples. In Figures 1.5 and 1.6 it is presented the basic
design of the backscattering and the forward scattering setups with their optical components.
Figure 1.5:
Forward-
scattering
approach with a
basic disposition.
Figure 1.6:
Backscattering
approach with a
basic disposition.
30 Chapter 1. Experimental Guidelines
At this point it is relevant to stress that the laser cannot bring information from the interior of
an opaque sample, thereby restricting the information near the surface when the tissue allows some
transmission of the light in the layers beneath the surface. In turn, when the sample allows high
transmission such as a liquid or a gel, the backscattering approach must consider the adoption of a
reflective background (white or light enough) to return the light to the camera.
In the optical setup, the lasers and the cameras are the components with great variations. HeNe
lasers are the most used, however one can see great use of solid state lasers in the literature. Despite
its usage, we have to be careful with the quality of the laser beam, choosing a solid state laser that
has stability of the light intensity over time, as well as spatial homogeneity of the laser beam.
One can question the adoption of solid state lasers to measure the sensitive biospeckle due
to the mode hopping phenomenon that can cause some fluctuations of the laser beam over time.
However, despite the caution regarding this occurrence, we could not yet identify any compromise
our results with the adoption of solid state lasers.
Regarding the cameras, one can see analogue devices first used in biospeckle applications,
followed by the digital cameras which represented a great jump in the researches in the field, though
one can see every day a new revolution represented by new features such as speed, resolution
and communication with computers. One example is the USB interface, which can be considered
the best interface between camera and computers, so far. Among the great variety of cameras
in the market, the mini-microscopes with built-in macro lenses are a good options, since the
speckle pattern demands magnification to be observed properly. The main drawback of the mini-
microscopes is the absence of built-in iris control which is interesting for adjusting the size of the
speckle grains and filtering the light.
The USB protocol is easy to access through many programs, such as the ones we adopt here in
this guide. Thus, by means of known and stable functions we can access the data of a camera from
the software and control it.
We shall move to another part of the optical arrangement that causes many queries, the beam
expander. The expansion of the beam is a basic step in the biospeckle analysis, however you should
have in mind the quality of the light in the surface avoiding, for example, the under-exposition. The
best beam expander one can use is the microscope’s objective, since it does not distort the beam
like the common concave lenses.
The quality of the speckle pattern is the main query after the experimental configuration is
set, and it is a key point concerning the biospeckle application. Thus, the challenge is to tailor the
quality of the speckle pattern to each illuminated sample. The level of quality can be summarized
by the quality of the grains, i.e. the size of the grain, that needs to be larger than a pixel, and its
contrast, that is linked to the compatibility speed between the camera and the phenomenon as well
as linked to the level of illumination.
This guide will present in the next sections the Quality Test Protocol to help the users to tailor
their experimental configuration. Additional elements adopted to help the adjust of the level of
illumination are the neutral filter that can be placed before the beam expander, and the ground glass
usually adopted in the forward-scattering.
1.4 On-line Adjustments 31
values greater than 250 are considered saturated. The saturation and under-exposition tests finally
return a picture with saturated regions filled with intensity values equal to 255 (or red), and dark
regions filled with zero (or blue), as shown in Figure 1.11.
In this case, the area with saturation is exactly in a very important area of the seed, thus
compromising the analysis.
1.5 Quality Tests 33
The second test of quality is the contrast (specifically, the spatial image contrast). It defines the
compatibility between the velocity of the camera and the phenomenon observed, or the focus in the
picture. The way to carry out this test is based on the contrast test proposed by J. Briers (1975),
where the contrast of a ROI in one speckle pattern can be expressed by the Equation (1.1),
σ
C= . (1.1)
µ
p
So that σ = < (I − µ)2 > and µ =< I > which represent the spatial standard deviation and
the spatial mean value respectively. Both values are related to the intensities I inside of a ROI.
Thus, C defines the degree of difference or opposition between intensities. A high contrast C is
34 Chapter 1. Experimental Guidelines
characterized by a ROI with a high definition of the grains, whereas a low contrast is characterized
by a ROI with blurring.
In Figure 1.12, one speckle pattern of a paint drying over time presents the aim of this test. Just
5 minutes after painting, it is possible to observe how the speckle pattern is blurred as a result of the
high speed of the boiling, if compared with the speed of the camera. Therefore, after 15 minutes
one can see the speckle pattern with well-defined grains, and then the ideal condition to carry on
the biospeckle analysis. If you decide to acquire data of this phenomenon at 5 minutes your results
will be compromised by the aliasing.
Figure 1.12: Speckle patterns in different instants presenting the blurring at the first instant.
Reprinted from Publication Optics and Lasers in Engineering, 61, Junio Moreira, R. R. Cardoso,
R. A. Braga, Quality test protocol to dynamic laser speckle analysis, Pages No. 8-13, Copyright
(2014), with permission from Elsevier.
The contrast test applied to the first image of the maize biospeckle data (BRAGA, 2015), Figure
1.13, presents an area of low contrast (blue zone) in the middle of the embryo, at the same place as
1.5 Quality Tests 35
the saturation area, meaning the interference of the over-exposure of light in the contrast of speckle
grains.
and
Ca = σa /µa , (1.3)
p
where µa =< a > and σa = < (a − µa )2 > are the mean value and standard deviation the set
of values a = {A(i0 − 1, j0 ), A(i0 , j0 − 1), A(i0 , j0 ), A(i0 , j0 + 1), A(i0 + 1, j0 )} respectively. The
36 Chapter 1. Experimental Guidelines
value Cmax represents the maximum value of spatial contrast in all windows W (i, j) in the activity
indicator.
The Figure 1.15 represents the outcome of applying the homogeneity test on the maize bio-
speckle data (BRAGA, 2015) for mapping the areas that have the same activity, in order to choose
the best ROI to conduct numerical analysis. Therefore, you can elect one ROI with high homogene-
ity avoiding areas that presents transitions. This test is useful when the sample cannot be considered
as homogeneous such as in the case of the maize, with many distinct areas in the biospeckle point
of view.
1.6.1 MHI
We present in this book the OCTAVE and MATLAB procedures to run the MHI; however, it also
can be used by means of an executable free software Speckle Tool at (BRAGA et al., 2014).
The basic idea to compute MHI will be presented in the next steps, and we will use a collection
of pictures of a student lifting his arm to illustrate it. In the case of Figure 1.16, the arm is in its final
position. Notice that the student has on his chest a paper with the identification of the university
and of our center.
The first step of MHI procedure is the subtraction of two subsequent 8-bit images, Il and Il−1 ,
getting a matrix Sl as
Sl = Il − Il−1 . (1.4)
38 Chapter 1. Experimental Guidelines
The result of subtraction can be seen in Figure 1.17, where Sl is the silhouette of two consecutive
images.
The image Sl resulted from the subtraction must be transformed in binary (Equation 1.5), and
therefore a threshold must be proceeded for each pixel (i, j), so that
1 if |S (i, j)| > Z
l
Tl (i, j) = (1.5)
0 if |S (i, j)| ≤ Z
l
and the result of this action on Figure 1.17 can be seen in Figure 1.18. Where the matrix Tl is the
thresholded image of Sl using a Z limit.
The history of the motion of the arm is therefore recorded by the MHI procedure, in the instant
l, through the next equations,
N−1
MHIl = 255 ∑ Tl−k hk , (1.6)
k=0
N −k
hk = , (1.7)
M
where the hk value is the weighting that is based on the image’s age and M = N(N + 1)/2 is equal
to a summation of N first natural numbers, so that the summation of all hk is ever 1.0. Thus, the
1.6 Methods of Data Analysis - On-line Methods 39
last motions receive the highest gray level, then it is possible to follow the movement while the
student lifts his arm.
In Figure 1.19 it is possible to see the MHI of an arm being lifted from its first position on the
bottom to the top position. The light values of gray means movement, where the higher values
address the latest changes in the positioning. See also the sensitivity of the technique that offers the
ability to read the acronyms in the student’s chest.
One needs to observe that the MHI procedure can be adjusted by means of at least three factors,
the number of images that will be part of the buffer, the limit of the threshold and the weighting of
the subtractions. The adjustments of those factors will let you bias your on-line observation with
respect to the phenomenon speed and as well as tailor the sensitivity of the method.
Finally, the gray level can be enhanced by a pseudo-color image as can be seen in Figure 1.20.
The same idea is adopted in the speckle pattern images and you can see one example in
Figure 1.21 when a maize seed, illuminated by a laser, is observed on-line by the MHI. In our
laboratories, we adjust the experimental configuration using the MHI on-line before assembling
the first collection of images to proceed the Quality Test procedure (see Figure 1.4).
40 Chapter 1. Experimental Guidelines
The off-line analyses are usually a relevant way to process the biospeckle data, and as you could
see in Figure 1.4 they can be done by means of graphical or numerical approaches. The off-line
analysis also allows the adoption of frequency domain approach, since in on-line approaches the
low number of frames are prohibitive in this domain. The information about the methods will be
presented here (Part1) only to let you know the main concepts of each one, since the details can be
seen in Parts 2 and 3 of this guide book.
An illustration of graphical analysis outcome of biospeckle data can be seen in Figure 1.22, where
the original photo of a coffee seedling had its root illuminated by a laser and the images were
analyzed using a graphical approach. Usually, graphical outcomes are presented in gray levels (8
bits), or alternatively in pseudo-color, with the activity represented from blue, low activity, to red,
high activity. If it were gray, the outcome would be from black, low activity, to white, high activity.
The main outcome of the graphical analysis is the map of activity, and it is adopted in heterogeneous
samples where one desires to identify distinct areas. It is possible to get a numerical figure from
these graphs finding the mean values in a Region Of Interest (ROI). The extraction of the numerical
values from the graphical outcomes is not the best approach when one need comparisons since they
are restrict to the levels of gray (0 to 255).
One can list some methods to compute the graphical outcomes, but the most used in the
literature are three:
• Average Difference (AD) also called Fujii method (FUJII et al., 1987; FUJII; ASAKURA,
1975);
• Generalized Differences (GD) (ARIZAGA et al., 2002);
• Temporal speckle Standard Deviation (SD) (BLOTTA et al., 2011).
1.7 Methods of Data Analysis - Off-line Methods 41
Fujii method (FUJII et al., 1987; FUJII; ASAKURA, 1975), originally called Average Difference
(AD), is the first method known and it provides an outcome with a relative value, since the presence
of the denominator in Equation (1.8) makes each difference relative to the intensities observed.
Thus, Ik represents an image (intensity matrix) taken in the instant k, which is presented in Equation
(1.8)
|Ik − Ik−1 |
AD = ∑ . (1.8)
k Ik + Ik−1
One consequence of this is the ability of the Fujii method to enhance the differences in areas of the
image that are dark, thereby the final image is clearer than the other graphical methods, and it is
possible to see in Figure 1.23. In the figure, the Fujii method was applied in the maize seed and the
smoothness in the final image can be observed.
Generalized Difference (GD) method (ARIZAGA et al., 2002) in turn, as its name says, provides
the difference of each image with respect to all the others. The absence of the normalization as
occurred in Fujii method creates a sharp outcome with the areas of activity well delimited, see
Figure 1.24 and compare the result with the Figure 1.23. One issue concerning the GD method is
the high computer time-consuming regarding the generalized differences. In Equation (1.9) it is
possible to see the method.
Where the image Ik is compared to all the images Ik−l of the collection.
our laboratories, Equation (1.10), where the Ik matrix represents the image taken in the instant k,
E[Ik ] means the temporal mean value of Ik , for all k, and N means the number of images analyzed,
s
1 N
SD = |Ik − E[Ik ]|2 . (1.10)
N∑k
The numerical methods are adopted when one desires to quantify the level of changes in a speckle
pattern in time, which is also known as level of activity. The main assumption to use a numerical
approach is that the area analyzed is homogeneous. It is possible to get the level of changes from
the graphical outcomes, however there are some particular approaches to provide the values related
to the level of changes in a speckle pattern. The numerical and graphical methods adopt the same
statistical and mathematical approaches, and thus they can be associated (BRAGA et al., 2012).
The importance of the Quality Test plays a key point here, particularly the homogeneity.
Oulamara; Tribillon; Duvernoy (1989a) constructed what we know as Temporal History of the
Speckle Pattern (T HSP), and opened the way to analyze the phenomenon by means of numerical
outcomes, in a ROI within a supposed homogeneous area, though monitoring one line, of M pixels,
in time through N samples.
Therefore, the construction of the T HSP traditionally adopts one line or column in time;
however, when the homogeneity level of the ROI is not high, the adoption of a line or a column can
compromise the results. An alternative approach that we are using with success is the construction
of a T HSP by means of a collection of M points randomly chosen in the first image and with the
same points monitored in time. In Figure 1.25, it is possible to see a T HSP of an active sample
and, in Figure 1.26, the T HSP of a non-active sample, thus the T HSP can be a good graphical
information of the level of activity. Compare the images and observe the lines better defined in
Figure 1.26 than in Figure 1.25. The visual comparisons work well with different activities, but it is
not the case when we have levels much closer than the ones of the example, thereby the need of
numerical outcomes.
The T HSP images are the base of some methods to obtain the numerical outcomes such as the
autocorrelation (XU; JOENATHAN; KHORANA, 1995), the Inertia Moment (IM) (ARIZAGA;
TRIVI; RABAL, 1999), and the Absolute Value of the Differences (AV D) (BRAGA et al., 2011),
which is a variation of the inertia moment. The contrast (J. BRIERS, 1975) that is linked to the
on-line approaches is another way to get numerical values, and as well as the autocorrelation of
recorded images (without using the T HSP) (KURENDA; ADAMIAK; ZDUNEK, 2012). Other
variations linked to the IM and AV D tried to enhance their robustness, particularly regarding the
normalization (CARDOSO; BRAGA, 2014). In this guide you will find the way to understand how
the IM and the AV D are implemented, including their variations.
44 Chapter 1. Experimental Guidelines
Co-occurrence Matrix
where the COM matrix represents a transition histogram of intensity. Thus, COM(i, j) has the
number of times a transition of an intensity level i to j happens.
1.7 Methods of Data Analysis - Off-line Methods 45
In Figure 1.27, one can see the co-occurrence matrix of the T HSP presented by Figure 1.25,
that is, of a animal sperm with high activity. It is possible to observe that the points are spread
along the main diagonal, but with higher dispersion than the COM from a T HSP representing
low activity (Figure 1.28), such as the T HSP of Figure 1.26. The COM, such as the T HSP, are
graphical options to evaluate the level of activity of a sample; however, the numerical outcome like
inertia moment or AV D is relevant to statistical analysis and comparisons between close stages.
The Equation (1.12), proposed by Xu; Joenathan; Khorana (1995), is the correlation of the time
history speckle pattern, T HSP, proposed by Oulamara; Tribillon; Duvernoy (1989a).
46 Chapter 1. Experimental Guidelines
The memory of the phenomenon is tested using only the M pixels analyzed by the T HSP.
M
∑ T HSP(m, i)T HSP(m, i + l)
m=1
Cil = s . (1.12)
M M
∑ T HSP2 (m, i) ∑ T HSP2 (m, i + l)
m=1 m=1
Finally, the correlation value to a lag “l” is calculated as the Equation (1.13)
1 N/2
Cl = ∑ Cil , (1.13)
N/2 i=1
Inertia Moment
The Inertia Moment (IM) is based on the construction of the Time History Speckle Pattern (T HSP)
first proposed by Oulamara; Tribillon; Duvernoy (1989a). Of generic way, the calculus of inertia
moment is presented in the Equation (1.15),
COM(i, j)
IM = ∑ ∑ |i − j|2 (1.15)
i j Normalization
The normalization shown in this equation can be the one proposed by Arizaga; Trivi; Rabal
(1999), which makes the sum of values in each line of the COM equal to one, or other normalizations
such as the one proposed by Cardoso; Braga (2014) in order to reduce the effect of inhomogeneities
in the analyzed images.
The Average Value of Difference (AV D) in the Equation (1.16), with difference of IM, replaces
the square operation by the absolute value, being a way to overcome the effect of the square that
increases the perception of high changes in the T HSP, rather than the low changes, thus distorting
the outcomes (CARDOSO; BRAGA, 2014).
COM(i, j)
AV D = ∑ ∑ |i − j| (1.16)
i j Normalization
1.7 Methods of Data Analysis - Off-line Methods 47
It is possible to have many variations of IM and AV D regarding some changes in their equations,
for instance, related to normalization of the data and the way the outcomes are presented. The
outcomes can be used apart or together in order to best evaluate the phenomenon. More details can
be read in the other two sections of the book.
The frequency analysis of the biospeckle laser data is an useful way to isolate in the signal of each
pixel in time the components that can match to a particular biological phenomenon. There are some
techniques to transform the signal from time to frequency domain. We will present here a library
based on filter banks to deal with the biospeckle signal. This filter bank can be interpreted as
• A step of a filtering in frequency bands,
• A step of discrete wavelet transform, or
• A step of continuous wavelet transform of a discrete signal.
The aim is usually the transformation of the signal to the frequency domain in order to
manipulate it easily. The elimination of some frequency components is the common action
before the reconstruction of the signal in the time domain using the inverse transformation. The
elimination allows numerical or graphical analysis of the biospeckle data without some non-
desirable components that are assumed to be linked to a particular biological phenomenon. For
instance, if you want to isolate the respiration of a tissue, you can eliminate all the components
related to other phenomena, and then analyze the data only with the supposed components linked
to the respiration process (ALVES; BRAGA; VILAS-BOAS, 2013).
It is possible to construct a scheme of filtering in frequency bands using a filter bank. A filter bank
step separates the information in two complementary parts so that the summation of outputs is equal
to the input (Figure 1.29a). Where a signal DATA is divided in the output signals DATA1, DATA01,
DATA001 and DATA000. DATA represents the information, for all samples k, of a pixel Ik (x, y) or a
set of pixels Ik . The Figure 1.29c shows the frequency response for the system in the Figure 1.29a.
Each one of the output signals, with sampling frequency Fs , has the information of only a frequency
band and it can be processed with all methods of biospeckle analysis seen in the previous sections.
The reconstruction of original signal DATA can be reached summing all the signals. The variables
H0, H1, G0, G1, W0 and W1 represent filters (see Equation (1.17)), so that the filters in cascade can be
replaced by an equivalent, as in the Figure 1.29b, where the operator “∗” represents the convolution.
Then, for example, in the case presented here it is right to say that
DATA1 = DATA ∗ H1
DATA01 = DATA ∗ H0 ∗ G1
(1.17)
DATA001 = DATA ∗ H0 ∗ G0 ∗W 1
DATA000 = DATA ∗ H0 ∗ G0 ∗W 0
48 Chapter 1. Experimental Guidelines
In the scheme of Figure 1.29, when DATA contains N samples, the outputs DATA1, DATA01, DATA001
and DATA000 also contain N samples.
(a) Filtering in frequency bands using a filter bank step with (b) Equivalent filtering scheme
complementary outputs. to figure (a).
represents the low part of frequency whereas the variable that adds a 1 represents the high part of
frequency.
Figure 1.30a shows the signal DATA with N samples, which represents the information for all
samples k of a pixel Ik (x, y) or a set of pixels Ik ; being decomposed in the coefficients DATA00,
DATA01, DATA10 and DATA11, with dN/4e samples (being dae the ceil function of a). In the the
scheme of decomposition, Figure 1.30a, the coefficients represent the information of frequency
bands with the same bandwidth as can be seen in the Figure 1.30c.
(a) Decomposition in frequency bands using (b) Reconstruction of signal of figure (a) using
quadrature mirror filters in analysis mode. quadrature mirror filters in synthesis mode.
(d) Reconstruction of signal in a frequency band using the coefficients DATAij of figure (a).
Figure 1.30b shows the reconstruction DATA of the signal DATA from the coefficients obtained in
the scheme of Figure 1.30a using quadrature mirror filters in synthesis mode. Similarly to analysis
mode, and in reverse, the synthesis mode uses two up-samplers ( ) (DISTEFANO; STUBBERUD;
WEHBRING, 2011) and two filters G0 = H0 and G1 = −H1, additionally the synthesis mode needs
a gain stage of 2 ( ). An important rule to perfect reconstruction demands that the Z transform,
H0 (Z), of H0 filter should satisfy the Equation (1.18),
a0 and a1 being real values. Specifically, to the case of synthesis, for the block proposed here, to
have a perfect reconstruction with a similar amplitude of input signal, it needs that a0 = 1.
In some cases, we need to analyze only some frequency bands, and we want to save processing
time reconstructing only these bands. For these cases, it is convenient to use a reconstruction
scheme as showed in the Figure 1.30d, where the coefficients DATAij, for any i, j ∈ {0, 1}, are
50 Chapter 1. Experimental Guidelines
used to get DATAij that represents a portion of DATA in the frequency band i j (Equation 1.19).
Therefore, it is correct to say that
We can decompose a discrete signal x(k) in components wa (k) (Equation 1.20) both with N samples,
using a Continuous Wavelet Transform (CW T ) (POPOV; ZHUKOV, 2009). Therefore, we analyze
the signal in a new space where each scale factor, relative to a, represents the behavior of a frequency
band for each sample k. Thus, the general expression of CW T of a discrete signal is
where all the wavelets ψa (k) (Equation 1.21) follow the same formation ruler using the scale factor
sa ,
1 k
ψa (k) = √ ψ0 ∧ s0 = 1, (1.21)
sa sa
the function ψ0 being called mother wavelet, which is chosen at the discretion of each user. In the
Equation (1.21), ψa (k) is considered a function whose domain is a set of integers. Therefore, a
discrete function ψa (k) can be considered as a wavelet (POPOV; ZHUKOV, 2009) if it fulfills the
Equation (1.22)
Established the rules of a CW T , if we consider ψa (k) as an even function, the discrete signal
wa (k) (Equation 1.23), in the instant k, can be interpreted as the convolution of a signal x(k) with a
wavelet ψa (k). So that
In this sense we can say that the CW T , wa (n), represents a filtered part in a non-causal form of the
signal x(k), see Figure 1.31a. The considerations presented in the Equation (1.22) guarantee that
ψa (k) is a band pass filter with an equal mean spectral energy for any scale sa .
Whereas previously explained, in the context of biospeckle analysis, the Figure 1.31b shows the
signal DATA, that represents the information for all samples k of a pixel Ik (x, y) or a set of pixels Ik ,
being decomposed in {DATA0, DATA1, DATA2, ..., DATAM} using a CW T . The Figure 1.31c shows
an example of frequency responses of a system in the CW T decomposition (Figure 1.31b), using a
Morlet wavelet (MORLET et al., 1982a; MORLET et al., 1982b) as mother, for the case of scale
factors with form sa = 2a . Therefore, as it can be seen, the work with CW T gives us a restriction
of filter family, but in the other hand, it gives us a wide freedom to use the scale factor. For this
1.7 Methods of Data Analysis - Off-line Methods 51
reason when we use a CW T we should be careful in choosing a mother wavelet to have a frequency
response of the system that fulfills our requirements.
(a) Non-causal filter using a wavelet (b) Decomposition in frequency bands using
ψa . a set of wavelets.
(c) Frequency response in the system of figure (b) using the Morlet wavelet with sa = 2a .
1.9 Exercises
What do we Expect you Should Know About the Theme Before Use the Biospeckle
• You should know about laser features.
• You should know about coherent light.
• You should know about scattering of light.
• You should know about electromagnetic wave interference.
• You should know about Fourier analysis.
• You should know about statistical analysis of biological samples.
• You should know basic programming.
II
Part 2: BSL Tool Library User
Manual
2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.1 Overview of BSL Tool Library
2.2 News
2.2 News
• Functions to load in a package a set of images.
• Functions to deal with many time history speckle patterns.
• Functions to analyse numerically the activity of BSL. For example, AVD (BRAGA et al.,
2011), inertia moment (ARIZAGA; TRIVI; RABAL, 1999), etc.
• Functions to create maps of activity of BSL. For example Fujii (FUJII; ASAKURA, 1975),
generalized differences (ARIZAGA et al., 2002), standard deviation (NOTHDURFT; YAO,
2005), etc.
• Functions to test the quality (CARDOSO; BRAGA; RABAL, 2012) of a collection of images.
3. Getting Started with BSL Tool Library
In order to use the Biospeckle Laser Tool Library it is important to have some previous knowledges
and an equipment with minimal characteristics, in the next subsections we will show the necessary
requirements.
When a user starts the study of BSL phenomenon and the use of BSL Tool Library, he will perceive
the need to know some concepts. Next we will enumerate a list that, in our view, includes everything
a user must known.
Speckle laser theory: To use the BSL Tool Library it is necessary a basic knowledge of BSL
phenomenon; for example, knowing in which cases to use an activity index or another,
or what procedures make a specific technique. In any case, the documentation of library
functions has references to the scientific paper that defines or describes the technique.
Algorithm: The BSL Tool Library was written to be easy to use, with a modular focus and
imperative programming style. Thus, an user only needs a basic knowledge of algorithm to
begin working with the library.
Knowledge of OCTAVE or MATLAB: Given that the library is written in the code style and
syntax of OCTAVE and MATLAB, it is necessary that the user has a minimal knowledge of
some of this two interpreters. In this sense, the library works well in both, and this is due to
the high compatibility between OCTAVE and MATLAB.
60 Chapter 3. Getting Started with BSL Tool Library
HOME=getenv('HOME');
This returns the value of the system environment variable HOME (for example, HOME='/home/user
name'). It is important to highlight that, in computer operating systems based in GNU with kernel
Linux, the HOME directory is also represented by the symbol "~". This directory has a mix of user
files and user application configuration files. Thus, we propose that the application libraries be
inside “lib” directory in HOME ; for example, the libraries that only run over OCTAVE should be in
the path
~/lib/octave/
The same way to the libraries that only run over MATLAB should be in
~/lib/matlab/
By other side, if the libraries can be run in OCTAVE and MATLAB, it is better to have the libraries
in a directory such as:
~/lib/octmat/
Thus, the "octmat" directory will have a subdirectory tree such as:
~/lib/octmat/mylibrary1
~/lib/octmat/myLibrary2
...
~/lib/octmat/libraryOfMyBrother
62 Chapter 3. Getting Started with BSL Tool Library
~/lib/octmat/libraryOfMyTeacher
...
~/lib/octmat/bsltl
As in the previous subsection, libraries in Microsoft operating system should be grouped in a known
directory such as HOME . It can be found using (in OCTAVE or MATLAB) the function getenv()
with the next code:
HOME=getenv('USERPROFILE');
This returns, in the variable HOME, the value of the system environment variable USERPROFILE (for
example, HOME='C:\Users\username'). Once we know this value, we suggest that the application li-
braries should be in the “lib” directory in HOME ; for example, using the value of HOME assumed before,
the libraries that only run over OCTAVE should be in the path: 'C:\Users\username\lib\octave\'.
But, for simplify the notation, here we use
lib\octave\
Thus we understand that the paths are always inside HOME directory. Following the same notation,
the libraries that only run over MATLAB should be in
lib\matlab\
and the libraries that can be interpreted in OCTAVE and MATLAB would be in
lib\octmat\
lib\octmat\mylibraryA
lib\octmat\mylibraryB
...
lib\octmat\libraryOfMyFriend
lib\octmat\libraryOfMyTeacher
...
lib\octmat\bsltl
Where each subdirectory inside “octmat” represents a library (package). In the similar way, the
directories “octave” and“matlab” also have a subdirectory tree with libraries sorted by name and if
necessary by version.
3.2 Good Programming Practices 63
~/projects/octmat/
projets\octmat\
Thereby, if for example HOME='C:\Users\username', the code project will be located in the
directory 'C:\Users\username\projets\octmat\MyCodeTest1'.
The projects’ path follows the same rule specified in Section 3.2.1, where projects that run in
OCTAVE and MATLAB should be inside a directory called “octmat”, projects that only run over
OCTAVE should be inside a directory called “octave” and projects that only run over MATLAB
should be inside a directory called “matlab”.
MY_LIBRARY1_DIR='C:\Users\username\lib\octmat\mylibrary1';
addpath(MY_LIBRARY1_DIR);
In turn, if we have a variable MY_LIBRARY2_DIR that represent a library path where the routines are
grouped in subdirectories,
MY_LIBRARY2_DIR='C:\Users\username\lib\octmat\mylibrary2';
the command that adds the path MY_LIBRARY2_DIR and the subdirectories, to OCTAVE/MATLAB
search path is
addpath(genpath(MY_LIBRARY2_DIR));
Instruction 3.4: Adding the directory pointed by variable MY_LIBRARY2_DIR and subdirectories
to OCTAVE/MATLAB search path.
In the last command, the function genpath() returns a list of all subdirectories in MY_LIBRARY2_DIR.
USER_PATH= userpath();
If necessary you can change the user path, for example 'C:\Users\username\anyaddress'
userpath('C:\Users\username\anyaddress');
thus, we can write the Instruction 3.3 or 3.4 in the startup.m file, located in 'USER_PATH' directory,
to automatically load a library.
but depending on how OCTAVE is initiated or configured, the location can be different. This
file can be used to make changes in the OCTAVE default environment to adopt in a particular
project.
Thus, in order to load some libraries automatically, as showed in Instruction 3.3 and 3.4, we can
add these routines in any of these .octaverc files.
Thus, each time OCTAVE starts we need to use the next command to load the mylibrary1 library/-
package.
graphics_toolkit("gnuplot");
only “gnuplot” graphics toolkit supports latex rendering in OCTAVE 4.0; such as “fltk” and “qt”
are not yet supported. Use the function available_graphics_toolkits() to see the complete list
of graphics toolkits
available_graphics_toolkits();
page_screen_output(0);
page_output_immediately(1);
where the function page_screen_output(0) disables the option that sends the output through of
the pager, when this is very long. The function page_output_immediately(1) enables the output
print as soon as it is available.
66 Chapter 3. Getting Started with BSL Tool Library
With this method, the package is configured to be unloaded by default and it should be loaded each
time that OCTAVE starts; the command will be:
After loading, all the functions of BSL Tool Library will be available to be used.
The package is configured to be unloaded by default and it should be loaded each time that OCTAVE
starts. The command will be:
After loading, all the functions of BSL Tool Library will be available.
BSLTL_DIR='C:\Users\username\lib\octmat\bsltl\inst';
addpath(genpath(BSLTL_DIR));
The subdirectory 'inst' is added to the path to load only the functions of the library and not the
configuration files. The function genpath() generates a list with the directories and sub directories
of BSLT L package. The function addpath() add all directories of BSLT L to the search path. More
details about automatically loading the library can be seen in the Subsection 3.2.3.
4. BSL Tool Library cookbook
In this chapter, you will found a set of examples of BSL Tool Library (BSLT L). All examples
assume that there exists an image data package in the directory IMAGESDIR ; for example this
directory can be
IMAGESDIR='~/data/cafe-biospeckle/sem1';
IMAGESDIR='D:\data\cafe-biospeckle\sem1';
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
70 Chapter 4. BSL Tool Library cookbook
Another interesting example is the loading process of 128 images in “bmp” format, loaded from
image “cafe1.bmp” to image “cafe128.bmp”. The word “cafe” means coffee in Portuguese.
DATA=datapack(IMAGESDIR,'cafe',1,128,'bmp');
In both cases, the datapack DATA is a 3-dimensional matrix with NLIN lines
NLIN=size(DATA,1);
NCOL columns
NCOL=size(DATA,2);
NTIMES=size(DATA,3);
Sometimes we see that the images in a datapack DATA have unwanted regions, thus in order to create
a new datapack without these regions, it is possible to crop the DATA with datacut() function.
DATACUT=datacut(DATA);
This function opens a window (Figure 4.1) for interactive graphic selection of two points to define
a new region.
The datapack DATACUT is also a 3-dimensional matrix with NTIMES=128 images, but NLIN and
NCOL are reduced.
Another interesting function is datapack_to_gif(). This function creates a “gif” file with
some characteristics as observed in the example
datapack_to_gif(DATA,'image.gif',10,jet,1);
4.2 Time History Speckle Pattern 71
This function creates, from a datapack DATA, an image with the filename “image.gif”, 10 frames,
and color map “jet” with a delay of 1 frame per second. To see other options of the color map you
can use the OCTAVE/MATLAB comand: help colormap;.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
where the function thsp() makes the time history speckle pattern of one line or column. In this
case, “1” indicates that a line will be used (to select a column you must use the value “2”), and the
selected line is “240”. The result is a 2-dimensional matrix called THSP with the number of lines
equal to the number of columns in the speckle pattern image and the numbers of columns equals
to the number of images of DATA, in this case 128 images, meaning the time. Other examples of
function datapack() can be found in the Section 4.1.
To see the content of THSP matrix, it is possible to use the next code:
imagesc(THSP);colormap gray;grid;
xlabel('k');
ylabel('Points in the image datapack');
title('THSP');
The function imagesc() shows the THSP matrix using all color map levels. Here we used the gray
scale color map. The result can be seen in the Figure 4.2.
THSP
Points in the image datapack
100
200
300
400
Figure 4.2: Time history speckle pat-
20 40 60 80 100 120
tern of a line from a biospeckle col-
k lection of images in a datapack.
Additionally, if you want to make a time history speckle pattern of a set of random uniformly
selected points (PAPOULIS, 1984), you can use the next code:
72 Chapter 4. BSL Tool Library cookbook
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
[THSP POINTS]=thsp_random(DATA,200);
where the function thsp_random() uses 200 points to create the time history speckle pattern in the
THSP matrix; optionally, the function returns the used points.
Another random selection function is the thsp_gaussian(), which uses a Gaussian distribution
(PAPOULIS, 1984) around one point. The next code
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
[THSP POINTS]=thsp_gaussian(DATA,200,25,[250,250],'on');
uses a datapack called DATA, to get the time history speckle pattern from 200 points randomly
selected around the (line, column) = (250, 250); these data are loaded in the variables THSP and
POINTS respectively. The points follow a Gaussian distribution of mean zero and standard deviation
equal to 25. The optional function parameter 'on' enable the graphic output of selected points as
can be seen in the Figure 4.3.
100
200
300
400
Figure 4.3: Randomly selected points
100 200 300 400 following a Gaussian distribution.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
shows how to get the COM matrix from the time history speckle pattern, THSP, of a line in a collection
of images. The line used in this example is the number 240 of datapack DATA. Examples of functions
datapack() and thsp() can be seen in the Sections 4.1 and 4.2.
4.4 Probability Mass Function 73
If you want to plot the COM matrix you can follow the next code:
imagesc(COM);colorbar;grid;
xlabel('j');
ylabel('i');
title('COM');
The graphic seen in the Figure 4.4 represents the dispersion of subsequent pixels in the lines of the
THSP matrix, i.e. the jump of intensity level “i” to “ j” of two consecutive intensity samples within a
THSP matrix. The function imagesc() shows the COM matrix in color, representing the amount of
times the jumps of i → j happens.
COM
40
50
30
100
i
20
150
200 10
Figure 4.4: COM of a line in image
datapack with the color bar represent-
250 0 ing the amount of times the jumps
50 100 150 200 250
j occurred.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
74 Chapter 4. BSL Tool Library cookbook
[Pr Z]=pmfad(COM);
The vectors Pr and Z have 256 elements, representing the probability Pr(|i − j| = z) and the values
of z restricted to 0 ≤ z ≤ 255, being z an integer; both vectors are evaluated from the co-occurrence
matrix COM. In this case, the matrix COM is calculated from the time history speckle pattern (THSP)
at line number 240, which was formed by images from the directory pointed by the IMAGESDIR
variable. Additionally, examples using functions datapack(), thsp() and coom() can be found in
the Sections 4.1, 4.2 and 4.3 respectively.
In order to see the Pr vector content, it is possible to use the next code:
plot(Z,Pr,'--o'),grid
xlabel('|i-j|=z');
ylabel('Probability');
title('Probability Mass Function');
xlim ([0 50]);
The result can be seen in the Figure 4.5. Here, it is easy to note that the highest occurrence
probability is Pr(|i − j| = 1).
0.05
0.04
Probability
0.03
0.02
0.01
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
[Pr W]=pmfrd(COM);
4.5 Numerical Methods 75
The vectors Pr and W have 511 elements, representing the probability Pr(( j − i) = w) and the
values of w restricted to −255 ≤ w ≤ 255, being w an integer. Both vectors are evaluated from the
co-occurrence matrix COM, which in turn is calculated from the time history speckle pattern (THSP)
at the line number 240 of a datapack that was formed by images from the directory pointed by the
IMAGESDIR variable. Additionally, examples using the functions datapack(), thsp() and coom()
can be found in the Sections 4.1, 4.2 and 4.3 respectively.
The probability mass function Pr is shown in the next code:
plot(W,Pr,'--o'), grid on
xlabel('(j-i)=w');
ylabel('Probability');
title('Probability mass function');
xlim ([-50 50]);
The result is shown in Figure 4.6. In the image, it is easy to see that the mean value is w = w∗ ,
being w∗ ≈ 0 . It is very interesting to analyze the case when w∗ > 0 and w∗ < 0; the first case
indicates that the light intensities are growing and will come into saturation. In the second case, the
light intensities are decreasing and will come into darkness.
0.035
0.03
0.025
Probability
0.02
0.015
0.01
0.005
Figure 4.6: Regular probability mass
0 function of a line from a collection of
-40 -20 0 20 40
(j-i)=w images.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
[IM1 IM2]=inertiamoment(COM,2)
76 Chapter 4. BSL Tool Library cookbook
The inertia moment is calculated by the function inertiamoment() from a co-occurrence matrix
COM, which in turn is calculated using the time history speckle pattern (THSP). In this example, it
we used the line number 240 of the datapack DATA that was formed by images from the directory
pointed by the IMAGESDIR variable. Additionally, examples using the function datapack(), thsp()
and coom() can be found in the Sections 4.1, 4.2 and 4.3 respectively. The previous code will return
the information:
By default, the function inertiamoment() returns the inertia moment IM1 with the normalization
of the co-occurrence matrix proposed by Cardoso; Braga (2014); the parameter “2” in the function
inertiamoment() indicates that the function will return a second parameter IM2 of type “2” (with
the normalization of the co-occurrence matrix proposed by Arizaga; Trivi; Rabal (1999)).
It is interesting to note that, if we define the expectation operator E[.] and use the Cardoso’s
normalization, then the inertia moment IM1 is the second moment E[(i − j)2 ] of the probability
mass function Pr((i − j) = w) returned by function pmfrd(), see Section 4.4.2. In this way, if we
√
assume E[i − j] ≈ 0, then the value IM1 = 18.936 can be considered as the standard deviation of
the probability mass function returned by function pmfrd(). The next code generates the Figure
4.7, which shows these relations.
Pr=pmfrd(COM);
Z=[-255:255];
figure(1)
plot(Z,Pr,'--o',sqrt(IM1)*ones(1,17),[0:16]*0.05/16,'--s'),grid
hx=xlabel('(i-j)=w');
hy=ylabel('Probability');
ht=title('Probability Mass Function');
hl=legend('pmfrd()','sqrt(IM1)','location','northwest');
xlim([-30 30]);
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
4.5 Numerical Methods 77
0.03
0.02
0.01
√
Figure 4.7: IM1 and pmfrd() func-
0 tion of a line from a collection of ima-
-30 -20 -10 0 10 20 30
(i-j)=w ges.
COM=coom(THSP);
[AVD1 AVD2 AVD3 AVD4]=avd(COM,2,3,4)
Where
AVD1 is the value of AV D with the normalized co-occurrence matrix proposed by Cardoso; Braga
(2014), being AVD1 = E[|i − j|].
AVD2 is the value of the second moment of AV D with the normalized co-occurrence matrix proposed
by Cardoso; Braga (2014), being AVD2 = E[|i − j|2 ]. This is similar to the inertia moment
technique (ARIZAGA; TRIVI; RABAL, 1999) with the Cardoso’s normalization.
AVD3 is the second central moment of AV D (variance) with the normalized co-occurrence matrix
proposed by Cardoso; Braga (2014), being AVD3 = E[|i − j|2 ] − AVD12 .
AVD4 is the value of AV D with the normalized co-occurrence matrix proposed by Arizaga; Trivi;
Rabal (1999).
Only AVD1 is an obligatory output parameter of function avd(), while the others are enabled by
using of optional input parameters “2,3,4”. This indicates that the function should also return the
values: AVD2 for “2”, AVD3 for “3” and AVD4 for “4”.
All AV D outcomes in the previous code example are calculated from a co-occurrence matrix
COM, which in turn is calculated from the time history speckle pattern (THSP) of the line number 240
of datapack DATA that was formed by images from the directory pointed by the IMAGESDIR variable.
Additionally, examples using the functions datapack(), thsp() and coom() can be found in the
Sections 4.1, 4.2 and 4.3 respectively. The code will return the next information.
So that AVD1 = E[|i − j|] = 13.764 represents the first moment of probability mass function
√ p
Pr(|i − j| = z) and AVD3 = E[|i − j|2 ] − AVD12 = 13.005 represents the second central moment
of probability mass function Pr(|i− j| = z). The next code generates the Figure 4.8 which represents
the relations between the AV D values with the probability mass function Pr(|i − j| = z) returned by
pmfad(), presented in the Section 4.4.1.
[Pr Z]=pmfad(COM);
figure(1)
plot( Z,Pr,'--o', ...
AVD1*ones(1,17),[0:16]*0.085/16,'--s', ...
AVD1-sqrt(AVD3)*ones(1,17),[0:16]*0.065/16,'r--<', ...
AVD1+sqrt(AVD3)*ones(1,17),[0:16]*0.065/16,'r-->'),grid
hx=xlabel('|i-j|=z');
hy=ylabel('Probability');
ht=title('Probability Mass Function');
hl=legend('pmfad()','AVD1','AVD1-sqrt(AVD3)','AVD1+sqrt(AVD3)');
xlim([0 40]);
0.06
0.04
0.02
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
Where
RVD1 is the value of RV D with the normalized co-occurrence matrix proposed by Cardoso; Braga
(2014), being RVD1 = E[ j − i].
RVD2 is the value of the second moment of RV D with the normalized co-occurrence matrix
proposed by Cardoso; Braga (2014), being RVD2 = E[( j − i)2 ]. This is similar to inertia
moment technique (ARIZAGA; TRIVI; RABAL, 1999) with the Cardoso’s normalization.
RVD3 is the second central moment of RV D (variance), with the normalized co-occurrence matrix
proposed by Cardoso; Braga (2014), being RVD3 = E[( j − i)2 ] − RVD12 .
RVD4 is the value of RV D with the normalized co-occurrence matrix proposed by Arizaga; Trivi;
Rabal (1999).
Only RVD1 is an obligatory output parameter of function rvd(), while the others are enabled by
the use of the optional input parameters “2,3,4”. This indicates that the function should also return
the values: RVD2 for “2”, RVD3 for “3” and RVD4 for “4”.
All RV D outcomes in the previous code are calculated from a co-occurrence matrix COM, which
in turn is calculated from the time history speckle pattern (THSP) of the line number 240 in the
datapack DATA which was formed by images from the directory pointed by the IMAGESDIR variable.
Additionally, examples using the functions datapack(), thsp() and coom() can be found in the
Sections 4.1, 4.2 and 4.3 respectively. The code will return the next information.
So that RVD1 = E[ j − i] = 0.0095912 represents the first moment of probability mass function
√ p
Pr(( j − i) = w) and RVD3 = E[( j − i)2 ] − RVD12 = 18.936 represents the second central mo-
ment of probability mass function Pr(( j − i) = w). The next code generates the Figure 4.9, which
represents the relations between the RV D values with the probability mass function Pr(( j − i) = w)
returned by the pmfrd() function, as presented in the Section 4.4.2.
Pr=pmfrd(COM);
N=length(Pr);
W=[0:N-1]-round((N-1)/2);
figure(1)
plot( W,Pr,'--o', ...
RVD1*ones(1,17),[0:16]*0.05/16,'--s', ...
RVD1-sqrt(RVD3)*ones(1,17),[0:16]*0.03/16,'r--<', ...
RVD1+sqrt(RVD3)*ones(1,17),[0:16]*0.03/16,'r-->'),grid
hx=xlabel('(j-i)=w');
80 Chapter 4. BSL Tool Library cookbook
hy=ylabel('Probability');
ht=title('Probability Mass Function');
hl=legend('pmfrd()','RVD1','RVD1-sqrt(RVD3)','RVD1+sqrt(RVD3)');
xlim([-40 40]);
0.03
0.02
0.01
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
COM=coom(THSP);
[NUMAD1 NUMAD2]=numad(COM,2)
Where,
NUMAD1 is the first moment of NUMAD using the normalized co-occurrence matrix proposed by
Cardoso; Braga (2014), where NUMAD1= E[|i − j|/(i + j)].
NUMAD2 is the second moment of NUMAD using the normalized co-occurrence matrix proposed
by Cardoso; Braga (2014), where NUMAD2= E[|i − j|2 /(i + j)2 ].
Only NUMAD1 is an obligatory output parameter of the function numad(), while the other is enabled
by using of optional input parameter “2”. This indicates that the function should also return the
value NUMAD2.
All NUMAD outcomes in the previous code example are calculated from a co-occurrence
matrix COM, which in turn is calculated from the time history speckle pattern (THSP) of the line
number 240 in the datapack DATA , which was formed by images from the directory pointed by the
IMAGESDIR variable. Additionally, examples using the functions datapack(), thsp() and coom()
can be found in the Sections 4.1, 4.2 and 4.3 respectively. The code will return the next information.
4.5 Numerical Methods 81
Please wait...
DATA Pack loaded...[OK]
NUMAD1 = 0.084686
NUMAD2 = 0.013135
So that NUMAD1= E[|i − j|/(i + j)] = 0.084686 represents the first moment of NUMAD and
NUMAD2= E[|i − j|2 /(i + j)2 ] = 0.013135 represents the second moment of NUMAD.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
THSP=thsp(DATA,1,240);
The vectors C1 and C2 have the correlation values of pixel inside of the THSP matrix of the line
number 240 in the datapack DATA formed by images of the directory pointed by the IMAGESDIR
variable. The difference between C1 and C2 lies in that C1 use the correlation proposed by Xu;
Joenathan; Khorana (1995) and C2 uses the Pearson correlation (ZDUNEK et al., 2007). L1 and L2
represent the sample lag for the correlations C1 and C2 respectively.
The next code generates the Figure 4.10, which shows the two types of correlations returned by
the thsp2corr() function, where it is possible to see the similarity between both results. It is also
possible to note that the pixel informations slightly tends to be repeated every 11 samples.
[ax,p1,p2]=plotyy(L1,C1,L2,C2);
Examples using the functions datapack() and thsp() can be found in the Sections 4.1 and 4.2
respectively.
82 Chapter 4. BSL Tool Library cookbook
1 1
0.95
0.99
0.9
C1
C2
0.98 0.85
0.8
0.97
0.75
0.96 0.7
Figure 4.10: Time history speckle pattern to
0 10 20 30 40 50 60
L1 and L2 correlation coefficient.
The next code shows the use of the stscorr() function, which implements a method to analyze the
spatial-temporal speckle correlation between matrices (ZDUNEK et al., 2007) .
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
tau=1;
[C T]=stscorr(DATA,tau,42);
The C vector has the values of spatial-temporal speckle correlation between the images inside of the
datapack DATA, which was formed by the images in the directory pointed by the IMAGESDIR variable.
In this case the matrix (image) in the position 42 of the datapack (DATA(:,:,42)) is correlated
with all other matrices, so that in each correlation one element of the vector C is filled with the
Pearson correlation coefficient. The stscorr() function considers that the images were obtained in
intervals of tau = 1 second. Thus the vector T is returned with these time intervals.
The Figure 4.11 shows the image returned by the stscorr() function, where it is possible to
see a graphic of the C vector versus the T vector.
0.95
Correlation coefficients
0.9
0.85
0.8
Examples using the datapack() function can be found in the Section 4.1.
4.6 Graphic Methods 83
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
FUJII=fujii(DATA);
The FUJII matrix is the result of the Fujii technique application over a datapack DATA formed by
128 images in the directory pointed by the IMAGESDIR variable. Additionally, examples using the
datapack() function can be found in the Section 4.1.
The Figure 4.12 shows the outcome of the FUJII matrix.
Fujii Method
40
100
30
200
20
300
10
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
GENDIFF=gendiff(DATA);
The GENDIFF matrix is the result of the generalized difference method application on a datapack
DATA formed by 128 images in the directory pointed by IMAGESDIR variable. Additionally, examples
using the datapack() function can be found in the Section 4.1.
The gendiff() function has a considerable computational cost, thus it has a verbose output.
Next we can see the outcome of gendiff().
The Figure 4.13 shows the outcome of GENDIFF matrix of a collection of images of a coffee seed.
40
100
30
200
20
300
10
400 Figure 4.13: Map of activities ob-
0 tained by the GD method on a col-
100 200 300 400
lection of images of a coffee seed.
The next code shows the use of stdcont() function, which implements temporal speckle contrast
matrix (NOTHDURFT; YAO, 2005). Additionally, the function returns the temporal speckle
standard deviation matrix and temporal speckle mean matrix.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
[C D E]=stdcont(DATA);
The C matrix is the temporal speckle contrast matrix created from a datapack DATA that was formed
by 128 images in the directory pointed by the IMAGESDIR variable. Additionally, the function returns
the matrices D and E which are the temporal speckle standard deviation matrix and temporal speckle
mean matrix respectively. Examples using the datapack() function can be found in the Section
4.1.
The Figure 4.14 shows the outcome of matrices C, D and E.
4.6 Graphic Methods 85
Images: Speckle Contrast Images: Speckle Standard Deviation
40
0.6
100 100
30
300 300
0.2
10
400 400
0 0
100 200 300 400 100 200 300 400
(a) Temporal speckle contrast matrix C. (b) Temporal speckle standard deviation matrix
D.
Images: Speckle Mean
200
100
150
200
100
300
50
400
Figure 4.14: Matrices returned by stdcont() function, with (a) representing the Temporal speckle
contrast matrix, named C, (b) representing the Temporal speckle standard deviation matrix, named
D, and (c) representing the Temporal speckle mean matrix, named E.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
GIM=graphim(DATA);
The GIM matrix is the result of applying the inertia moment technique on a datapack DATA that was
formed by 128 images in the directory pointed by the IMAGESDIR variable. Additionally, examples
using the datapack() function can be found in the Section 4.1.
The Figure 4.15 shows the outcome of GIM matrix of a coffee seed.
Graphic IM Method
2000
100
1500
200
1000
300
500
400
0 Figure 4.15: Graphic inertia moment
100 200 300 400
method of a coffee seed.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
GAVD=graphavd(DATA);
The GAVD matrix is the result of applying the AV D technique on a datapack DATA that was formed
by 128 images in the directory pointed by the IMAGESDIR variable. Additionally, examples using
the datapack() function can be found in the Section 4.1.
The Figure 4.16 shows the outcome of GAVD matrix of a coffee seed.
30
100
200 20
300
10
400
0 Figure 4.16: Graphic AV D method of
100 200 300 400
a coffee seed.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
4.6 Graphic Methods 87
GRVD=graphrvd(DATA);
The GRVD matrix is the result of applying the RV D technique on a datapack DATA that was formed
by 128 images in the directory pointed by the IMAGESDIR variable. Additionally, examples using
the datapack() function can be found in the Section 4.1.
The Figure 4.17 shows the outcome of GRVD matrix applied in a coffee seed.
100 0.5
200 0
300 -0.5
400 -1
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
GPTD=graphptd(DATA,0.5);
The GPTD matrix is the result of the PT D technique over a datapack DATA that was formed by
128 images in the directory pointed by the IMAGESDIR variable. Additionally, examples using the
datapack() function can be found in the Section 4.1.
The Figure 4.18 shows the outcome of the GPTD matrix applied in a coffee seed.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
LIN=240; LIN_WIDE=64;
COL=320; COL_WIDE=64;
88 Chapter 4. BSL Tool Library cookbook
100
4
200 3
2
300
1
400
0 Figure 4.18: Parameterized form of
100 200 300 400
Temporal Difference method.
PORTIONDATA=DATA(LIN+[0:LIN_WIDE-1],COL+[0:COL_WIDE-1],:);
[K D E]=graphkurt(PORTIONDATA);
MEAN=mean2(K)
STDDEV=std2(K)
The K matrix is the kurtosis of a datapack PORTIONDATA, which, in turn, is a portion of the datapack
DATA that was formed by 128 images in the directory pointed by the IMAGESDIR variable. In this
case, PORTIONDATA is a portion of 64 × 64 pixels from the position (line, column) = (240, 320). In
the last code, the graphkurt() function also returns the temporal speckle standard deviation matrix
D and the temporal speckle mean matrix E (NOTHDURFT; YAO, 2005). Additionally, the spatial
mean (MEAN) and the spatial standard deviation (STDDEV) of K matrix are calculated. See the results
of the code presented above:
Here, it is interesting to note that the kurtosis value of Gaussian random variable is 3.0. The last
result shows that the kurtosis of random variables in PORTIONPACK is closed to a Gaussian type. The
Figure 4.19 shows the content of K matrix in a graphic mode applied in a coffee seed.
Examples using the datapack() function can be found in the Section 4.1.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
4.6 Graphic Methods 89
LIN=240; LIN_WIDE=64;
COL=320; COL_WIDE=64;
PORTIONDATA=DATA(LIN+[0:LIN_WIDE-1],COL+[0:COL_WIDE-1],:);
[S D E]=graphskew(PORTIONDATA);
MEAN=mean2(S)
STDDEV=std2(S)
The S matrix is the skewness of a datapack PORTIONDATA, which, in turn, is a portion of the datapack
DATA that was formed by 128 images in the directory pointed by the IMAGESDIR variable. In this
case, PORTIONDATA is a portion of 64 × 64 pixels from the position (line, column) = (240, 320).
The graphskew() function also returns the temporal speckle standard deviation matrix D and the
temporal speckle mean matrix E (NOTHDURFT; YAO, 2005). The last code also calculates the
spatial mean (MEAN) and the spatial standard deviation (STDDEV) of S matrix, with the outcome
presented highlighted:
Here, it is interesting to note that the skewness value of the Gaussian random variable is 0.0. The
last result shows that the skewness of random variables in PORTIONPACK is closed to a Gaussian
type. The Figure 4.20 shows the content of S matrix in a graphic mode applied in a coffee seed and
the examples using the datapack() function can be found in the Section 4.1.
90 Chapter 4. BSL Tool Library cookbook
10
1.5
20
1
30
0.5
40
0
50
-0.5
60 -1
Figure 4.20: Temporal speckle skew-
10 20 30 40 50 60
ness matrix of a coffee seed.
The next code shows the use of graphmhi() function, which implements the motion history image
technique (DAVIS, 2001).
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
MHI=graphmhi(DATA,11);
The MHI matrix is the result of applying the motion history image technique on a datapack DATA
that was formed by 128 images in the directory pointed by the IMAGESDIR variable. In this case, a
threshold of 11 is used, and it means that only intensity values larger than 11 are considered activity
changes. The Figure 4.21 shows the content of the MHI matrix. Examples using the datapack()
100
200
300
400
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
IMAGE1=DATA(:,:,1);
[Img S D]=satdark(IMAGE1,8,8,20,150,50);
The Img matrix is an image with dark and saturated areas manually introduced in some regions of
the speckle pattern, in this case over the first image IMAGE1 of the datapack DATA of a coffee seed.
The datapack was formed by the images in the directory pointed by the IMAGESDIR variable. In this
case, windows with 8 × 8 pixels were used to analyze the saturation and the sub-exposition. The
satdark() function considers that the windows are saturated when more than 50 percent of pixels
are greater than the gray level 150. On th other hand, the function consider the windows in darkness
or sub-exposed to laser light when more than 50 percent of pixels are lower than the gray level 20.
Additionally, the function returns the S and D matrix, which are matrices with values “0” or “1”.
The S matrix has values “1” in the pixels with saturation, and The D matrix has values “1” in the
pixels with darkness, in accordance with the levels offered as input. The Figures 4.22, 4.23a and
4.23b show the content of matrices Img, S and D, respectively.
Preview
250
100 200
150
200
100
300
50
400 Figure 4.22: Image with dark or sat-
0 urated areas of a coffee seed, in this
100 200 300 400
case introduced manually.
Examples using the datapack() function can be found in the Section 4.1.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
92 Chapter 4. BSL Tool Library cookbook
Saturation Zone Image Dark Zone Image
1 1
0.6 0.6
200 200
0.4 0.4
300 300
0.2 0.2
400 400
0 0
100 200 300 400 100 200 300 400
(a) Image with saturated areas. (b) Image with dark areas.
IMAGE1=DATA(:,:,1);
[C mC]=sscont(IMAGE1,8,8);
The C matrix is the windowed spatial speckle contrast (CARDOSO; BRAGA; RABAL, 2012)
over the first image IMAGE1 of the datapack DATA. The datapack was formed by the images in the
directory pointed by the IMAGESDIR variable. In this case, windows with 8x8 pixels were used. In
each window,the spatial speckle contrast is calculated within the C matrix. This value indicates
the relation between the spatial standard deviation and the spatial mean value. Additionally, the
function returns the mC value, that is the mean value of the contrasts in all windows in C. The Figure
4.24 shows the content of C matrix.
100 0.4
200 0.3
300
0.2
Examples using the datapack() function can be found in the Section 4.1.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
[Y X]=homogeneity(DATA,8,8,0);
The Y matrix represents the homogeneity (CARDOSO; BRAGA; RABAL, 2012) percentages in
the windows of a datapack DATA that was formed by 128 images in the directory pointed by the
IMAGESDIR variable. In this case, windows of 8 × 8 pixels were created and the inertia moment
method (ARIZAGA; TRIVI; RABAL, 1999) was applied in each one (Type 0). Additionally, the
function returns the X matrix, where each element of X represents the spatial mean value of inertia
moment in the windows of Y.
The homogeneity() function, in the last code, returns a graphical outcome with the inertia
moment activity indicator (see Figure 4.25a) and the homogeneity Y matrix (see Figure 4.25b).
100 100 80
800
600 60
200 200
400 40
300 300
200 20
400 400
0
100 200 300 400 100 200 300 400
Examples using the datapack() function can be found in the Section 4.1.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
ORDER=32;
The code implements a filtering scheme in frequency bands, the same as shown in the Figure 4.26,
where a datapack DATA that was formed by 128 images in the directory pointed by the IMAGESDIR
variable is separated in datapacks, { DATA1, DATA01, DATA001, DATA000 } with signals, each one
pertaining to a specific frequency band. In the first step we used a low pass H0 FIR filter, with
cut-off at 1/2 of Fs /2 (half the sampling frequency), and the signal in the datapack DATA is divided
into the datapacks DATA0 and DATA1, with the frequency bands [0, Fs /4] and [Fs /4, Fs /2] respectively.
In the second step, using a low pass G0 FIR filter, with cut-off at 1/4 of Fs /2, the signal in the
datapack DATA0 is divided into the datapacks DATA00 and DATA01 with the frequency bands [0, Fs /8]
and [Fs /8, Fs /4] respectively. And finally, similarly to the last cases a low pass W0 FIR filter with
cut-off at 1/8 of Fs /2 is used to separate DATA00 in DATA000 and DATA001, with the frequency bands
[0, Fs /16] and [Fs /16, Fs /8] respectively.
At this point, we have a set of datapacks separated in frequency bands, in which we can apply
any of the biospeckle analysis methods seen in the last sections. For example, the next code uses
the AV D method in graphic mode on the datapacks { DATA1, DATA01, DATA001, DATA000 }.
GAVD =graphavd(DATA,'off');
GAVD_ =graphavd(DATA1+DATA01+DATA001+DATA000,'off');
GAVD1 =graphavd(DATA1,'off');
GAVD01 =graphavd(DATA01,'off');
GAVD001=graphavd(DATA001,'off');
GAVD000=graphavd(DATA000,'off');
The next code generates the Figure 4.27, which shows the results of comparing the matrices GAVD
and GAVD_, that means the result of the AV D graphic activity indicator over the datapack DATA and
its homologue evaluated from a datapack formed by summing DATA1+ DATA01+ DATA001+ DATA000.
4.8 Frequency Analysis 95
figure(1);
imagesc(GAVD,[0 36]);colorbar;
title('Graphic AVD method');
figure(2);
imagesc(GAVD_,[0 36]);colorbar;
title('Graphic AVD method');
30 30
100 100
200 20 200 20
300 300
10 10
400 400
0 0
100 200 300 400 100 200 300 400
(a) AV D method in graphic mode of a data- (b) AV D method in graphic mode of a data-
pack DATA. pack formed by summing DATA1+ DATA01+
DATA001+ DATA000.
Figure 4.27: Comparison between the AV D graphic activity indicator of the datapack DATA and its
homologue evaluated from a datapack formed by the reconstructed signal.
Finally, the next code generates the Figure 4.28, which shows the result comparing the matrices
GAVD1, GAVD01, GAVD001 and GAVD000 with the same color map. The matrices are the results of the
AV D graphic activity indicator on the datapacks DATA1, DATA01, DATA001 and DATA000, respectively.
figure(3);
imagesc(GAVD1,[0 36]);colorbar;
title('Graphic AVD method');
figure(4);
imagesc(GAVD01,[0 36]);colorbar;
title('Graphic AVD method');
figure(5);
imagesc(GAVD001,[0 36]);colorbar;
title('Graphic AVD method');
figure(6);
imagesc(GAVD000,[0 36]);colorbar;
title('Graphic AVD method');
96 Chapter 4. BSL Tool Library cookbook
Graphic AVD method Graphic AVD method
30 30
100 100
200 20 200 20
300 300
10 10
400 400
0 0
100 200 300 400 100 200 300 400
(a) AV D method in graphic mode of a data- (b) AV D method in graphic mode of a dat-
pack DATA1. Frequency band between Fs /4 apack DATA01. Frequency band between
and Fs /2 hertz. Fs /8 and Fs /4 hertz.
Graphic AVD method Graphic AVD method
30 30
100 100
200 20 200 20
300 300
10 10
400 400
0 0
100 200 300 400 100 200 300 400
(c) AV D method in graphic mode of a dat- (d) AV D method in graphic mode of a data-
apack DATA001. Frequency band between pack DATA000. Frequency band between 0
Fs /16 and Fs /8 hertz. and Fs /16 hertz.
Figure 4.28: Comparison between the AV D graphic activity indicator of datapacks in different
frequency bands.
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
ORDER=33;
H0=qmfmaker(ORDER);
The code implements a decomposition scheme in coefficients with information of frequency bands,
same as shown in the Figure 4.29.
The datapack DATA was formed by L = 128 images (samples) in the directory pointed by
IMAGESDIR variable and it is separated in datapacks, {DATA11, DATA10, DATA01, DATA00}, with
informations that pertain, each one, at a specific frequency band. In the first step we use a QMF filter,
and the signal in the datapack DATA, with L samples is decomposed in the datapacks (coefficients)
DATA0 and DATA1, with informations of frequency bands [0, Fs /4] and [Fs /4, Fs /2] respectively, both
outputs having dL/2e images. In the second step two QMF filters are used, and the datapacks
DATA0 and DATA1 are decomposed in the coefficients {DATA00, DATA01} and {DATA10, DATA11},
with informations of frequency bands {[0, Fs /8], [Fs /8, Fs /4]} and {[Fs /4, 3Fs /8], [3Fs /8, Fs /2]}
respectively, all outputs having dL/4e images.
At this point it is important to note that the coefficients {DATA11, DATA10, DATA01, DATA00} do
not have an immediate relation with the datapack DATA, and to reconstruct this signal it is necessary
to apply the Inverse Discrete Wavelet Transform (IDW T ) to the coefficients.
DATA0_ = firsynthesisbank(DATA00,DATA01,H0);
DATA1_ = firsynthesisbank(DATA10,DATA11,H0);
98 Chapter 4. BSL Tool Library cookbook
DATA_ = firsynthesisbank(DATA0_,DATA1_,H0);
The code implements a reconstruction scheme as shown in the Figure 4.30, where the coef-
ficients {DATA00, DATA01, DATA10, DATA11} were obtained with a decomposition as presented in
Figure 4.29. All the QMF filters in synthesis mode implemented with the firsynthesisbank()
function receive as input parameter a H0 FIR filter, with cut-off frequency at Fs /4, which is the
same used in the decomposition scheme shown in the Figure 4.29. Thus, H0 is used to calculate the
filters G0 and G1 used in the synthesis blocks in the Figure 4.30.
In the first step of the reconstruction scheme, the coefficients {DATA00, DATA01} and {DATA10,
DATA11}, with L = 32 samples each one, are used by two QMF filters in synthesis mode to get the
reconstructed coefficients DATA0_ and DATA1_, with 2L samples, homologous to the coefficients
DATA0 and DATA1 in the Figure 4.29. In the second step, the coefficients DATA0_ and DATA1_ are used
by QMF filter in synthesis mode, and a datapack DATA_ is recovered, which is the reconstructed
version of DATA seen in the scheme of Figure 4.29.
We can compare the original datapack and the reconstructed version using any of the biospeckle
analysis method seen in the last sections; for example, we can use the PT D method in graphic
mode:
The Figure 4.31 shows the matrices GPTD and GPTD_, that are the results of the PT D method in
graphic mode on the datapack DATA and your homologue DATA_.
4.8 Frequency Analysis 99
Graphic PTD Method with P=0.8 Graphic PTD Method with P=0.8
15 15
100 100
10 10
200 200
300 300
5 5
400 400
0
100 200 300 400 100 200 300 400
(a) PT D method in graphic mode of a data- (b) PT D method in graphic mode of a data-
pack DATA. pack DATA_.
Figure 4.31: Comparison between the PT D activity indicator of datapack DATA and DATA_.
Figure 4.32: Reconstruction scheme of a coefficient with the analysis path [i, j].
The code implements, for each coefficient obtained in the decomposition scheme of Figure
4.29, a reconstruction branch as shown in the Figure 4.32. Where, following the name notation used
in the decomposition scheme, the end part of the coefficient names indicates the decomposition
path used in their creation. For example, the datapack DATAij follows the decomposition path [i j].
Thus, all the steps implemented with the firsynthesispath() function follow an inverse path of
the decomposition. Finally, the firsynthesispath() function reconstructs the information in the
100 Chapter 4. BSL Tool Library cookbook
coefficient DATAij using a H0 FIR filter and the decomposition path [i j]. H0 is used to calculate
the filters G0 and G1, being H0 a filter with cut-off frequency at Fs /4, and it is the same used in
the decomposition scheme shown in the Figure 4.29. The datapacks {DATA00_, DATA01_, DATA10_,
DATA11_} represent the reconstructed signals of the coefficients {DATA00, DATA01, DATA10, DATA11}
respectively. So that, each signal DATAij_ has the information of the frequency band i j. Thus, we
can say that, DATA__, the sum of all DATAij_ signals, is equivalent to the reconstructed signal DATA_
seen in the Section 4.8.3.
Having the datapacks {DATA00_, DATA01_, DATA10_, DATA11_}, we can compare them using
any of the biospeckle analysis methods seen in the last sections; by example we can use the AV D
method in graphic mode:
GAVD11_ = graphavd(DATA11_,'off');
GAVD10_ = graphavd(DATA10_,'off');
GAVD01_ = graphavd(DATA01_,'off');
GAVD00_ = graphavd(DATA00_,'off');
The next code generates the Figure 4.33, which shows the matrices { GAVD11_, GAVD10_,
GAVD01_, GAVD00_ } with the same color map.
figure(3);
imagesc(GAVD11_,[0 27.062]);colorbar;
title('Graphic AVD method');
figure(4);
imagesc(GAVD10_,[0 27.062]);colorbar;
title('Graphic AVD method');
figure(5);
imagesc(GAVD01_,[0 27.062]);colorbar;
title('Graphic AVD method');
figure(6);
imagesc(GAVD00_,[0 27.062]);colorbar;
title('Graphic AVD method');
The first step to work with the Continuous Wavelet Transform (CW T ) of a discrete signal is to
choose the mother wavelet. In this sense, the next code shows a way to get a set between the
domains {−3.5, +3.5}, of Morlet wavelets (MORLET et al., 1982a; MORLET et al., 1982b),
according to the CW T scheme shown in the Figure 4.34b, where a datapack DATA is decomposed
4.8 Frequency Analysis 101
Graphic AVD method Graphic AVD method
25 25
100 100
20 20
200 15 200 15
10 10
300 300
5 5
400 400
0 0
100 200 300 400 100 200 300 400
(a) GAVD11_ matrix. Frequency band be- (b) GAVD10_ matrix. Frequency band be-
tween 3Fs /8 and Fs /2 hertz. tween Fs /4 and 3Fs /8 hertz.
Graphic AVD method Graphic AVD method
25 25
100 100
20 20
200 15 200 15
10 10
300 300
5 5
400 400
0 0
100 200 300 400 100 200 300 400
(c) GAVD01_ matrix. Frequency band be- (d) GAVD00_ matrix. Frequency band be-
tween Fs /8 and Fs /4 hertz. tween 0 and Fs /8 hertz.
Figure 4.33: AV D method in graphic mode of the datapacks {DATA00_, DATA01_, DATA10_,
DATA11_}.
PSI0=PSI0/sum(PSI0.^2);
PSI1=PSI1/sum(PSI1.^2);
PSI2=PSI2/sum(PSI2.^2);
As it can be seen, the code gets the vectors PSI0, PSI1 and PSI2, that represent the wavelets ψ0 ,
ψ1 and ψ2 with 33, 65 and 129 points respectively; so that the wavelet ψi is a 2i scaled function of
mother wavelet ψ0 , and all wavelets use their middle element to represent the sample in the time
zero. The code also normalize the amplitude to fulfill the wavelet condition (POPOV; ZHUKOV,
2009).
102 Chapter 4. BSL Tool Library cookbook
Once the creation of the wavelets is completed, we can see the frequency response using the
freqmod() function, which has two input parameters, the first is a vector that represents a wavelet
to analyze and the second parameter is the resolution (number of points) of the frequency response.
The function returns two vectors, the first is the modulus of Fourier transform of the studied wavelet,
and the second is the normalized frequency for each element of the first vector. The normalization
is performed so that the value 2 represents the frequency sampling value Fs . Thus, the next code
shows the use of the freqmod() function over the vectors PSI0, PSI1 and PSI2.
2
Freq. response of PSI0
Freq. response of PSI1
Freq. response of PSI2
1.5
|Magnitude|
0.5
(b) CW T scheme of
0
0 0.2 0.4 0.6 0.8 1 datapack DATA.
W/pi normalized frequency
Figure 4.34a shows graphically the frequency response of wavelets. It is easy to see that, by
using of a scaled factor 2i in the creation of wavelets, if the wavelet ψ0 is centered in the frequency
F0 , then the wavelet ψi will be centered in the frequency F0 /2i .
figure(1);
plot(F0,FR0,'-o',F1,FR1,'-s',F2,FR2,'->');
legend( 'Freq. response of PSI0', ...
'Freq. response of PSI1', ...
'Freq. response of PSI2');
ylabel('|Magnitude|');
xlabel('W/\pi normalized frequency');
Once the wavelets are defined, we can decompose a datapack DATA (signal of Figure 4.34b)
convolving it with the wavelets. The next code shows the use of the datapack_conv() function,
which implements the convolution of two signals, where the first input parameter is a datapack DATA,
which represents the input signal and the second is a vector, which represents the impulse response
of the convolver block. Thus, the convolution is performed on the scope of the first parameter, and
4.9 Extra Functions 103
the number of samples that returns the function is the same as in the DATA. The datapack DATA was
formed by 128 images (samples) in the directory pointed by the IMAGESDIR variable.
DATA = datapack(IMAGESDIR,'',1,128,'bmp');
DATA0 = datapack_conv(DATA,PSI0);
DATA1 = datapack_conv(DATA,PSI1);
DATA2 = datapack_conv(DATA,PSI2);
The datapacks DATA0, DATA1 and DATA2 conform to the CW T of datapack DATA, and their signals
represent DATA portions according to the frequency response shown in the Figure 4.34a. The next
code shows the analysis of these datapacks using the AV D method in graphic mode.
GAVD0 = graphavd(DATA0,'off');
GAVD1 = graphavd(DATA1,'off');
GAVD2 = graphavd(DATA2,'off');
The next code generates the Figure 4.35, which shows graphically the comparison of the
matrices GAVD0, GAVD1 and GAVD2, using the same color map.
figure(2);
imagesc(GAVD0,[0 18.226]);colorbar;
title('Graphic AVD method');
figure(3);
imagesc(GAVD1,[0 18.226]);colorbar;
title('Graphic AVD method');
figure(4);
imagesc(GAVD2,[0 18.226]);colorbar;
title('Graphic AVD method');
DATA=datapack(IMAGESDIR,'',1,128,'bmp');
GAVD=graphavd(DATA,'off');
WLines=7;
WColumns=7;
GAVDW = mwindowing(GAVD,WLines,WColumns);
104 Chapter 4. BSL Tool Library cookbook
Graphic AVD method Graphic AVD method
15 15
100 100
200 10 200 10
300 300
5 5
400 400
0 0
100 200 300 400 100 200 300 400
(a) GAVD0 matrix. Frequency band centered (b) GAVD1 matrix. Frequency band centered
in F0 . in F0 /2.
Graphic AVD method
15
100
200 10
300
5
400
0
100 200 300 400
Figure 4.35: AV D method in graphic mode of the datapacks DATA0, DATA1 and DATA2.
The code returns the GAVDW matrix, filled with the mean values of the analysis windows in
the GAVD matrix; being that, the GAVD matrix was segmented in windows of WLines×WColumns
pixels. This matrix is the result of applying the AV D method in graphic mode over a datapack DATA,
that was formed by 128 images in the directory pointed by the IMAGESDIR variable. Additionally,
examples using the functions datapack() and graphavd() can be found in the Section 4.1 and
Section 4.6.5, respectively.
The next code generates a set of graphics comparing the matrices GAVD and GAVDW. The
figure(1) and figure(2) show the matrices GAVD and GAVDW, respectively. In both cases the same
color map are used. By other side, the figure(3) shows GAVDW matrix; so that, the blue and red
colors represent the minimum and maximum values in the matrix. All these graphics can be seen in
the Figure 4.36.
figure(1);
imagesc(GAVD,[0,35.654]);
colorbar;
title('Graphic AVD method');
figure(2);
4.9 Extra Functions 105
imagesc(GAVDW,[0,35.654]);
colorbar;
title('Mean values in the graphic AVD method');
figure(3);
imagesc(GAVDW);
colorbar;
title('Mean values in the graphic AVD method');
200 20
200 20
300
10
300
10
400
0 400
100 200 300 400
0
100 200 300 400
(a) Graphic representation of GAVD matrix.
(b) Graphic representation of GAVDW matrix
with the same color map as in the figure (a).
Mean values in the graphic AVD method
100 20
200 15
300 10
400 5
M = [ [0 10 20 30]; ...
[30 20 20 10]; ...
[0 10 2 0]; ...
]
106 Chapter 4. BSL Tool Library cookbook
[A B]=threshold2d(M,20)
The matrix A is a truncated version of matrix M, so that any value of A is greater than 20 and all
values greater than 20 are replaced by 20. Additionally, the threshold2d() function returns the B
matrix so that A + B = M, as presented highlighted.
M =
0 10 20 30
30 20 20 10
0 10 2 0
A =
0 10 20 20
20 20 20 10
0 10 2 0
B =
0 0 0 10
10 0 0 0
0 0 0 0
The hbpmf() function implements the binary entropy from a probability mass function. For example,
the next code calculates the binary entropy H≡ Hb (A, B) of two random variables A and B; with
possible values {A0 , A1 , A2 } and {B0 , B1 , B2 , B3 } respectively; and with a joint probability mass
function P≡ Pr(A, B) as shown in the Table 4.1.
Pr(A, B) B0 B1 B2 B2
A0 0.0 0.1 0.2 0.1
A1 0.1 0.2 0.0 0.1
A2 0.0 0.1 0.1 0.0
SUM=sum(sum(P))
H=hbpmf(P)
4.9 Extra Functions 107
Here, it is important to note that the sum of all elements in P should be 1.0 given that this is a
probability. The result can be seen highlighted:
SUM = 1
H = 2.9219
5. Additional Informations
1. What do I need to proceed when this message appears: Warning: your version of
GraphicsMagick limits images to 8 bits per pixel
This message is only a warning, and it means that GraphicsMagick can only work with
images of 8 bits per pixel. The BSLT L package was written for working with 8 bits, so there
is no problem in the BSLT L applications. However, if this message is annoying you, the
problem can be solved by compiling the last stable version of GraphicsMagick (currently
v.1.3.21). Before compiling the GraphicsMagick, all dependencies should be installed. In
GNU/Linux, you can do it using this instruction in the Terminal:
Bibliography . . . . . . . . . . . . . . . . . . . . . . . 157
Books
Sites
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
6. Functions’ Descriptions
DATA = datapack(IMGDIR,IMGNAME,IMGN1,IMGN2,IMGFMT);
DATA = datapack(IMGDIR,IMGNAME,IMGN1,IMGN2,IMGFMT,LPOS,CPOS,NLIN,NCOL);
114 Chapter 6. Functions’ Descriptions
Inputs:
IMGDIR - is the directory path where the images are. These images should have their
names in the following format NAME=[IMGNAME,'num','.',IMGFMT]. For ex-
ample, the images could have the following names: fig1.bmp, fig2.bmp,
..., fig128.bmp, so that, for this case, IMGNAME='fig', IMGFMT='bmp' and
num will be an integer with values from IMGN1=1 to IMGN2=128.
IMGNAME - is the pre-name of the file. For example: if the files in IMGDIR are tagged as
fig1.bmp, then IMGNAME='fig'.
IMGN1 - is the index of the first image. For example: if the files have names from
fig1.bmp to fig128.bmp, then IMGN1=1.
IMGN2 - is the index of last image. For example: if the files have names from fig1.bmp
to fig128.bmp, then IMGN2=128.
IMGFMT - is the file format of the images. For example: if the files are tagged as fig1.bmp,
then IMGFMT='bmp'.
LPOS - [Optional]. It is the first line position of a region of interest (ROI) in the images.
When it is used this optional parameter, CPOS, NLIN and NCOL are mandatory
and the datapack is formed by the ROI. If this parameter is not used, then the
datapack is formed with the complete image.
CPOS - [Optional]. It is the first column position of a ROI.
NLIN - [Optional]. It is the number of lines of a ROI.
NCOL - [Optional]. It is the number of columns of a ROI .
Output:
DATACUT = datacut(DATA);
% Load the indexes of LINES and COLUMNS cropped in the datapack DATA.
[DATACUT LINES COLUMNS]= datacut(DATA);
Input:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN and
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
Outputs:
DATACUT - is the cut part of the speckle datapack (DATA), where DATACUT is a 3D matrix
created by grouping NTIMES cut parts of DATA.
LINES - [Optional] is a vector with two elements, which are the first line and the last
line in the cut part of DATA.
COLUMNS - [Optional] is a vector with two elements, which are the first column and the
last column in the cut part of DATA.
h=datapack_to_gif(DATA,Filename,Frames);
datapack_to_gif(DATA,Filename,Frames);
datapack_to_gif(DATA,Filename,Frames,Map);
datapack_to_gif(DATA,Filename,Frames,Map,Time);
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
Filename - is the name of the gif file.
Frames - is the number of frames in the gif file.
Map - [Optional] is the color map, where the value can be: jet, gray, hsv, ..., etc. By
default it is jet. For example, see the command: colormap('list')
Time - [Optional] is the time between frames in the gif file. By default it is 0.5 sec.
Output:
Figure 6.2: Time history speckle pattern construction. Evolution on time of a set of M points in the
speckle image. Thus, this set of points will be represented in the lines of a T HSP matrix, and the
column represents the evolution on time
these two options. NTIMES represents the number of images in the datapack and 1 ≤ k ≤ NTIMES.
Therefore, the T HSP pattern is a matrix where each column is a representation of only one line or
column in the S position of all Ik matrices whereas the other lines or columns are discarded (Figure
6.3).
For using this function, just type the following command at the prompt:
Y = thsp(DATA,R,S);
Inputs:
DATA - is the speckle datapack, where DATA is a 3D matrix created by grouping NTIMES
intensity matrices with NLIN lines and NCOL columns. When N=size(DATA),
then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
R - is a parameter to define if one line or column is to be analyzed over time:
if R is equal to 1, you choose the lines from the images to make the THSP and
if R is equal to 2, you choose the columns, otherwise an error occurs.
S - is the line or column position used to make the time history speckle pattern.
The function does not verify if S is in the range, so the user has to check it
previously.
Output:
Y - is the THSP matrix, where Y is a 2D matrix with M lines and NTIMES columns. M
is equal to NCOL when R is 1, or M is equal to NLIN when R is 2. Y is a matrix
where each column is a representation of only one line or column in the position
S of DATA.
6.2.3 Function thsp_random() - Time History Speckle Pattern of a Random Points Set
This function creates the Time History Speckle Pattern (T HSP) from a set of M points selected
randomly, following a uniform distribution to choose the positions in the first image of the datapack.
The pattern THSP is a 2D matrix with M lines and NTIMES columns, where M is the number of selected
random points in each image Ik for 1 ≤ k ≤ NTIMES, where NTIMES is the number of images. Thus,
the main point here is that the pixels of the first column of the T HSP represent a set of points
chosen in the first image. These points, randomly selected in the first image, stand still and appear
in the same position in the other NTIMES-1 images.
For using this function, just type the following commands at the prompt:
Inputs:
DATA - is the speckle datapack, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then N(1,1)
represents NLIN and N(1,2) represents NCOL and N(1,3) represents NTIMES.
M - is the number of points, randomly selected.
Outputs:
THSP - is the time history speckle pattern matrix, where THSP is a 2D matrix with M
lines and NTIMES columns.
POINTS - [Optional]. It is a matrix with two columns and M lines. Thus, each line
represents each of the random points with their position in the image. The
first element of points represents the line position, and the second, the column
position.
6.2.4 Function thsp_gaussian() - Time History Speckle Pattern of a Random Points Set
with Gaussian Distribution
This function creates the Time History Speckle Pattern (T HSP) from a set of randomly selected M
points, following a 2D Gaussian distribution around the point P0 in the first image I1 ≡ DATA(:, :, 1),
and through Ik ≡ DATA(:, :, k), ∀k. These points are concentrated mostly in a radius Sigma around
P0. The pattern T HSP is a 2D matrix with M lines and NTIMES columns. Thus, the main point here
is that the pixels in the first column of the T HSP are a set of points in the first image. The random
points selected in this image stand still and appear in the same position in the other NTIMES-1
images, following a Gaussian distribution.
For using this function, just type any of the following commands at the prompt:
6.3 Creating and Working with the Co-occurrence Matrix 119
THSP = thsp_gaussian(DATA,M,Sigma);
Inputs:
DATA - is the speckle datapack, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then N(1,1)
represents NLIN and N(1,2) represents NCOL and N(1,3) represents NTIMES.
M - is the number of points, randomly selected following a Gaussian distribution.
Sigma - is the standard deviation in pixels.
P0 - [Optional] is the initial point, around which M point are selected to create the
time history speckle pattern. If this parameter is not used then a window is
enabled in order to select a point P0.
SHOW - [Optional] It can be used in the last position of input. It enables a graphic
output of the selected points in the THSP. SHOW='on' for enabling, SHOW='off'
by default.
Outputs:
THSP - is the time history speckle pattern matrix, where THSP is a 2D matrix with M
lines and NTIMES columns.
POINTS - [Optional]. is a matrix with two columns and M lines. Thus, each line represents
each of the random points with their position in the image.
The Co-occurrence Matrix (COM), is also known as GLCM (gray-level co-occurrence matrix),
GLCH (gray-level co-occurrence histogram) or spatial dependence matrix. Formally, the co-
occurrence matrix (HARALICK; SHANMUGAM; DINSTEIN, 1973) of an image I of M lines and
N columns is defined, for each pixel I(x, y) ∈ I, as in the Equation (6.1).
1, if I(x, y) = a
and I(x + ∆x, y + ∆y) = b
M N
C∆x,∆y (a, b) = ∑ ∑ and 1 ≤ x + ∆x ≤ M (6.1)
x=1 y=1
and 1 ≤ y + ∆y ≤ N
0, otherwise
120 Chapter 6. Functions’ Descriptions
This function calculates the Co-occurrence Matrix (COM) (ARIZAGA; TRIVI; RABAL, 1999).
The coom() function represents the case when in the Equation (6.1) (∆x, ∆y) = (0, 1), and the
matrix under analysis is a time history speckle pattern (THSP) matrix, where time is represented in
the columns. Thus, the co-occurrence COM matrix returned by coom() function is calculated as in
the Equation (6.2)
1, if THSP(i, j) = a
M N−1
COM(a, b) = ∑ ∑ and THSP(i, j + 1) = b (6.2)
i=1 j=1
0, otherwise
Thus, the co-occurrence matrix represents the occurrences of intensity jumps, between any two
consecutive points. Thus, the matrix can be understood as the quantity of times that: any pixel
in any instant k with intensity Ik (x, y) ≡ Ik = i, has an intensity jump to intensity Ik+1 = j in the
instant k + 1 , see Figure 6.4.
To use this function just type the following command at the prompt:
COM = coom(THSP);
Input:
THSP - is an integer 2D matrix that represents the time history speckle pattern. This
matrix can be obtained by using the function thsp() seen in the Section 6.2.
For this purpose it is necessary that the THSP matrix only has values between
0 and 255, since the function does not make this verification and it truncates
values outside this interval.
Output:
COM - is a 2D matrix, with 256 lines and 256 columns, which represents the co-
occurrence matrix of the THSP matrix. The element COM(a, b) in the COM matrix
represents the quantity of times that, in two successive columns of the THSP
matrix, the intensity values changed from a − 1 to b − 1.
6.3 Creating and Working with the Co-occurrence Matrix 121
For using this function, just type any of the following commands at the prompt:
Pr = pmfad(COM);
[Pr Z] = pmfad(COM);
Input:
COM - is the co-occurrence matrix, which is a 2D matrix with 256 lines and 256
columns.
Outputs:
Pr - is a vector with the probability mass function Pr(|i − j| = z), where Pr(z+1) is
the probability of happening an absolute intensity jump of value z, ∀ 0 ≤ z ≤ 255.
Pr is a vector with 256 elements.
Z - [Optional] is a vector with the absolute intensities jumps |i − j| = z, so that
Z=[0:255].
Pr = pmfrd(COM);
[Pr W] = pmfrd(COM);
122 Chapter 6. Functions’ Descriptions
Input:
COM - is the co-occurrence matrix, which is a 2D matrix with 256 lines and 256
columns.
Outputs:
Pr - is a vector with the probability mass function Pr(( j − i) = w), where Pr(w+256)
is the probability of happening an absolute intensity jump of value w, ∀ −255 ≤
w ≤ 255. Pr is a vector with 511 elements.
W - [Optional] is a vector with the intensities jumps ( j − i) = w, so that
W=[-255:255].
The Inertia Moment (IM) (ARIZAGA; TRIVI; RABAL, 1999) analyzes the square difference
between the intensity values Ik = i in time k, and the intensity Ik+1 = j in time k + 1 for any value
of k. Thus, the IM method (Equation 6.3) gets a measurement of relative square intensity jump
value, in a same region, between the consecutive images Ik and Ik+1 ,
IM = ∑ Mi j (i − j)2 . (6.3)
ij
The last equation shows that the IM value is a weighted value of (i − j)2 , where the weighting
factor Mi j is calculated from the co-occurrence matrix, COM (Equation 6.4). Many authors have a
different way to do the weighting. For example, Arizaga; Trivi; Rabal (1999) define
COM(i, j)
Mi j = . (6.4)
∑m COM(i, m)
On the other hand Cardoso; Braga (2014) define Mi j as in the Equation (6.5),
COM(i, j)
Mi j = . (6.5)
∑lm COM(l, m)
This latter approach is particularly interesting since Mi j can be seen as the probability mass function
of happening a square intensity jump from i to j, thus, the weighting factor will be Mi j ≡ Pr(i → j).
Thus, the IM value will be the expected value of (i − j)2 , also known as first moment of (i − j)2 ,
IM = E[(i − j)2 ] (Equation 6.6). The Table 6.1 shows the types of inertia moments known in the
literature.
Where the IM moment (IM1 ) is:
COM(i, j)
E[(i − j)2 ] = ∑ (i − j)2 . (6.6)
ij ∑lm COM(l, m)
6.4 Calculating the Inertia Moment 123
And, the IM moment following Arizaga; Trivi; Rabal (1999) (IM2 ) is presented as in the
Equation (6.7),
COM(i, j)
EAriz. [(i − j)2 ] = ∑ (i − j)2 . (6.7)
ij ∑m COM(i, m)
This function returns the Inertia Moment (IM) (ARIZAGA; TRIVI; RABAL, 1999). The inertiamo
ment() function needs a co-occurrence matrix COM as input and calculates the two types of IM
values shown in Table 6.1. By default the inertiamoment() function returns the IM1 , see (6.6), but
this function accepts one second parameter. See Table 6.1.
For using this function, just type any of the following commands at the prompt:
IM1 = inertiamoment(COM);
% If it is necessary to get IM2
[IM1 IM2] = inertiamoment(COM,2);
Inputs:
COM - is a 2D matrix, with 256 lines and 256 columns, which represents a co-
occurrence matrix of a THSP matrix, see section 6.2. The element COM(a, b) in
the co-occurrence matrix represents the quantity of times that, in two successive
columns of a THSP matrix, the intensity values jumps from a − 1 to b − 1.
TYPE - [Optional] When this parameter is used, the function returns an additional
result in the same position of output.
If TYPE is equal to 2, the function also returns the IM2 (see Table 6.1).
Outputs:
The Absolute Value of the Differences (AV D) method (BRAGA et al., 2011) is a modification of
the Inertia Moment (IM) (ARIZAGA; TRIVI; RABAL, 1999). where we analyze the absolute
difference between the intensity value Ik = i in time k, and the intensity Ik+1 = j in time k + 1
for any value of k. Thus, the AVD method (Equation 6.8) presents a measurement relative to the
absolute intensity jump value between the consecutive images, Ik and Ik+1 ,
AV D = ∑ Mi j |i − j|. (6.8)
ij
The last equation shows that the AV D value is a weighted value of |i − j|, where the weighting factor
Mi j is calculated from the co-occurrence matrix COM, as seen in section 6.3 and 6.4.1. The AV D
value will be the expected value of |i − j|, also known as first moment of |i − j|, AV D = E[|i − j|].
The Table 6.2 shows the types of AV D known in the literature.
COM(i, j)
E[|i − j|] = ∑ |i − j| (6.9)
ij ∑lm COM(l, m)
COM(i, j)
E[(i − j)2 ] = ∑ (i − j)2 (6.10)
ij ∑lm COM(l, m)
And the AV D first moment following Arizaga; Trivi; Rabal (1999) (AV D4 ) is:
COM(i, j)
EAriz. [|i − j|] = ∑ |i − j| (6.12)
ij ∑m COM(i, m)
This function returns the Absolute Value of the Differences (AV D) (BRAGA et al., 2011). The
avd() function needs a co-occurrence matrix COM as input and calculates the types of AV D values
shown in Table 6.2. By default, the avd() function returns the AV D1 , see (6.9), but this function
accepts more parameters.
For using this function, just type any of the following commands at the prompt:
AVD1 = avd(COM);
% If it is necessary to get AVD2
[AVD1 AVD2] = avd(COM,2);
% If it is necessary to get all AVD types.
[AVD1 AVD2 AVD3 AVD4] = avd(COM,2,3,4);
% The order of input parameters is relative to
% the order of output values.
[AVD1 AVD4 AVD3 AVD2] = avd(COM,4,3,2);
Inputs:
COM - is a 2D matrix, with 256 lines and 256 columns, which represents a co-
occurrence matrix of a THSP matrix (section 6.2). The element COM(a, b)
in the co-occurrence matrix represents the quantity of times that, in two con-
secutive columns of a THSP matrix, the intensity values jump from a − 1 to
b − 1.
TYPE - [Optional] This parameter can be used many times. When it is used this
parameter the function returns an additional result in the same position.
If TYPE is equal to 2, the function also returns the AV D2 , see Table 6.2.
If TYPE is equal to 3, the function also returns the AV D3 , see Table 6.2.
If TYPE is equal to 4, the function also returns the AV D4 , see Table 6.2.
Outputs:
The Regular Value of the Differences (RV D) method is a modification of the Inertia Moment (IM).
The RV D analyzes the difference between the intensity value Ik = i in time k, and the intensity
Ik+1 = j in time k + 1 to any value of k. Thus, the RV D method (Equation 6.13) measures a relative
jump between the consecutive images, Ik and Ik+1 .
RV D = ∑ Mi j ( j − i) (6.13)
ij
The last equation shows that the RV D value is a weighted value of ( j − i), where the weighting
factor Mi j is calculated from the co-occurrence matrix, COM, seen in Section 6.3. Many authors have
a different way to calculate this factor. For example, Arizaga; Trivi; Rabal (1999) define Mi j as
in Equation (6.4). On the other hand, Cardoso; Braga (2014) define Mi j as in Equation (6.5) This
latter approach is particularly interesting since Mi j can be seen as the probability mass function of
an intensity jump from i to j, so the weighting factor Mi j ≡ Pr(i → j). Known this, the RV D value
will be the expected value of ( j − i), also known as first moment, RV D = E[ j − i]. The Table 6.3
shows all types of RV D known in the literature.
COM(i, j)
E[ j − i] = ∑ ( j − i) (6.14)
ij ∑lm COM(l, m)
COM(i, j)
E[( j − i)2 ] = ∑ ( j − i)2 (6.15)
ij ∑lm COM(l, m)
6.6 Calculating the Regular Value of the Differences 127
And the RV D first moment following Arizaga; Trivi; Rabal (1999) (RV D4 ) is:
COM(i, j)
EAriz. [ j − i] = ∑ ( j − i) (6.17)
ij ∑m COM(i, m)
This function returns the Regular Value of the Differences (RV D). The rvd() function needs a
co-occurrence matrix COM as input and calculates all RV D types shown in Table 6.3. By default, the
rvd() function returns the RV D1 , see Equation (6.14).
For using this function, just type any of the following commands at the prompt:
RVD1 = rvd(COM);
% If it is necessary to get RVD2
[RVD1 RVD2] = rvd(COM,2);
% If it is necessary to get all RVD types.
[RVD1 RVD2 RVD3 RVD4] = rvd(COM,2,3,4);
% The order of input parameters is relative to
% the order of output values.
[RVD1 RVD4 RVD3 RVD2] = rvd(COM,4,3,2);
Inputs:
COM - is a 2D matrix, with 256 lines and 256 columns, which represents a co-
occurrence matrix of a THSP (Section 6.2). The element COM(a, b) in the co-
occurrence matrix represents the quantity of times that, in two successive
columns of a THSP matrix, the intensity values jump from a − 1 to b − 1.
TYPE - [Optional] This parameter can be used many times. When it is used, the
function returns an additional result in the same position.
If TYPE is equal to 2, the function also returns the RV D2 (Table 6.3).
If TYPE is equal to 3, the function also returns the RV D3 (Table 6.3).
If TYPE is equal to 4, the function also returns the RV D4 (Table 6.3).
Outputs:
|i − j|
NUMAD = ∑ Mi j (6.18)
ij i+ j
The last equation shows that the NUMAD value is a weighted value of |i − j|/(i + j), where the
weighting factor Mi j is calculated from the co-occurrence matrix COM, as seen in section 6.3. The
NUMAD value is the expected value of |i − j|/(i + j), also known as first moment of |i − j|/(i + j),
so that NUMAD = E[|i − j|/(i + j)]. The Table 6.4 shows the types of NUMAD values known in
the literature (REIS; RABAL; BRAGA, 2016).
NUMAD1 = numad(COM);
6.8 Calculating the Correlation in the Speckle Pattern 129
Inputs:
COM - is a 2D matrix, with 256 lines and 256 columns, which represents a co-
occurrence matrix of a THSP matrix (Section 6.2). The element COM(a, b)
in the co-occurrence matrix represents the quantity of times that, in two con-
secutive columns of a THSP matrix, the intensity values jump from a − 1 to
b − 1.
TYPE - [Optional] When this parameter is used the function returns an additional result
in the second position.
If TYPE is equal to 2, the function also returns the NUMAD2 (Table 6.4). Other-
wise, an error occurs.
Outputs:
Two types of correlations used in the analysis of the biospeckle images can be found in the literature.
We rename them as correlation Type 1 and Type 2 as seen in the Table 6.5.
TYPE DESCRIPTION
1 The correlation coefficient, used by Xu; Joe-
nathan; Khorana (1995) (Equation 6.21).
2 The Pearson correlation coefficient, used by
Zdunek et al. (2007) (Equation 6.22).
The Equation (6.21) shows the correlation coefficient (Type 1) of a and b, including the
continuous part of signal,
< ab >
corr(a, b) ≡ √ . (6.21)
< a2 >< b2 >
The Equation (6.22) shows the correlation coefficient (Type 2) of a and b, excluding the continuous
part of signal,
Where the operator < . > is the spatial expected operator; and the values µa =< a > and µb =<
p
b > are the spatial mean values of matrices or vectors a and b. In addition, σa = < (a − µa )2 >
p
and σb = < (b − µb )2 > are the spatial standard deviation values of a and b.
This function calculates the space-time speckle correlation technique (XU; JOENATHAN; KHO-
RANA, 1995). This calculates the correlation between the pixels analyzed in the time history
speckle pattern. Thus, we use, as input data, the matrix THSP of M lines and NTIMES columns,
which represents the intensity time evolution of M pixels in NTIMES samples. So that, the correla-
tion Cil (Equation 6.23) is calculated between all pixels T HSP(:, i) in the instant i and the pixels
T HSP(:, i + j) in the instant i + j,
The function finally returns, Cl (Equation 6.24), the mean value of this correlations for a lag of l,
NT IMES/2
1
Cl = ∑ Cil . (6.24)
NT IMES/2 i=1
We can use two types of correlation functions corr(), as shown in Table 6.5.
For using this function, just type any of the following commands at the prompt:
C = thsp2corr(THSP);
C = thsp2corr(THSP,TYPE);
[C L] = thsp2corr(THSP);
[C L] = thsp2corr(THSP,TYPE);
% Getting the vector C, with the Pearson correlation coefficients,
% and the sample lag vector (L).
[C L] = thsp2corr(THSP,2);
Inputs:
THSP - is an integer 2D matrix that represents the time history speckle pattern. This
matrix can be obtained using the function thsp().
TYPE - [Optional]
If TYPE is equal to 1, the function uses the Type 1 correlation, see Table 6.5.
If TYPE is equal to 2, the function uses the Type 2 correlation, see Table 6.5.
By default TYPE is equal to 1.
Outputs:
where corr() function is the correlation Type 2 seen in the Table 6.5.
To use this function just type any of the following commands at the prompt:
C = stscorr(DATA,Tau,K0)
[C LTau] = stscorr(DATA,Tau,K0)
[C LTau L] = stscorr(DATA,Tau,K0)
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
Tau - is the sampling rate in seconds.
K0 - is the number of the reference frame used in correlation analysis.
Outputs:
matrices Ik ≡ DATA(:, :, k), 1 ≤ k ≤ NTIMES, as can be seen in the Equation (6.26). Thus, the matrix
operations are made element by element,
NTIMES−1
|Ik − Ik+1 |
FUJII = ∑ . (6.26)
k=1 Ik + Ik+1 + eps
The original Fujii technique does not have the eps term. In Octave/Matlab eps is the distance from
1.0 to the next largest double-precision number ( eps = 2−52 ).
2 × 100
Y = FUJII (6.27)
NTIMES − 1
Ik +Ik+1
Where (NTIMES − 1) is the number of elements in the sum, 2 is a factor to turn 2 a mean
value and 100 is a percentage factor. Thus, the Y matrix (Equation 6.28) represents the expected
Ik +Ik+1
percentage value of the absolute difference |Ik − Ik+1 | relative to the mean value 2 for any two
consecutive values. In other words Y is the average percentage change of |Ik − Ik+1 |.
" #
|Ik − Ik+1 |
Y = 100 E Ik +Ik+1
(6.28)
2
For using this function, just type any of the following commands at the prompt:
Y = fujii(DATA);
% Disabling the graphical output.
Y = fujii(DATA,'off');
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off', then the result is not plotted. By
default, SHOW='on'.
Output:
M−1 M−k
GD = ∑ ∑ |Ik − Ik+l | (6.29)
k=1 l=1
The function is normalized to Y (Equation 6.30) with the number of elements in the sum.
GD
Y= M
(6.30)
2
M
is the binomial coefficient of M and 2. This is the number of combinations of M items
Where 2
taken 2 at a time. Thus Y matrix represents the expected value of absolute difference |Ik1 − Ik2 |
(Equation 6.31) for any two different k1 and k2 values.
For using this function, just type any of the following commands at the prompt:
Y = gendiff(DATA);
% Disabling the graphical output.
Y = gendiff(DATA,'off');
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
To get the temporal speckle contrast image, first it is necessary to get the temporal speckle
mean matrix (Equation 6.32), µ, as
NTIMES
1
µ = E[Ik ] = ∑ Ik , (6.32)
NTIMES k=1
We use here the population standard deviation. Finally, the temporal speckle contrast image can be
calculated using the Equation (6.34),
σ
Contrast = (6.34)
µ
For using this function, just type any of the following commands at the prompt:
The function returns the temporal speckle contrast matrix, and additionally returns the temporal
speckle standard deviation and the temporal speckle mean matrix following the Equations (6.32),
(6.33) and (6.34).
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off', then the result is not plotted. By
default, SHOW='on'.
6.9 Graphical Methods 135
Outputs:
NTIMES−1
1
GIM = E[(Ik − Ik+1 )2 ] = ∑ (Ik − Ik+1 )2 (6.35)
NTIMES − 1 k=1
For using this function, just type any of the following commands at the prompt:
GIM = graphim(DATA);
This function also shows a figure with the GIM method outcome.
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
graphavd() uses, as input data, a 3D matrix (DATA) created by grouping intensity matrices Ik ≡
DATA(:, :, k), 1 ≤ k ≤ NTIMES.
NTIMES−1
1
GAV D = E[|Ik − Ik+1 |] = ∑ |Ik − Ik+1 | (6.36)
NTIMES − 1 k=1
For using this function, just type the following command at the prompt:
GAVD = graphavd(DATA);
This function also shows a figure with the GAV D method outcome.
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
NTIMES−1
1
GRV D = E[Ik+1 − Ik ] = ∑ (Ik+1 − Ik ) (6.37)
NTIMES − 1 k=1
For using this function, just type any of the following commands at the prompt:
GRVD = graphrvd(DATA);
This function also shows a figure with the GRV D method outcome.
6.9 Graphical Methods 137
Inputs:
DATA - is the speckle data. Where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
This function implements the Parameterized form of Temporal Difference (PT D) (MINZ; NIRALA,
2014) method. The function graphptd() returns a normalized matrix with the values of PT D
method (Equation 6.38). It uses, as input data, a 3D matrix (DATA) created by grouping intensity
matrices Ik ≡ DATA(:, :, k), 1 ≤ k ≤ NTIMES.
Thus, the PT D method is shown in the next equation
NTIMES−1
PT D = ∑ |Ik − Ik+1 | p . (6.38)
k=1
The last expression is normalized to Equation (6.39) with the number of elements in the sum
PT D
GPTD = E[|Ik − Ik+1 | p ] = . (6.39)
NTIMES − 1
So that, GPTD matrix represents the expected value of the absolute difference |Ik − Ik+1 | p for any k
value.
For using this function, just type any of the following commands at the prompt:
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
This function implements the temporal speckle kurtosis (SHESKIN, 2003) matrix. It uses, as input
data, a 3D matrix (DATA) created by grouping intensity matrices Ik ≡ DATA(:, :, k), 1 ≤ k ≤ NTIMES.
In order to get the temporal speckle kurtosis matrix, first it is necessary to get the temporal
speckle mean matrix, µ, and the temporal speckle standard deviation matrix, σ , as presented
in Equations (6.32) and (6.33). Thus, the temporal speckle kurtosis matrix is calculated as the
Equation (6.40),
" 4 #
Ik − µ
K=E . (6.40)
σ
For using this function, just type any of the following commands at the prompt:
The function returns the temporal speckle kurtosis matrix and additionally returns the temporal
speckle standard deviation matrix and temporal speckle mean matrix following the Equations (6.32),
(6.33) and (6.40).
6.9 Graphical Methods 139
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping matrices
with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Outputs:
For using this function, just type any of the following commands at the prompt:
The function returns the temporal speckle skewness matrix and additionally returns the temporal
speckle standard deviation matrix and the temporal speckle mean matrix following the Equations
(6.32), (6.33) and (6.40).
140 Chapter 6. Functions’ Descriptions
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Outputs:
S - Returns a matrix that represents the temporal speckle skewness of image data-
pack.
D - [Optional] Returns a matrix that represents the temporal speckle standard
deviation of image datapack.
E - [Optional] Returns a matrix that represents the temporal speckle mean of image
datapack.
This function implements the Motion History Image (MHI) technique (GODINHO et al., 2012;
DAVIS, 2001). The function considers the activity of a pixel, which should have an absolute
intensity jump superior to U. It uses, as input data, a 3D matrix (DATA) created by grouping intensity
matrices Ik ≡ DATA(:, :, k), 1 ≤ k ≤ NTIMES.
The calculus of MHI matrix, that is the result of applying the MHI technique, can be seen in the
Equations (6.42), (6.43), (6.44) and (6.45).
Sk = Ik − Ik−1 . (6.42)
1 if |Sk (i, j)| > U
Tk (i, j) = (6.43)
0 if |Sk (i, j)| ≤ U
NTIMES−2
MHI = 255 ∑ TNTIMES−i hi , (6.44)
i=0
being that
NTIMES − 1 − i
hi = (6.45)
M
6.10 Frequency Analysis 141
MHI=graphmhi(DATA,U);
% Disabling the graphical output.
MHI=graphmhi(DATA,U,'off');
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
U - is the activity threshold. Only the changes of intensity larger than U. 0 ≤ U ≤ 255
are considered an activity
SHOW [Optional] If SHOW is equal to string 'off' then the result is not plotted. By
default, SHOW='on'.
Output:
MHI - is the motion history image matrix of datapack. The elements with highest gray
values in the matrix address to most recent activities.
H(Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.46)
where M2 = bM/2c.
Thus, the elements of H vector represent an impulse response function, h[n], with the value hM2
142 Chapter 6. Functions’ Descriptions
in the instant n = 0, and value 0 for n < −M2 or M − 1 − M2 < n. The convolution of datapack
DATA and the vector H return in the datapack DATAOUT, and the operation is applied in the scope of
DATA, so that the size of DATAOUT is equal to the size of DATA.
Thus, the datapacks DATA and DATAOUT are 3D matrices created by grouping intensity matrices
Ik ≡ DATA(:, :, k) and Ok ≡ DATAOUT(:, :, k) respectively, for 1 ≤ k ≤ NTIMES (Equation 6.47). The
convolution aforementioned can be expressed as
NTIMES
Ok = ∑ Ii h[k − i]. (6.47)
i=1
For using this function, just type the following command at the prompt:
DATAOUT = datapack_conv(DATA,H)
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
H - is a vector with M elements, which represents the impulse response function
h[n], while the M2 = bM/2c element represents the h[0] value.
Output:
DATAOUT - is a datapack, where DATAOUT is a 3D matrix with the same size of DATA and is
the result of the convolution of DATA and H.
H0 (Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.48)
where the value hM2 represents the value in the instant n = 0 and M2 = bM/2c. Similarly, the vector
H1 follows the same formation rule of vector H0.
The firfilterbank() function implements two modes (Figure 6.6), as seen in the Table 6.6.
For using this function, just type any of the following commands at the prompt:
TYPE DESCRIPTION
'MODE0' This mode is composed of two non-causal FIR filters, represented by H0 and H1
as seen in the Figure 6.6a. Thus, it can accept as input parameter a H0 filter or, the
H0 and H1 filters.
If only the H0 filter is delivered as input parameter, then the H1 filter is calculated
as the complement filter of H0, so that H1 (Z) = 1 − H0 (Z).
'MODE2' This mode uses two non-causal FIR filters, H0 and H1, as seen in the Figure
6.6b. The difference with the mode 'MODE0' is that it only can accept H0 as input
parameter and should have an even number of elements, M.
The H1 filter will be calculated as the quadrature mirror filter (AGRAWAL; SAHU,
2013) of H0; so that H1 (Z) = H0 (−Z). Finally after the filters, H0 and H1, there
are down-samplers by 2.
Thus, this mode is commonly used with a low pass H0 non-causal FIR filter with
cut-off in Fs /4, being Fs the sampling frequency. For perfect reconstruction, it is
necessary that H02 (Z) − H02 (−Z) ≡ AZ B for any A and B real.
(a) Step of FIR filter bank. (b) Quadrature mirror filter in analysis mode.
Inputs:
DATA - is the speckle data, where DATA is a 3D matrix created by grouping NTIMES
matrices with NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
FILTER - is a matrix (with 2 lines) or a vector, where FILTER=H0 or FILTER=[H0;H1]. H0
and H1 represent two FIR filters. FILTER=H0 is used in the mode 'MODE2', while
FILTER=H0 or FILTER=[H0;H1] can be used in the mode 'MODE0'.
MODE - is the mode type used in the step filter bank. It can be 'MODE0' or 'MODE2'.
Outputs:
DATA0 - is obtained after the output of H0 filter, when each pixel of datapack DATA is sent
as input. If the used mode has a down-sampler after the filter, then DATA0 is the
output of the down-sampler.
DATA1 - is obtained after the output of H1 filter, when each pixel of datapack DATA is sent
as input. If the used mode has a down-sampler after the filter, then DATA1 is the
output of the down-sampler.
The function accepts a H0 filter as input parameter, so that the filters G0 and G1 are calculated as
its function of this. The H0 filter must be a low-pass FIR filter with cut-off at Fs /4, being Fs the
sampling frequency.
6.10 Frequency Analysis 145
If H0 = [h0 , h1 , h2 , ..., hM−1 ], then its Z transform is expressed by the Equation (6.49),
H0 (Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.49)
where the value hM2 represents the value in the instant n = 0 and M2 = bM/2c. Thus, the filters G0
and G1 are calculated as G0 (Z) = H0 (Z) and G1(Z) = −H0 (−Z).
The input datapacks, DATA0 and DATA1 are the outputs of a quadrature mirror filter in analysis
mode, as in the function firfilterbank() in MODE='MODE2'. Thus, in order to have a perfect
reconstruction of inputs it is necessary that the H0 filter fulfills the following H02 (Z) − H02 (−Z) ≡
AZ B for any real A and B.
For using this function, just type the following command at the prompt:
DATA=firsynthesisbank(DATA0,DATA1,H0);
Inputs:
Output:
DATA - is the synthesis of the speckle datapacks DATA0 and DATA1. The number of
images inside DATA is twice the number of images inside DATA0 and DATA1.
The function uses a set of blocks Bi to reconstruct DATA, with 1 ≤ i ≤ L, with L being the number of
elements of the binary vector SEQ= [ j1 , j2 , ..., jL ], so that ∀i, ji ∈ {0, 1}. Each reconstruction block
Bi is composed of:
• An up-sampler by 2,
• A gain of 2 and
• A non-causal G ji FIR filter.
As shown in Figure 6.8, the blocks B1 , B2 , B3 , ... and BL are called in inverse order to the vector
SEQ.
If the H0 = [h0 , h1 , h2 , ..., hM−3 , hM−2 , hM−1 ] then its Z transform is expressed by the Equation
(6.50),
H0 (Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.50)
M2 = bM/2c and the filters G0 and G1 are calculated as G0 (Z) = H0 (Z) and G1 (Z) = −H0 (−Z)
respectively.
If a datapack DATA is reconstructed as in the Figure 6.9, then in order to have a perfect
reconstruction of signal in the DATA obtained at the end of a path SEQ, it is necessary that the H0
filter, delivered to the firsynthesispath() function, fulfill the following H02 (Z) − H02 (−Z) ≡ AZ B
for any real A and B.
Figure 6.9: Datapack DATA obtained at the end of a path SEQ=[0 1 1].
For using this function, just type the following command at the prompt:
DATAOUT=firsynthesispath(DATA,H0,SEQ);
Inputs:
Output:
DATAOUT - is the synthesis of the speckle datapack DATA. The number of images inside
DATAOUT is 2L times the number of images of DATA, L being =length(SEQ).
H(Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.51)
with M2 = bM/2c and the element hM2 representing the value in the instant n = 0. Known this, we
can describe the expression returned by the freqmod() function as: a vector AH of N elements with,
|H(e jw )|, and the modulus of the frequency response of the system with 0 ≤ w ≤ π. The function
also returns a vector FREQN with the normalized frequency for each analyzed point in the vector
AH, so that a value equal to a, in the FREQN vector, represents w = aπ or in other words a frequency
aFs /2, Fs being the frequency sampling.
For using this function, just type any of the following commands at the prompt:
Inputs:
H - is a vector [h0 , h1 , h2 , ..., hM−1 ] with the parameters of the impulse response h[n].
The element hM2 represents the value in the instant n = 0.
N - is the number of analysis points in the frequency response.
Outputs:
for any real A and B, so that, the standard deviation of the values in |D(eiw )| is the minimum to
0 ≤ w ≤ π.
For using this function, just type any of the following commands at the prompt:
H=qmfmaker(ORDER);
The Figure 6.10 shows an example of |D(eiw )| of a low-pass FIR filter, H, of ORDER=31 and with
cut-off at Fs /4.
Input:
ORDER - is the order of H = [h0 , h1 , ..., hORDER ] FIR filter. The function tries to fulfill
D(Z) ≡ H 2 (Z) − H 2 (−Z) = AZ B for any real A and B. For this reason, the
number of elements of FIR filter must be even and consequently the ORDER
should be odd.
6.10 Frequency Analysis 149
1.01
1
1.008
0.8
1.006
|D(exp(i w))|
|D(exp(i w))|
0.6
1.004
0.4
1.002
0.2 1
0 0.998
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
w/pi w/pi
(a) Frequency response, |D(eiw )|, for 0 ≤ (b) Zoom of frequency response in the figure
w ≤ π. (a). showing the small ripples in details.
Output:
H - is a vector with the parameters of a low-pass FIR filter with a cut-off at Fs /4,
Fs being the sampling frequency.
H0 (Z) = h0 Z +M2 + h1 Z +M2 −1 + ... + hM2 + ... + hM−1 Z +M2 −(M−1) , (6.53)
H1=qmfmirror(H0);
[H1 AD FREQN]=qmfmirror(H0);
[H1 AD FREQN]=qmfmirror(H0,N);
Inputs:
Outputs:
This function returns the binary entropy H of a probability mass function Pr(a) or Pr(a, b) following
the Equations (6.54) and (6.55) respectively,
For using this function, just type the following command at the prompt:
H=hbpmf(Pr);
Input:
Pr - is a probability mass function. The sum of all values Pr(a, b) could be 1.0.
Output:
The threshold2d() function uses a matrix X as input parameter and returns another matrix X1
similar to X, but with elements smaller than the thresholded value U. Thus, all elements in X superior
to U are truncated to U, creating X1.
For using this function, just type any of the following commands at the prompt:
X1=threshold2d(X,U);
[X1 X2]=threshold2d(X,U);
Inputs:
Outputs:
This function divides the MAT matrix in windows of WLines lines and WColumns columns, then the
mean value of all elements is calculated. With this information, a new matrix MATW is created with
the same size and as the MAT, and the mean values in the MAT matrix are replaced in all elements in
the MATW matrix for each window.
For using this function, just type any of the following commands at the prompt:
MATW = mwindowing(MAT,WLines,WColumns);
% Mean values, in analysis windows of 8x10 pixels, in the MAT matrix.
MATW = mwindowing(MAT,8,10);
Inputs:
Output:
Inputs:
Outputs:
F - is an image with dark or saturated areas in a region of interest (ROI). The dark
windows are filled with 0, and the saturated windows with 255. A window is
considered as dark or saturated, when a collection of values within the matrix
overcomes a percentage established by the user in the ROI.
S - is a matrix with the same size of F, which has ones in regions with saturated
windows and zeros in other ROI’s.
D - is a matrix with the same size of F, which has ones in regions with dark windows
and zeros in other ROI’s.
spatial mean µ l seen in the Equation (6.57). All the pixels in analysis windows are filled with the
contrast value Cl ,
σl
Cl = , (6.56)
µl
where
and
q
l
σ = < (W l − µ l )2 >. (6.58)
For using this function, just type any of the following commands at the prompt:
[C,mC] = sscont(DATAFRAME,WLines,WColumns);
% Windows analysed (ROI) of 6x5 pixels.
[C,mC] = sscont(DATAFRAME,6,5);
Inputs:
Outputs:
Homogeneity of spatial variability (CARDOSO; BRAGA; RABAL, 2012) divides a datapack (DATA)
in 3D analysis windows (or sub datapacks) of NTIMES matrices with WLines lines and WColumns
columns, where DATA is a 3D matrix grouping intensity matrices Ik ≡ DATA(:, :, k), 1 ≤ k ≤ NTIMES.
In these windows we calculate the activity indicator selected with the input variable Type. Once the
activity indicator value A(i, j) of window (i, j) is known for all windows, the homogeneity values
H(i, j) are calculated as 1 the Equation (6.59),
C(i, j)
H(i, j) = 100 1 − , (6.59)
Cmax
where the value C(i, j) is calculated as in the Equations (6.60), (6.61), (6.62), and (6.63),
σZ (i, j)
C(i, j) = , (6.60)
µZ (i, j)
1
µZ (i, j) = Z (i, j) (l), (6.61)
5∑l
1
σZ2(i, j) = (Z (i, j) (l) − µZ (i, j) )2 , (6.62)
5∑l
and Cmax represent the maximum value of spatial contrast of all C(i, j) values.
For using this function, just type any of the following commands at the prompt:
[Y X] = homogeneity(DATA,WLines,WColumns,Type);
Inputs:
DATA - is the speckle data. Where DATA is a 3D matrix grouping NTIMES matrices with
NLIN lines and NCOL columns. When N=size(DATA), then
N(1,1) represents NLIN,
N(1,2) represents NCOL and
N(1,3) represents NTIMES.
WLines - is the number of lines in the ROI.
WColumns - is the number of columns in the ROI.
Type - If Type is 1, AVD (BRAGA et al., 2011) is used as activity indicator. If Type
is 2, it is used the temporal speckle standard deviation as activity indicator
(NOTHDURFT; YAO, 2005). Otherwixe, the inertia moment (ARIZAGA;
TRIVI; RABAL, 1999) technique is used as activity indicator. In the cases of
AV D and inertia moment, the Cardoso’s normalization (CARDOSO; BRAGA,
2014) is used over the co-occurrence matrix. In all cases, the activity indicators
were calculated over all pixels in the window and not only over a line.
6.12 Quality Tests 155
Outputs:
[Mor+82a] MORLET, J. et al. Wave propagation and sampling theory-Part I: Complex signal
and scattering in multilayered media. In: Geophysics 47(2): 203–221. 1982.
[Mor+82b] MORLET, J. et al. Wave propagation and sampling theory-Part II: Sampling theory
and complex waves. In: Geophysics 47(2): 222–236. 1982.
[NY05] NOTHDURFT, R.; YAO, G. Imaging obscured subsurface inhomogeneity using laser
speckle. In: Optics Express 13(25): 10034–10039. 2005.
[OTD89a] OULAMARA, A.; TRIBILLON, G.; DUVERNOY, J. Biological Activity Measure-
ment on Botanical Specimen Surfaces Using a Temporal Decorrelation Effect of
Laser Speckle. In: Journal of Modern Optics 36: 165–179. 1989.
[OTD89b] OULAMARA, A.; TRIBILLON, G.; DUVERNOY, J. Biological Activity Measure-
ment on Botanical Specimen Surfaces Using a Temporal Decorrelation Effect of
Laser Speckle. In: Journal of Modern Optics 36(2): 165–179. 1989.
[Pap84] PAPOULIS, A. Probability, Random Variables, and Stochastic Processes. McGraw-
Hill Series in Electrical Engineering. McGraw-Hill. ISBN: 9780070484689. 1984.
[PZ09] POPOV, A.; ZHUKOV, M. Computation of continuous wavelet transform of discrete
signals with adapted mother functions. In: Proc. SPIE 7502: pages. 2009.
[RB08] RABAL, H. J.; BRAGA, R. A. Dynamic Laser Speckle and Applications. Optical
Science and Engineering. CRC Press. Avaiable at:https://books.google.com.b
r/books?id=T4MA_XtWAwMC . 2008.
[RRB16] REIS, R. O.; RABAL, H. J.; BRAGA, R. A. Light intensity independence during
dynamic laser speckle analysis. In: Optics Communication 366: 185–193. 2016.
[She03] SHESKIN, D. J. Handbook of Parametric and Nonparametric Statistical Proce-
dures: Third Edition. CRC Press. 2003.
[VH92] VETTERLI, M.; HERLEY, C. Wavelets and filter banks: theory and design. In:
Signal Processing, IEEE Transactions on 40(9): 2207–2232. 1992.
[XJK95] XU, Z.; JOENATHAN, C.; KHORANA, B. M. Temporal and spatial properties of the
time-varying speckles of botanical specimens. In: Optical Engineering 34(5): 1487–
1502. 1995.
[Zdu+07] ZDUNEK, A. et al. New nondestructive method based on spatial-temporal speckle cor-
relation technique for evaluation of apples quality during shelf-life. In: International
Agrophysics 21(3): 305–310. 2007.
Websites
[BPM] BRAGA, R. A.; PUJAICO RIVERA, F.; MOREIRA, J. Biospeckle Laser Tool
Library v1.0.0. Avaiable at:http://repositorio.ufla.br/handle/1/11116 ,
visited on 04/29/2016.
160 Chapter 6. Functions’ Descriptions
A F
AD FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Fujii . . . . . . . . . . . . . . . . . . . . . . . 41, 83, 131 Frequency Analysis . . . . . . . . . . . . . 47, 93, 141
AVD . . . . . . . . . . . . . . . . . . . 46, 76, 85, 124, 135 Convolution . . . . . . . . . . . . . . . . . . . . . . . 141
CWT . . . . . . . . . . . . . . . . . . . . . . . . . . 50, 100
DWT . . . . . . . . . . . . . . . . . . . . . . 48, 96, 142
C Filter Bank . 47, 48, 50, 96, 142, 144, 145,
148, 149
COM . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 72, 119
Filtering . . . . . . . . . . . . . . . . . . . 47, 93, 142
Contrast . . . . . . . . . . . . . . . . . . . . . . . . . . . 84, 133
Frequency Response . . . . . . . . . . . . . . . 147
Correlation . . . . . . . . . . . . . . . . . . 45, 81, 82, 129
IDWT . . . . . . . . . . . . . 48, 97, 99, 144, 145
QMF . . . . . . . . . . . . . . . . . . 48, 96, 148, 149
Fujii
D
AD . . . . . . . . . . . . . . . . . . . . . . . . 41, 83, 131
Datapack . . . . . . . . . . . . . . . . . . . . . . . . . . 69, 113
E G
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
System Requirements . . . . . . . . . . . . . . . 60
I User Requirements . . . . . . . . . . . . . . . . . . 59
RVD . . . . . . . . . . . . . . . . . . . . . . 78, 86, 126, 136
IM . . . . . . . . . . . . . . . . . . . . . 46, 75, 85, 122, 135
Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
S
K SD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42, 84, 133
Skewness . . . . . . . . . . . . . . . . . . . . . . . . . . 88, 139
Kurtosis . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 138
T
M
Threshold . . . . . . . . . . . . . . . . . . . . . . . . . 105, 151
MHI . . . . . . . . . . . . . . . . . . . . . . . . . . . 37, 90, 140
THSP . . . . . . . . . . . . . . . . . . . . . . . . . . 43, 71, 116
N
W
NUMAD . . . . . . . . . . . . . . . . . . . . . . . . . . 80, 128
Website
Numerical Methods . . . . . . . . . . . . . . . . . . 43, 75
Bug Reports . . . . . . . . . . . . . . . . . . . . . . . 110
Download Page . . . . . . . . . . . . . . . . . . . . 110
P Home Page. . . . . . . . . . . . . . . . . . . . . . . .110
Windowing . . . . . . . . . . . . . . . . . . . . . . . 103, 151
PMF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
PMFAD . . . . . . . . . . . . . . . . . . . . . . . 73, 121
PMFRD . . . . . . . . . . . . . . . . . . . . . . . 74, 121
PTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 137
Recommendations
Gnu/Linux . . . . . . . . . . . . . . . . . . . . . . . . . 61
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Repository
Picture Packages . . . . . . . . . . . . . . . . . . . 110