Simulating Speckle With Mathematica 9781510656543, 9781510656550, 1510656545

The speckle phenomenon is ubiquitous, occurring in all regions of the electromagnetic spectrum, as well as in both ultra

132 76

English Pages 102 [104] Year 2022

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Table of Contents – Open First
Introduction
speckle_amplitude
speckle_intensity
image_speckle
freespace_speckle
low_light_level
speckle_phase_vortices
polarization_speckle
speckle_metrology
AppendixA
AppendixB
Blank Page
Blank Page
Blank Page
Blank Page
Blank Page
Blank Page
Blank Page
Blank Page
Recommend Papers

Simulating Speckle With Mathematica
 9781510656543, 9781510656550, 1510656545

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

Simulating Speckle with Mathematica Joseph W. Goodman

®

Library of Congress Cataloging-in-Publication Data Names: Goodman, Joseph W., author. Title: Simulating speckle with Mathematica / Joseph W. Goodman, Stanford University. Description: Bellingham, Washington : SPIE, [2022] | Includes bibliographical references. Identifiers: LCCN 2022030726 | ISBN 9781510656543 (paperback) | ISBN 9781510656550 (pdf) Subjects: LCSH: Speckle--Computer simulation. | Speckle--Mathematical models. | Mathematica (Computer file) Classification: LCC QC427.8.S64 G659 2022 | DDC 535/.470113--dc23/eng20220919 LC record available at https://lccn.loc.gov/2022030726 Published by SPIE P.O. Box 10 Bellingham, Washington 98227-0010 USA Phone: +1 360.676.3290 Fax: +1 360.647.1445 Email: [email protected] Web: www.spie.org Copyright © 2022 Society of Photo-Optical Instrumentation Engineers (SPIE) All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means without written permission of the publisher. The content of this book reflects the work and thought of the author. Every effort has been made to publish reliable and accurate information herein, but the publisher is not responsible for the validity of the information or for any outcomes resulting from reliance thereon. Wolfram Mathematica and Mathematica are registered trademarks. Wolfram Language, MathLM, Computable Document Format, Wolfram Desktop, Wolfram|One, and Wolfram Cloud are trademarks of Wolfram Research, Inc. Wolfram|Alpha is a registered trademark of Wolfram Alpha LLC. The cover image was simulated from the painting “The Audience” by Gene Walch. Printed in the United States of America. First printing 2022. For updates to this book, visit http://spie.org and type “PM355” in the search field.

Simulating Speckle with Mathematica Joseph W. Goodman

SPIE PRESS Bellingham, Washington USA

®

Simulating Speckle with Mathematica ®

Joseph W. Goodman Stanford University

Table of Contents 1. Introduction 1.1. Mathematica Background 1.2. Speckle Background 1.3. Methods for Simulating Speckle 2. First-Order Statistics of Speckle Amplitude 2.1. Speckle as a Sum of Independent Random Complex Phasors 2.2. Amplitude Statistics of the Sum of Many Random Phasors with Unit Lengths and Random Phases 2.3. Amplitude Statistics of the Sum of a Large Number of Unit-Length Random Phasors and One Large Phasor 2.4. Amplitude Statistics of the Sum of a Small Number of Unit-Length Random Phasors 3. First-Order Statistics of Speckle Intensity 3.1. Intensity Statistics of the Sum of Many Random Phasors with Unit Lengths and Random Phases 3.2. Intensity Statistics of the Sum of a Large Number of Unit-Length Random Phasors and One Large Phasor 3.3. Intensity Statistics of the Sum of a Small Number of Unit-Length Random Phasors 3.4. Intensity Statistics for Sums of Independent Speckle Patterns 3.5. Intensity Statistics of Partially Developed Speckle 4. Simulation of Speckle in Optical Imaging 4.1. Generation of a Discrete Diffuser Array with Correlated Phases 4.2. Speckle in an Imaging Geometry 4.3. The Autocorrelation Function of Speckle Intensity

vi

5.

6.

7.

8.

9.

Table of Contents

4.4. The Power Spectrum of Speckle Intensity 4.5. Effect of Speckle on Resolution 4.6. Speckle in Color Images Simulation of Speckle in Free-Space Propagation 5.1. The Diffuser 5.2. The Fresnel Transfer Function Approach 5.3. The Fresnel Transform Approach Speckle at Low Light Levels 6.1. Photocount Image of a Uniform Intensity 6.2. The Negative-Binomial Distribution 6.3. Photocount Image for a Speckle Pattern with Uniform Statistics 6.4. Photocount Image for a Diffuse Structured Object Speckle Phase Vortices 7.1. Generating the Speckle Pattern 7.2. Finding the Zeros of Intensity 7.3. Phase Behavior in the Vicinity of the Zeros of Intensity Polarization Speckle 8.1. The Polarization Ellipse and the Degree of Polarization 8.2. Generating the Two Polarization Components 8.3. Generating a Filtered Speckle Pattern 8.4. Generating the Polarization Ellipses 8.5. Visualizing Polarization Speckle Speckle Simulation for Metrology 9.1. Measurement of In-Plane Displacement 9.2. Electronic Speckle Pattern Interferometry 9.3. Phase-Shifting Speckle Interferometry

Appendix A – Some Subtleties in Speckle Simulation With the 4f System A.1. Effects on the Speckle Contrast A.2. Simulation With a Smoothed Phase A.3. Simulation With an Unsmoothed Phase Appendix B – Some Subtleties in Dealing With Mathematica Images B.1. Dimensions of Data Arrays and Images B.2. Images When the Data Range Exceeds (0, 1)

Table of Contents

B.3. Effect of Using ImageAdjust[] on an Image B.4. Arrays With Bipolar Values B.5. A Problem Encountered When Starting With an Image Acknowledgements References

vii

1. Introduction The speckle phenomenon is ubiquitous in many fields of science and technology. Speckle phenomena can be seen in many different imaging modalities, including acoustical imaging (e.g., medical ultrasound) and microwave imaging (e.g., synthetic-aperture radar imaging). This book focuses on simulating optical speckle with Mathematica® , but the same methods used can in many cases be applied to other imaging modalities. The reader may wonder why Mathematica has been chosen as the software package for this book. There are several reasons for this choice. First, and most important, Mathematica allows the interspersing of both continuous and discrete calculations under one umbrella. Second, using Mathematica, text, code, and illustrations can be included in the same document. Third, using Mathematica we can create dynamic figures, parameters of which the user can change at will. However, such manipulation cannot be performed in the printed version of the book, so we have avoided manipulable figures in what follows and replaced them by arrays of static figures. Lastly, this author loves Mathematica for its flexibility and comprehensiveness. It seems there are almost an infinite set of capabilities of the program, many of which lie hidden for the novice user but which gradually are revealed as the use of the program increases. This book has been written entirely in Mathematica. It can be read with the full program Mathematica or with the free program Wolfram Player available for download from the Wolfram site. The Mathematica files for all chapters can be found at the following URL: http://spie.org/Samples/Pressbook_Supplemental/PM355_sup.zip This book is meant as a companion to the book Speckle Phenomena in Optics: Theory and Applications, 2nd Edition, published by SPIE Press (Ref. [1]). An extensive list of references can be found in that book.

1.1 Mathematica Background For some background that will be helpful to the reader new to Mathematica, see Ref. [2]. There are many books that describe the capabilities of Mathematica. Ref. [3] is especially comprehensive. Our goal here is to not only present methods for simulating speckle in various situations and applications, but also to introduce the reader to the capabilities of Mathematica. In what follows we present some salient features of Mathematica that will help the novice get started. 1. Built-in functions of Mathematica always begin with upper-case letters. If the command consists of a concatenation of two separate words, both words must begin in upper-case letters. 2. In order to avoid confusion with built-in commands, user-defined functions should usually begin with a lower-case letter. However, it is permissible to begin commands with an upper-case letter in a font that is different than Source Code Pro, the usual font for Mathematica input. As an example,  is not the same as N. 3. Mathematica reduces an input that is a rational number to the equivalent simplest rational number possible. The ratio 32/6 yields 16/3, but does not produce an approximate decimal result. To obtain a decimal result, place a decimal point at the end of either the numerator or the denominator. Thus, 32./6 yields the result 5.33333. 4. The arguments of functions must be enclosed in square brackets [ ]. Curly brackets { } are reserved for containing lists, which can represent vectors and matrices, and are also used for variable ranges in, for example, plot commands. Parentheses ( ) are reserved for grouping mathematics. 5. When a function is first defined, each independent variable on the left of the definition must be followed by an underbar _. Underbars are not used on the right of the definition, or when the function is called by later code. 6. The symbol := is a delayed equality, for which the operation of equality is made only when the symbol on the left is called in later programming. 7. The symbol %, when used as the argument of a function, represents the last previous output, which is now used as the input to this new function. %% represents the second-to-last output, etc. 8. Often certain symbols may be used more than once in a program, with their meaning having changed between uses. If h is the symbol, then the command Clear[h] erases the definition of the symbol h and allows a new definition to be made. To clear more than one symbol, for example, h and g, use Clear[h,g]. To clear all symbols and functions that have been previously defined, use the command Clear["Global`*"]. 9. The symbol ; at the end of an expression to be evaluated indicates that the evaluation should take place, but the result of the evaluation should be suppressed until it is needed later in the program. 10. The symbol I (or ) is used in Mathematica for the imaginary constant -1 . The symbol D[] indicates a derivative operation. 11. To execute a command in Mathematica, place the cursor in the same cell (cells are indicated by vertical lines on the right of the notebook) as the command, and press the shift key and the return key simultaneously. 12. The symbols && mean a logical and; the symbols || mean a logical or.

2

Chapter 1

13. Multiplication can be indicated by either * or by a space between the two quantities to be multiplied. 14. When dealing with a complex number c, the command Abs[c] yields the magnitude of c, and Arg[c] gives the phase angle of c in radians. 15. Mathematica input commands are always written in Source Code Pro semi-bold font. In the event that a Mathematica command extends beyond the end of a line, you may find that a hyphen has been inserted in the command. This hyphen is not part of the command. When viewing this material with either the Mathematica or the Wolfram Player programs, if you change the size of the window, the line breaks will change, with the result that these hyphens should disappear. At the start we define a considerable number of initialization commands that determine certain parameters, such as the size of images, and certain operators that we will describe when we first use them. These initialization cells are in a hidden cell at the start of each Mathematica notebook chapter. In Chapter 1 you can open this cell by clicking on the gray line that appears just above the chapter title, and then going to the menu above, clicking Cell, then Cell Properties, and then Open. However, there is no need to open that cell unless you wish to see it. The initialization cell is repeated at the beginning of each chapter that follows so that you can access any chapter directly and evaluate the initialization cell in that chapter. It is not possible to see the initialization cells in the printed version of the book. The astute reader may notice that sometimes we bundle several Mathematica commands in one input cell, while in other cases we list the commands in separate cells. The same commands are executed in the same order in both cases, but sometimes breaking one cell into several helps reduce white space in the PDF version of the chapters. Mathematica will not break a single cell and its output when it paginates the PDF version. Four sets of user-defined Mathematica commands are used many times in this book. The first are commands for forward and inverse discrete Fourier transforms (DFTs) in any number of dimensions, which are applied to lists, i.e., discrete data arrays: dft[arg_] := Fourierarg, FourierParameters  {1, - 1} idft[arg_] := InverseFourierarg, FourierParameters  {1, - 1}. There are corresponding user-defined commands for Fourier transforms and inverse Fourier transforms of two-dimensional (2D) continuous functions (by continuous, we mean not discrete): ft2[arg_] := FullSimplifyFourierTransformarg, {x, y}, {u, v}, FourierParameters  0, - 2 * Pi ift2[arg_] := FullSimplify InverseFourierTransformarg, {u, v}, {x, y}, FourierParameters  0, - 2 * Pi. An additional pair of commands converts a 2D real numerical array to image format: Image[array], and a command to convert a 2D image (in image format) back to numerical data: ImageData[image]. Hopefully, the reader will remember and understand these commands when they are encountered in the chapters that follow. See Appendix B for a discussion of some subtleties of these latter two commands. Lastly are some definitions of functions that are used a number of times in the chapters that follow. These include: rect[x] = UnitBox[x] which is unity for x
0, 4 * π ^ 2 *  * NIntegrater * (BesselJ[0, 2 * π * r / Sqrt[]]) ^  * BesselJ[0, 2 * π *  * r], r, 0, Infinity, MaxRecursion  20, PrecisionGoal  100

The command MaxRecursion->20 instructs the numerical integration procedure to recursively subdivide the integration interval no more than 20 times. PrecisionGoal->100 instructs the procedure to aim for a relative error of 100 digits. That is, the error in calculating a quantity g should aim for error ⩽ |g| × 10-100 . These commands are included to promote accuracy in the numerical integration. We can now calculate (and suppress) the plots obtained by numerical integration for  = 1 to 6. As  increases, the probability density function approaches a Rayleigh density, which is the result for  = ∞. A Quiet[] command around the calculations is included to suppress certain warnings from Mathematica. The 6 plots are included as individual elements of the list q. These calculations take a substantial amount of time. Each numerical integration has been placed in a separate cell so that if readers execute the code, they can keep track of the progress of the computations by examining which cells have completed their work. In[]:=

q = Table0, i, 1, 6; Quiet q〚1〛 = Plotk[, 1], {, 0.6, 1.4}, PlotRange  {0, 100}, Filling  None, PlotStyle  Red;

12

Chapter 2

In[]:=

Quietq〚2〛 = Plotk[, 2], {, 0, 1.5}, PlotRange  {0, 5}, Filling  None, PlotStyle  Red;

In[]:=

Quietq〚3〛 = Plotk[, 3], {, 0, 1.9}, PlotRange  {0, 2}, Filling  None, PlotStyle  Red;

In[]:=

Quietq〚4〛 = Plotk[, 4], {, 0, 2}, PlotRange  {0, 1}, Filling  None, PlotStyle  Red;

In[]:=

Quietq〚5〛 = Plotk[, 5], {, 0, 2.3}, PlotRange  {0, 1}, Filling  None, PlotStyle  Red;

In[]:=

Quietq〚6〛 = Plotk[, 6], {, 0, 2.3}, PlotRange  {0, 1}, Filling  None, PlotStyle  Red;

Finally, we show the theoretical and simulation results superimposed for each value of  included in the calculations. In[]:=

GraphicsRow LabeledShowhist〚1〛, q〚1〛, PlotLabel  " = 1", {"", "p()"}, Bottom, Left, LabeledShowhist〚2〛, q〚2〛, PlotLabel  " = 2", {"", "p()"}, Bottom, Left

 =2

 =1

Out[]=

p()

100

5

80

4

60

p()

3

40

2

20

1

0

0.6

0.8

1.0

1.2

0

1.4

0.2

0.4



In[]:=

0.6

0.8

1.0

1.2

1.4



GraphicsRow LabeledShowhist〚3〛, q〚3〛, PlotLabel  " = 3", {"", "p()"}, Bottom, Left, LabeledShowhist〚4〛, q〚4〛, PlotLabel  " = 4", {"", "p()"}, Bottom, Left

 =3

Out[]=

 =4

2.0

1.0

1.5

0.8

p() 1.0

p()

0.4

0.5 0.0

0.6

0.2 0.0 0.5

1.0 

1.5

0.5

1.0 

1.5

2.0

First-Order Statistics of Speckle Amplitude

In[]:=

13

GraphicsRow LabeledShowhist〚5〛, q〚5〛, PlotLabel  " = 5", {"", "p()"}, Bottom, Left, LabeledShowhist〚6〛, q〚6〛, PlotLabel  " = 6", {"", "p()"}, Bottom, Left

 =5

Out[]=

p()

 =6

1.0

1.0

0.8

0.8

0.6

p()

0.6

0.4

0.4

0.2

0.2

0.0

0.5

1.0 

1.5

2.0

0.0

0.5

1.0

1.5

2.0



The agreements between theory and simulation are good. The trend towards a Rayleigh distribution as  grows is clear. There are many other variations on the theme of random phasor sums. For example, the lengths of the component phasors may be random, and/or the number of component phasors may be random. However, rather than pursue these topics in this chapter on the statistics of amplitude, we turn next to the statistics of intensity, which is a topic more relevant to optical speckle.

3. First-Order Statistics of Speckle Intensity In the optical region of the spectrum, detectors are unable to follow the ultra-fast cycles of the optical field amplitude, but rather, they respond to incident power or intensity, averaged over some response time of the detector and some finite area of the detector element. For that reason, in studying speckle in the optical region of the spectrum, the intensity statistics of random phasor sums are of much greater interest than amplitude statistics. We now turn our attention to simulating the intensity statistics of random phasor sums. The Mathematica code used in the previous chapter for various amplitude cases can be reused with small changes. Instead of calculating the length of the random phasor sums, we must calculate the squared length of those sums, for the squared length corresponds to intensity. Accordingly, we modify the previous code to calculate intensity statistics.

3.1 Intensity Statistics of the Sum of Many Random Phasors with Unit Lengths and Random Phases The modified code for calculating an approximation to the intensity statistics, as drawn from Section 2.1 above, is as follows: In[]:=

Clear, ℳ, real, imag, phi, t, p1, p2  = 100; ℳ = 10 000; real = Parallelize[Table[0, {k, 1, ℳ}]]; imag = Parallelize[Table[0, {k, 1, ℳ}]]; Fori = 1, i ≤ ℳ, i ++, phi = Parallelize[Table[RandomReal[{- π, π}], {k, 1, }]]; t = (1 / Sqrt[]) * ExpI * phi; reali = Total[Re[t]]; imagi = Total[Im[t]];

In[]:=

p1 = Histogramreal ^ 2 + imag ^ 2, 200, "PDF";

One change has been made in the last line of the code. The square root needed to calculate amplitude has been removed, with the result that we are calculating a histogram of intensity. We wish to compare this histogram with the theoretical result for the negative-exponential probability density function (PDF) of intensity (with mean unity), valid when an infinite number of normalized phasors compose the sum: In[]:=

p2 = PlotPDFExponentialDistribution[1], x, {x, 0, 4.0}, Filling  None, PlotStyle  Red, ImageSize  200; LabeledShow{p1, p2}, ImageSize  200, {"p(ℐ)", "ℐ"}, Left, Bottom 1.0 0.8 0.6

Out[]=

p(ℐ)

0.4 0.2 0.0

1

2

3

4

ℐ As can be seen, the match is quite good, and would be even better if we used a larger number of trials (larger ℳ). It is of interest to know the mean and the standard deviation of the resulting approximate PDF represented by the histogram. Mathematica has commands that allow us to directly calculate these quantities:

16

Chapter 3

In[]:= Out[]= In[]:= Out[]=

Meanreal ^ 2 + imag ^ 2 1.00462 StandardDeviationreal ^ 2 + imag ^ 2 0.992107

The mean and the standard deviation are both close to unity; in the case of an infinite number of unit-amplitude phasors (with a 1/  normalization), they would each be exactly unity. An important property of any speckle pattern is what is known as its contrast, which is defined as the ratio of the standard deviation of intensity to the mean intensity. In this case with 100 random phasors, the contrast is In[]:= Out[]=

 = StandardDeviationreal ^ 2 + imag ^ 2  Meanreal ^ 2 + imag ^ 2 0.987548

When the number of random phasors approaches infinity, in theory, the contrast approaches unity.

3.2 Intensity Statistics of the Sum of a Large Number of Unit-Length Random Phasors and One Large Phasor We can use the code developed in Section 2.3 with minor changes to calculate histograms. Again,  represents the total number of phasors while ℳ represents the number of random trials. The symbol  represents the number of different amplitudes of the large phasor for which we calculate histograms. Note that when p = 1, the large phasor takes on the value 0. In[]:=

Clear, , ℳ, real, imag, hist, phi, t  = 100; ℳ = 10 000;  = 3; real = Parallelize[Table[0, {k, 1, ℳ}]]; imag = Parallelize[Table[0, {k, 1, ℳ}]]; hist = Parallelize[Table[0, {k, 1, }]];

In[]:=

Forp = 1, p ≤ , p ++, Fori = 1, i ≤ ℳ, i ++, phi = Parallelize[Table[RandomReal[{- π, π}], {k, 1, }]]; t = (1 / Sqrt[]) * ExpI * phi; t〚 / 2〛 = 2 * (p - 1); (* Here is where we converted one phasor to be of different length than the others *) reali = Total[Re[t]]; imagi = Total[Im[t]]; hist〚p〛 = Histogramreal ^ 2 + imag ^ 2, 100, "PDF"; (*This is the line of code we changed - Square root removed. *)

We now form a list k, the elements of which are the three histograms we have calculated: In[]:=

k = hist〚1〛, hist〚2〛, hist〚3〛;

Now from Eq. (3.24) of Ref. [1], with I = 2σ2 = 1 and the intensity of the special phasor equal to I0 = 0, 2, and 4, we plot the 3 theoretical results for an infinite number of phasors. In[]:=

p1 = PlotExp[- (x + 0)] * BesselI[0, Sqrt[x] * 0], {x, 0, 5}, Filling  False, PlotStyle  Red, PlotLabels  Placed["

I0 = 0", Top];

p2 = PlotExp[- (x + 4)] * BesselI[0, 2 * Sqrt[x] * 2], {x, 0, 30}, Filling  False, PlotStyle  Red, PlotLabels  Placed["I0 = 4", Top]; p3 = PlotExp[- (x + 16)] * BesselI[0, 2 * Sqrt[x] * 4], {x, 0, 30}, Filling  False, PlotStyle  Red, PlotLabels  Placed["I0 = 16", Top];

First-Order Statistics of Speckle Intensity

In[]:=

17

LabeledShow[{k, p1, p2, p3}, PlotRange  {{0, 30}, {0, 1}}], {"p(ℐ)", "ℐ"}, Left, Bottom 1.0 I0 = 0 0.8

0.6 Out[]=

p(ℐ) 0.4

0.2 I0 = 4 5

I0 = 16 15

10

20

25

30

ℐ For A0 = 0, we obtain the exponential probability density function with mean unity. As the amplitude of the one large phasor grows, we see that the probability density function moves to the right and spreads out. The spreading is caused by interference between the large phasor and the sum of the smaller phasors, which in effect amplifies the fluctuations associated with the sum of the unit-amplitude phasors. The probability density function approaches a Gaussian density with mean A20 as  → ∞.

3.3 Intensity Statistics of the Sum of a Small Number of Unit-Length Random Phasors We can use a sightly modified version of the code from Section 2.4 for this calculation, replacing the amplitude by intensity. However, we also add some lines to the code that will allow us to calculate the contrast of the speckle when the number of phasors is between 1 and 10. Note that the code below effectively has 100,000 iterations, and therefore takes considerable time to execute. In[]:=

Clear, ℳ, 0, real, imag, hist, phi, t 0 = 10; ℳ = 10 000; real = Parallelize[Table[0, {k, 1, ℳ}]]; imag = Parallelize[Table[0, {k, 1, ℳ}]]; hist = Parallelize[Table[0, {k, 1, 0}]]; magsq = ParallelizeTable0, i, 1, 0; For = 1,  ≤ 0,  ++, Fori = 1, i ≤ ℳ, i ++, phi = Parallelize[Table[RandomReal[{- π, π}], {k, 1, }]]; t = (1 / Sqrt[]) * ExpI * phi; reali = Total[Re[t]]; imagi = Total[Im[t]]; magsq〚〛 = real ^ 2 + imag ^ 2; hist〚〛 = Histogram[magsq〚〛, 100, "PDF"];

Once this code has executed, we can plot histograms representing various approximate probability density functions for different numbers of phasors. The plots are suppressed so that they can be displayed with GraphicsGrid[] in a later line. The vertical axes in these graphs can be interpreted as the (approximate) probability density of intensity. Only results for  equal to 1 through 6 are shown below. The theoretical curves can be found by a modification of the probability density functions of the amplitude. The rule for transformation of variables in statistics, valid when the intensity ℐ is equal to 2 , leads to the following relationship between these probability densities: pI (I ) =

1 2ℐ



p  ℐ  = 2 π2  ρ J0 0

2πρ



J0 2 π

ℐ ρ  ρ,



where the subscripts on the probability density functions indicate which variables they apply to. Let z[ℐ_,_] represent the density function for intensity:

18

Chapter 3

In[]:=

Clear[z, , q] z[ℐ_, _] := 2 * π ^ 2 * NIntegrateρ * BesselJ0,

2*π *ρ

 ^  * BesselJ0, 2 * π *

ℐ * ρ,

 ρ, 0, Infinity, MaxRecursion  20, PrecisionGoal  100 The variable q that follows is a list, each element of which is a plot of the theoretical probability density function for intensity for a different value of . The command Quiet[] suppresses any comments Mathematica makes about the accuracy of the numerical integrations. Again, we place each numerical integration in a separate cell to facilitate tracking the completion of the evaluation. In[]:=

Clear[q] q = Table0, i, 1, 6;

In[]:=

q〚1〛 = QuietPlotz[ℐ, 1], {ℐ, 0, 2}, PlotRange  {0, 200}, Filling  None, PlotStyle  Red;

In[]:=

q〚2〛 = QuietPlotz[ℐ, 2], {ℐ, 0, 2}, PlotRange  {0, 5}, Filling  None, PlotStyle  Red;

In[]:=

q〚3〛 = QuietPlotz[ℐ, 3], {ℐ, 0, 3}, PlotRange  {0, 2}, Filling  None, PlotStyle  Red;

In[]:=

q〚4〛 = QuietPlotz[ℐ, 4], {ℐ, 0, 4}, PlotRange  {0, 1.5}, Filling  None, PlotStyle  Red;

In[]:=

q〚5〛 = QuietPlotz[ℐ, 5], {ℐ, 0, 4}, PlotRange  {0, 1}, Filling  None, PlotStyle  Red;

In[]:=

q〚6〛 = QuietPlotz[ℐ, 6], {ℐ, 0, 4}, PlotRange  {0, 1}, Filling  None, PlotStyle  Red;

Next we show superpositions of the histograms and the theoretical curves. When  = 1, the numerical integration attempts to depict a delta function at ℐ = 1, and the histogram is hidden by the results. A comparison of these results with those obtained by numerical integration shows good agreement, which would be even better if ℳ were chosen larger. Note that by the time  = 6, the probability density function is beginning to resemble a negative-exponential curve, except that the maximum value of ℐ for which the probability is non-zero is ℐ = 6 (the intensity when all 6 phasors, each of length 1/ 6 , are aligned in the same direction). In[]:=

GraphicsRow LabeledShowhist〚1〛, q〚1〛, PlotLabel  " = 1", {"p(ℐ)", "ℐ"}, Left, Bottom, LabeledShowhist〚2〛, q〚2〛, PlotLabel  " = 2", {"p(ℐ)", "ℐ"}, Left, Bottom

 =2

 =1

5

200

4

150 Out[]=

p(ℐ) 100

p(ℐ)

3 2

50 0

1 0.6

0.8

1.0 ℐ

1.2

1.4

0

0.5

1.0 ℐ

1.5

2.0

First-Order Statistics of Speckle Intensity

In[]:=

GraphicsRow LabeledShowhist〚3〛, q〚3〛, PlotLabel  " = 3", {"p(ℐ)", "ℐ"}, Left, Bottom, LabeledShowhist〚4〛, q〚4〛, PlotLabel  " = 4", {"p(ℐ)", "ℐ"}, Left, Bottom

 =4

 =3 1.5

2.0 1.5 Out[]=

1.0

p(ℐ) 1.0

p(ℐ) 0.5

0.5 0.0

0.5

1.0

1.5

2.0

2.5

0.0

3.0

1



In[]:=

2

3

4



GraphicsRow LabeledShowhist〚5〛, q〚5〛, PlotLabel  " = 5", {"p(ℐ)", "ℐ"}, Left, Bottom, LabeledShowhist〚6〛, q〚6〛, PlotLabel  " = 6", {"p(ℐ)", "ℐ"}, Left, Bottom

 =6

 =5 1.0 0.8

0.8

0.6 Out[]=

p(ℐ)

p(ℐ)

0.6

0.4

0.4

0.2

0.2

0.0

1

2

3 ℐ

4

5

0.0

1

2

3

4



GraphicsRow LabeledShowhist〚5〛, q〚5〛, PlotLabel  " = 5", {"p(ℐ)", "ℐ"}, Left, Bottom, LabeledShowhist〚6〛, q〚6〛, PlotLabel  " = 6", {"p(ℐ)", "ℐ"}, Left, Bottom It’s also of interest to calculate the contrast of the speckle for small numbers of phasors. Such a plot is calculated below.

19

20

Chapter 3

c = TableStandardDeviation[magsq〚〛]  Mean[magsq〚〛], {, 1, 0}; ListPlotc, AxesLabel  {" ", "Contrast"}, BaseStyle  FontSize  12, PlotRange  {0, 1.0}, PlotStyle  PointSize[.02] Contrast 1.0 0.8 0.6 Out[]=

0.4 0.2 0

2

4

6

8

10



As can be seen from this plot, the contrast approaches unity (the contrast for fully developed speckle) when the number of phasors  is 10 or more.

3.4 Intensity Statistics for Sums of Independent Speckle Patterns In this section we examine the intensity statistics of a sum of fully developed speckle pattern intensities. First it is important to point out that when fully developed speckle patterns are added on an amplitude basis, the amplitude statistics do not change in form. The amplitude statistics of the real and imaginary parts of the speckle fields still obey zero-mean, circular Gaussian statistics. The intensity statistics remain negative exponential, and the contrast of the speckle intensity remains unity. When speckle patterns are added on an intensity basis, the results are more interesting. The theory for fully developed speckle shows that if k statistically independent speckle intensities with equal means ℐ0 are added, the resulting probability density function is approximately a gamma density with k degrees of freedom, p I  =

I k -1 Γ(k) ℐ0 k

exp -

I

,

ℐ0

for I ≥ 0, and where ℐ0 is the mean intensity of any one of the k speckle patterns. ℐ0 is unity if we normalize the amplitudes of the ℳ component phasors in each phasor sum by 1/ ℳ . Then the probability density function becomes p(I ) =

I k -1 Γ(k)

exp(-I ).

This result strictly holds only when each of the component speckle intensities arises from an infinite number of scattered contributions. However, as we shall see, the approximation is a good one when a large number (in our case, 10,000) of component phasors contribute to each speckle pattern. In[]:=

Clear[] ℳ = 10 000;  = 7;  = 100; real = Table[0, {k, 1, ℳ}]; imag = Table[0, {k, 1, ℳ}]; magsq = Table[0, {k, 1, }]; sum = Table[0, {k, 1, }]; hist = Table[0, {k, 1, }];

The above code simply initializes tables that will be ready to accept entries generated by the code that follows. For this code, an explanation may be in order. The line defining phi generates  ×  random phases and then partitions that array into  sub-arrays, each of which is used to define an array of phasors t, which is also partitioned into  sub-arrays. One can think of each -length sub-list as defining one of the  rows of a matrix. The commands Total[Re[t],{1}] and Total[Im[t],{1}] sum down each of the  columns of the matrix. There results a matrix with one column and  rows, each row representing the result of the set of ℳ trials that generate the statistics of real and imaginary parts. It is then possible to form the intensity that results from each of the ℳ trials as magsq. Now having an array of  intensities, each produced by ℳ independent trials, it is possible to sum k of those intensities, with k ranging from 1 to , yielding the histograms shown

First-Order Statistics of Speckle Intensity

21

below. In[]:=

Cleark, i Fork = 1, k ≤ , k ++, Fori = 1, i ≤ ℳ, i ++, phi = PartitionTableRandomReal[{- π, π}], j, 1,  * , ; t = (1 / Sqrt[]) * Exp * phi; reali = Total[Re[t], {1}]; imagi = Total[Im[t], {1}]; magsq = real ^ 2 + imag ^ 2; sum = Table[Sum[magsq〚All, x〛, {x, 1, k, 1}], {k, 1, , 1}]; hist = TableHistogram[sum〚k〛, 100, "PDF"], {k, 1, , 1};

We next generate the corresponding theoretical results valid for an infinite number of random phasors in each component speckle pattern. The code follows: In[]:=

Clear[p, k] p[ℐ_] = Table[(1 / Gamma[k]) * ℐ ^ (k - 1) * Exp[- ℐ], {k, 1, 10}];

Now we plot a series of histograms for different numbers of speckle intensity patterns added, and overlay those results with the theoretical curves for an infinite number of random phasors in each case. To save space, we show results only for 1, 3, 5, and 7 added speckle intensities. In[]:=

a1 = LabeledShowhist〚1〛, Plotp[ℐ]〚1〛, {ℐ, 0, 4}, PlotStyle  Red, Filling  None, PlotLabel  "k = 1", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

a3 = LabeledShowhist〚3〛, Plotp[ℐ]〚3〛, {ℐ, 0, 9}, PlotStyle  Red, Filling  None, PlotLabel  "k = 3", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

a5 = LabeledShowhist〚5〛, Plotp[ℐ]〚5〛, {ℐ, 0, 13}, PlotStyle  Red, Filling  None, PlotLabel  "k = 5", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

a7 = LabeledShowhist〚7〛, Plotp[ℐ]〚7〛, {ℐ, 0, 17}, PlotStyle  Red, Filling  None, PlotLabel  "k = 7", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

GraphicsRow{a1, a3}, ImageSize  600

k =3

k =1

Out[]=

p(ℐ)

1.0

0.30

0.8

0.25

0.6

0.20 p(ℐ) 0.15

0.4

0.10

0.2 0.0

0.05 1

2 ℐ

3

4

0.00

2

4 ℐ

6

8

22

Chapter 3

In[]:=

GraphicsRow{a5, a7}, ImageSize  500 k =5

k =7

0.20

0.15

0.15 Out[]=

p(ℐ)

p(ℐ) 0.10

0.10

0.05

0.05 0.00 .

5

10

15

0.00

5



10

15



Again, the agreement is reasonably good, and would be improved with a larger value of ℳ. As k increases, the histogram is approaching a Gaussian probability density with a mean equal to k, i.e., the number of speckle patterns added, since each pattern had a mean of unity.

3.5 Intensity Statistics of Partially Developed Speckle Attention is now turned to the case of partially developed speckle. Such speckle occurs in practice when light is reflected from a surface that has a roughness that is less than a half wavelength of the light, or when light is passed through a diffuser that randomizes the phase of the light by less than 2π radians. It may also be observed when an adaptive-optics system in a telescope does not fully compensate for the wavefront perturbations introduced by the turbulent atmosphere. The parameter 0 is the total number of different phase standard deviations that are included in the computation, while again the parameter ℳ is the total number of trials in the calculation and  is the number of phasors added on each trial. Each phasor has a length 1/  . We assume that the phase of the scattered light is a Gaussian (or normal) random variable with zero mean and variable standard deviation equal to s × π/8, where s ranges from 1 to 8 in increments of 1. Thus, the phase standard deviation ranges from π/8 to π in increments of π/8. During each step through the i index, a magnitude-squared averaged over ℳ trials of the random phasor sum is calculated. Each step of the s index increases the phase standard deviation in increments of π/8, with s ranging from 1 to 0 = 8. For each value of s, histograms of the real part of the complex amplitude, the imaginary part, and the squared magnitude are calculated. If we choose ℳ = 10,000 to obtain accurate histograms, the calculation takes a long time. First we establish tables into which various results can be placed. histr holds the histograms of the real part of the complex amplitude for different values of s, histi holds histograms of the imaginary part of the complex amplitude, and hist holds histograms of the intensity of the speckle pattern. In[]:=

Clear[, ℳ, ]  = 8; ℳ = 10 000;  = 100; real = Parallelize[Table[0, {k, 1, ℳ}]]; imag = Parallelize[Table[0, {k, 1, ℳ}]]; magsq = Parallelize[Table[0, {k, 1, ℳ}]]; mag = Parallelize[Table[0, {s, 1, }]]; histr = Parallelize[Table[0, {s, 1, }]]; histi = Parallelize[Table[0, {s, 1, }]]; hist = Parallelize[Table[0, {s, 1, }]];

Next we run 10,000 trials, adding 100 phasors on each trial, and increase the standard deviation of the Gaussian phase by increments of π/8 on each of the 8 outer iterations. Histograms of the real and imaginary parts of the complex amplitude are calculated for each phase standard deviation, as is also a histogram of the intensity.

First-Order Statistics of Speckle Intensity

In[]:=

23

Fors = 1, s ≤ , s ++, Form = 1, m ≤ ℳ, m ++, complex = 1 

  * Parallelize

TableExpI * RandomVariateNormalDistribution[0, s * π / 8], {n, 1, }; real〚m〛 = Re[Total[complex]]; imag〚m〛 = Im[Total[complex]]; histr〚s〛 = Histogram[real, 100, "PDF"]; histi〚s〛 = Histogramimag, 100, "PDF"; hist〚s〛 = Histogramreal ^ 2 + imag ^ 2, 100, "PDF"; It is instructive in this case to examine the behaviors of the real part () and imaginary part () of the complex amplitude as a function of the standard deviation of the phase. The plots below begin with s = 1 in the specific case considered here and gradually step up to s = 8 in steps of 1. Note that the symbol  represents the real part of the complex amplitude and the symbol  represents the imaginary part. The histograms of the real and imaginary parts are plotted in the same figure, with p() on the left of each figure and p() on the right. In[]:=

p1 = LabeledShowhisti〚1〛, histr〚1〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 10}, {0, 3}}, PlotLabel  "σϕ = π/8", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p2 = LabeledShowhisti〚2〛, histr〚2〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 10}, {0, 1.5}}, PlotLabel  "σϕ = π/4", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p3 = LabeledShowhisti〚3〛, histr〚3〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 8}, {0, 0.8}}, PlotLabel  "σϕ = 3π/8", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p4 = LabeledShowhisti〚4〛, histr〚4〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 6}, {0, 0.8}}, PlotLabel  "σϕ = π/2", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p5 = LabeledShowhisti〚5〛, histr〚5〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 4}, {0, 0.8}}, PlotLabel  "σϕ = 5π/8", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p6 = LabeledShowhisti〚6〛, histr〚6〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 2.5}, {0, 0.8}}, PlotLabel  "σϕ = 3π/4", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p7 = LabeledShowhisti〚7〛, histr〚7〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 2.5}, {0, 0.8}}, PlotLabel  "σϕ = 7π/8", {"p(), p()", ", "}, Left, Bottom;

In[]:=

p8 = LabeledShowhisti〚8〛, histr〚8〛, AxesOrigin  {0, 0}, PlotRange  {{- 2, 2.5}, {0, 0.8}}, PlotLabel  "σϕ = π", {"p(), p()", ", "}, Left, Bottom;

In[]:=

GraphicsRow{p1, p2}, ImageSize  600

σϕ = π/8

σϕ = π/4

3.0

1.5

2.5 2.0 Out[]=

p(), p( )

1.0 p(), p( )

1.5 1.0

0.5

0.5 -2

2

4 , 

6

8

10

-2

2

4 , 

6

8

10

24

Chapter 3

In[]:=

GraphicsRow{p3, p4}, ImageSize  600

σϕ = 3π/8

Out[]=

p(), p( )

σϕ = π/2

0.8

0.8

0.6

0.6 p(), p( )

0.4

0.4

0.2

0.2

-2

2

4

6

-2

8

2

, 

In[]:=

p(), p( )

σϕ = 3π/4

0.8

0.8

0.6

0.6 p(), p( )

0.4

0.4

0.2

-2

0.2

-1

1

2

3

-2

4

-1

, 

In[]:=

1

2

1

2

, 

GraphicsRow{p7, p8}, ImageSize  600 σϕ = π

σϕ = 7π/8

Out[]=

6

GraphicsRow{p5, p6}, ImageSize  600

σϕ = 5π/8

Out[]=

4

, 

p(), p( )

0.8

0.8

0.6

0.6 p(), p( )

0.4

0.4 0.2

0.2

-2

-1

1

2

, 

-2

-1 , 

When s = 1 (standard deviation of the phase σϕ = π/8, top left), the histogram of the real part lies to the right while the histogram of the imaginary part remains centered on the origin. The real part is to the right because, for small phase fluctuations, all random phasors lie closer and closer to the real axis, developing a bias for the real part but not for the imaginary part. In addition, the histogram of the real part narrows in width and increases in height, approaching a delta function on the real axis at location  when the phase fluctuations vanish. Since both the real and imaginary parts are still sums of many contributions, the central limit theorem holds and their statistics are approximately Gaussian. However, it is clear that when the phase standard deviation is small, the variances of the real and imaginary parts are no longer equal, a condition referred to as non-circular statistics. For large phase fluctuations, such as s = 8 or σϕ = π, the histograms of the real and imaginary parts overlap, both centered on the origin. In this case we have fully developed speckle. It is also of interest to examine the histograms of intensity: In[]:=

q1 = LabeledShowhist〚1〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = π/8", {"p(ℐ)", "ℐ"}, Left, Bottom;

First-Order Statistics of Speckle Intensity

In[]:=

q2 = LabeledShowhist〚2〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = π/4", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q3 = LabeledShowhist〚3〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = 3π/8", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q4 = LabeledShowhist〚4〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = π/2", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q5 = LabeledShowhist〚5〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = 5π/8", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q6 = LabeledShowhist〚6〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = 3π/4", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q7 = LabeledShowhist〚7〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = 7π/8", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

q8 = LabeledShowhist〚8〛, AxesOrigin  {0, 0}, PlotRange  All, PlotLabel  "σϕ = π", {"p(ℐ)", "ℐ"}, Left, Bottom;

In[]:=

GraphicsRow{q1, q2}, ImageSize  600

σϕ = π/8

σϕ = π/4

0.25 0.08

0.20

Out[]=

p(ℐ)

0.06

0.15

p(ℐ)

0.10

0.04

0.05

0.02 20

40

60

10

80

20

30

In[]:=

50

60

70

GraphicsRow{q3, q4}, ImageSize  600

σϕ = π/2

σϕ = 3π/8 0.12

0.08

0.10

0.06 Out[]=

40





p(ℐ)

0.08 p(ℐ)

0.04

0.06 0.04

0.02

0.02 10

20 ℐ

30

40

5

10

15 ℐ

20

25

25

26

Chapter 3

In[]:=

GraphicsRow{q5, q6}, ImageSize  600

σϕ = 3π/4

σϕ = 5π/8 0.20

0.6 0.5

0.15 Out[]=

p(ℐ)

p(ℐ)

0.10

0.4 0.3 0.2

0.05

0.1 5

10

15

2

4

6



In[]:=

10

12

GraphicsRow{q7, q8}, ImageSize  600

σϕ = π

σϕ = 7π/8

1.0

0.8

0.8

0.6 Out[]=

8



p(ℐ)

p(ℐ)

0.6

0.4

0.4

0.2

0.2 2

4

6

8



2

4

6

8



Note that both the horizontal and vertical scales change with the value of σϕ . Two limiting cases for the probability density of intensity can be identified. (1) When the standard deviation is small, the probability density function of intensity approaches a delta function at location  . In the limiting case of vanishing σϕ , all  phasors are pointing in the same direction (along the real axis), and due to the normalization by 1/  , the total amplitude is  , yielding an intensity of  . (2) When the phase standard deviation is on the order of π radians or greater, the probability density function of intensity is well approximated by a negative exponential, as expected for fully developed speckle. In the limit of phase fluctuations much smaller than 2π radians, an approximation to the probability density of intensity can be found. In the small-phase case, exp(ϕ) ≈ 1 + ϕ and 1 + ϕ2 = 1 + ϕ2 . It follows that in this limit of small phase fluctuations, the statistics of intensity are those of the square of a Gaussian random variable riding on a large constant value. The appropriate probability transformation shows that the resulting probability density is that of a chi-square distribution with one degree of freedom. An analytic solution in the more general case of arbitrary phase-standard-deviation has not been found, to the best of this author’s knowledge.

4. Simulation of Speckle in Optical Imaging In this chapter we examine methods for simulating speckle in optical imaging. Unlike the 1D examples in previous chapters, the simulations in this chapter will be two-dimensional, since images are 2D entities. Discrete models must be used in the simulations. Thus, the field complex amplitudes must be represented by discrete arrays, and therefore sampling is inherent in the simulation. An important question concerns the sampling density that must be used in the various cases, with the density chosen high enough to avoid aliasing. According to the sampling theorem, the required density depends on the bandwidth of the complex amplitude representation of the light leaving the rough surface or diffuser. In our previous 1D simulations of speckle, we have used independent diffuser phase samples, i.e., samples with no local correlations. A Fourier transform of a diffuser model with no phase correlations exhibits no bandwidth limitation, and therefore results in aliasing. The aliasing is not always harmful. Aliasing of the circular complex Gaussian field samples results in another circularly symmetric complex Gaussian field, so the statistics of the field are not changed. Nonetheless, in some applications it is useful or even necessary to minimize the aliasing by introducing correlations between the diffuser phase samples, thereby reducing the diffuser bandwidth. Accordingly, we will introduce correlations between adjacent phase samples, which will reduce the bandwidth of the diffuser. The further the correlations extend in the discrete diffuser phase array, the smaller the resulting bandwidth of that diffuser. It should be noted that even creating a completely bandlimited phase array (i.e., one with a sharp cutoff in spatial frequency space) will not create a perfectly bandlimited wave generated by the diffuser. This is because a perfectly bandlimited phase ϕ does not generate a perfectly bandlimited exp(ϕ), unless ϕ is ≪ 2π. The nonlinearity of the complex exponential function generates frequency components that were not present in the phase sequence. However, bandlimiting the phase sequence does narrow the spectrum of the complex exponential, as we shall see. Note also that bandlimiting the complex exponential function (rather than the phase) would generate a diffuser with both amplitude and phase fluctuations, rather than just the phase fluctuations we seek. There are two ways to produce phase sequences with correlations between neighboring samples. One is to create a phase sequence with statistically independent samples of field and then convolve this sequence with a finite averaging window, the width of the window determining the extent of the correlations. A second method is to Fourier transform a sequence of independent phases, filter this sequence with a finite stop in the Fourier domain, and inverse Fourier transform the resulting spectral sequence to produce a complex field with correlations between pixels. In what follows, we use the first of these two methods. Once the phase sequence with correlations has been generated, a sequence of complex phasors with these phases can be easily constructed.

4.1 Generation of a Discrete Diffuser Array with Correlated Phases As mentioned above, it is important in some problems to be able to simulate a diffuser that has an approximately limited bandwidth, rather than the infinite bandwidth of a sequence of totally independent phasors. It is the correlation area of the phasor array representing the light leaving the diffuser that ultimately limits the angular spread of that light (Ref. [1], Section 5.3.2). Limitation of the spread of transmitted light is equivalent to limiting the spatial bandwidth of the diffused light. Introduction of correlations between the complex amplitudes of the light leaving the diffuser while maintaining the phase-only character of the diffuser requires introduction of correlations between the phases of those amplitudes. In this section we construct a diffuser with correlated phases (and therefore correlated transmitted complex amplitudes) that will be used throughout this chapter in speckle simulations. Generation of a phase-correlated diffuser with limited spread of light requires that several subtleties be taken into account. The first is that to generate fully developed speckle, the phases of the samples of the light amplitudes in the various correlation areas must fluctuate over at least 2π radians. If this is not the case, the spectrum of the transmitted light when the diffuser is illuminated by a normally incident plane wave will have a strong Fourier component at the origin in the frequency plane, corresponding to undiffracted light. We desire to generate a spectrum that is tapered towards the edges of the Fourier plane but lacks a dominating discrete component at the origin. In addition, if the phase fluctuations are too small, the speckle field will not obey circular Gaussian statistics. A second constraint, rather the opposite of the first, is that the phase fluctuations of the smoothed phase should not be too much greater than the required 2π radians. The reason lies in the fact that, for a given correlation area extent, the angles spread by a diffuser, and therefore the bandwidth of its spectrum, depend on the range of the slope fluctuations of the phase at each point. As the correlation extent of the phases is held constant by a fixed area of the averaging filter, increases of the phase standard deviation in the uncorrelated phase array will result in a larger range of slopes and therefore a wider bandwidth. To achieve a desired spectral spread in the Fourier plane of the complex field, the standard deviation of the uncorrelated phases and the area of the averaging filter must be simultaneously adjusted. An increase in the area of the averaging filter requires an increase of the phase standard deviation to hold the spectral spread constant. Thus, there are many different

28

Chapter 4

solutions for the two parameters (standard deviation and area of smoothing) that achieve a prescribed spectral spread. To construct a limited-bandwidth diffuser, we begin by generating a sequence of uncorrelated Gaussian-distributed phases with zero mean and a standard deviation chosen carefully. This sequence of phases will then be convolved with a circular uniform averaging window with a diameter that also must be chosen carefully. As mentioned above, the area of the averaging filter affects the standard deviation of the resulting smoothed phase sequence, reducing the phase standard deviation below that of the original uncorrelated sequence. In the example that follows, the standard deviation of the original phase sequence and the diameter of the averaging filter have been chosen after extensive experimentation to yield a pair of parameters that achieve the desired result. Note that since the original phase sequence is random, different trials yield somewhat different results, but the choice of parameters below yields adequately consistent results. We begin by defining the array size of the simulation to be 1024 × 1024 pixels and, based on considerations discussed in Appendix A, the smoothing filter diameter to be 20 pixels. We create a 1024 × 1024 array named uncorrelated consisting of independent zero-mean Gaussian phases with standard deviation 25π. We also create a uniform, circular smoothing filter named kernel with a diameter of 20 pixels and with amplitudes normalized by the area of the smoothing function. In[]:=

 = 1024; ℳ = 20; uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 25 * π], {}, {}; kernel = (1 / (π * (ℳ / 2) ^ 2)) * TablecircSqrti - ℳ / 2 + 1 ^ 2 + j - ℳ / 2 + 1 ^ 2  (ℳ / 2), i, 1, ℳ, j, 1, ℳ;

Next, we smooth the uncorrelated sequence of phases by convolving it with the smoothing filter. Note that the command ListConvolve[kernel,uncorrelated,1] will perform a convolution between the smoothing filter and the list of uncorrelated random samples. The numeral 1 at the end of the ListConvolve[] command assures that only the central 1024 × 1024 results of the convolution are retained. We also plot a slice through the center of the smoothed array so that we can observe the fluctuations of the smoothed phase, checking to see the extent of the fluctuations. In[]:=

smooth = ListConvolve[kernel, uncorrelated, 1]; ListPlotsmooth〚All,  / 2〛, AxesLabel  "Pixel Number", "Smoothed Phase" Smoothed Phase

10 5 Out[]=

200

400

600

800

1000

Pixel Number

-5 -10

Next we convert the smoothed phase sequence into a sequence of complex field amplitudes. Plots of central slices through the real part and the imaginary part of the amplitude array are shown. The values of both the real part and imaginary part of the phasor amplitude should extend from –1 to 1 and be more-or-less equally positive and negative. In[]:=

diffuser = Exp[I * smooth];

In[]:=

p1 = ListPlotRediffuser〚All,  / 2〛, PlotRange  All, PlotRangePadding  0.01, AxesLabel  "Pixel Number", "Real Part";

In[]:=

p2 = ListPlotImdiffuser〚All,  / 2〛, PlotRange  All, PlotRangePadding  0.01, AxesLabel  "Pixel Number", "Imaginary Part";

Simulation of Speckle in Optical Imaging

In[]:=

GraphicsRow{p1, p2}, ImageSize  500

Real Part 1.0

Imaginary Part 1.0

0.5 Out[]=

29

0.0

0.5 200

400

600

800

1000

Pixel Number

0.0

-0.5

-0.5

-1.0

-1.0

200

400

600

800 1000

Pixel Number

The command PlotRangePadding->number is sometimes needed to allow full visualization of the numbers appearing on the vertical axis of plots such as these. Finally, we show an image of the Fourier plane intensity when only the diffuser defined above is used. In[]:=

diffuserspectrum = RotateRightFourierdiffuser, { / 2,  / 2}; ImageAdjustImageAbsdiffuserspectrum ^ 2, ImageSize  200, {1, 0.01}

Out[]=

The spectrum is certainly not perfectly bandlimited, but it is tapered with much more energy near the center and much less near the edges of the array. We will use this diffuser, named diffuser, in the simulations that follow.

4.2 Speckle in an Imaging Geometry Our model for an imaging system is a simple 4f geometry as discussed in Section 1.3. The beauty of this system from the simulation point-ofview is that the complex-amplitude distribution of the light in the focal plane is simply the scaled Fourier transform of the complex field distribution leaving the object plane, and we can use discrete Fourier transforms to propagate between the various planes. Since we are simulating speckle, we shall assume that in addition to a planar object in the initial plane there also exists a co-planar diffuser through which the object is illuminated. Alternatively, the object itself can be assumed to be rough on the scale of wavelength, jumbling the phases randomly over 2π radians or more. We begin our considerations with an object that consists only of the correlated-phase diffuser constructed above. Our simulation will yield an image that is a field of statistically similar speckle with no other image structure. From this image, we can then determine many statistical properties of the speckle, for example, the autocorrelation function of the speckle intensity, as well as its power spectrum. The first step is to generate the speckled image. The focal-plane stop has diameter , which can be adjusted by a reader using the Mathematica program. The effect of the stop is to filter the spectrum of the phase-correlated diffuser such that the image is no longer a pure phase distribution with uniform intensity, but rather is a mixture of phase and intensity fluctuations. The intensity fluctuations are in fact speckle, and it is these fluctuations that we shall study. We wish to determine the structure of the autocorrelation function of intensity and to explore its dependence on the structure of the focal-plane stop and the phase correlation function. The simulation again operates on an  ×  array, where  = 1024. The diameter  of the (approximately) circular stop in the imaging system focal plane is taken to be 64 pixels. The image amplitude is found by Fourier transforming the complex-amplitude array in the object plane, multiplying the resulting spectrum by the finite stop, and inverse Fourier transforming the result to obtain the amplitude distribution in the image. Note that both the stop and the Fourier transform are centered at coordinates (/2, /2). The discrete Fourier transforms are performed by Mathematica using the fast Fourier transform (FFT) algorithm. Finally, the image intensity is found by taking the squared magnitude of the image amplitude. The approximate average width of a speckle in

30

Chapter 4

the image plane is given by the total number of simulation samples divided by the diameter of the stop in pixels. In the case at hand, the diameter of the stop is 64 and / = 1024/64 = 16. In[]:=

Clear[k, stop, imageampl, imageintens];

In[]:=

 = 1024;  = 64;

In[]:=

stop[_] = Parallelize[Table[ circ[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }]];

In[]:=

imageampl = idftstop[32] * RotateRightdftdiffuser, { / 2,  / 2}; imageintens = Absimageampl ^ 2;

The display of the resulting speckle pattern is obtained by converting the image intensity data array to an image with the command Image[], and adjusting the brightness and contrast with the command ImageAdjust[] to obtain a good image. Note that the pair {a,b} in the argument of ImageAdjust[] adjusts the contrast (through a) and the brightness (through b) to improve the display of the image. In[]:=

Image20 * imageintens, ImageSize  250

Out[]=

The factor of 20 in the above command is included to bring the brightness of the image into a proper range for viewing.

4.3 The Autocorrelation Function of Speckle Intensity We turn now to a calculation of the autocorrelation of the speckle intensity, or more correctly stated, the autocovariance, since we will subtract estimates of the mean intensity. The result will also be normalized to unity at the origin, thus yielding the normalized autocovariance of intensity, which we represent by the symbol γ. For circular complex Gaussian field amplitudes, the normalized covariance of intensity is equal to the squared magnitude of the normalized covariance of field amplitude, represented by μ. Thus γ = μ2 (Ref. [4], Section 2.8.3). According to the van Cittert–Zernike theorem (Ref. [4], Section 5.7), the normalized autocorrelation function μ of the complex field in the image plane is related to the intensity distribution IP (α, β) across the exit pupil of the imaging system through a scaled Fourier transform,

  IP (α, β)  μ (Δx, Δy) =

-

2π λ

f

(Δx α+Δy β)

∫ ∫ IP (α, β)  α  β

αβ ,

where the integration is over the entire (α, β) pupil plane, f is the focal length of the lens, and λ is the wavelength. The coordinates in the exit pupil are (α, β); the coordinates in the normalized autocovariance plane are the difference coordinates ( Δx = x1 – x2 , Δy = y1 – y2 ), where (x, y) are coordinates in the image plane. Since the intensity IP (α, β) is a discrete approximation to a circle, centered on the optical axis (i.e., centered on the origin), the form of μ should theoretically be the normalized Fourier transform of the circle (in this case, a continuous circular function), or

Simulation of Speckle in Optical Imaging

In[]:=

31

μ[Δx_, Δy_] = FourierTransformcirc[Sqrt[α ^ 2 + β ^ 2]], {α, β}, {Δx, Δy}, FourierParameters  {0, - 2 π} BesselJ1, 2 π

Out[]=

Δx2 + Δy2 

Δx2 + Δy2

The autocovariance of speckle intensity is the squared modulus of this quantity, as plotted below: In[]:=

Plot3DAbs[μ[Δx, Δy]] ^ 2, {Δx, - 2, 2}, {Δy, - 2, 2}, Ticks  None, ImageSize  250

Out[]=

Because we are interested only in the form of the result, we have assumed that the radius of the circle is 1 and that λf = 1. Our goal now is to determine how closely the normalized autocovariance function of the discrete intensity data matches the form of the theoretical normalized autocovariance. The command ListCorrelate[] performs the same operation as ListConvolve[], but without a reversal of the kernel. To obtain an autocorrelation of a list named list, the command would be written ListCorrelate[list,list]. Recall the subtlety that if a 1 is added at the end of the argument of the ListCorrelate command, the correlation will be an array of the same size as that of the image being correlated (1024 × 1024 in this case). We now calculate the autocovariance of the intensity distribution in the image plane. In[]:=

listcorr = ListCorrelateimageintens - MeanFlattenimageintens, imageintens - MeanFlattenimageintens, 1; listcorr1 = RotateRightlistcorr, { / 2,  / 2};

The Flatten[] command is used to reduce the 2D image to an equivalent 1D list over which the average intensity can be calculated, including all data points in the array. The resulting full autocovariance function is plotted below: In[]:=

ListPlot3Dlistcorr1  Maxlistcorr, PlotRange  All, ImageSize  250

Out[]=

This plot shows the full structure of the entire covariance array. Using the Take[] command, we focus attention on the central peak by plotting only a 90 × 90 sub-array in the center of the full covariance array, normalizing the result by the maximum value of the covariance. In[]:=

smalllistcorr = Takelistcorr1  Maxlistcorr, {442, 582}, {442, 582};

32

Chapter 4

In[]:=

ListPlot3Dsmalllistcorr, PlotRange  All, Ticks  None, ImageSize  250

Out[]=

There are several reasons that the simulation result is not exactly the same as the theoretical result: (1) the discretized circular stop does not have exactly the same shape as a true circle; (2) the calculation of the speckle intensity is over a finite array of statistical samples, and yields a slightly different result on each evaluation run; and (3) The van Cittert–Zernike theorem theoretical result assumes that the average intensity distribution over the circular pupil is constant, while the shaping of the diffuser spectrum caused by phase correlations has resulted in departures from a constant average intensity over that aperture.

4.4 The Power Spectrum of Speckle Intensity The power spectral density of speckle-pattern intensity is given by the Fourier transform of the pattern’s autocorrelation function, according to the Wiener–Khinchin theorem (Ref. [4], Section 3.4). However, to obtain a smooth and accurate power spectrum, many different diffusers with independent phase distributions must be generated and the resulting power spectral estimates must be averaged over these results. Thus, if we take the 2D discrete Fourier transform of the array listcorr1, we will find a noisy estimate of the power spectral density, except for a missing delta function at the origin that would arise from the mean value of the array, which we have subtracted. An alternative approach to finding the power spectrum is simply to calculate the squared magnitude of the Fourier transform of the speckle intensity distribution, after the mean intensity has been subtracted. Again we arrive at an extremely noisy estimate, and an average over an ensemble of diffusers is required to reduce the level of noise. Both of these approaches are illustrated below. Fourier transform of the autocovariance function: In[]:=

psd = RotateRightFourierlistcorr, { / 2,  / 2}; ListPlot3DTake[psd / Max[Abs[psd]], {412, 612}, {412, 612}], PlotRange  All, ImageSize  250, Ticks  None

Out[]=

Fourier transform of the mean-subtracted intensity distribution: In[]:=

psd2 = AbsRotateRightdftimageintens - Meanimageintens, { / 2,  / 2} ^ 2;

Simulation of Speckle in Optical Imaging

In[]:=

33

ListPlot3DTake[psd2 / Max[psd2], {412, 612}, {412, 612}], PlotRange  All, ImageSize  250, Ticks  None

Out[]=

A close examination shows that both approaches yield roughly similar results for the power spectral density of the speckle pattern intensity. For comparison purposes, it’s of interest to calculate the theoretical power spectral density, which is given by the Fourier transform of the theoretical intensity covariance distribution presented above (neglecting the delta function at the origin). The theoretical power spectral density can be calculated as indicated below, assuming that the radius of the circular stop is unity and the product λf is also unity. The parameters (u, v) represent a spatial frequency pair. The plot has been normalized by π, which is the value of the theoretical power spectral density at the origin. In[]:=

theorypsd[u_, v_] = FourierTransformAbs[μ[Δx, Δy]] ^ 2 / π, {Δx, Δy}, {u, v}, FourierParameters  {0, - 2 * π}; Plot3Dtheorypsd[u, v], {u, - 4, 4}, {v, - 4, 4}, PlotRange  All, AxesLabel  {u, v, "psd"}, ExclusionsStyle  Automatic, ImageSize  250

Out[]=

It seems plausible that if the noisy discrete results were averaged over a large number of different diffuser realizations, the discrete power spectra would begin to resemble the theoretical result.

4.5 Effect of Speckle on Resolution In this section we wish to explore the effects of speckle on an observer’s ability to resolve small features in an image. The section is divided into two subsections, the first illustrating an object consisting of an opaque structure on a transparent background and the second consisting of a transparent structure on an opaque background.

Opaque Structure on a Transparent Background The object of interest in this case will be a standard Air Force test target as shown below, named testtarget. The ColorConvert[] command converts what originally is an RGB image into a grayscale image. White regions on this target are assumed to be completely transparent and black areas to be completely opaque.

34

Chapter 4

In[]:=

testtarget = ColorConvert

, "Grayscale";

Next we find the size of this object, and then select a 1024 × 1024 subset of the pixels that includes the finest sets of target bars. We call this subset newtarget. In[]:= Out[]= In[]:=

ImageDimensions[testtarget] {1636, 1650} newtarget = Take[ImageData[testtarget], {460, 1483}, {460, 1483}]; Dimensions[newtarget] Image[newtarget]

Out[]=

{1024, 1024}

Out[]=

Thus, the new image is 1024 × 1024 in size and includes the finest sets of bars. The imaging system is again assumed to have a 4f geometry. The focal-plane stop is defined to be circular with a diameter . If we are to compare an image with speckle to an image without speckle (i.e., the same imaging system but without a diffuser present), both cases should be filtered by the same aperture of diameter  in the Fourier plane. The stop diameter is taken to be 200 pixels in the examples below. The filtered version of the speckle-free image is now calculated. Display of the result is held back until it can be shown side-by-side with the speckled version of the same image.

Simulation of Speckle in Optical Imaging

In[]:=

35

Clearimageampl, imageintens,   = 200; stop[_] = Parallelize Tablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }; imageampl = idftstop[] * RotateRightdft[newtarget], { / 2,  / 2}; imageintens = Absimageampl ^ 2; v1 = ImageAdjustImageimageintens, {1, 1};

This will be the image to which we will compare the speckled image below. Now insert the diffuser in the object plane. The diffuser is the same phase-correlated diffuser as was defined above. The total object is then the product of the diffuser and the test target. The focal-plane stop is again taken to have a diameter of  = 200. In[]:=

Clearimageampl, imageintens,   = 1024;  = 200; diffuser = Exp[I * smooth]; totalobj = newtarget * diffuser; imageampl = idftstop[] * RotateRightdfttotalobj, { / 2,  / 2}; imageintens = Absimageampl ^ 2;

In[]:=

v2 = ImageAdjust[Image[imageintens], {1, 2}];

Now we show the two images to be compared side-by-side: In[]:=

GraphicsRow[{v1, v2}]

Out[]=

Note again that, in the speckled image, the {1,2} in the last part of the above ImageAdjust[] command adjusts the contrast and the brightness of the image. Increasing the brightness parameter from 2 to a larger value such as 20 increases the saturation of the speckle, making the speckled areas more uniform, but does not appreciably improve resolution. Comparison of the speckled image and the image without speckle confirms that speckle has seriously degraded the resolution. For example, the central portion of the original image of the target to the left of the small dark square can be partially resolved in the filtered speckle-free image but is mostly masked by speckle in the speckled image. Given the results above, we can conclude that speckle has a serious negative effect on our ability to resolve detail in an image. It might be argued that we have chosen a worst case for resolution by using an object that has mostly a transparent background with an opaque structure. In the next section we investigate whether switching to an object with an opaque background and transparent structure yields improved image resolution.

36

Chapter 4

Transparent Structure on an Opaque Background In this subsection, the previous object will be negated to create a transparent structure on an opaque background, and our goal is to see if this is a more favorable situation for image resolution. We start with the same object used previously and invert the grayscale: In[]:=

negated = ColorNegate[Image[newtarget]]

Out[]=

In[]:= Out[]=

ImageDimensions[negated] {1024, 1024}

To make a fair comparison of this image with its speckled version, we must apply the same Fourier filter to this image that we will use for the speckled image: In[]:=

 = 200;  = 1024; imageampl = idftstop[] * RotateRightdft[ImageData[negated]], { / 2,  / 2}; imageintens = Absimageampl ^ 2; c1 = ImageAdjustImageimageintens, {1, 1};

We delay display of this image until we can present it side-by-side with the speckled version. Now we superimpose the diffuser created above with the filtered object we just created. In[]:=

 = 1024;  = 200; totalobj = ImageData[negated] * diffuser; imageampl = idftstop[] * RotateRightdfttotalobj, { / 2,  / 2}; imageintens = Absimageampl ^ 2;

In[]:=

c2 = ImageAdjustImageimageintens, {1, 10};

Now the two images can be presented side-by-side. The speckled image has intentionally been saturated by choosing the second number in the ImageAdjust[] command to be 10 in order to bring out as much bright detail as possible.

Simulation of Speckle in Optical Imaging

In[]:=

37

GraphicsRow[{c1, c2}]

Out[]=

We find that in the image with speckle, we can resolve some but not all of the structure to the left of the small speckled square just below the large speckled square, so we conclude that in our second example we can resolve slightly more detail than in the first, but we still lose significant resolution.

4.6 Speckle in Color Images Our examples in Section 4.5 both involve grayscale images. In this section we wish to illustrate a case of colored speckle, as might be seen if red, green, and blue lasers were to illuminate a rough surface with different reflectivities at these three wavelengths. We again assume a 4f imaging system with a pupil stop, normal plane-wave incidence on the diffuser, and observation of the colored speckled image. We assume RGB illumination with three lasers having wavelengths of 630 nm (red), 532 nm (green), and 465 nm (blue). These wavelengths can be changed by the reader with Mathematica if you wish to execute the program. The color image that we introduce at the input of the system is shown in the image below:

In[]:=

colorpicture =

The dimensions of this image are first determined.

;

38

Chapter 4

In[]:= Out[]=

ImageDimensionscolorpicture {256, 356}

The image consists of three images combined, namely a red image, a green image, and a blue image. We can separate and display grayscale versions of these three images with the Mathematica command ColorSepatate[]. In[]:=

GraphicsRowColorSeparatecolorpicture, ImageSize  400

Out[]=

All three wavelengths pass through the very same thin diffuser (or are reflected from the same rough surface). For this reason, we start with a random model for the common path-length differences experienced by all three wavelengths on passage through the same diffuser. There are two subtleties that must be accounted for an accurate model: 1) Passage of the three wavelengths through the same diffuser implies that the random phases imparted to each wavelength are different. If ℓ represents a path-length delay suffered by the light at a particular point on the diffuser, then the phase shift experienced by wavelength λ on passage through the diffuser at that point will be Δϕ = 2 π



.

λ

Thus, the phase shift is wavelength dependent, a fact that must be taken into account. 2) The average speckle size is smaller for short wavelengths than for long wavelengths. The average width of a speckle is proportional to w≈

λf

D

,

where D is the diameter of the focal plane aperture, and f is the focal length of the lenses in the 4f system. Thus, if the wavelength becomes shorter, the speckle width becomes narrower. Both of these effects need to be taken into account in the model. The first effect, dependence of phase shifts on wavelength, is taken care of by starting with a random model for the path-length differences introduced by the diffuser, and converting to a phase shift by using the equation above for phase shift Δϕ. Thus, each wavelength will have associated with it a different phase diffuser, even though all diffusers stem from the same path-length-difference model. If the separations of the three wavelengths are sufficiently large, as they are in the case of RGB illumination, then each of the diffuser phase models can be considered statistically independent of the other two (see Section 6.3.2 of Ref. [1]). In the code that follows, we build a model for the path-length-difference fluctuations, starting with independent Gaussian-distributed samples and smoothing them with an averaging window. Again, the parameter ℳ represents the diameter of a circular smoothing window, while the new parameter ℋ represents the desired standard deviation of the path-length difference fluctuations. Again, the command ListConvolve[] is used to smooth the initial array of independent numbers. A normalization of the kernel by

7 8

ℳ is found to be needed to achieve an approxi-

mately 200 μm path-length-difference standard deviation when we choose ℋ to be 200 μm. We plot a slice through the path-length profile to see a sample of its excursions. In[]:=

ℳ = 12;  = 1024;

In[]:=

ℋ = 200; (* ℋ is the path length standard deviation in microns *)

In[]:=

pathlength = ParallelizeTableRandomVariateNormalDistribution[0, ℋ], {}, {};

In[]:=

kernel = 1 / (ℳ * 7 / 8) * TablecircSqrti - ℳ / 2 ^ 2 + j - ℳ / 2 ^ 2  (ℳ / 2), i, 1, ℳ, j, 1, ℳ;

Simulation of Speckle in Optical Imaging

In[]:=

smoothlength = ListConvolve[kernel, pathlength, 1];

In[]:=

ListPlotsmoothlength〚All,  / 2〛,

39

AxesLabel  "Pixel Number", "Smoothed Phase", ImageSize  400 Smoothed Phase 600 400 200 Out[]=

200

400

600

800

1000

Pixel Number

-200 -400 -600

In[]:= Out[]=

StandardDeviation[Flatten[smoothlength]] 201.715

The standard deviation is seen to be close to our goal of 200 μm. With the path-length-difference model in hand, we can now turn our attention back to the colored object. The object is initially only 256 × 356 pixels in size. In order to sample its spectrum more finely and to match its size to that of the diffuser, we increase the size of this model to 1024 × 1024 pixels by padding with zeros in both dimensions. After the calculations are complete, we can crop the image back to its original size. The command needed to create the expanded image is In[]:=

myimage = ImageCropImagePadcolorpicture, 768 / 2, {1024, 1024}; ImageDimensionsmyimage

Out[]=

{1024, 1024}

The ImagePad[] command pads with the same number of zeros in all dimensions, leaving one dimension larger than the other, while the ImageCrop[] command reduces the larger dimension to match the smaller dimension, i.e., to achieve 1024 × 1024 pixels. In addition, we now separate the RGB colors in this new expanded image. In[]:=

separated = ColorSeparatemyimage;

The next step is to set parameter values and establish tables into which results can be placed. Each of the tables allows for three entries, one for each wavelength. In[]:=

 = 1024;  = 500; diffuserphase = Table0, i, 1, 3; diffuser = Table0, i, 1, 3; totalobject = Table0, i, 1, 3; imageampl = Table0, i, 1, 3; imageintens = Table0, i, 1, 3; speckledimage = Table0, i, 1, 3; λ = {.630, .532, .465}; (* Wavelength in microns *)

Unfortunately, there is no practical way to shrink the spectrum with the choice of the second parameter to account for shorter wavelengths. An alternative that is entirely equivalent is to increase the diameter of the Fourier pupil stop by an appropriate ratio of wavelengths, thereby making the average speckle size smaller for shorter wavelengths. For the first wavelength, λ〚1〛, the pupil diameter can remain , but for λ〚2〛 the pupil diameter should be changed to

λ〚1〛 λ〚2〛

, and for λ〚3〛 the pupil diameter should be

λ〚1〛 λ〚3〛

. In the code below, we compute the diffuser

phase shift for each wavelength based on the path-length-difference distribution, then create the diffuser amplitude transmittance from the phase shifts. Each of the three color-separated image planes is operated on separately, with proper phase shifts and pupil sizes to create three colorseparated speckled images. These three speckled images are cropped to the original size of the object and displayed side-by-side. The images

40

Chapter 4

are then combined to produce a speckled color image. Note that the constant 4π multiplies the path length due to the assumption that the speckle patterns are viewed in reflection, rather than in transmission through a diffuser. In[]:=

stop [_] := Parallelize Tablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, } diffuserphase〚1〛 = 4 * Pi * smoothlength / λ〚1〛; diffuser〚1〛 = ExpI * diffuserphase〚1〛; totalobject〚1〛 = ImageData[separated〚1〛] * diffuser〚1〛; imageampl〚1〛 = idftstop[] * RotateRightdfttotalobject〚1〛, { / 2 + 1,  / 2 + 1}; imageintens〚1〛 = Absimageampl〚1〛 ^ 2; s1 = speckledimage〚1〛 = ImageCropImageAdjustImageimageintens〚1〛, {1, 3}, {256, 356};

In[]:=

stop [_] := Parallelize Tablecirc[Sqrt[((x -  / 2 - 1) ^ 2 + (y -  / 2 - 1) ^ 2)] / ((λ〚1〛 / λ〚2〛) * ( / 2))], {x, 1, }, {y, 1, } diffuserphase〚2〛 = 4 * Pi * smoothlength / λ〚2〛; diffuser〚2〛 = ExpI * diffuserphase〚2〛; totalobject〚2〛 = ImageData[separated〚2〛] * diffuser〚2〛; imageampl〚2〛 = idftstop[] * RotateRightdfttotalobject〚2〛, { / 2 + 1,  / 2 + 1}; imageintens〚2〛 = Absimageampl〚2〛 ^ 2; s2 = speckledimage〚2〛 = ImageCropImageAdjustImageimageintens〚2〛, {1, 3}, {256, 356};

In[]:=

stop [_] := Parallelize Tablecirc[Sqrt[((x -  / 2 - 1) ^ 2 + (y -  / 2 - 1) ^ 2)] / ((λ〚1〛 / λ〚3〛) * ( / 2))], {x, 1, }, {y, 1, } diffuserphase〚3〛 = 4 * Pi * smoothlength / λ〚3〛; diffuser〚3〛 = ExpI * diffuserphase〚3〛; totalobject〚3〛 = ImageData[separated〚3〛] * diffuser〚3〛; imageampl〚3〛 = idftstop[] * RotateRightdfttotalobject〚3〛, { / 2 + 1,  / 2 + 1}; imageintens〚3〛 = Absimageampl〚3〛 ^ 2; s3 = speckledimage〚3〛 = ImageCropImageAdjustImageimageintens〚3〛, {1, 3}, {256, 356};

In[]:=

GraphicsRow{s1, s2, s3}, ImageSize  400

Out[]=

Now we combine these images into a single color image and display the original object and the speckled image side-by-side.

Simulation of Speckle in Optical Imaging

In[]:=

41

finalimage = speckledimage〚1〛, speckledimage〚2〛, speckledimage〚3〛; combined = ColorCombinefinalimage;

In[]:=

GraphicsRowMagnifyImageCropmyimage, {256, 356}, 1.1, ImageAdjustcombined, {1, 5}, ImageSize  500

Out[]=

A close examination of the colored specked image reveals some interesting facts. First, the red speckle lobes do seem to be slightly wider than the green or blue speckle lobes, as they should be. Secondly, because the wavelength separations are wide enough to generate independent speckle patterns in the three colors, one can distinguish what mixtures of colors were used for various regions of the original object. For example, in the yellow hair of the speckled image we see a mixture of mostly red and green speckle, while in the white face we see a mixture of all three colors in separate speckles. The magenta shirt sleeve on the left has a mixture of red and blue speckles. It’s also interesting that the RGB speckles overlap enough to maintain a rendering of the original colors. While it is not easy to estimate the magnitude of each color component from this combined picture, this may be possible from the color-separated pictures that were combined to produce the speckled color image.

5. Simulation of Speckle in Free-Space Propagation Calculating the diffraction patterns of clear apertures of various shapes is a common task. However, similar calculations for apertures with a complex internal structure are less common. In the case studied here, the internal structure of a rectangular aperture is a random pattern of phase representing a diffuser. To perform the simulation of propagation, choices must be made for the number of samples within the aperture (the parameter ℳ in what follows) and the total number of samples in the simulation (the parameter  in what follows), as well as the method of calculation. Guidelines for choices of these parameters and methods for clear apertures do not apply in this more complex case. The geometry assumed for these simulations is shown in the figure below:

A normally incident plane wave from a highly coherent source, indicated by the arrows on the left, is incident on a diffuser, and light is scattered in many directions. The incident uniform light spot is bounded by an aperture. The goal is to find the speckle pattern in a plane at a normal distance z from the average diffuser surface, indicated by the vertical line labeled observation plane, and to observe the changes in that pattern as z is changed. Because of the long computation times required for 2D simulations, the simulations in this chapter will be 1D. Generalizations to two dimensions will be fairly obvious, and as computer speeds continue their upward march, 2D simulations may become less time consuming in the near future.

5.1 The Diffuser We will now construct a 1D correlated-phase diffuser similar to the 2D version constructed in the previous chapter. A difference from the previous chapter, besides the smaller dimensionality, is that this 1D diffuser will be imbedded in a surrounding padding of zeros. The first simulation will have  pixels, ℳ of which are diffuser and  – ℳ of which are zeros. We occasionally use the symbol  to represent the ratio /ℳ, which is the ratio of the total number of samples to the number of those samples lying in the diffuser aperture. The reason for padding with zeros is that the more the diffuser is padded with zeros, the finer the sampling will be in the spectrum of the diffuser and in its diffraction pattern. The choices of  and ℳ must be tailored to the problem at hand. We elaborate on this issue in the two sections to follow. Initially, we let  = 4096 and ℳ = 512. Note that in the Mathematica code, we are using script , ℳ, and  to avoid any confusion with Mathematica commands, which always begin with non-script upper-case letters. The second approach will use a different value for ℳ. We wish to create a diffuser Fourier spectrum that is tapered to small values at the window edges to avoid significant aliasing. Constructing such a diffuser requires the introduction of correlations between phase samples. This is accomplished by first generating a length- ℳ array of uncorrelated Gaussian-distributed phases and then smoothing that array with a finite window via convolution. For the kernel in this case we choose a sinc-function (sinc[x]=

sin[π x] πx

) smoothing window (i.e., a convolution kernel) with a main-lobe half-width of  = 8 pixels.

44

Chapter 5

In[]:=

Clear[, ℳ, ]  = 4096;  = 8; ℳ = 512; uncorrelated1 = ParallelizeTableRandomVariateNormalDistribution[0, 4 * π], {ℳ};

In[]:=

kernel = (1 / ) * ParallelizeTablesinci  , i, - 5 * , 5 * ; ListPlotkernel, PlotLabel  "The Convolution Kernel" The Convolution Kernel

0.10

Out[]=

0.05

20

40

60

80

The standard deviation of the phase in the uncorrelated array is chosen to be 4π radians. Smoothing reduces the excursions of the phase due to averaging, as we shall see. The following Mathematica code generates a random but smoothed phase profile and calculates the standard deviation of the phase: In[]:=

smooth = ListConvolve[kernel, uncorrelated1, 1]; StandardDeviation[smooth]

Out[]=

4.47472

A plot of the smoothed phase profile is shown below. In[]:=

ListPlotsmooth, AxesLabel  "Pixel Number", "Smoothed Phase", ImageSize  400 Smoothed Phase

5

Out[]=

100

200

300

400

500

Pixel Number

-5

-10

We have plotted the smoothed phase array to make sure that the range of fluctuations of the phase is reasonable. The average width of the speckle lobes is about 17 pixels, the width of the main lobe of the smoothing kernel. Next, the diffuser amplitude transmittance is calculated from the smoothed phase, and its real and imaginary parts are plotted to see whether they fill the range –1 to 1 more-or-less uniformly. In[]:=

diffuser = Exp[I * smooth];

In[]:=

p1 = ListPlotRediffuser, PlotRange  All, AxesLabel  "Pixel Number", "Real Part", PlotRangePadding  0.01;

In[]:=

p2 = ListPlotImdiffuser, PlotRange  All, AxesLabel  "Pixel Number", "Imaginary Part", PlotRangePadding  0.01;

Simulation of Speckle in Free-Space Propagation

In[]:=

GraphicsRow{p1, p2}, ImageSize  600

Real Part 1.0

Imaginary Part 1.0

0.5 Out[]=

45

0.0

0.5

100

200

300

400

500

Pixel Number

0.0

-0.5

-0.5

-1.0

-1.0

100

200

300

400

500

Pixel Number

The positive and negative ranges seem to be reasonably well filled. The average width of the autocorrelation function of the real or imaginary parts of the diffuser amplitude transmittance is about 5 pixels, less than that of the phase function due to phase wrapping at 2 π boundaries. Now we calculate and plot the squared modulus of the Fourier spectrum of the diffuser with a smoothed phase after padding the array with (  – ℳ)/2 zeros on both sides. The user-defined command dft[] performs a discrete Fourier transform, as defined in the hidden initialization cell at the beginning of this chapter (see the horizontal gray line at the start of this and every chapter). The PadRight command pads with zeros on the right to create a length  sequence. In[]:=

diffuserspectrum = dftPadRightdiffuser, ; ListPlotRotateRightAbsdiffuserspectrum ^ 2,  / 2, AxesLabel  "Pixel Number", "Spectral Power", Joined  True, ImageSize  400

Spectral Power

6000 5000 4000 Out[]=

3000 2000 1000

1000

2000

3000

4000

Pixel Number

The diffuser spectrum is seen to be well tapered, with significant power between indices 1000 and 3000, approximately.

5.2 The Fresnel Transfer Function Approach The propagation and diffraction calculation can be carried out in several different ways, but we choose first what has been called the Fresnel transfer function approach. In what follows, complex fields and other complex-valued quantities are rpresented by bold-faced characters. The (1D for speed of computation) field U(x; z) some distance z away from the diffuser is given by 2

U (x; z) = Fourier-1 Fourier {diffuser} *  πλz u  , where U(x;0) represents the field leaving the diffuser, “Fourier” is a Fourier transform operator, and “Fourier -1 ” is an inverse Fourier transform operator. The variable u represents spatial frequency. The quadratic-phase spectral factor can be characterized by a Fresnel number. Let the diffuser aperture width be represented by L; the full width of the diffuser plane represented in the simulation is therefore L. It follows from the properties of the discrete Fourier transform that the spectral samples are separated by distance

1 L

. Thus, the quadratic-phase exponential transfer function can be written in discrete form as

46

Chapter 5

λz

T (p; z)  exp π

Q2 L2

p2 ,

where p is an index that runs from –/2 + 1 to /2. When the diffraction pattern of the finite-area diffuser is observed at distance z from the diffuser plane, the diffraction by the finite window of the diffuser (rather than the internal structure of the diffuser itself) can be characterized by a Fresnel number defined by ( L / 2) 2 ℱ =

L2 =

λz

4 λz

.

It then follows that the transfer function of free space, after discretization, is given by T (p; z) = exp π

1 4 2 ℱ

p2  = expπ

ℳ2

4  2 ℱ

p2  ,

where p runs from 0 to  – 1.

The quadratic-phase transfer function has frequency as its independent variable. The rate of change of the frequency index determines whether there is aliasing due to the transfer function in both the frequency domain and the space domain. Much can be learned by finding the maximum rate at which the argument of the transfer function changes and, in particular, what parameters can minimize that rate. We assume that the total number of sample points  is fixed, the parameter p has extreme values of ±ℳ/2, and the Fresnel number ℱ can take on values over a wide range, say 0.01 to 1000. The maximum rate of change of the transfer function argument can be found by differentiating that argument with respect to p: 

πℳ2 p

π ℳ2 p2

 p 4  2 ℱ

=

2  2 ℱ

.

But the maximum value of p is ℳ/2, so πℳ2 p

2  2 ℱ

πℳ3 = max

4  2 ℱ

.

If the total number of sample points  is assumed fixed, we see that large values of the Fresnel number ℱ imply the smallest rate of change (and therefore the lowest danger of aliasing). This method for calculating the diffraction pattern of a diffuser works best close to the diffuser aperture, where the Fresnel number ℱ is large. We also see that the rate of change can be further reduced by using a small value of ℳ. However, the number of samples ℳ within the diffuser must also be large enough to adequately sample the field fluctuations induced by the diffuser. Thus, the optimum choice of parameters is to use the smallest value of ℳ that will adequately sample the diffuser field and to pad with zeros so that the total number of samples equals . Notice also that increasing the total number  of samples by a multiplier m should enable reducing the Fresnel number ℱ by a factor m2 without increasing aliasing. With these thoughts in mind, we create the  = 4096-length quadratic-phase transfer function. We choose ℳ = 512, which is the number of data points used to create the diffuser. To explore whether aliasing is occurring in the transfer function, we plot the real (or imaginary) part of the transfer function for various values of ℱ and look for replications of the spectrum that would be an indication of aliasing. Below we show plots of the real part of the transfer function for various values of ℱ. The parameter ℒ is the base 10 logarithm of ℱ. In[]:=

 = 4096; ℳ = 512;

In[]:=

g = Table0, i, 1, 6;

In[]:=

transferfunc[ℒ_] = ParallelizeTableExp- I *

In[]:=

π * ℳ^2 4 *  ^ 2 * (10 ^ ℒ)

* i - ℳ / 2 ^ 2, i, 0, ℳ - 1;

Forℒ = - 2, ℒ ≤ 3, ℒ ++, g〚ℒ〛 = ListPlotRetransferfunc[ℒ], ImageSize  500, PlotRange  {- 1, 1}, PlotRangePadding  .03, InterpolationOrder  2, Joined  True, Ticks  {{0, 200, 400}, {- 1, 0, 1}}, PlotLabel  "ℱ= " ToString N10ℒ ;

Simulation of Speckle in Free-Space Propagation

In[]:=

47

GraphicsRow{g〚- 2〛, g〚- 1〛}, ImageSize  600 ℱ= 0.01

ℱ= 0.1

1

1

Out[]=

0

200

400

-1 In[]:=

0

200

400

-1

GraphicsRow{g〚0〛, g〚1〛}, ImageSize  600 ℱ= 1

ℱ= 10

1

1

Out[]=

0

200

400

-1 In[]:=

0

200

400

-1

GraphicsRow{g〚2〛, g〚3〛}, ImageSize  600 ℱ= 100

ℱ= 1000

1

1

Out[]=

0

200

400

-1

0

200

400

-1

For the numbers chosen, aliasing is evident for ℱ ≲ 1. Next we must inverse Fourier transform the product of the diffuser spectrum and the quadratic-phase transfer function. The diffuser spectrum has already been calculated above and is of length 4096, while the transfer function array must be padded to achieve the same length. In the figures below we normalized plots of the diffraction pattern for a number of different values of the Fresnel number. In[]:=

diffractionpattern[ℒ_] := Absidftdiffuserspectrum * RotateRightPadRighttransferfunc[10 ^ ℒ], , ( - ℳ) / 2 ^ 2

In[]:=

d = Table0, j, 1, 6;

In[]:=

Forℒ = - 2, ℒ ≤ 3, ℒ ++, d〚ℒ〛 = ListPlotRotateRightdiffractionpattern[ℒ]  Maxdiffractionpattern[ℒ],  / 2, PlotLabel  "ℱ= " ToString N10ℒ , PlotRange  All, PlotRangePadding  .002, ImageSize  400, Joined  True, Ticks  {{1000, 2000, 3000}, All};

48

Chapter 5

In[]:=

GraphicsRow[{d〚- 2〛, d〚- 1〛}] ℱ= 0.01

Out[]=

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

In[]:=

ℱ= 0.1

1000

2000

0

3000

1000

3000

GraphicsRow[{d〚0〛, d〚1〛}] ℱ= 1

Out[]=

ℱ= 10

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

In[]:=

2000

1000

2000

0

3000

1000

2000

3000

GraphicsRow[{d〚2〛, d〚3〛}] ℱ= 100

Out[]=

ℱ= 1000

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

1000

2000

3000

0

1000

2000

3000

Note that the value of ℱ for each diffraction pattern appears at the top of the plot. There are several points to be made based on this set of plots: ◼ The transfer functions for Fresnel numbers of 1 or less show signs of aliasing, but the diffraction pattern for Fresnel number 1 does not

show signs of aliasing, perhaps because of the random nature of the diffuser. ◼ The diffraction pattern expands as the light propagates away from the aperture, an expected property of diffraction. ◼ When the Fresnel number grows to be 10 or more, the diffraction pattern is confined to roughly the same width as the diffuser, i.e., ℳ =

512 pixels. ◼ There is comparatively little change of the diffraction pattern when the Fresnel number is 10 or larger. This is because a large portion of

the propagation transfer function has become approximately unity for these Fresnel numbers. ◼ As the Fresnel number grows very large, the diffraction pattern never approaches the constant intensity characteristic of a pure phase diffuser. This is because we have limited the extent of the non-zero part of the transfer function to ℳ pixels, thereby cutting off higher-

frequency components that are needed to produce a pure phase function. We add a note here that the reader should not expect the outlines of the speckle pattern profile to follow the diffraction pattern of a rectangular aperture with no diffuser. The reason is that the correlations of the diffuser fluctuations change the nature of the diffraction pattern above and beyond the simple addition of speckle.

Simulation of Speckle in Free-Space Propagation

49

For a diffuser or scattering spot that is limited by a finite aperture, such as the rectangular aperture used above, and for the size of the arrays used here, the Fresnel transfer function method works best for Fresnel numbers of 1 or greater. Equivalently, the method works best in the region of Fresnel diffraction from the bounding aperture. In the section that follows, we discuss an alternative method, the Fresnel transform approach, which is better suited for small Fresnel numbers, for which Fraunhofer diffraction eventually becomes dominant.

5.3 The Fresnel Transform Approach An alternative method for calculating free-space propagation of speckle patterns is the Fresnel transform approach. In this case, again in one dimension, we write the speckle field as U (x; z) =

1 

π



λz

x2

 U (α; 0) 

π



α2

λz



L

λz

-

2π λz



 α.

Here the variable α represent a coordinate in the plane of the diffuser, and the symbol L is the width of the diffuser aperture. The complex field U(α; 0) within the aperture of width L represents the field transmitted by the diffuser. We recognize that the integral is a scaled Fourier transform of the product of the diffuser function and a scaled quadratic-phase exponential with variable α. In calculating speckle intensity patterns, the quadratic-phase exponential appearing before the integral signs can be dropped since it does not affect intensity, and we ignore the scaling factor 1/ λz . Again, the diffuser aperture width is assumed to be L, and the total width of the padded diffuser is  = L. The input plane is sampled in an length 1D array, which means that the distance between samples is Δα = L/. It follows that a discretized speckle field can be calculated by a scaled discrete Fourier transform. An important fact follows from the properties of the discrete Fourier transform, namely, that Δu Δα = 1/, where Δu is the distance between samples in the frequency plane, and Δα is the spacing between samples in the input plane. But from the arguments of the Fourier transform kernel, the frequency variable u must be replaced by

x λz

in the diffraction calculation. Therefore, we

conclude that Δα Δx = λz/ . Thus, for fixed Δα, , and λ, as the distance z increases (ℱ decreases), a unit spacing in the calculated observation plane represents an increasing physical distance. This behavior is different than that of the Fresnel transfer function method, for which the spacing between samples in the diffraction plane remains constant. To summarize, using this method we should not expect to see the diffraction pattern expanding as we reduce ℱ. To simplify the notation, let Δα = δ and let Δx = Δ. The relationships discussed in the paragraph above imply that δΔ = λz/N. The above equation can be discretized as follows (neglecting the quadratic-phase function preceding the integral signs): N -1

Uk (z) =  Up (0) exp p=0

π λz

δ2 p2  × exp-

2π λz

k p δ Δ .

For the moment, focus attention on the quadratic-phase exponential. Note that because δ = L/ℳ we can write exp

π δ2 λz

p2  = exp

where ℱ is again the Fresnel number of the finite diffuser aperture, ℱ =

4 π NF

(L / 2)2 λz

p2 ,

ℳ2

.

As we did above, we examine the maximum rate of change of the quadratic-phase exponential argument. Differentiating with respect to the index p, 

4 π ℱ

p



2

p2 =

8 π ℱ

p.

ℳ2

Since the maximum value of p is ℳ/2, we find that 8 π ℱ 2



4 π ℱ

p

= max

.



Thus, we see that aliasing will be minimized when the Fresnel number ℱ is small and the number of samples ℳ within the diffuser aperture is large. These are exactly opposite conditions compared with those required for the Fresnel transfer function method. Now operating on the Fourier transform kernel, exp-

2π λz

k p δ Δ  = exp-

2π N

k p .

Since this method benefits from large ℳ, whereas the Fresnel transfer function method benefits from small ℳ, we create a new diffuser within a larger aperture, holding  constant at 4096 and setting ℳ = 1024. The smoothing kernel is the same as used earlier, and the phase standard deviation for the uncorrelated sequence is again 4π.

50

Chapter 5

In[]:=

Clearkernel, uncorrelated, smooth, , ℳ, diffuser

In[]:=

 = 4096;  = 8; ℳ = 1024;

In[]:=

uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 4 * π], {ℳ};

In[]:=

kernel = (1 / ) * Tablesinci  , i, - 5 * , 5 * ;

In[]:=

smooth = ListCorrelate[kernel, uncorrelated, 1];

The smoothed phase sequence is plotted and its standard deviation is calculated. In[]:=

ListPlotsmooth, AxesLabel  "Pixel Number", "Smoothed Phase", ImageSize  400 StandardDeviation[smooth] Smoothed Phase

10

5

Out[]=

200

400

600

800

1000

Pixel Number

-5

-10

-15 Out[]=

4.5891

Excursions in the plot of the smoothed phase frequently extend beyond 2π. The diffuser amplitude transmittance is now formed, and its intensity Fourier spectrum is calculated. In[]:=

diffuser = Exp[I * smooth];

In[]:=

diffuserspectrum = dftArrayPaddiffuser, ( - ℳ) / 2;

In[]:=

ListPlotRotateRightAbsdiffuserspectrum ^ 2,  / 2, AxesLabel  "Pixel Number", "Spectral Power", ImageSize  400, Joined  True Spectral Power

10 000

8000

Out[]=

6000

4000

2000

1000

2000

3000

4000

Pixel Number

We are now ready to write some Mathematica code to perform the diffraction calculation. We use diffuser created above and we use script letters  and ℳ. The operations needed are implemented by the following code. The real part of the quadratic-phase exponential is plotted first for several values of ℱ to explore aliasing problems. In[]:=

Clear[ℱ, exp]

In[]:=

f = Table0, i, 1, 6;

Simulation of Speckle in Free-Space Propagation

In[]:=

 = 4096; ℳ = 1024;

In[]:=

exp[ℒ_] := TableExpI * 4 * Pi * 10 ^ ℒ * p ^ 2 / ℳ ^ 2, {p, - ℳ / 2, ℳ / 2 - 1};

In[]:=

Forℒ = - 2, ℒ ≤ 3, ℒ ++, f〚ℒ〛 = ListPlotRe[exp[ℒ]], ImageSize  500, InterpolationOrder  2, PlotLabel  "ℱ= " ToString N10ℒ , Joined  True, PlotRange  {- 1, 1}, PlotRangePadding  0.1;

In[]:=

GraphicsRowf〚- 2〛, f〚- 1〛, f〚0〛, ImageSize  600 ℱ= 0.01

Out[]=

In[]:=

1.0

1.0

1.0

0.5

0.5

0.5

0.0

0.0

200

400

600

800

1000

200

400

600

800

1000

0.0

-0.5

-0.5

-0.5

-1.0

-1.0

-1.0

200

400

600

800

1000

800

1000

GraphicsRowf〚1〛, f〚2〛, f〚3〛, ImageSize  600 ℱ= 10

Out[]=

ℱ= 1

ℱ= 0.1

ℱ= 100

ℱ= 1000

1.0

1.0

1.0

0.5

0.5

0.5

0.0

200

400

600

800

1000

0.0

200

400

600

800

1000

0.0

-0.5

-0.5

-0.5

-1.0

-1.0

-1.0

200

400

600

Aliasing begins to occur occurs when ℱ is larger than 100 in this set of results. Now we examine the calculated diffraction patterns. In[]:=

Clearfield, ℱ, exp

The quadratic phase function is created and the diffracted field is computed. In[]:=

exp[ℱ_] := TableExpI * 4 * Pi * ℱ * p ^ 2 / ℳ ^ 2, {p, - ℳ / 2, ℳ / 2 - 1};

In[]:=

field[ℱ_] := RotateRightdftArrayPadexp[ℱ] * diffuser, ( - ℳ) / 2,  / 2;

Note that the command ArrayPad, unlike PadRight, adds ( – ℳ)/2 zeros to both sides of the array. Next we plot normalized diffraction patterns for six different Fresnel numbers. In[]:=

w = Table0, i, 1, 6;

In[]:=

Forℒ = - 2, ℒ ≤ 3, ℒ ++, w〚ℒ〛 = ListPlotAbsfield[10 ^ ℒ] ^ 2  MaxAbsfield[10 ^ ℒ] ^ 2, PlotLabel  "ℱ= " ToString N10ℒ , PlotRangePadding  0.1, ImageSize  400, Ticks  {{1000, 2000, 3000}, All}, Joined  True, PlotRange  All;

51

52

Chapter 5

In[]:=

GraphicsRow[{w〚- 2〛, w〚- 1〛}] ℱ= 0.01

Out[]=

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

In[]:=

ℱ= 0.1

1000

2000

3000

0

1000

ℱ= 10

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

In[]:=

1000

2000

3000

0

1000

2000

3000

GraphicsRow[{w〚2〛, w〚3〛}] ℱ= 100

Out[]=

3000

GraphicsRow[{w〚0〛, w〚1〛}] ℱ= 1

Out[]=

2000

ℱ= 1000

1.0

1.0

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0

1000

2000

3000

0

1000

2000

3000

The conclusions we draw from these plots are as follows: ◼ The spacing between pixels in the diffraction pattern increases as the Fresnel number shrinks, and it is for this reason that the pattern does not expand as ℱ grows small. ◼ Significant aliasing sets in for Fresnel numbers somewhat larger than 100. ◼ For Fresnel number 0.1 or smaller in these results, the diffraction pattern does not change appreciably with further decreases, and is in fact

equal to the intensity Fourier spectrum of the diffuser, a consequence of the Fourier transform relationship between the diffuser field and the diffracted field in the Fraunhofer region. ◼ The Fresnel transform method works best for small Fresnel numbers, while the Fresnel transfer function method works best for large Fresnel numbers.

6. Speckle at Low Light Levels In this chapter we explore the properties of speckle when detected at low light levels. The model used is semiclassical, based on the assumption that light of uniform intensity ℐ incident on a detector pixel results in a Poisson distribution of photoelectrons with an average number of photoevents proportional to the integral of ℐ. Thus, if n(x, y) represents the number of photoevents occurring from the detector pixel centered at (x, y), the mean number of such photoevents is given by n (x, y) =

η



  ℐ (x, y)  x  y, 

where η is the quantum efficiency of the detector, h is Planck’s constant, ν is optical frequency, and  is the area of the photodetector pixel. The multiplier of the integral above represents the efficiency with which integrated intensity is converted into numbers of photoevents (see Ref. [1], Section 8.2 for a more detailed discussion of this subject). Thus, in simulations, a list or array of intensity values incident on an array of detector pixels generates an array of numbers representing photocounts with varying means from the detector pixels. The number of elements in the intensity array in general will be greater than the number of elements in the photocount array, since detector pixels may integrate over several speckles. If the intensity across a given detector element is constant, the statistics of the number of photoevents will obey a Poisson distribution. On the other hand, if the intensity across a given detector element is not constant, as would be the case for an incident speckle pattern, the photoevent statistics are modified, as described below. To illustrate the generation of Poisson-distributed counts from a detector array, for simplicity we start with a uniform intensity over all elements of the array and generate independent Poisson photocounts with identical means at each element of the array. To do so requires partitioning the array of  pixels representing the intensity distribution of the wavefield incident on the detector array into

 

×

 

super-pixels, each represent-

ing one detector element. Within one super-pixel there are  ×  samples of the incident intensity, over which we must sum to obtain the integrated intensity falling on that super-pixel.

6.1 Photocount Image of a Uniform Intensity First we create the uniform intensity array incident on the detector, with each intensity pixel having value unity. We choose to represent the incident intensity by a 1024 × 1024 array and the number of intensity pixels within a super-pixel as 16 × 16. The command Partition[] is used to separate the array into super-pixels. The intensity of each sample is chosen to be unity. In[]:=

Clear, , , incident, superpixel  = 1024;  = 16; incident = ParallelizeTable1, i, 1, , j, 1, ; superpixel = Partitionincident, {, }; Dimensionssuperpixel

Out[]=

{64, 64, 16, 16}

We now have a 64 × 64 array of detector super-pixels, each containing 16 × 16 samples of the incident intensity. We next need to sum the samples in each of the super-pixels to calculate integrated intensity values incident on each super-pixel. The command Total[list,2] sums over all elements of a 2D list (in this case the samples within each super-pixel), yielding an array of super-pixel integrated intensities. In[]:=

integratedintens = ParallelizeTableTotalsuperpixeli, j, 2, i, 1,  / , j, 1,  / ; Dimensionsintegratedintens

Out[]=

{64, 64}

Next, we generate independent Poisson variates at each super-pixel. For simplicity, we set the constant η/hν equal to unity in what follows.

Chapter 6

54

In[]:=

poissondata = ParallelizeTableRandomVariatePoissonDistributionintegratedintensi, j, i, 1,  / , j, 1,  / ;

Finally, we visualize the super-pixel photocounts as an image for a uniform incident intensity: In[]:=

ImageAdjustImagepoissondata

Out[]=

We see that the uniform intensity incident on the detector array generates a significant variation of the detected signal due to the Poisson statistical variations of the photoevents associated with detection.

6.2 The Negative-Binomial Distribution If instead of a constant intensity falling on a super-pixel, there is a speckle pattern, the photocount statistics are no longer Poisson-distributed. Instead the proper distribution to use is a negative-binomial distribution for the number of photocounts (Ref. [1], p. 424). The extra statistical fluctuations of the speckle pattern induce extra fluctuations of the photocounts from a super-pixel, and these extra fluctuations lead to the negative-binomial distribution. Note that the fluctuations of the incident speckle pattern are partially reduced by integration of those fluctuations over each super-pixel when the speckle is finer than the size of the super-pixel, and this is why the negative-binomial distribution is appropriate, rather than the Bose–Einstein distribution, which would apply if there were a single speckle incident on each detector element. Mathematica has knowledge of the negative-binomial distribution, but not exactly in the form we need. From the reference given above, the probability of k photocounts occurring in a super-pixel is given by P (k ) =

Γ(k + m) Γ(k + 1) Γ(m)

m

1+

-k

k

1+

k m

-m

,

where k is the number of counts, k is the average number of counts, and m is the average number of speckles per super-pixel. On the other hand, the Mathematica form of the negative-binomial distribution is P (k ) = where

m+k-1 is a binomial coefficient and is equivalent to m-1

the second form of the distribution is

m 1-p p

m+k-1 m p ( 1 - p) k , m-1 Γ  m +k  Γ k +1 Γ(m)

. The mean of the first form of the distribution is k, while the mean of

. Equating the two expressions for the mean, we obtain the equivalences p= 1+

k

-1

m

1 - p = 1 +

m -1 k

 .

Speckle at Low Light Levels

55

The Mathematic command for the binomial distribution takes the form BinomialDistribution[m,p]. Therefore, to account for the presence of speckle, we need to substitute the command NegativeBinomialDistribution[m,(1+kbar/m)^(-1)] for the command PoissonDistribution[kbar], where kbar is our Mathematica representation for k, the average number of photocounts. Under the simplifying assumption that η/hν = 1, in the (i, j)th super-pixel, kbar is equal to the integratedintens[[i,j]]. We now proceed to find the photocount array when speckle is incident on the detector array.

6.3 Photocount Image of a Speckle Pattern with Uniform Statistics We start with a simulated speckle pattern, which we assume appears in the image of some object illuminated through a diffuser. For this example, we assume that the object is totally featureless and transparent, so that we can concentrate on a field of speckle with the same statistics at each pixel. We create the spectrally tapered diffuser with the same program used in Chapter 4, showing only the power spectrum of the diffuser. The parameter  represents the the diameter of the smoothing filter. We choose  = 1024 and  = 20. In[]:=

 = 1024;  = 20;

In[]:=

uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 25 * π], {}, {};

In[]:=

kernel = (1 / (π * ( / 2) ^ 2)) * TablecircSqrti -  / 2 ^ 2 + j -  / 2 ^ 2  ( / 2), i, 1, , j, 1, ;

In[]:=

smooth = ListCorrelate[kernel, uncorrelated, 1];

In[]:=

diffuser = Exp[I * smooth];

In[]:=

diffuserspectrum = RotateRightFourierdiffuser, { / 2,  / 2};

In[]:=

Image0.5 * Absdiffuserspectrum ^ 2

Out[]=

A focal-plane stop with a diameter of 64 pixels is now defined, and the spectrum of the diffuser is passed through this stop, followed by an inverse DFT. Finally, the intensities are calculated at each pixel, and the speckle pattern is presented as an image. In[]:=

Clearstop, imageampl1, imageintens1, , stop;  = 128; stop = Parallelize Tablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }; imageampl1 = idftstop * RotateRightdftdiffuser, { / 2,  / 2};

In[]:=

imageintens1 = Absimageampl1 ^ 2;(*before integration over the super-pixels*)

We calculate an image of the speckle pattern incident on the detector array and delay its display until a bit later:

56

Chapter 6

In[]:=

r1 = Image7 * imageintens1;

Multiplication by the constant 3 is done just to bring the brightness of the image into a proper range. As a matter of interest, we calculate the contrast of the speckle pattern incident on the detector array: In[]:=

Clear[]  = StandardDeviationFlattenimageintens1  MeanFlattenimageintens1

Out[]=

1.02554

The contrast of the speckle is very close to unity, as it should be for fully developed speckle. See Appendix A for more detail on the proper choice of aperture diameter to assure fully developed speckle. Now we subdivide the speckle intensity array into 64 × 64 super-pixels, each containing 16 × 16 intensity samples, and sum over those intensities to produce a total detected intensity for each super-pixel. In[]:=

Clearsuperpixel, intintensity superpixel = Partitionimageintens1, {, }; intintensity = ParallelizeTableTotalsuperpixeli, j, 2, i, 1,  / , j, 1,  / ; r2 = Image0.03 * intintensity;

An approximate way to calculate the parameter ℳ needed below is as follows. The 1D width of a speckle will be approximately / = 1024/128 = 8 pixels. For super-pixels of width 16 × 16 pixels, we would expect roughly 4 to 5 speckles in the area of a super-pixel, depending on a more precise definition of the width of a speckle. A more accurate way to estimate ℳ is by calculating the contrast 2 of the integrated intensity pattern. In theory, the contrast should equal 1/ ℳ , so ℳ = 1/22 . In[]:= Out[]=

2 = StandardDeviationFlattenintintensity  MeanFlattenintintensity 0.480289

It follows that In[]:= Out[]=

ℳ = 1 / 2 ^ 2 4.33506

This is the value we use for ℳ in the negative-binomial distribution. In[]:=

negbinomdata = ParallelizeTable RandomVariateNegativeBinomialDistributionℳ, 1 + integratedintensi, j  ℳ ^ (- 1), i, 1,  / , j, 1,  / ; r3 = Image0.0015 * negbinomdata;

Below we show, left to right, the intensity pattern incident on the array, the integrated intensities for the array of super-pixels, and the photocounts produced by the super-pixels. In[]:=

GraphicsRow[{r1, r2, r3}]

Out[]=

Note that bright integrated intensities sometimes generate high photocounts and sometimes do not, due to the statistical nature of the conversion of integrated intensity into photocounts.

Speckle at Low Light Levels

57

6.4 Photocount Image for a Diffuse Structured Object Until now, we have considered only uniformly transmitting, unstructured objects, with and without a diffuser present. Now we turn to considering an object that actually contains structure. We will again use the image of the test chart from Chapter 4. As before, we reduce this image to 1024 × 1024 pixels. We use the same diffuser as was defined in the previous section.

In[]:=

testtarget = ColorConvert

In[]:=

newtarget = Take[ImageData[testtarget], {460, 1483}, {460, 1483}];

In[]:=

Dimensions[newtarget]

Out[]=

, "Grayscale";

{1024, 1024}

In this case, a Fourier stop with a diameter of  = 128 pixels is inserted in the focal plane and the filtered image intensity is calculated. The average width of a speckle within a super-pixel will be approximately (1024 / 128) = 8. Thus, there are again approximately 4 to 5 average speckles within a single 16 × 16 super-pixel. In[]:=

Clear, , stop, imageampl2, imageintens2  = 1024;  = 128; stop[_] = Parallelize Tablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }; totalobj = newtarget * diffuser; imageampl2 = idftstop[] * RotateRightdfttotalobj, { / 2,  / 2}; imageintens2 = Absimageampl2 ^ 2;

A display of the filtered image is delayed until it can be shown together with the corresponding photocount image. In[]:=

w1 = Image10 * imageintens2;

The super-pixels are defined and the intensity sums within each super-pixel are calculated. In[]:=

Clearsuperpixel, intintensity2 superpixel = Partitionimageintens2, {, }; intintensity2 = ParallelizeTableTotalsuperpixeli, j, 2, i, 1,  / , j, 1,  / ; w2 = Image0.04 * intintensity2;

Summed intensity values in each super-pixel are used to generate negative-binomial-distributed photocounts. An image of the photocount array is computed and delayed for display next to the speckle pattern that gave rise to it. Again, there are approximately four speckles per super-pixel, but we use the value calculated from the contrast above. In[]:=

data = ParallelizeTable RandomVariateNegativeBinomialDistributionℳ, 1 + intintensity2i, j  ℳ ^ (- 1), i, 1,  / , j, 1,  / ; w3 = Image[0.03 * data];

58

Chapter 6

The speckle pattern is shown below on the left, the integrated intensity pattern is shown in the middle, and the corresponding photocount image is shown on the right. In[]:=

GraphicsRow[{w1, w2, w3}]

Out[]=

From these images it is clear that the super-pixels cover more than a single speckle. Only those detector pixels that contain mostly bright speckles generate a high photocount. We also note that the values of integrated intensity have less dynamic range than the counts in the photocount image, presumably due to the extra fluctuations introduced by the negative-binomial statistics. Resolution in the photocount image is poorer than in either the speckled image or the integrated intensity image. Finally, we investigate the histograms of the three images using the Mathematica command ImageHistogram[]. The histogram of speckle intensity is shown first. It is very close to a negative-exponential curve. In[]:=

ImageHistogram[w1, 100, Frame  False, Axes  True]

Out[]=

The histogram of integrated intensity follows and is distinctly not negative exponential due to the integration over several speckles. In[]:=

ImageHistogram[w2, 100, Frame  False, Axes  True]

Out[]=

Finally, we show the discrete histogram of the photocount array, which has some saturation at the dark end and the bright end. In[]:=

Out[]=

ImageHistogram[w3, 100, Frame  False, Axes  True]

7. Speckle Phase Vortices In this chapter we explore some interesting properties of speckle behavior in the vicinity of the locations where speckle intensity vanishes (i.e., near the zeros of speckle intensity). To do so, we first generate a speckle pattern from a simple simulated uniform diffuse object. We then find the real and imaginary parts of the speckle field and find where each of them simultaneously is zero. At such points the intensity is also zero. We then explore the structure of the speckle phase in regions close to and surrounding these zeros of intensity. For a more detailed discussion of this subject, see Ref. [5].

7.1 Generating the Speckle Pattern We begin with a relatively small random array of phasors (size ℳ × ℳ ) with phases that vary between 0 and 2π with uniform statistics. We do not bother to introduce correlations between phases in this case because spectral aliasing does not change the amplitude statistics of the speckle in the Fourier plane. We pad this diffuser array with zeros to size  ×  in order to achieve closely spaced samples in the speckle pattern. Choose the array sizes: In[]:=

 = 512; ℳ = 8;

Create the phasor array: In[]:=

diffuser = TableExpI * 2 * Pi * RandomReal[], {ℳ}, {ℳ};

Pad the array and check its size: In[]:=

padded = PadRightdiffuser, {(), ()}; Dimensions[Abs[padded] ^ 2]

Out[]=

{512, 512}

Calculate the speckle amplitude in the Fourier plane: In[]:=

speckampl = dft[padded];

Calculate the speckle intensity distribution and find its maximum value: In[]:=

speckintens = Abs[speckampl] ^ 2; Maxspeckintens

Out[]=

446.966

Compute a density plot of the speckle intensity: In[]:=

Out[]=

s0 = ListDensityPlotspeckintens, Mesh  False, ImageSize  200, ColorFunction  GrayLevel

60

Chapter 7

7.2 Finding the Zeros of Intensity Find the real and imaginary parts of the speckle amplitude: In[]:=

real = Re[speckampl]; imag = Im[speckampl];

Find and temporarily suppress contour plots of the zeros of the real (purple contours) and imaginary (green contours) parts of the speckle amplitude: In[]:=

s1 = ListContourPlotreal, Contours  {0}, ContourStyle  Thickness[.008], RGBColor[1, 0, 1], ContourShading  False;

In[]:=

s2 = ListContourPlotimag, Contours  {0}, ContourStyle  Thickness[.008], RGBColor[0, 0.7, 0], ContourShading  False;

Now find the locations where the intensity goes to zero, or very near zero (0.05 as compared with the maximum intensity calculated above). If the contour value is chosen too small, the zeros may be missed by the sampling grid. The zeros of intensity will be colored black. In[]:=

s3 = ListContourPlotspeckintens, Contours  {0.05}, ContourStyle  Thickness[.008], RGBColor[0, 0, 0], ContourShading  False;

Now show all three plots superimposed: In[]:=

s8 = Show{s1, s2, s3}, ImageSize  200 500

400

300 Out[]=

200

100

0 0

100

200

300

400

500

The small black dots represent points where the intensity is zero or very near zero. More-elongated black dots represent regions where there are multiple zeros close together or a small region where the intensity is very close to zero. A superposition of the speckle intensity and the contours of zero of the real and imaginary parts shows that the contours do cross at locations where the speckle intensity vanishes. In[]:=

Show{s0, s1, s2}, ImageSize  200

Out[]=

Next, we wish to explore the behavior of the phase of the speckle amplitude in regions close to these zeros of intensity.

Speckle Phase Vortices

61

7.3 The Phase Behavior in the Vicinity of the Zeros of Intensity To explore the speckle phase in regions close to the intensity zeros, we create a contour plot of the phase for 8 discrete values of phase between –3π/4 and π. The quantity c is a list containing the 8 values of phase for which we desire contours. Note that if you slide your mouse over the figure on the left below, you can see the value of the phase for each contour as the mouse hovers over it. In order to interpret the contour plot, we show that plot and the contours of zero of the real and imaginary parts side-by-side. In[]:=

phase = Arg[speckampl]; c = Table[n * π / 4, {n, - 3, 4}]; s4 = ListContourPlotphase, Contours  c, ContourStyle  Black, Thickness[0.005], ContourShading  None, ContourLabels  Automatic, ImageSize  200;

In[]:=

GraphicsRow[{s4, s8}] 500

500

400

400

300

300

200

200

100

100

Out[]=

0

0 0

100

200

300

400

500

0

100

200

300

400

500

The phase contours seen in this plot require some detailed discussion. First, you may have noticed that the heaviest black contours show more than one phase value as you slowly slide the mouse over them. This behavior is due to a discontinuity in the arctangent function, which is used to obtain the phase. The plot below shows the arctangent function for ranges of positive and negative values of the real and imaginary parts, x and y. In[]:=

Plot3D[Arg[x + I * y], {x, - 5, 5}, {y, - 100, 100}, AxesLabel  {x, y}]

Out[]=

Note the discontinuity in the y direction when x is negative. Thus, the Arg[] function has a continuous transition from – π/2 to π/2 in the y direction when x is positive, but a discontinuous jump from –π to π when x is negative. It follows that all of the calculated contours of angle appear superimposed in one contour that is therefore darker than the other contours when the imaginary part of the speckle complex amplitude is zero and the real part of the complex amplitude is negative. Such is the case for the darkest contours in the phase contour plot on the left above, which coincide with contours of the imaginary part being zero and the real part being negative in the plot of the zeros of the real and imaginary parts on the right above. We now examine a small portion of the phase contour plot.

62

Chapter 7

π

100



2

4

80 0 3π π

60

π

-

4

-

2

π

2

-

4

0

Out[]=

3π 4 π

40

π

-

4

4 π -

2 20

π

π

2

4 3π



-

0 0

4 20

π

4 40

60

80

2 100

For the plot above, we have isolated a small region of a phase contour plot from a different evaluation of the notebook to illustrate the behavior of phase in the vicinity of zeros of intensity. Note that the contours run continuously from a zero of intensity to another zero of intensity. Also, recall that a contour labeled 0 corresponds to an imaginary part of the field equal to zero, while the contours labeled – π/2 and π/2 are contours for which the real part of the field is zero. For the contours surrounding the zero of intensity located at approximate coordinates (27, 78) (i.e., the top node), if we start with the contour labeled 0 at the top and proceed clockwise around the node where contours converge, we pass through contours 0, –3π/4, –π/2, –π/4, π/4, π/2, and 3π/4 in that order. Thus, to move from negative phase to positive phase, we must circle in a clockwise direction. Now focus on the opposite intensity zero at approximate coordinates (78, 41). Start again with the contour for phase equal 0 and proceed from contours of negative phase to contours of positive phase. This time we circle the bottom intensity zero in the counterclockwise direction. Thus, opposite nodes are said to have opposite polarity and, because the phases circulate around the intensity zeros, we say that each node is the center of a phase vortex. There is a striking similarity between the phase contours and the lines of electric field that pass from a positive electric charge to a negative electric charge. We don’t pursue this analogy further here.

8. Polarization Speckle The discussions of speckle in the previous chapters have implicitly assumed that the light in the speckle pattern is perfectly polarized. In many practical applications, especially when multiple scattering is present, the light scattered by the rough object or the diffuser may be partially or totally depolarized. In fact, just as the intensity of the light varies across the speckle pattern, so too the state of polarization may vary. This random fluctuation of polarization has become known as polarization speckle. For a more detailed discussion of this topic, see Ref. [6].

8.1 The Polarization Ellipse and the Degree of Polarization A useful description of the state of polarization is the polarization ellipse, which is a graphical representation of the path followed by the tip of the electric vector through one oscillation cycle. The ellipse is characterized by the parameter a representing the major semi-axis, b representing the minor semi-axis, and Ψ representing the angle of the major axis with respect to the x axis. See the example figure below and the code that generates it. In this case, Ψ = π/6, a = 4, and b = 2. In[37]:=

p1 = GraphicsRotateCircle[{0, 0}, {4, 2}], Pi  6, Axes  True, ImageSize  300; l1 = Line[{{- 3.438, - 1.997}, {3.426, 2.041}}]; l2 = Line[{{- 0.9848, 1.737}, {0.9686, - 1.732}}]; p2 = Graphics[{Dashed, l1}]; p3 = Graphics[{Dashed, l2}];

In[]:=

Show[p1, p2, p3]

2

a

1 Ψ -3

-2

-1

1

-1

2

3

b

-2

Let the bold-faced symbols Ax and Ay represent the complex-valued x and y polarization components of the vector optical field A, respectively. Both components are complex-valued, having magnitudes Ax and Ay , and phases θx and θy , respectively. Each complex field component obeys circular complex Gaussian statistics. If we define δ to be equal to θy – θx , the length of the major and minor semi-axes of the ellipse and the angle of the major axis with respect to the x axis can be shown to be given by [Ref. 7, p. 47]: a=

A2x cos2 Ψ + A2y sin2 Ψ + 2 Ax Ay cosΨ sinΨ cos δ

b=

A2x sin2 Ψ + A2y cos2 Ψ - 2 Ax Ay cosΨ sinΨ cos δ Ψ=

1 2

arctan

2 Ax Ay cos δ A2x -A2y

.

Furthermore, there must be correlations between certain components of these complex fields. We define the complex correlation coefficient μ (magnitude μ and phase ϕ) between Ax and Ay to be

64

Chapter 8

Ax A⋆y

μ = μ ϕ =

 Ax  2  Ay 

2

.

2

Note that Ax 2 = Ix , i.e., the intensity in the x component of polarization, and likewise Ay  = Iy for the y component. It follows that

Ix Iy μ

= A x Ay . ⋆

Now define a complex-valued row vector V as V = Ax , A y  , and form the average of the outer product V t V* to define the coherency matrix (see Ref. 1, Section 4.6.1): C=

Ax 2 Ax A*y 2

Ix

=

Ix Iy μ

Ix Iy μ

A x Ay  Ay  *

*

Iy

,

where as usual, the overbar signifies a statistical average. The matrix C is Hermitian and therefore has two non-negative, real eigenvalues, λ1 and λ2 . To find those eigenvalues, we use Mathematica’s Eigenvalues[] command: In[42]:=

Clearix, iy, μ c = ix, Sqrtix * iy * μ, Sqrtix * iy * Conjugate[μ], iy; MatrixForm[c]

Out[44]//MatrixForm=

ix

ix iy μ

ix iy Conjugate[μ]

iy

The matrix has two eigenvalues that differ only through the sign difference following the first i y . In[45]:=

e = Eigenvalues[c] 1

Out[45]=



2 1 2

ix + iy -

ix2 - 2 ix iy + iy2 + 4 ix iy μ Conjugate[μ] ,

ix + iy +

ix2 - 2 ix iy + iy2 + 4 ix iy μ Conjugate[μ] 

The degree of polarization of the wave is defined by the following expression: P =

λ1 - λ2 

.

λ1 + λ2

For the general coherency matrix above, since the second eigenvalue is larger than the first, the degree of polarization is given by In[46]:=

p = FullSimplify[(e〚2〛 - e〚1〛) / (e〚1〛 + e〚2〛)] 2

ix - iy + 4 ix iy μ Conjugate[μ] Out[46]=

ix + iy

In equation form, 2

P =

Ix - Iy  + 4 Ix Iy μ2

Ix + Iy

.

Note that the degree of polarization depends on both the real and imaginary parts of μ through μ2 . In our simulation below, we will be able to specify the degree of polarization of the wave from the values assumed for I x , Iy , and μ.

Polarization Speckle

65

8.2 Generating the Two Polarization Components If we wish to simulate polarization speckle, the challenge is to generate two appropriate complex circular Gaussian random arrays, A x and Ay . The average intensities Ix and Iy must first be chosen, since they may be different in general. For our simulation, the total intensity is I 0 = Ix + Iy , and for simplicity choose I0 = 1. We then choose Ix = 0.7, Iy = 0.3. Also recall the fact that σ2x = Ix /2 = 0.35 and σ2y = Iy /2 = 1.5. Finally, we must also choose a magnitude and phase for the complex correlation coefficient; let μ = 0.2 and ϕ = π/10, implying that cos ϕ = 0.95 and sin ϕ = 0.31. The reader may wish to choose different parameters in the code below. The degree of polarization represented by these parameters is In[47]:= Out[47]=

p = Sqrt(0.7 - 0.3) + 4 * 0.7 * 0.3 * Abs0.2 * ExpI * Pi  10 ^ 2  (0.7 + 0.3) 0.658483

First we generate a complex-valued  ×  = 512 × 512 array representing Ay , with identically distributed and independent real and imaginary parts. As throughout, we avoid using non-script upper-case letters in Mathematica code. In[48]:=

 = 512; x = 0.7; y = 0.3; μ = 0.20; ϕ = π / 10; ay =

y / 2 * TableRandomVariateNormalDistribution[0, 1], i, 1, , j, 1,  + I * TableRandomVariateNormalDistribution[0, 1], i, 1, , j, 1, ;

The next challenge is to generate a similar complex random array Ax with proper average intensity and proper correlation with the Ay array. We do so by generating an array that is a weighted and phase-shifted version of Ay plus a weighted statistically independent, circularly complex Gaussian array, with the fractions and phase shift determined by the complex correlation coefficient: In[51]:=

ax = 

x / 2 

y / 2  * (μ * Exp[I * ϕ] * ay) +

x / 2 *

1 - μ2 *

TableRandomVariateNormalDistribution[0, 1], i, 1, , j, 1,  +

x / 2 *

1 - μ2 * I * TableRandomVariateNormalDistribution[0, 1], i, 1, , j, 1, ; To check whether our technique has worked properly, we first calculate the mean intensities of the two arrays and compare them with the assumed intensities: In[52]:= Out[52]= In[53]:= Out[53]=

mx = Mean[Flatten[Abs[ax] ^ 2]] 0.699606 my = Mean[Flatten[Abs[ay] ^ 2]] 0.299817

Note again that the Flatten[] operations convert the 2D  ×  arrays into 1D length- 2 arrays, allowing averaging over all elements of those arrays. The results are very close to the 0.7 and 0.3 that we assumed at the start, and would be even closer if larger arrays were used. Next compare the complex correlation coefficient obtained from operations on the arrays to the assumed complex correlation coefficient: In[54]:= Out[54]=

mu = MeanFlatten[ax] * FlattenConjugate[ay]  Sqrt[mx * my] 0.190244 + 0.0616999 

The magnitude and phase of the complex correlation coefficient in the simulation are: In[55]:= Out[55]= In[56]:= Out[56]=

Abs[mu] 0.199999 Arg[mu] 0.313617

The magnitude of the complex correlation coefficient is very close to the assumed value of 0.2. Now compare the value of the phase in the simulation to that of the assumed phase: In[57]:=

N[π / 10]

Out[57]=

0.314159

66

Chapter 8

Again, the result in the simulation is very close to the value assumed at the start. Having generated the arrays A x and Ay with the desired properties, we can now calculate the polarization ellipse at every point in a simulated speckle pattern.

8.3 Generating a Filtered Speckle Pattern It is now time to generate the intensity distribution of the speckle pattern of the partially polarized wave. To do so, we first low-pass filter the complex fields Ax and Ay , producing two new fields Bx and By . Only if we filter the complex fields Ax and Ay will we generate a speckle pattern. To accomplish the filtering, we convolve Ax and Ay with a rectangular smoothing window of size 8 × 8 pixels. We show the total speckle intensity below. In[58]:=

ℳ = 8; smooth = (1 / ℳ ^ 2) * ConstantArray[1, {ℳ, ℳ}]; bx = ListConvolve[smooth, ax, 1]; by = ListConvolve[smooth, ay, 1];

In[62]:=

ListDensityPlot[Abs[bx] ^ 2 + Abs[by] ^ 2]

Out[62]=

The complex fields Bx and By are the fields that generate both the intensity and the polarization ellipse at each point in the simulation.

8.4 Generating the Polarization Ellipses The task now is to generate arrays that represent the polarization ellipse parameters a, b, and Ψ at each of the 512 × 512 points in the filtered speckle pattern, using the equations presented at the beginning of this chapter. We begin by generating the Ψ array: In[63]:=

Ψ = 0.5 * ArcTan[(2 * Abs[bx] * Abs[by] * Cos[Arg[by] - Arg[bx]])] / (Abs[bx] ^ 2 - Abs[by] ^ 2);

Next we generate the major axis semi-length a and the minor axis semi-length b, and then rotate the ellipse by angle Ψ: In[64]:=

a = SqrtAbs[bx] ^ 2 * Cos[Ψ] ^ 2 + Abs[by] ^ 2 * Sin[Ψ] ^ 2 + 2 * Abs[bx] * Abs[by] * Cos[Ψ] * Sin[Ψ] * Cos[Arg[by] - Arg[bx]];

In[65]:=

b = SqrtAbs[bx] ^ 2 * Sin[Ψ] ^ 2 + Abs[by] ^ 2 * Cos[Ψ] ^ 2 2 * Abs[bx] * Abs[by] * Cos[Ψ] * Sin[Ψ] * Cos[Arg[by] - Arg[bx]];

We are now ready to visualize the behavior of the polarization across the speckle pattern.

8.5 Visualizing Polarization Speckle The intensity at each point in the speckle pattern is given by a2 + b2 . We generate a density plot of intensity for only a 40 × 40 sub-array of the

Polarization Speckle

67

speckle pattern in the figure p1 and delay its display. We illustrate with a sub-array in order to make the polarization ellipses discernable in the overlapped image to follow. The ellipses for all points are stored in a table and figure p1: In[66]:=

p1 = GraphicsTableRotateRGBColor[1, 1, 0], Thick, Circlei, j, 2 * ai, j, 2 * bi, j, Ψi, j, i, 1, 40, j, 1, 40;

We have used the weighting factor 2 in this equation in order to make the ellipses small enough to avoid significant overlap but still easily seen in the final plot that follows. The delayed figure p2 displays the intensity in the speckle pattern: In[67]:=

p2 = ListDensityPlot[ Transpose[Take[Abs[bx] ^ 2 + Abs[by] ^ 2, {1, 40}, {1, 40}]], PlotRange  All];

As an aside, the reason we use the Transpose[] operation is that the image format for a graphics image is the transpose of the format for a density plot. The transpose can be applied to either of the two images. We now show a superposition of the speckle pattern intensity and the ellipses at each point in the small portion of the array we have chosen to illustrate: In[70]:=

Show{p2, p1}, ImageSize  400

Out[70]=

The state of polarization is seen to vary across the array in a complex and random manner, thus leading to the name polarization speckle for this phenomenon. The polarization state changes significantly over a distance that is roughly equal to the width of each speckle. Bright speckles have large polarization ellipses, and regions of low intensity have small polarization ellipses. Some bright speckles have polarization that is nearly linear and some have polarization that is nearly circular, while elliptical polarizations dominate.

9. Speckle Simulation for Metrology In most imaging applications, speckle is a nuisance, and various methods are used to attempt to suppress it. However, in the field of metrology, speckle can be a friend rather than a foe, and many methods for using speckle in measurement have been devised. Here we will simulate only a few of such methods; the interested reader is referred to Ref. [1], (Chapter 9), for a more comprehensive discussion of this topic, together with references to the pertinent original publications.

9.1. Measurement of In-Plane Displacement An early application of speckle to metrology was for measurement of lateral in-plane displacement. Assume that we are imaging a finite region on a rough object and we observe speckle in the image. The object then moves laterally and we wish to use a second exposure to determine the amount of lateral movement. As the object translates, the speckle in its image translates as well, but with some change as new scatterers move into the fixed illuminated region and previous scatterers move out of the illuminated region. We assume that the optical imaging system is a 4f system of the same type we have used in other chapters. The rough object lies in the front focal plane of a positive lens with focal length f. In the rear focal plane of that lens there is an aperture, centered on the optical axis, that restricts the area through which light can pass. At one further focal length a second positive lens, again with focal length f, captures the light passed by the aperture and passes it on to its rear focal plane where a filtered image of the rough surface is found. First we generate a diffuser representing the rough object that will be laterally translated. Again, we smooth the diffuser so that it has a finite phase correlation length. Next we define a finite window corresponding to the finite illumination spot on the diffuser. This window remains fixed while the diffuser moves under it. The number of pixels in the simulation is  × ,  represents the width of the rectangular smoothing functions that introduce correlations in the phase function of the diffuser,  ×  represents the area of the finite illumination window on the diffuser ( < ), and  ×  represents the area of the square focal-plane aperture. First we establish the values of the parameters in the simulation. In[]:=

Clear[, , , ]  = 512;  = 8;  = 256;  =  / 4;

The diffuser is illuminated by a finite spot of light of dimension  ×  and the diffuser translates through this spot, moving new diffuser pixels into the illuminated spot and losing some old diffuser pixels at the same time. We have chosen  to be 256, half the size of the full diffuser in this simulation. We can then define the square window function on the diffuser: In[]:=

window = ParallelizeTablerecti -  / 2   * rectj -  / 2  , i, 1, , j, 1, ;

Next we generate the windowed diffuser with smoothed phase and calculate its complex Fourier spectrum, centering the spectrum at indices (/2, /2). In order to generate a diffuser spectrum that tapers down at high frequencies, we find by trial and error that a choice of standard deviation of 32π in uncorrelated and a choice of 8 for  yields the result shown below. Other solutions are also possible, for example, a smaller value of  and a smaller value of standard deviation. In[]:=

uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 32 * π], i, 1, , j, 1, ;

In[]:=

kernel = ParallelizeTablerecti   * rectj  , i, - , , j, - , ;

In[]:=

smooth = (1 / (2 *  + 1)) ^ 2 * ListConvolve[kernel, uncorrelated, 1];

In[]:=

diffuser1 = Exp[I * smooth] * window;

In[]:=

diffuserspectrum1 = RotateRightdftdiffuser1, { / 2,  / 2};

As used in previous chapters, the dft is a user-defined command that performs a discrete Fourier transform using the FFT algorithm.

70

Chapter 9

In[]:=

ListPlot3DAbsdiffuserspectrum1 ^ 2, PlotRange  All, PlotLabel  "Windowed Diffuser Power Spectrum"

Out[]=

The next task is to pass the windowed diffuser power spectrum through the focal-plane filter and on to the image plane where the speckle pattern will be observed. We have chosen the diameter of the circular filter to be equal to /4. Thus, the circular stop in the focal plane is defined as follows: In[]:=

 =  / 4; stop = ParallelizeTable circ[Sqrt[((x -  / 2 - 1) ^ 2 + (y -  / 2 - 1) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, };

The windowed and filtered diffuser spectrum is then passed to the image plane with an inverse DFT: In[]:=

imageampl1 = idftdiffuserspectrum1 * stop;

Again idft is a user-defined command to perform an inverse discrete Fourier transform. This first image intensity is the squared magnitude of the image amplitude. In[]:=

d1 = Absimageampl1 ^ 2; Image[2 * d1]

Out[]=

There are two separately detected speckle pattern images, the first pattern represented by d1 and the second pattern represented by d2. The second pattern is shifted to the right within the fixed window, with some new speckles entering from the left and some old speckles exiting to the right. The parameter shift represents the number of pixels of shift introduced in the second pattern in both the x and y directions.

Speckle Simulation for Metrology

71

Initially, we shift the diffuser under the fixed window by +20 pixels in the x direction and 0 pixels in the y direction. In[]:=

shift = {20, 0};

In[]:=

diffuser2 = RotateRightExp[I * smooth], shift * window;

In[]:=

diffuserspectrum2 = RotateRightdftdiffuser2, { / 2,  / 2};

In[]:=

imageampl2 = idftdiffuserspectrum2 * stop;

In[]:=

d2 = Absimageampl2 ^ 2; Image[2 * d2]

Out[]=

The speckle pattern has been translated upwards by 20 pixels in the combined pattern above. (See Appendix B for a discussion of the interchange of horizontal and vertical orientations when the command Image[] is used). Next we perform a cross-correlation of the two speckle patterns d1 and d2 from which we hope to identify the transverse motion of the diffuser. In[]:=

ListPlot3DRotateRightListCorrelate[d1, d2, 1], { / 2,  / 2}, PlotRange  All, AxesLabel  {y, x}, ImageSize  250

Out[]=

A large correlation peak is seen at (x = 256 + 20, y = 0) pixels from the origin. Thus, from the cross-correlation we can determine not only the amount of translation in number of pixels but also the direction of that translation. Next we shift by a larger amount, 100 pixels in the negative x direction.

72

Chapter 9

In[]:=

shift = {- 100, 0}; diffuser2 = RotateRightExp[I * smooth], shift * window; diffuserspectrum2 = RotateRightdftdiffuser2, { / 2,  / 2}; imageampl2 = idftdiffuserspectrum2 * stop; d2 = Absimageampl2 ^ 2; totalintensity = d1 + d2; ListPlot3DRotateRightListCorrelate[d1, d2, 1], { / 2,  / 2}, PlotRange  All, AxesLabel  {y, x}, ImageSize  250

Out[]=

The peak is found at (x = 256 – 100, y = 0). The final example involves a shift of 150 pixels in the x direction and 50 pixels in the y direction. In[]:=

shift = {150, 50};

In[]:=

diffuser2 = RotateRightExp[I * smooth], shift * window;

In[]:=

diffuserspectrum2 = RotateRightdftdiffuser2, { / 2,  / 2};

In[]:=

imageampl2 = idftdiffuserspectrum2 * stop;

In[]:=

d2 = Absimageampl2 ^ 2;

In[]:=

ListPlot3DRotateRightListCorrelate[d1, d2, 1], { / 2,  / 2}, PlotRange  All, AxesLabel  {y, x}, ImageSize  250

Out[]=

The correlation peak is much smaller and harder to see than in the previous cases. With a large shift, many new speckles enter the finite window through which the second diffuser moves, and many old speckles leave, reducing the strength of the correlation peak. We conclude that cross-correlation of the image speckle intensity patterns produced by the unshifted and shifted speckle images can identify the amount of translation and the direction of translation of the shifted diffuser. A simple diffuser has been used to represent a more complex diffusely scattering object, to which identical methods can be applied.

Speckle Simulation for Metrology

73

9.2 Electronic Speckle Pattern Interferometry Electronic speckle pattern interferometry, or ESPI, is a method for measuring the z-deformation of an object under load. If at a given transverse (x, y) point the object moves in the direction of the optical axis by a distance Δz, then the light reflected from that point suffers a phase change of Δϕ, where Δz

Δϕ = 4 π

.

λ

Thus, if the phase shift can be measured, the axial displacement of the surface can be determined. For the origin of this technique, see Ref. [8]. The ESPI method uses electronic detection and therefore has gained popularity as detector technology has improved by leaps and bounds over the last few decades. A simplified ESPI optical system that we use for our simulation here consists of the following: (1) a 4f optical system with a finite aperture in its focal plane; (2) a diffusely reflecting object that is coherently illuminated normally, and that is mechanically unloaded in one recorded image frame and is loaded in a second recorded image frame; (3) a reference plane wave, coherent with respect to the light reflected from the object, that is normally incident on the detector and interferes with each of the two image speckle patterns; and (4) an electronic detector capable of recording each of two speckle patterns sequentially. The presence of the reference wave modifies the recorded speckle patterns as described below. Let the intensity of the reference wave at the detector be represented by ℐr and let its constant phase across the detector surface be θr . The intensity of the object wave incident on the detector will vary with position, and we represent its intensity at the detector by ℐo (x, y). Let θo (x, y) represent the spatial distribution of phase in the speckle pattern at the detector when the object is not under load. Then θo (x, y) + Δϕ(x, y) is the phase of the object wave when the object is under load. The detected intensities when not under load and when under load are therefore as follows: Unloaded: ℐu (x, y) = 

ℐr eθr +

2

ℐo (x, y) eθo x,y  = ℐr + ℐo (x, y) + 2

ℐr ℐo (x, y) cos[θr - θo (x, y)]

Loaded: ℐl (x, y) = 

ℐr eθr +

2

ℐo (x, y) eθo x,y+Δϕx,y  = ℐr + ℐo (x, y) + 2

ℐr ℐo (x, y) cos[θr - θo (x, y) - Δϕ(x, y)].

ESPI detects each of these intensity patterns sequentially and stores them. The two detected intensities are then subtracted and the difference image is subjected to full-wave rectification. For simplicity, we leave the (x, y) dependencies implicit in what follows, making the notation a bit simpler. Consider the squared magnitude of the difference of the two detected intensities: ℐu - ℐl 2 = 4 ℐr ℐo cos(θr - θo ) - cos(θr - θo - Δϕ)2 .

With appropriate trigonometry, we arrive at ℐu - ℐl  = 4

ℐr ℐo sin

Δϕ

2

sin θr - θo -

Δϕ

2

.

Note that the magnitude operations correspond to full-wave rectification. The speckle phase θo will vary rapidly, assuming that the speckle is finer than the desired fringes, i.e., those due to the sin

Δϕ

2

term.

Our first task is to simulate the diffuse object, which will be a simple phase-correlated diffuser. The code below is similar to that used to generate a phase-correlated diffuser in Section 6.2, except that a second diffuser is defined that contains a circularly symmetric added phase function using the Gaussian function gaus[], defined in the initialization cell and in Chapter 1, which represents the deformation we wish to detect and measure. Thus, the maximum value of the added Gaussian phase term is Δϕ/2 = 6π. First define the diffuser without the added phase term. In[]:=

 = 1024;  = 20;

In[]:=

uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 25 * π], {}, {};

In[]:=

kernel = (1 / (π * ( / 2) ^ 2)) * TablecircSqrti -  / 2 ^ 2 + j -  / 2 ^ 2  ( / 2), i, 1, , j, 1, ;

In[]:=

smooth = ListCorrelate[kernel, uncorrelated, 1];

In[]:=

diffuser1 = Exp[I * smooth];

In[]:=

diffuserspectrum1 = RotateRightFourierdiffuser1, { / 2,  / 2};

Now define the second diffuser that is identical to the first diffuser except for an added phase term representing the structure we wish to

74

Chapter 9

measure (it may represent a defect in an optically rough machined part, for example). The defect is defined by a Gaussian-shaped term, where gaus[r/400] = exp[–π(r / 400)2 ]. With the constant 400 in the denominator of the argument, this function falls to amplitude 0.5 at r ≈150 pixels. In[]:=

diffuser2 = ExpI * smooth + ParallelizeTable12 * Pi * gausSqrti -  / 2 ^ 2 + j -  / 2 ^ 2  400, i, 1, , j, 1, ; diffuserspectrum2 = RotateRightFourierdiffuser2, { / 2,  / 2};

The next step is to image each of the two diffusers by means of the 4f system with a focal-plane stop that is circular with a diameter of 128 pixels. First we define the focal-plane stop. In[]:=

Clearstop, imageampl1, imageintens1, , stop;  = 128; stop = Parallelize Tablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, };

Next we calculate and display the intensity image of the first diffuser. Multiplication of the image intensity by the factor 0.6 is introduced simply to adjust the grayscale of the image. The reference wave is represented by the constant 1, effectively taking the phase of that normally incident wave as the phase with respect to which all other phases are referenced. In[]:=

imageampl1 = 1 + idftstop * RotateRightdftdiffuser1, { / 2,  / 2}; imageintens1 = Absimageampl1 ^ 2; 0.6 * Imageimageintens1, ImageSize  200

Out[]=

Now we calculate and display the image of the second diffuser, i.e., the one with the defect. Again, the reference wave is represented by an amplitude of unity. In[]:=

imageampl2 = 1 + idftstop * RotateRightdftdiffuser2, { / 2,  / 2};

In[]:=

imageintens2 = Absimageampl2 ^ 2;

In[]:=

Image0.6 * imageintens2, ImageSize  200

Out[]=

Speckle Simulation for Metrology

75

There is no sign of the defect in the above speckle pattern. This defect will reveal itself only through the modulus of the intensity difference. Finally, we calculate the absolute value of the difference of the two image intensities: In[]:=

diff = Absimageintens1 - imageintens2; ImageAdjustImagediff, ImageSize  200, {1, .5}

Out[]=

There are 6 fringe peaks within the visible result (counting the outer ring), consistent with the number of peaks expected from the term sin

Δϕ

2



with Δϕ = 12π. There is a zero of intensity at the center of the pattern. A zero occurs in the pattern each time Δϕ is an integer multiple of 2π. Knowing the wavelength λ, we can relate the fringes to the depth of the defect through the relation Δz =

λΔϕ 2π

. However, in the case of a phase

perturbation that exceeds 2π radians, the phase Δϕ is wrapped into the interval 0 to 2π. For the example at hand, each ring of near-zero intensity corresponds a transition of phase across a 2π boundary. If we start at the edge of the pattern where the intensity is near zero, and move inward towards the center, then we can deduce the unwrapped phase by adding 2π each time we cross a zero ring. One can imagine much more complicated examples in which this procedure would be more difficult. Thus, we have simulated ESPI with a specific example. The reader should be aware that there are other geometries used for ESPI, including different types of reference waves, ranging from spherical waves and even to speckle field references.

9.3 Phase-Shifting Speckle Interferometry An alternative method for measuring the phase shift of a defect in a speckle field was invented independently by Creath (Ref. [9]) and Nakadate and Saito (Ref. [10]). See also Ref. [11] by Wyant for a very complete discussion of this method. The method again involves interfering a speckle image field with a reference, but this time the reference must have a controllable phase. A piezoelectric-controlled mirror that can step through several axial positions can control the phase of the reference wave in discrete steps. The optical system is again the 4f imaging system of the previous section, and the reference is assumed again to be normally incident on the detector, where it interferes with the amplitude image of the rough object (the diffuser). For each state of the reference wave, we capture a loaded and unloaded image, just as in ESPI, and we find the absolute value of the difference of the loaded and unloaded image intensities. diffuser1 from the previous section will again represent the unloaded image. We will also use diffuser2 and the bump gaus[r/400] for the deformation from the previous section. However, we need to use these quantities four times with four different reference phases. The four different intensities are calculated and displayed below. In[]:=

imageampl2a = Exp[- I * 3 * π / 4] + idftstop * RotateRightdftdiffuser2, { / 2,  / 2}; imageintens2a = Absimageampl2a ^ 2;

In[]:=

imageampl2b = Exp[- I * π / 4] + idftstop * RotateRightdftdiffuser2, { / 2,  / 2}; imageintens2b = Absimageampl2b ^ 2;

In[]:=

imageampl2c = Exp[I * π / 4] + idftstop * RotateRightdftdiffuser2, { / 2,  / 2}; imageintens2c = Absimageampl2c ^ 2;

In[]:=

imageampl2d = Exp[I * 3 * π / 4] + idftstop * RotateRightdftdiffuser2, { / 2,  / 2}; imageintens2d = Absimageampl2d ^ 2;

Now the magnitudes of the differences between imageintensity1 and the four different imageintensity2s are calculated and the results are plotted in an image array:

76

Chapter 9

In[]:=

Clear[, ℬ, , ]  = Absimageintens1 - imageintens2a; ℬ = Absimageintens1 - imageintens2b;  = Absimageintens1 - imageintens2c;  = Absimageintens1 - imageintens2d;

In[]:=

GraphicsGrid{{Image[], Image[ℬ]}, {Image[], Image[]}}, ImageSize  250

Out[]=

To recover the Gaussian phase bump on diffuser2, one method is to form the following calculation: Δϕ = arctan

+--ℬ

.

+-ℬ-

Define num as the numerator of the fraction and denom as the denominator: In[]:=

num =  +  -  - ℬ; denom =  +  - ℬ - ;

Now form an image of the arctan, which should yield Δϕ. In[]:=

ImageArcTan[denom, num], ImageSize  200

Out[]=

There are two important questions to ask about this result. First, why are there rings in this image of Δϕ? The answer is again that the method recovers Δϕ only modulo 2π; and the rings are jumps between π and –π. The plot below shows the original continuous Gaussian function modulo 2π, and the rings are seen in this image, too, although they are much more narrow than in the result of the speckle calculation. In[]:=

f = Table12 * Pi * gausSqrti -  / 2 ^ 2 + j -  / 2 ^ 2  400, i, 1, , j, 1, ; g = Modf, 2 * Pi;

Speckle Simulation for Metrology

In[]:=

77

Imageg, ImageSize  200

Out[]=

Which brings us to the second question, why are the rings so much wider in the speckle calculation than in the display of the Gaussian function modulo 2π? The answer is that the presence of speckle makes the transitions through multiples of 2 π much broader than for a function with no speckle. In addition, there is a sign of darkening at the very center of the speckle result that is not present in the continuous Gaussian modulo 2π. This dip may also be caused by the presence of speckle, which for some speckle lobes causes the result to cross a 2 π boundary at the origin. There also may be a difference in the phase wrapping occurring in the arctan function and the Gaussian perturbation. We have seen that it is only possible to recover the original phase shift Δϕ, modulo 2π. This result naturally leads to the issue of phase unwrapping, which, if successful, would allow us to recover a closer approximation to the continuous phase distribution. There is a considerable amount of literature on phase unwrapping in two dimensions, including at least one book (see, for example, Ref. [12]). The issue is complicated by the presence of phase vortices in a speckle pattern, which lead to different paths through the phase array, yielding different unwrapped phases. We will not pursue this issue here, but the interested reader can consult the reference mentioned above.

Appendix A – Some Subtleties in Speckle Simulation With the 4f Imaging System

A.1 Effects on the Speckle Contrast As pointed out in Section 1.3, there are some subtleties associated with the generation of simulated speckle using the 4f imaging system that arise from the finite size of the arrays used in the simulation. The phenomenon involves a complicated relationship between the size of the arrays used and the diameter of the focal-plane stop. It is possible to choose these parameters in such a way that the contrast of the speckle (i.e., the standard deviation of intensity normalized by the mean intensity) never achieves its ideal value of unity. Two effects can be identified. To understand these effects, it is helpful to consider how much of the diffuser contributes to the value of intensity at any single point in the image plane. With a finite focal-plane aperture diameter, there is a weighting function on the diffuser that averages over a finite region, adding complex-valued sample points that contribute to the image amplitude and intensity at a point. The smaller the focal-plane aperture, the broader that weighting function on the diffuser becomes; and the larger the diameter of the aperture, the narrower that weighting function becomes. The sum of the complex phasors within that averaging region generates a new complex phasor, one that has length and phase determined by interference between the complex diffuser pixels lying within the averaging region. If the focal-plane aperture is 1 pixel in diameter, a single spectral sample passes the focal plane and the intensity in the image plane is constant, with contrast equal to zero for any single diffuser. If the focal-plane aperture has a diameter of size 2  or larger (this size circle covers the corners of the rectangular sample array), the extent of the weighting function on the diffuser will be one pixel, covering only one phase cell of the diffuser. The result is a pure phase image with contrast zero. Thus, we see that in the limits of small or large focal-plane apertures, the speckle contrast in the image can be reduced, either due to the small number of phasors contributing to image intensity at an image point in the former case, or due to partial resolution of the pure phase diffuser in the latter case. See the figure just above Section 3.4 in Chapter 3 for a discussion of speckle contrast for small numbers of equal-strength phasors.

A.2. Simulation With a Smoothed Phase In this section we investigate the contrast of image speckle as a function of Fourier-plane aperture size, starting with a phase that has been smoothed to reduce aliasing. We start with an  ×  = 1024 × 1024 array of statistically independent phase samples. Each phase sample is a Gaussian random variable with zero mean and standard deviation σ = 25π. The choice of σ is made in conjunction with the diameter of the smoothing function to produce a diffuser Fourier spectrum that is tapered towards the edges, thus decreasing aliasing. The smoothing function is a discrete approximation to a uniform circle with a diameter of  = 20 pixels. The standard deviation of the smoothed phase is calculated to make sure it’s reasonable. The diffuser is then calculated as a complex exponential with argument  times the smoothed phase, and the diffuser spectrum is calculated. In[]:=

 = 1024;  = 20; Clearuncorrelated, kernel, smooth, diffuser, diffuserspectrum, ; uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 25 * π], {}, {}; kernel = (1 / (π * ( / 2) ^ 2)) * TablecircSqrti -  / 2 ^ 2 + j -  / 2 ^ 2  ( / 2), i, 1, , j, 1, ; smooth = ListConvolve[kernel, uncorrelated, 1]; diffuser = Exp[I * smooth]; diffuserspectrum = RotateRightFourierdiffuser, { / 2,  / 2};

The standard deviation of the smoothed phase is a reasonable number, given that we would like to have some excursions that exceed 2 π.

80

Appendix A

In[]:= Out[]=

StandardDeviation[Flatten[smooth]] 4.4649

While the standard deviation is less than 2π, excursions of the phase will be larger than the standard deviation. We now display a slice through the center of the diffuser spectrum intensity to assess the degree of tapering. In[]:=

ListPlotAbsdiffuserspectrum〚 / 2 + 1, All〛 ^ 2, Joined  True, ImageSize  300 20

15

Out[]= 10

5

200

400

600

800

1000

Aliasing remains in the diffuser spectrum (as would be the case even if the phase were perfectly bandlimited), but the taper of the spectrum does reduce its effects. Next we create a loop that calculates the contrast of the image speckle for each value of aperture diameter . The result on each pass through the loop is a number pair, {, }, that specifies the contrast  for each value of . The values of  and  are cleared at the end of each pass through the loop. The values of  for which the contrast is calculated are the 12 powers of 2 from power 0 to power 11. The calculation takes a bit of time, so be patient. First the aperture array stop is calculated for a given . Calculation of the image amplitude requires an inverse Fourier transform of stop times diffuserspectrum. The image intensity is then calculated, followed by the calculation of the intensity contrast. There are 12 iterations of the loop, so the computation takes a bit of time. Be patient. In[]:=

Clear, stop, imageampl, imageintens, result; result = Table0, i, 1, 12; imageintens = Table0, i, 1, 12;

In[]:=

Fori = 1, i ≤ 12, i ++,  = 2 ^ i - 1; stop[_] = ParallelizeTablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }, ProgressReporting  False; imageampl = idftstop[] * diffuserspectrum; imageintensi = Absimageampl ^ 2;  = StandardDeviationFlattenimageintensi  MeanFlattenimageintensi; resulti = {, }; Clear[, ]

The result is the following set of number pairs for  and : In[]:= Out[]=

result 1, 3.20949 × 10-14 , {2, 0.805963}, {4, 0.882621}, {8, 0.990456}, {16, 1.07012}, {32, 1.02526}, {64, 1.0385}, {128, 1.02201}, {256, 0.953361}, {512, 0.77946}, {1024, 0.443991}, 2048, 7.12993 × 10-16 

We visualize this result with a log-linear plot of the points.

Some Subtleties in Speckle Simulation With the 4f Imaging System

In[]:=

81

ListLogLinearPlotresult, PlotRange  {0, 1.2}, Ticks  {{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048}, {0, 0.2, 0.4, 0.6, 0.8, 1.0}}, AxesLabel  "Diameter ", "Contrast ", Filling  Axis, PlotStyle  PointSize[Large], AxesOrigin  {1 / 2, 0}, ImageSize  400 Contrast 

1.

0.8

Out[]=

0.6

0.4

0.2

1

2

4

8

16

32

64

128

256

512 1024 2048

Diameter 

These results will vary with each run of the program due to the statistical nature of the problem, but quite consistently, aperture diameters of 16, 32, 64, and 128 produce contrast that is close to what would be expected for fully developed speckle, i.e., unity. The values of contrast that are not close to unity suggest that the probability density function of the image intensity is not negative exponential in those cases. We can test this hypothesis by computing histograms of image intensity for a variety of values of  and comparing the result to a negative-exponential curve. We compute histograms for  = 2, 4, 8, 16, 64, 256, 512, and 1024 (i = 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11). Display of the histograms is suppressed until they can all be shown together in an array. In[]:=

Cleari; i = Table[0, {k, 1, 10}]; Clear[p]; p = Table[0, {k, 1, 10}];

In[]:=

Fori = 1, i ≤ 10, i ++,  = 2 ^ i; pi = HistogramFlattenimageintensi + 1, 500, "PDF", Axes  False, PlotLabel  " = " ToString N2 ^ i

In[]:=

GraphicsRow[{p〚1〛, p〚2〛, p〚3〛, p〚4〛}] =2

=4

=8

 = 16

 = 128

 = 256

Out[]=

In[]:=

GraphicsRow[{p〚5〛, p〚6〛, p〚7〛, p〚8〛}]  = 32

Out[]=

 = 64

82

Appendix A

In[]:=

GraphicsRow{p〚9〛, p〚10〛}, ImageSize  300  = 512

 = 1024

Out[]=

As can be seen, for  = 32 through 256, the histograms resemble a negative-exponential curve. For  = 2, 4, 8, 16, 512, and 1024, the histograms depart from a negative-exponential shape. These results are more-or-less consistent with the contrast values obtained above. Significant departures from unity contrast result in histograms that depart from a negative-exponential shape. Note, however, that these results vary somewhat from run to run of the program. To be safe, with the other parameters chosen here and based on the contrast and histogram results, values of  of 32 through 128 are recommended. For apertures in the middle range of openings assumed above, i.e., 32, 64, and 128, there are still enough degrees of freedom passed by the aperture to generate fully developed speckle. For small values of the Fourier aperture diameter, the weighting function in object space is so broad that only a few uncorrelated random phasors contribute to the intensity at each image point. For large values of the aperture diameter, the weighting function on the object becomes so narrow that the image intensity at a single point has only a few random correlated phasor contributions and the contrast of the speckle drops below unity. It should be noted that larger array sizes than the ones used here will produce a broader range of diameters of the focal-plane stop that will yield fully developed speckle. It is of some interest to know the extent of the correlation between spectral intensities incident on the focal-plane aperture because correlation between such pixels reduces the effective number of degrees of freedom in the speckle intensity (i.e., the effective number of independent phasors that have been added at each image point). We calculate the normalized autocovariance of the Fourier spectrum intensity incident on the aperture, and plot a central slice through that function. In[]:=

correlation = RotateRight ListCorrelateAbsdiffuserspectrum ^ 2 - MeanFlattenAbsdiffuserspectrum ^ 2, Absdiffuserspectrum ^ 2 - MeanFlattenAbsdiffuserspectrum ^ 2, 1, { / 2,  / 2};

In[]:=

corrcoeff = correlation  MaxFlattencorrelation;

In[]:=

ListPlotcorrcoeff〚 / 2 + 1, All〛, PlotRange  All, Joined  True 1.0 0.8 0.6

Out[]=

0.4 0.2

200

400

600

800

1000

The peak value of normalized autocovariance is unity and occurs at the single point ( /2 + 1, /2 + 1), but there is a broad correlation mound that extends from about pixel 300 to about pixel 700, or about 400 pixels wide (depending on how one measures width) at a maximum level of about 0.2. This broad correlation mound reduces the effective number of degrees of freedom passed by the Fourier aperture for any aperture size. Note also that some negative correlation exists for spectral intensity points that are far apart.

A.3. Simulation With an Unsmoothed Phase Tapering the spectrum of the diffuser to avoid aliasing is important when the diffuser is sandwiched with an object we wish to image. The product of the diffuser transmittance and the object transmittance results in a convolution of their respective amplitude Fourier spectra, and a consequent broadening of the total spectrum, leading to unwanted aliasing that may affect the image of the object. However, when we are imaging the diffuser alone, as was the case in the previous section, we argue that the introduction of aliasing is not harmful. This is because the addition of a sample with circular Gaussian amplitude statistics from the primary (central) spectral island with an overlapping circular Gaussian sample from another spectral island results in a new sample that also obeys circular Gaussian statistics. Aliasing in this case does nothing to

Some Subtleties in Speckle Simulation With the 4f Imaging System

83

change the statistics of the intensity spectra. Given this argument, in this section we repeat portions of the previous section, but with a diffuser that has not been smoothed. Borrowing code from the previous section, but with modifications to eliminate the smoothing of phase, we again compute the contrast of the intensity of the image speckle as a function of the focal-plane aperture diameter. First we create the new diffuser and check the standard deviation of its phase. In[]:=

Clear, uncorrelated, stop, imageampl, imageintens, result, diffuser, diffuserspectrum;  = 1024; uncorrelated = ParallelizeTableRandomVariateNormalDistribution[0, 2 * π], {}, {};

Next we check the standard deviation of the phase, create the diffuser, and calculate its Fourier spectrum. In[]:=

StandardDeviation[Flatten[uncorrelated]] diffuser = Exp[I * uncorrelated]; diffuserspectrum = RotateRightFourierdiffuser, { / 2,  / 2};

Out[]=

6.28209

The sample standard deviation is on the order of 2π radians. Next we take a look at a slice through the center of the intensity incident on the focal plane. In[]:=

ListPlotAbsdiffuserspectrum〚 / 2 + 1, All〛 ^ 2, Joined  True, ImageSize  300

8

6

Out[]=

4

2

200

400

600

800

1000

As expected, there is now no tapering of the spectrum near its edges because we have not smoothed the phase. Next we calculate the contrast of the image speckle intensity for the diameter of the focal-plane stop  ranging from one pixel to 2048 pixels in powers of 2. Again, the calculation requires a bit of time. In[]:=

result = Table0, i, 1, 12; imageintens = Table0, i, 1, 12;

In[]:=

Fori = 1, i ≤ 12, i ++,  = 2 ^ i - 1; stop = ParallelizeTablecirc[Sqrt[((x -  / 2 ) ^ 2 + (y -  / 2 ) ^ 2)] / ( / 2)], {x, 1, }, {y, 1, }, ProgressReporting  False; imageampl = idftstop * diffuserspectrum; imageintensi = Absimageampl ^ 2;  = StandardDeviationFlattenimageintensi  MeanFlattenimageintensi; resulti = {, }; Clear[, ]

84

Appendix A

In[]:= Out[]=

result 1, 1.65784 × 10-14 , {2, 0.626332}, {4, 0.681504}, {8, 1.11643}, {16, 0.973228}, {32, 1.00888}, {64, 1.02403}, {128, 0.995112}, {256, 0.989456}, {512, 0.953967}, {1024, 0.616344}, 2048, 7.12553 × 10-16 

We again visualize this result with a log-linear plot: In[]:=

ListLogLinearPlotresult, PlotRange  {0, 1.3}, Ticks  {{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048}, {0, 0.2, 0.4, 0.6, 0.8, 1.0}}, AxesLabel  "Diameter ", "Contrast ", Filling  Axis, PlotStyle  PointSize[Large], AxesOrigin  {1 / 2, 0}, ImageSize  400 Contrast 

1. 0.8 Out[]=

0.6 0.4 0.2

1

2

4

8

16

32

64

128

256

512 1024 2048

Diameter 

0 As can be seen from this plot, the contrast is near unity over a wider range of values of the aperture diameter. Histograms for the same values of  used above (except 1 and 2048) are now calculated. In[]:=

Cleari; i = Table[0, {k, 1, 10}]; Clear[p]; p = Table[0, {k, 1, 10}];

In[]:=

Fori = 1, i ≤ 10, i ++,  = 2 ^ i; pi = HistogramFlattenimageintensi + 1, 500, "PDF", Axes  False, PlotLabel  " = " ToString N2 ^ i

In[]:=

GraphicsRow[{p〚1〛, p〚2〛, p〚3〛, p〚4〛}] =2

=4

=8

 = 16

 = 128

 = 256

Out[]=

In[]:=

GraphicsRow[{p〚5〛, p〚6〛, p〚7〛, p〚8〛}]  = 32

Out[]=

 = 64

Some Subtleties in Speckle Simulation With the 4f Imaging System

In[]:=

85

GraphicsRow{p〚9〛, p〚10〛}, ImageSize  300  = 512

 = 1024

Out[]=

The histograms for  = 64, 128, 256, and 512 closely match a negative-exponential curve. All other values of  yield histograms that depart from negative-exponential results. The lack of phase smoothing in this case has resulted in a slightly broader range of aperture diameters  yielding fully developed speckle. Again we calculate and plot the normalized autocovariance function of the light intensity incident on the focal plane. In[]:=

correlation = RotateRight ListCorrelateAbsdiffuserspectrum ^ 2 - MeanFlattenAbsdiffuserspectrum ^ 2, Absdiffuserspectrum ^ 2 - MeanFlattenAbsdiffuserspectrum ^ 2, 1, { / 2,  / 2}; corrcoeff = correlation  MaxFlattencorrelation; ListPlotcorrcoeff〚 / 2 + 1, All〛, PlotRange  All, Joined  True 1.0

0.8

0.6 Out[]=

0.4

0.2

200

400

600

800

1000

The correlation mound extending around the unity peak in the smoothed-phase case is now absent. In the previous case, the correlation mound had been introduced by the smoothing of the phase sequence. Since no smoothing was done here, the mound has vanished, and there should be no correlation between pixels in the Fourier plane, thus yielding more degrees of freedom passing through the focal-plane aperture than in the smoothed-phase case.

Appendix B – Some Subtleties in Dealing with Mathematica Images In the chapters of this book, we have often had occasion to use the Mathematica commands Image[] and ImageData[] when moving between numerical data and images. Given an array of real numbers, an image can be obtained by using the command Image[array], while to go in the opposite direction, from an image to real numbers, the command ImageData[image] is used. There are some peculiarities of these commands that we wish to point out here.

B.1 Dimensions of Data Arrays and Images To start, we define an array of random real numbers that lie between 0 and 1, intentionally making the lengths of the two dimensions of the array unequal: In[73]:= Out[73]=

data = TableRandomReal[], i, 1, 4, j, 1, 3 {{0.196136, 0.518268, 0.233036}, {0.756317, 0.0983559, 0.335059}, {0.478396, 0.604937, 0.662963}, {0.894975, 0.707075, 0.916227}}

The array can be shown in the form of a matrix: In[74]:=

MatrixForm[data]

Out[74]//MatrixForm=

0.196136 0.518268 0.233036 0.756317 0.0983559 0.335059 0.478396 0.604937 0.662963 0.894975 0.707075 0.916227

The dimensions of the array are: In[75]:= Out[75]=

Dimensions[data] {4, 3}

Note that the first number that Dimensions[] returns is the length of the columns of the matrix (the number of rows), while the the second number is the length of the rows (the number of columns). We now create an image of the data: In[76]:=

Out[76]=

myimage = Imagedata, ImageSize  150

88

Appendix B

We see that the columns of length 4 and the rows of length 3 are preserved in the image. Now we exercise the ImageDimensions[]command: In[77]:= Out[77]=

ImageDimensionsmyimage {3, 4}

Evidently, this command returns the length of the image rows first and the length of the image columns second, the reverse of the command Dimensions[] used on the data array. Next we return to the data array from the image: In[78]:=

MatrixFormImageDatamyimage

Out[78]//MatrixForm=

0.196136 0.518268 0.233036 0.756317 0.0983559 0.335059 0.478396 0.604937 0.662963 0.894975 0.707075 0.916227

The original data array has been successfully recovered.

B.2. Images When the Data Range Exceeds (0, 1) Now suppose that we generate a real random number array with entries lying between 0 and 2: In[79]:= Out[79]=

data2 = TableRandomReal[{0, 2}], i, 1, 4, j, 1, 3 {{0.502129, 0.501313, 1.7531}, {1.15723, 1.51878, 1.63401}, {1.60182, 0.235084, 0.362006}, {0.978041, 0.260865, 0.508647}}

In[80]:=

MatrixForm[data2]

Out[80]//MatrixForm=

0.502129 0.501313 1.7531 1.15723 1.51878 1.63401 1.60182 0.235084 0.362006 0.978041 0.260865 0.508647 Now form an image of this data: In[81]:=

myimage2 = Imagedata2, ImageSize  150

Out[81]=

Only 6 cells are visible, with another 6 being white (these numbers will change with different runs of the random-number generator). This is because the cells that are white represent data values that are greater than or near to 1. The command Image[] provides gray levels only for data values between 0 and 1; all larger values are in effect represented by the same gray level as 1. Nonetheless, we can recover our original data array from the image:

Some Subtleties in Dealing with Mathematica Images

In[82]:=

89

MatrixFormImageDatamyimage2

Out[82]//MatrixForm=

0.502129 0.501313 1.7531 1.15723 1.51878 1.63401 1.60182 0.235084 0.362006 0.978041 0.260865 0.508647

B.3 Effect of Using ImageAdjust[ ] on an Image When data, such as the array data2, falls outside the range 0 to 1, it is still possible to obtain a useful image using the command ImageAdjust[Image[data]]: In[83]:=

myimage3 = ImageAdjustImagedata2, ImageSize  150

Out[83]=

All cells now have observable gray levels, except for one cell that is entirely white. We can understand how Mathematica has treated the numbers leading to this image by executing the ImageData[] command: In[84]:=

MatrixFormImageDatamyimage3

Out[84]//MatrixForm=

0.175917 0.175379 1. 0.607469 0.845641 0.921547 0.900344 0. 0.0836101 0.489425 0.016983 0.18021

It’s now clear that Mathematica has found the maximum value in the array data2 and normalized all other elements by this value. The maximum data element appears white in this image since its normalized value is 1, and all others are normalized by the value of the element that appears white. Thus, it is clear that if one wants to preserve the values of the original, one should not assume that ImageData[ImageAdjust[Image[myimage3]]] will return the original values in the array. There exists a second way to bring data with a maximum value that lies outside the range (0, 1) into a form that displays as an acceptable image. This method simply carries out the same normalization used by the ImageAdjus[] command, normalizing the data by a constant that brings the data into the required range. For example, normalize data2 by its maximum value and display the result as an image. The maximum value will vary in both magnitude and position in the array for different runs, but the command Image[data2/Max[data2]] yields the following result:

90

Appendix B

In[85]:=

Imagedata2 / Max[data2], ImageSize  150

Out[85]=

This result is the same as obtained using the ImageAdjust[] command. There is one additional property of the ImageAdjust command worth mentioning here; that is, the addition of a pair of numbers that can adjust the contrast and the brightness of the image. For example, the command ImageAdjust[data,{2,4}] increases the contrast of the image by a factor of 2 and increases the brightness by a factor of 4. We generate new data on which to demonstrate this command: In[86]:= Out[86]=

data3 = TableRandomReal[{0, 0.5}], i, 1, 4, j, 1, 3 {{0.361605, 0.473254, 0.0673285}, {0.0947996, 0.179961, 0.386238}, {0.0311168, 0.0716942, 0.0500993}, {0.4159, 0.434259, 0.0430835}}

The data does not fill the range (0, 1). However, a useful image can be obtained with the following: In[87]:=

ImageAdjustImagedata3, ImageSize  150, {0.1, 1.7}

Out[87]=

We can see that the data has been visualized, but recovering the data from the image would not yield data3. In[88]:= Out[88]=

ImageDataImageAdjust[Image[data3], {0.1, 1.7}] {{1., 1., 0.149966}, {0.231555, 0.484483, 1.}, {0.0424169, 0.162932, 0.0987948}, {1., 1., 0.077958}}

B.4. Arrays With Bipolar Values Construct an array with both positive and negative real values: In[89]:= Out[89]=

data4 = TableRandomReal[{- 2, 2}], i, 1, 4, j, 1, 3 {{0.501285, - 0.918533, - 0.0685644}, {1.64736, - 0.240212, 0.994261}, {- 1.18837, - 0.253044, - 1.19937}, {- 0.178673, 0.494738, 1.77163}}

Some Subtleties in Dealing with Mathematica Images

In[90]:=

91

MatrixForm[data4]

Out[90]//MatrixForm=

0.501285 - 0.918533 - 0.0685644 1.64736 - 0.240212 0.994261 - 1.18837 - 0.253044 - 1.19937 - 0.178673 0.494738 1.77163 Now construct an image from this array: In[91]:=

myimage4 = Imagedata4, ImageSize  150

Out[91]=

Some of the black cells arise from negative numbers, which are treated as if their values were zero. Consider the effect of ImageAdjust[] on such an array. In[92]:=

ImageAdjustmyimage4

Out[92]=

What kind of change has been made in the original array by ImageAdjust[]? In[93]:=

MatrixFormImageDataImageAdjustmyimage4

Out[93]//MatrixForm=

0.572418 0.0945273 0.380615 0.958173 0.322841 0.738348 0.00370491 0.318522 0. 0.343554 0.570215 1. All elements are now non-negative and lie between 0 and 1. Some thought shows that this matrix has been obtained by the following formula: In[104]:=

MatrixFormdata4 + AbsMin[data4]  Max[data4] + AbsMin[data4]

Out[104]//MatrixForm=

0.572418 0.0945273 0.380615 0.958173 0.322841 0.738348 0.00370489 0.318522 0. 0.343554 0.570215 1.

92

Appendix B

The absolute value of the minimum value of the data has been added to each element of the data array, and for every element this sum has been normalized by the sum of the maximum value of the data array plus the absolute value of the minimum in the data array. Again, the reader should note that when ImageAdjust[]is applied to an image, the array recovered by ImageData[] in general is not the same array we started with.

B.5. A Problem Encountered When Starting With an Image Suppose that the start of our Mathematica program involves importing an image from a file on our computer. This can be done by simply dragging a JPEG version of the image into our Mathematica program. We convert that color image to a grayscale image.

In[95]:=

grayimage = ColorConvert

In[96]:=

ImageDimensionsgrayimage

Out[96]=

, "GrayScale";

{3024, 4032}

Now create a data array that we wish to multiply (element by element) by the data contained in grayimage. In[97]:=

newdata = TableRandom[], i, 1, 3024, j, 1, 4032; Dimensions[newdata]

Out[98]=

{3024, 4032}

Naturally, to multiply two data arrays element by element, they must be of the same size. Now multiply newdata by ImageData[grayimage]. In[99]:=

product = newdata * ImageDatagrayimage; Thread : Objects of unequal length in

{{0.705311 , }, } cannot be combined.

We obtain an error message stating that we are trying to multiply two arrays with different sizes, and yet the commands ImageDimensions[grayimage] and Dimensions[newdata] yield the same dimension pairs. We can resolve this mystery by asking the question, what are the dimensions of ImageData[grayimage]? In[100]:= Out[100]=

DimensionsImageDatagrayimage {4032, 3024}

We see that the conversion from an image to a data array has transposed that data array, making the image array size not match the newdata array size. This problem can be fixed by transposing the data array. Transposing the data array is preferred since we eventually want the image’s horizontal and vertical axes to remain unchanged. Thus, In[101]:=

newdata1 = Transpose[newdata]; Dimensions[newdata1]

Out[102]=

{4032, 3024}

Now it is possible to multiply the two arrays without error:

Some Subtleties in Dealing with Mathematica Images

In[103]:=

93

grayimage1 = Image2 * newdata1 * ImageDatagrayimage, ImageSize  200

Out[103]=

The two arrays have been successfully multiplied, element by element. The speckled appearance of the image is due to multiplication by the random array with elements between 0 and 1.

Acknowledgement I owe major thanks to two persons for their help in bringing this book to reality in its current form. First is the Senior Editor from the SPIE Press, Dara Burrows, whose 600+ suggestions greatly improved this book. Second is an anonymous reviewer, who read the manuscript extremely carefully and pointed out many improvements that could be made. I adopted nearly all of the suggestions made by both of these individuals.

References [1]. J.W. Goodman, Speckle Phenomena in Optics, Theory, and Applications, 2nd Edition, SPIE Press, Bellingham, Washington (2020) [doi: 10.1117/3.2548484]. [2]. B.F. Torrence and E.A. Torrence, The Student’s Introduction to Mathematica and the Wolfram Language, 3rd Edition, Cambridge University Press, Cambridge, UK (2019). [3]. H. Ruskeepää, Mathematica Navigator: Mathematics, Statistics and Graphics, 3rd Edition, Elsevier Academic Press, Burlington, Massachusetts (2009). [4]. J.W. Goodman, Statistical Optics, 2nd Edition, John Wiley & Sons, Hoboken, New Jersey (2015). [5]. I. Freund, “Optical vortices in Gaussian random wave fields: statistical probability densities,” J. Soc. Am. A 11, 1644–1652 (1994). [6]. W. Wang, S.G. Hanson, and M. Takeda, “Statistics of polarization speckle: theory versus experiment,” Proc. SPIE 7388, 738803 (2009) [doi: 10.1117/12.855761]. [7]. R.A. Chipman, W-S.T. Lam, and G. Young, Polarized Light and Optical Systems, CRC Press, Boca Raton, Florida (2019). [8]. J.N. Butters, “Speckle pattern interferometry using video techniques,” Opt. Eng. 10, 5–9 (1971) [doi: 10.1117/12.7971587]. [9]. K. Creath, “Phase-shifting speckle interferometry,” Appl. Opt. 24, 3053–3058 (1985). [10]. S. Nakadate and H. Saito, “Fringe scanning speckle-pattern interferometry,” Appl. Opt. 24, 2172–2180 (1985). [11]. J.C. Wyant, Phase-Shifting Interferometry, https://wp.optics.arizona.edu/jcwyant/wp-content/uploads/sites/13/2016/08/Phase-ShiftingInterferometry.nb_.pdf [12]. D.C. Ghiglia and M.D. Pritt, Two-Dimensional Phase Unwrapping: Theory, Algorithms and Software, Wiley Interscience, New York (1998).