|
PSFEstimationwithCPSO
|
This class represents the Search method Cooperative Particle Swarm Optimization (CPSO). More...
#include <cpso.hpp>
Public Member Functions | |
| CPSO (double *_zernikes, int *_phase_mask, int *_diffraction_mask, int _phase_size, int _image_size, int _n_zernikes, int _psf_range, WORD _w, WORD c1, WORD c2, WORD _reset_at, int _n_particles, int _n_swarms) | |
| The Contructor. | |
| ~CPSO () | |
| The destructor. | |
| void | set_images (double *object, double *image) |
| This method makes the final preparation for the search. | |
| void | finalize_cl () |
| Finalize all internal objects related to this CPSO instance. | |
| WORD | getMinCost () |
| Get the minimum cost obtained from all the swarms available. | |
| int | getBestPsfPos () |
| Get the position between all the particles of the best PSF found. | |
| void | getBestCoefs (WORD *_coefs) |
| Get the best coefficients. | |
| void | getBestPsf (WORD *psf) |
| Get the best PSF. | |
| void | getBestPsfe (WORD *psfe) |
| Get the best extracted (final) PSF. | |
| void | getBestPhase (WORD *phase) |
| Get the best phase. | |
| void | getBestConvolvedObject (WORD *conobj) |
| Get the best convolved object. | |
| void | getBestConvolvedObjectFFT (FFT_TYPE *conobj_fft) |
| Get the FFT of the best convolved object. | |
| void | getBestPsfeFFT (FFT_TYPE *psfe_fft) |
| Get the FFT of the best extracted PSF. | |
| void | getObjectFFT (FFT_TYPE *obj_fft) |
| Get the FFT of the object. | |
| void | getImageFFT (FFT_TYPE *img_fft) |
| Get the FFT of the image. | |
| void | replicateValue (WORD value, int sz, cl_mem cl_ref) |
| Replicate one value 'sz' times into a OpenCl pointer. | |
| void | setW (WORD _w) |
| Set the search parameter 'w' for all the particles. | |
| void | setC1 (WORD _c1) |
| Set the search parameter 'c1' for all the particles. | |
| void | setC2 (WORD _c2) |
| Set the search parameter 'c2' for all the particles. | |
| void | setOriginalPsf (WORD *original_psf) |
| Set the exact original PSF that caused the corruption over the image. | |
| double | calcPsfDifferences () |
| Calculate the difference from the Original PSF to the currently calculated PSF. | |
| void | run (TimeTracker **trackers, int n_cycles) |
| This method runs the search of the object over the image. | |
| void | runPsf (TimeTracker **trackers) |
| Runs 'number of particles * number of swarms' PSFs, that were configured previously for this CPSO instance. | |
| void | runPsf (TimeTracker **trackers, int n_psfs) |
| Runs 'n_psfs' PSFs. | |
| void | generatePhase (TimeTracker **tracker, int n_psfs) |
| This method calculates the phase and the pupil. | |
| void | makePsf (TimeTracker **tracker, int n_psfs) |
| Calculate the basic PSF information. | |
| void | convolveObj (TimeTracker **tracker, int n_psfs) |
| Convolve the object with the PSFs calculated, generating several corrupted images. | |
| void | calcCost (TimeTracker **tracker, int n_psfs) |
| Calculate the cost of the convolved objects. | |
| void | runCPSO (TimeTracker **tracker, int n_cycles) |
| Run the CPSO search. | |
| void | reduce_squares (TimeTracker **tracker, int n_reductions, int reduction_width, cl_mem square, cl_mem sum, WORD *result) |
| This method makes the reductions for 'n_reductions' matrixes. | |
| FFT_TYPE | validatePsf (double *psf) |
| Validate an external PSF. | |
| void | commitBestValues () |
| void | copyToDeviceAsFloat (cl_command_queue command_queue, cl_mem dest, double *values, int size) |
| void | copyToHostAsDouble (cl_command_queue command_queue, cl_mem src, double *values, int size) |
| void | lock () |
| Lock this CPSO instance. | |
| void | release () |
| Release this CPSO instance. | |
| bool | isInUse () |
| Inform if this CPSO instance is in use. | |
| WORD | getGBestCost () |
| Returns the best cost found by the search. Should be called Only after the run method has finished. | |
| void | setStartupCoefs (WORD *coefs) |
| Set the Zernike coefficients for the startup. | |
| void | saveFirstResult () |
| Save the results of the first Particle / PSF as the best value found so far. | |
Static Public Member Functions | |
| static void | store_static_data (cl_context _context, int _n_zernikes, int _phase_size, int _image_size, double *zernikes, int *phase_mask, int *_diffraction_mask) |
| This method is responsible for storing the static data. | |
| static void | clear_static_data () |
| Clear all the static data. | |
| static WORD | getRandCoef (double range) |
| Get a random coefficient within a specified range. | |
| static double | calc_mean (double *image, int img_area) |
| Calculate the mean of a set of values. | |
| static double | calc_variance (double *image, int img_area) |
| Calculate the variance of a set of values. | |
| static double | calc_stddev (double *image, int img_area) |
| Calculate the standard deviation of a set of values. | |
| static void | generateRandomCoefs (WORD *coefs, int n_zernikes, double range) |
| Generate random coefficients in a specific range. | |
| static void | generateNormalDistrRandomCoefs (WORD *coefs, int n_zernikes, double range) |
| Generate random coefficients in a normal distribution. | |
| static double | randNormalDistribution (double mean, double std_dev) |
| Generate a double value in a normal distribution. | |
| template<class T > | |
| static void | invertPsf (T *psf, T *psf_inv, int psf_size) |
| Invert the PSF to put the bright spot in the center of the image. | |
This class represents the Search method Cooperative Particle Swarm Optimization (CPSO).
All processing related to this search method is included into this class.
| CPSO::CPSO | ( | double * | _zernikes, |
| int * | _phase_mask, | ||
| int * | _diffraction_mask, | ||
| int | _phase_size, | ||
| int | _image_size, | ||
| int | _n_zernikes, | ||
| int | _psf_range, | ||
| WORD | _w, | ||
| WORD | c1, | ||
| WORD | c2, | ||
| WORD | _reset_at, | ||
| int | _n_particles, | ||
| int | _n_swarms | ||
| ) |
The Contructor.
It is responsible for requesting a queue for the OpenCl factory and for allocating all the static and non-static data.
| _zernikes | The complete Zernike matrix. |
| _phase_mask | The phase mask. |
| _diffraction_mask | The diffraction mask. |
| _phase_size | The phase mask. |
| _image_size | The image width. |
| _n_zernikes | The number of Zernike terms used for the calculations. |
| _psf_range | The Zernike coefficient range. |
| _w | The parameter w for the CPSO search. |
| c1 | The parameter c1 for the CPSO search. |
| c2 | The parameter c2 for the CPSO search. |
| _reset_at | The particle reset factor for the CPSO search. |
| _n_particles | The number of particles for the CPSO search. |
| _n_swarms | The number of swarms for the CPSO search. |
| double CPSO::calc_mean | ( | double * | values, |
| int | size | ||
| ) | [static] |
Calculate the mean of a set of values.
| values | The values to calculate the mean. |
| size | The array size. |
| double CPSO::calc_stddev | ( | double * | values, |
| int | size | ||
| ) | [static] |
Calculate the standard deviation of a set of values.
| values | The values to calculate the standard deviation. |
| size | The array size. |
| double CPSO::calc_variance | ( | double * | values, |
| int | size | ||
| ) | [static] |
Calculate the variance of a set of values.
| values | The values to calculate the variance. |
| size | The array size. |
| void CPSO::calcCost | ( | TimeTracker ** | tracker, |
| int | n_psfs | ||
| ) |
Calculate the cost of the convolved objects.
| tracker | The tracker. |
| n_psfs | The number of PSFs that were used on this search. |
| double CPSO::calcPsfDifferences | ( | ) |
| void CPSO::clear_static_data | ( | ) | [static] |
Clear all the static data.
This method Must be called only Once during the application life time!
| void CPSO::commitBestValues | ( | ) |
Not in use.
| void CPSO::convolveObj | ( | TimeTracker ** | tracker, |
| int | n_psfs | ||
| ) |
Convolve the object with the PSFs calculated, generating several corrupted images.
| tracker | The tracker. |
| n_psfs | The number of PSFs that will generate the same number of convolved objects. |
| void CPSO::copyToDeviceAsFloat | ( | cl_command_queue | command_queue, |
| cl_mem | dest, | ||
| double * | values, | ||
| int | size | ||
| ) |
Force the values to be copied from host to device as floats (not in use).
| void CPSO::copyToHostAsDouble | ( | cl_command_queue | command_queue, |
| cl_mem | src, | ||
| double * | values, | ||
| int | size | ||
| ) |
Force the values to be copied from device to host as doubles (not in use).
| void CPSO::generateNormalDistrRandomCoefs | ( | WORD * | coefs, |
| int | n_zernikes, | ||
| double | range | ||
| ) | [static] |
Generate random coefficients in a normal distribution.
| coefs | A pointer where the the coefficients will be generated. |
| n_zernikes | The number of coefficients to be generated. |
| range | The coefficients range. |
| void CPSO::generatePhase | ( | TimeTracker ** | tracker, |
| int | n_psfs | ||
| ) |
This method calculates the phase and the pupil.
| tracker | The tracker. |
| n_psfs | The number of PSFs to be calculated. |
| void CPSO::generateRandomCoefs | ( | WORD * | coefs, |
| int | n_zernikes, | ||
| double | range | ||
| ) | [static] |
Generate random coefficients in a specific range.
| coefs | A pointer where the the coefficients will be generated. |
| n_zernikes | The number of coefficients to be generated. |
| range | The coefficients range. |
| void CPSO::getBestCoefs | ( | WORD * | _coefs | ) |
Get the best coefficients.
| _coefs | The WORD pointer where to copy the coefficients. |
| void CPSO::getBestConvolvedObject | ( | WORD * | conobj | ) |
Get the best convolved object.
| conobj | The Host pointer where to copy the best convolved object. |
| void CPSO::getBestConvolvedObjectFFT | ( | FFT_TYPE * | conobj_fft | ) |
Get the FFT of the best convolved object.
| conobj_fft | The Host pointer where to copy the FFT of the best convolved object. |
| void CPSO::getBestPhase | ( | WORD * | phase | ) |
Get the best phase.
| phase | The Host pointer where to copy the best phase. |
| void CPSO::getBestPsf | ( | WORD * | psf | ) |
| void CPSO::getBestPsfe | ( | WORD * | psfe | ) |
| void CPSO::getBestPsfeFFT | ( | FFT_TYPE * | psfe_fft | ) |
| int CPSO::getBestPsfPos | ( | ) |
| void CPSO::getImageFFT | ( | FFT_TYPE * | img_fft | ) |
Get the FFT of the image.
| img_fft | The Host pointer where to copy the FFT of the image. |
| WORD CPSO::getMinCost | ( | ) |
Get the minimum cost obtained from all the swarms available.
| void CPSO::getObjectFFT | ( | FFT_TYPE * | obj_fft | ) |
Get the FFT of the object.
| obj_fft | The Host pointer where to copy the FFT of the object. |
| WORD CPSO::getRandCoef | ( | double | range | ) | [static] |
Get a random coefficient within a specified range.
| range | The range to generate the random value. |
| static void CPSO::invertPsf | ( | T * | psf, |
| T * | psf_inv, | ||
| int | psf_size | ||
| ) | [inline, static] |
| void CPSO::makePsf | ( | TimeTracker ** | tracker, |
| int | n_psfs | ||
| ) |
Calculate the basic PSF information.
| tracker | The tracker. |
| n_psfs | The number of PSFs to be calculated. |
| double CPSO::randNormalDistribution | ( | double | mean, |
| double | std_dev | ||
| ) | [static] |
Generate a double value in a normal distribution.
| mean | The mean of the normal distribution. |
| std_dev | The standard deviation of the normal distribution. |
| void CPSO::reduce_squares | ( | TimeTracker ** | tracker, |
| int | n_reductions, | ||
| int | reduction_width, | ||
| cl_mem | square, | ||
| cl_mem | sum, | ||
| WORD * | result | ||
| ) |
This method makes the reductions for 'n_reductions' matrixes.
Every summed matrix will return a WORD value inside the diff parameter, thus this parameter must have allocated enough space for the results.
| tracker | The tracker |
| n_reductions | The number of matrixes to be reduced. |
| reduction_width | The square matrix width. |
| square | The matrix data. |
| sum | The OpenCl pointer where the intermediate sum will be stored. |
| result | The pointer where every final resulting will be stored. |
| void CPSO::replicateValue | ( | WORD | value, |
| int | sz, | ||
| cl_mem | cl_ref | ||
| ) |
Replicate one value 'sz' times into a OpenCl pointer.
| value | The value to be replicated |
| sz | The number of times the values will be replicated. |
| cl_ref | The OpenCl pointer where to replicate the value. |
| void CPSO::run | ( | TimeTracker ** | trackers, |
| int | n_cycles | ||
| ) |
This method runs the search of the object over the image.
It must be called to start the CPSO search.
| trackers | The tracker. |
| n_cycles | The number of search cycles to be executed. |
| void CPSO::runCPSO | ( | TimeTracker ** | tracker, |
| int | n_cycles | ||
| ) |
Run the CPSO search.
| tracker | The tracker. |
| n_cycles | The number of cycles that this search was initially configured to run. |
| void CPSO::runPsf | ( | TimeTracker ** | trackers, |
| int | n_psfs | ||
| ) |
Runs 'n_psfs' PSFs.
| trackers | The trackers. |
| n_psfs | The number of PSFs to be calculated. |
| void CPSO::runPsf | ( | TimeTracker ** | trackers | ) |
Runs 'number of particles * number of swarms' PSFs, that were configured previously for this CPSO instance.
| trackers | The trackers. |
| void CPSO::set_images | ( | double * | object, |
| double * | image | ||
| ) |
This method makes the final preparation for the search.
It must be called to set the coefficients, the object and the image.
| object | The object that will be used as starting point to obtain the image. |
| image | The image that must be obtained by the search. |
| void CPSO::setC1 | ( | WORD | _c1 | ) |
Set the search parameter 'c1' for all the particles.
| _c1 | The search parameter c1. |
| void CPSO::setC2 | ( | WORD | _c2 | ) |
Set the search parameter 'c2' for all the particles.
| _c2 | The search parameter c2. |
| void CPSO::setOriginalPsf | ( | WORD * | original_psf | ) |
| void CPSO::setStartupCoefs | ( | WORD * | coefs | ) |
Set the Zernike coefficients for the startup.
It must be called before the search has begun.
| coefs | The Zernike coefficients for the startup. |
| void CPSO::setW | ( | WORD | _w | ) |
Set the search parameter 'w' for all the particles.
| _w | The search parameter w. |
| void CPSO::store_static_data | ( | cl_context | _context, |
| int | _n_zernikes, | ||
| int | _phase_size, | ||
| int | _image_size, | ||
| double * | zernikes, | ||
| int * | phase_mask, | ||
| int * | _diffraction_mask | ||
| ) | [static] |
This method is responsible for storing the static data.
It stores the static data Only Once for every available context. It's the developer's responsibility to call the static method clear_static_data after all the processing in all available CPSOs is done. This method can be called several times during the application life time.
| _context | The OpenCl context. |
| _n_zernikes | The number of Zernike terms used for the calculations. |
| _phase_size | The phase width. |
| _image_size | The image width. |
| zernikes | The complete Zernike matrix. |
| phase_mask | The phase mask. |
| _diffraction_mask | The diffraction mask. |
| FFT_TYPE CPSO::validatePsf | ( | double * | psf_data | ) |