1#ifndef TTTRLIB_CLSMIMAGE_H
2#define TTTRLIB_CLSMIMAGE_H
12#include "pocketfft/pocketfft_hdronly.h"
31template<
typename TS,
typename TE>
32static std::pair<int, int> find_clsm_start_stop(
34 int marker_start,
int marker_stop,
int marker_event,
35 unsigned long long* macro_time_arr,
43 for(; i_event < n; i_event++)
45 if(event_type_arr[i_event] != marker_event)
continue;
46 if(start_stop_arr[i_event] == marker_start)
52 for(;i_event < n; i_event++){
53 if(event_type_arr[i_event] != marker_event)
continue;
54 if(start_stop_arr[i_event] == marker_stop){
62 unsigned long stop_time = macro_time_arr[i_event] + duration;
63 for(;i_event < n; i_event++){
64 if(macro_time_arr[i_event] >= stop_time){
173 bool _is_filled_ =
false;
175 std::vector<CLSMFrame *> frames;
177 void remove_incomplete_frames();
179 void create_pixels_in_lines();
193 std::shared_ptr<TTTR>
tttr =
nullptr;
217 return frames.size();
258 TTTR *tttr_data =
nullptr,
259 std::vector<int> channels = std::vector<int>(),
261 const std::vector<std::pair<int,int>> µ_time_ranges = std::vector<std::pair<int,int>>()
286 std::vector<int> channels,
287 bool clear_pixel =
true,
288 std::vector<std::pair<int,int>> micro_time_ranges = std::vector<std::pair<int,int>>()
290 std::clog <<
"WARNING: 'fill_pixels' deprecated. Use 'fill'." << std::endl;
291 fill(tttr_data, channels, clear_pixel, micro_time_ranges);
307 std::clog <<
"WARNING: 'clear_pixels' deprecated. Use 'clear'." << std::endl;
321 void strip(
const std::vector<int> &tttr_indices,
int offset = 0);
353 float **output,
int *dim1,
int *dim2,
int *dim3,
int *dim4,
354 std::shared_ptr<TTTR>
tttr,
356 std::string correlation_method =
"default",
360 bool normalized_correlation =
false,
385 void get_intensity(
unsigned short **output,
int *dim1,
int *dim2,
int *dim3);
411 unsigned char **output,
int *dim1,
int *dim2,
int *dim3,
int *dim4,
412 int micro_time_coarsening = 1,
442 uint8_t* mask,
int dmask1,
int dmask2,
int dmask3,
443 unsigned int **output,
int *dim1,
int *dim2,
473 double **output,
int *dim1,
int *dim2,
int *dim3,
474 double microtime_resolution = -1.0,
475 int minimum_number_of_photons = 2,
507 float **output,
int *dim1,
int *dim2,
int *dim3,
int *dim4,
509 TTTR *tttr_irf =
nullptr,
510 double frequency = -1,
511 int minimum_number_of_photons = 2,
550 double **output,
int *dim1,
int *dim2,
int *dim3,
551 int minimum_number_of_photons = 3,
552 TTTR *tttr_irf =
nullptr,
double m0_irf = 1.0,
double m1_irf = 1.0,
554 std::vector<double> background = std::vector<double>(),
555 double m0_bg = 0.0,
double m1_bg = 0.0,
556 double background_fraction = -1.0
570 inline int to1D(
int frame,
int line,
int pixel) {
584 inline std::vector<int>
to3D(
int idx) {
589 return std::vector<int>{frame, line, pixel};
604 int frame, line, pixel;
612 CLSMLine* s_line = s_frame->lines[line];
613 CLSMPixel* s_pixel = &(s_line->pixels[pixel]);
695 void rebin(
int bin_line,
int bin_pixel);
709 unsigned int pixel_id,
711 std::vector<int>& target_pixel_ids,
712 std::vector<int>& target_probabilities
729 int frame_start,
int frame_stop,
730 int line_start,
int line_stop,
731 int pixel_start,
int pixel_stop
742 for (
unsigned int i = 1; i <
n_frames; i++) {
778 std::shared_ptr<TTTR> tttr_data =
nullptr,
782 std::vector<int> channels = std::vector<int>(),
783 std::vector<std::pair<int, int>> micro_time_ranges =
784 std::vector<std::pair<int, int>>()
794 for (
auto frame : frames) {
809 return frames[i_frame];
842 double **output,
int *dim1,
int *dim2,
int *dim3,
843 std::shared_ptr<TTTR> tttr_data =
nullptr,
845 double *images =
nullptr,
int input_frames = -1,
int input_lines = -1,
int input_pixel = 1,
846 std::vector<int> x_range = std::vector<int>({0, -1}),
847 std::vector<int> y_range = std::vector<int>({0, -1}),
848 std::vector<std::pair<int, int>> frames_index_pairs = std::vector<std::pair<int, int>>(),
849 std::string subtract_average =
"",
850 uint8_t *mask =
nullptr,
int dmask1 = -1,
int dmask2 = -1,
int dmask3 = -1
894 double** output,
int* dim1,
int* dim2,
int* dim3,
896 std::vector<int> x_range=std::vector<int>({0,-1}),
897 std::vector<int> y_range=std::vector<int>({0,-1}),
898 std::string subtract_average =
"",
899 double background = 0.0,
900 bool clip=
false,
double clip_max=1e6,
double clip_min=-1e6,
901 double *images =
nullptr,
int n_frames=-1,
int n_lines=-1,
int n_pixels=1,
902 uint8_t *mask =
nullptr,
int dmask1 = -1,
int dmask2 = -1,
int dmask3 = -1,
903 std::vector<int> selected_frames = std::vector<int>()
937 std::vector<int> marker_frame_start = std::vector<int>({4, 6}),
938 int marker_event_type = 15,
966 int start_event,
int stop_event,
968 int marker_event_type = 15,
996 int start_event,
int stop_event,
998 int line_duration = 2,
999 int marker_event_type = 15,
1018 if(
tttr !=
nullptr){
1019 auto header =
tttr->get_header();
1021 auto f = frames[frame];
1022 auto l = f->lines[line];
1024 int start = l->get_start();
1025 int stop = l->get_stop();
1027 unsigned long long t_stop =
tttr->macro_times[stop];
1028 unsigned long long t_start =
tttr->macro_times[start];
1029 unsigned long long dt = t_stop - t_start;
1030 double res = header->get_macro_time_resolution() * 1000.0;
ReadingRoutine
Different types of distances between two accessible volumes.
Definition CLSMImage.h:24
@ CLSM_SP8
Leica SP5.
Definition CLSMImage.h:27
@ CLSM_DEFAULT
Definition CLSMImage.h:25
@ CLSM_SP5
Default reading compute_icsroutine.
Definition CLSMImage.h:26
Definition CLSMFrame.h:12
Definition CLSMImage.h:161
std::vector< int > to3D(int idx)
Convert a one-dimensional index to three-dimensional coordinates (frame, line, pixel).
Definition CLSMImage.h:584
void get_phasor(float **output, int *dim1, int *dim2, int *dim3, int *dim4, TTTR *tttr_data, TTTR *tttr_irf=nullptr, double frequency=-1, int minimum_number_of_photons=2, bool stack_frames=false)
Computes the phasor values for every pixel.
CLSMImage(std::shared_ptr< TTTR > tttr_data=nullptr, CLSMSettings settings=CLSMSettings(), CLSMImage *source=nullptr, bool fill=true, std::vector< int > channels=std::vector< int >(), std::vector< std::pair< int, int > > micro_time_ranges=std::vector< std::pair< int, int > >())
Constructs a CLSMImage object from TTTR data.
std::shared_ptr< TTTR > get_tttr()
Definition CLSMImage.h:203
static std::vector< int > get_line_edges(TTTR *tttr, int start_event, int stop_event, int marker_line_start=1, int marker_line_stop=2, int marker_event_type=15, int reading_routine=CLSM_SP8)
Identifies line edges by reading start and stop markers in a time-tagged time-resolved (TTTR) dataset...
int get_n_frames() const
Get the number of frames in the CLSM image.
Definition CLSMImage.h:625
int marker_event
The event type used for the marker.
Definition CLSMImage.h:230
int marker_line_start
Defines the marker for a line start.
Definition CLSMImage.h:224
static void get_roi(double **output, int *dim1, int *dim2, int *dim3, CLSMImage *clsm=nullptr, std::vector< int > x_range=std::vector< int >({0,-1}), std::vector< int > y_range=std::vector< int >({0,-1}), std::string subtract_average="", double background=0.0, bool clip=false, double clip_max=1e6, double clip_min=-1e6, double *images=nullptr, int n_frames=-1, int n_lines=-1, int n_pixels=1, uint8_t *mask=nullptr, int dmask1=-1, int dmask2=-1, int dmask3=-1, std::vector< int > selected_frames=std::vector< int >())
Copies a region of interest (ROI) from the input images, performs background correction,...
void get_intensity(unsigned short **output, int *dim1, int *dim2, int *dim3)
Computes an intensity image.
int get_n_lines() const
Get the number of lines per frame in the CLSMImage.
Definition CLSMImage.h:637
bool skip_after_last_frame_marker
Definition CLSMImage.h:237
CLSMFrame * operator[](unsigned int i_frame)
Accessor for CLSMFrame at the specified index in CLSMImage.
Definition CLSMImage.h:808
size_t n_pixel
The number if pixels per line.
Definition CLSMImage.h:190
void copy(const CLSMImage &p2, bool fill=false)
Copy information from another CLSMImage object.
static std::vector< int > get_frame_edges(TTTR *tttr=nullptr, int start_event=0, int stop_event=-1, std::vector< int > marker_frame_start=std::vector< int >({4, 6}), int marker_event_type=15, int reading_routine=CLSM_SP8, bool skip_before_first_frame_marker=false, bool skip_after_last_frame_marker=false)
Retrieves the time-tagged time-resolved (TTTR) indices of frame markers for a Leica SP8 microscope.
void distribute(unsigned int pixel_id, CLSMImage *target, std::vector< int > &target_pixel_ids, std::vector< int > &target_probabilities)
Distribute the photons of a pixel_id to a set of pixel ids in a target image according to provided pr...
bool skip_before_first_frame_marker
Definition CLSMImage.h:236
std::shared_ptr< TTTR > tttr
Pointer to tttr data that used to construct the Image.
Definition CLSMImage.h:193
void get_fluorescence_decay(TTTR *tttr_data, unsigned char **output, int *dim1, int *dim2, int *dim3, int *dim4, int micro_time_coarsening=1, bool stack_frames=false)
Computes an image stack where the value of each pixel corresponds to a histogram of micro times in ea...
static void compute_ics(double **output, int *dim1, int *dim2, int *dim3, std::shared_ptr< TTTR > tttr_data=nullptr, CLSMImage *clsm=nullptr, double *images=nullptr, int input_frames=-1, int input_lines=-1, int input_pixel=1, std::vector< int > x_range=std::vector< int >({0, -1}), std::vector< int > y_range=std::vector< int >({0, -1}), std::vector< std::pair< int, int > > frames_index_pairs=std::vector< std::pair< int, int > >(), std::string subtract_average="", uint8_t *mask=nullptr, int dmask1=-1, int dmask2=-1, int dmask3=-1)
Performs an image correlation spectroscopy analysis via FFTs for a set of frames.
void clear_pixels()
Clears the time-tagged time-resolved (TTTR) indices stored in the pixels.
Definition CLSMImage.h:306
std::vector< int > marker_frame
Vector containing the tttr indices of the frame markers.
Definition CLSMImage.h:221
void fill(TTTR *tttr_data=nullptr, std::vector< int > channels=std::vector< int >(), bool clear=true, const std::vector< std::pair< int, int > > µ_time_ranges=std::vector< std::pair< int, int > >())
Fills the time-tagged time-resolved (TTTR) indices of the pixels with the indices of the photons that...
int get_n_pixel() const
Get the number of pixels per line in a frame of the CLSMImage.
Definition CLSMImage.h:649
void determine_number_of_lines()
static std::vector< int > get_line_edges_by_duration(TTTR *tttr, int start_event, int stop_event, int marker_line_start=1, int line_duration=2, int marker_event_type=15, int reading_routine=CLSM_SP8)
Identifies line edges by reading a start marker and using line duration as the stop criterion in a ti...
void crop(int frame_start, int frame_stop, int line_start, int line_stop, int pixel_start, int pixel_stop)
Crop the CLSMImage.
size_t size()
Get the number of frames in the CLSMImage.
Definition CLSMImage.h:216
void transform(unsigned int *input, int n_input)
Move the content of the Pixels based on source and target pixel indices.
void fill_pixels(TTTR *tttr_data, std::vector< int > channels, bool clear_pixel=true, std::vector< std::pair< int, int > > micro_time_ranges=std::vector< std::pair< int, int > >())
Fills the time-tagged time-resolved (TTTR) indices of the pixels with the indices of the channels tha...
Definition CLSMImage.h:284
CLSMImage(const CLSMImage &p2, bool fill=false)
Copy constructor for CLSMImage.
void get_fcs_image(float **output, int *dim1, int *dim2, int *dim3, int *dim4, std::shared_ptr< TTTR > tttr, CLSMImage *clsm_other=nullptr, std::string correlation_method="default", int n_bins=50, int n_casc=1, bool stack_frames=false, bool normalized_correlation=false, int min_photons=2)
Computes an image where pixels represent correlation curves.
void get_mean_lifetime(TTTR *tttr_data, double **output, int *dim1, int *dim2, int *dim3, int minimum_number_of_photons=3, TTTR *tttr_irf=nullptr, double m0_irf=1.0, double m1_irf=1.0, bool stack_frames=false, std::vector< double > background=std::vector< double >(), double m0_bg=0.0, double m1_bg=0.0, double background_fraction=-1.0)
Computes an image of average lifetimes.
void clear()
Clears the time-tagged time-resolved (TTTR) indices stored in the pixels.
size_t n_frames
The number of frames in an CLSMImage.
Definition CLSMImage.h:184
CLSMPixel * getPixel(unsigned int idx)
Get a pointer to a CLSMPixel object based on a one-dimensional index.
Definition CLSMImage.h:603
double get_line_duration(int frame=0, int line=0)
Obtains the duration of a line (in milliseconds) for a specified frame and line.
Definition CLSMImage.h:1016
int to1D(int frame, int line, int pixel)
Convert three-dimensional coordinates (frame, line, pixel) to a one-dimensional index.
Definition CLSMImage.h:570
double get_pixel_duration(int frame=0, int line=0)
Obtains the duration of a pixel (in milliseconds) for a specified frame and line.
Definition CLSMImage.h:1049
void set_tttr(std::shared_ptr< TTTR > v)
Definition CLSMImage.h:207
std::vector< CLSMFrame * > get_frames()
Retrieves the frames stored in the CLSMImage.
Definition CLSMImage.h:369
const CLSMSettings * get_settings()
Definition CLSMImage.h:211
virtual ~CLSMImage()
Destructor for CLSMImage.
Definition CLSMImage.h:793
std::string reading_routine
Definition CLSMImage.h:232
void get_mean_micro_time(TTTR *tttr_data, double **output, int *dim1, int *dim2, int *dim3, double microtime_resolution=-1.0, int minimum_number_of_photons=2, bool stack_frames=false)
Calculates an image stack where the value of each pixel corresponds to the mean micro time (in units ...
void create_frames(bool clear_first=true)
size_t n_lines
The number of lines per frames.
Definition CLSMImage.h:187
void append(CLSMFrame *frame)
Append a CLSMFrame to the CLSM image.
void strip(const std::vector< int > &tttr_indices, int offset=0)
Strips time-tagged time-resolved (TTTR) indices from all pixels in the image.
void get_decay_of_pixels(TTTR *tttr_data, uint8_t *mask, int dmask1, int dmask2, int dmask3, unsigned int **output, int *dim1, int *dim2, int tac_coarsening, bool stack_frames)
Computes micro time histograms for the stacks of images and a selection of pixels....
int marker_line_stop
Defines the marker for a line stop.
Definition CLSMImage.h:227
void stack_frames()
Stack frames in the CLSMImage.
Definition CLSMImage.h:740
void rebin(int bin_line, int bin_pixel)
Rebin a CLSMImage.
Definition CLSMImage.h:82
int reading_routine
Definition CLSMImage.h:92
std::vector< int > marker_frame_start
Vector containing the tttr indices of the frame markers.
Definition CLSMImage.h:101
int marker_line_stop
Defines the marker for a line stop.
Definition CLSMImage.h:98
CLSMSettings(bool skip_before_first_frame_marker=false, bool skip_after_last_frame_marker=false, int reading_routine=CLSM_DEFAULT, int marker_line_start=3, int marker_line_stop=2, std::vector< int > marker_frame_start=std::vector< int >({1}), int marker_event_type=1, int n_pixel_per_line=1, int n_lines=-1)
CLSMSettings Constructor.
Definition CLSMImage.h:134
bool skip_before_first_frame_marker
To skip incomplete frames.
Definition CLSMImage.h:89
int marker_event_type
The event type used for the marker.
Definition CLSMImage.h:104
int n_pixel_per_line
Definition CLSMImage.h:106
int marker_line_start
Defines the marker for a line start.
Definition CLSMImage.h:95
int n_lines
Definition CLSMImage.h:107
bool skip_after_last_frame_marker
Definition CLSMImage.h:90
Definition Correlator.h:21
Time-Tagged Time-Resolved (TTTR) data class.
Definition TTTR.h:195