# 3D Particle Locating Tutorial.¶

This is a tutorial to show you you can use the programs we have developed to analyze a single image. Multiple images can easily be analyzed by developing your own scripts.

The image file can be found here M_00009.png.

# This is the first line, we need to run some setup code.

%matplotlib inline

import pylab as plt
import numpy as np
from ImageAnalysisModParallel import *


f_name = 'M_00009.png'

fig1 = plt.figure(12)
ax1.imshow(image,interpolation = 'none')
plt.show() Here, lets zoom in on some particles.

window = image[350:650,550:850]
fig2 = plt.figure(13)
ax2.imshow(window,interpolation = 'none')
plt.show() Great. Now lets analyze this smaller image. The first thing we need to do is set some parameters.

Now, you don’t need to know what these all do now, we will talk about them later.

params =    {######################Image Analysis Parameters
'numProcess' : 3,              #number of processes to split analysis into
'slow_corr' : True,            #Optional parameter to tell it to use slow cross corr optimization algorithm
'peakWindow' : 12,             #half width of window used to find peaks. Should be at least as wide as peaks
'peakGradRatio' : 6.0,          #This is the minimum ratio of gradient / image_grad.std() it is used in initial peak finding.
'h_w_ratio_test_min' : 0.000,    #minimum value for mean/max of window as wide as two sigma
'h_w_ratio_test_max' : 20.0,    #Max value, Measure of acceptable level of signal to noise. (0.75 is reasonably high)
'corrWindow' : 30,             #This is half width of the correlation window
'fit_center_diff_max' : 6.0,         #Maximum difference between fit center and peak

'gaussWinFit' : 3,             #size of window for initial gaussian fit (3 ish)
'width_test_max' : 1.0,         #allowable difference between width of particle image and width of croscorr peak.
'p_p_fit_width' : 0.18,#0.18,   #Max width of peak as fit by gaussian. Most direct measure of uncertainty.
'minFreq' : 0.2,              #Minimum Frequency considered
'maxFreq' : 0.4,              #Maximum frequency considered
'numFreqs' : int(256),              #Number of frequencies used to calculate stored bessel functions
'maxError' : 5.0e-4,          #Maximum amount of relative error in curve fit allowed
'minPeakHeight' : 0.20,         #minimum allowed peak height  0.2
'minCenterSpread' : 0.1,      #minimum allowed std. of center locations for correlations 0.1
'maxFitStdDev' : 0.4,        #If we fit a gaussian to the ridge, this is the std of the fit. 0.2
'min2DFitCurve' : 0.2,         #This is the minimum acceptable curvature calculated in findConvMax 0.2
'minComplexTest' : 0.0001,        #1.75
'minOverlap' : 4.0,            #This is minimum distance between particles, if they are closer then this we deleat them
'regionOfInterest' : [10,-10,50,-50], #Box inscribing the region of interest (note, negative for max boundary)

######################Plotting Flags #########################################

'plotResult' : False,          #Turns on and off plotting of "result" for the image.
'plotParticles' : False,        #Turns on plotting particle windows
'plotFits'  : False,             #Turns on ploting of Curve fits
'printFits' : False,            #Turns on printing of curve fit information
'plotPeakFind' : False,        #plots found peaks over image. Good to test 'peakGradRatio'
'printParticles': False,        #Prints data about each potential particle, why fail, ext....
'plotEachPeak' : False,        #Plots each peak window, good for discovering if peak find is missing particles or being to generous.
'plot_conv_max' : False,        #Plots the convolution right before the maximum is found.
'debug_uncertainty' : False,    #Pltos stuff to debug uncertainty
}


Awesome. First, lets look at the plotting flags. Lets try playing with the peak finding plotting flags.

params['imageShape'] = np.shape(window)
params = besselCalc(params)

# Lets turn on the peak finding flag first

params['plotPeakFind'] = True

part_list = imageAnalysis(window,params) Great, it found both of the particles. You can just see the x’s above the center of each particle.

Now , lets run it and look at the heart of the algorithm, the convolution maximization.

params['plotPeakFind'] = False
params['plotFits'] = True

part_list = imageAnalysis(window,params)  This is a fantastic tool because it lets us see exactly what is going on with the cross correlations.

As you can see, for each particle the algorithm found a maximum, right arround 0.255 pixels^-1.

Lets purposefully screw up one of the parameters, in this case we will raise the minimum frequency above that of the actual frequency of the particle.

params['minFreq'] = 0.25
# Note: we have to recalculate our Bessel Basis...
params = besselCalc(params)

part_list = imageAnalysis(window,params)  