/* * segmentation.h * * Created on: Oct 28, 2019 * Author: lutton */ #ifndef SEGMENTATION_H_ #define SEGMENTATION_H_ #ifdef __cplusplus extern "C"{ #endif struct image_dimensions{ /* int N0; //actual number of nodes int R0; // actual number of rows int C0; // actual number of columns int Z0; // actual number of slices */ int c0; // start column of computed volume in actual volume (inclusive) int c1; // end column of computed volume in actual volume (exclusive) int r0; // start row of computed volume in actual volume (inclusive) int r1; // end row of computed volume in actual volume (exclusive) int z0; // start slice of computed volume in actual volume (inclusive) int z1; // end slice of computed volume in actual volume (exclusive) int N; //number of nodes in computed volume int R; //rows in computed volume int C; //columns in computed volume int Z; //slices in computed volume int E; //total number of edges // blocks are used by the GPU to split computations // images are split in 3D, with rows corresponding to y and columns corresponding to x // product of threads per block in all dimensions must be <=1024 int threads_per_block_x; int threads_per_block_y; int threads_per_block_z; int num_blocks_x; int num_blocks_y; int num_blocks_z; int edge_direction_count; }; struct segmentation_parameters{ float Ddt; // Ddt=D*Dt, D*dt/(w^2) << 1/2; int T; // Maximum number of timesteps, we use relative error to detect when to break int test_interval; // number of timesteps between testing relative error int img_interval; int test_time_start; // earliest timestep to test relative error int curv_interval; // number of timesteps between updating the curvature int curv_time_start; //earliest timestep to compute curvature float re_stop; // threshold for relative error at which the simulation stops float gamma_correction; // gamma filter parameter float t_norm; // threshold for the size of gradient when computing curvature int grad_step; int max_threads_per_block; float beta; float alpha; float kappa; float v_T; int augment_seeds; }; typedef enum {FLOAT_IM, BYTE_IM} im_t; int set_image_dimensions(unsigned char *seeds, struct image_dimensions *dims0, struct image_dimensions *dims1, int max_step); // sets dimensions struct with reduced image size based on seed position void * copy_image(void *img_in, struct image_dimensions *dims0, struct image_dimensions *dims1, im_t image_type); // crops the input image based on the values in the dims structure int set_neighbours(int *h_NR, int *h_NL, int *h_NR2, int *h_NL2, int *h_NRs, int *h_NLs, struct image_dimensions *dims, int s); int set_edges( float *h_w2, int *h_NR, float *h_img, struct segmentation_parameters *params, struct image_dimensions *dims ); // sets the edge weights and neighbour nodes based on image data and input parameters int set_seed_indicator(float *h_seed_indicator, unsigned char *h_seed_img, int N); int set_v0(float * h_v0, unsigned char *h_seed_img, int N); int halve_dimensions(unsigned char *seed_data, struct image_dimensions *dims0, struct image_dimensions *dims1); int optimize_parameters( float *h_img, unsigned char *h_seed_img, unsigned char *h_gt, struct image_dimensions *dims, struct segmentation_parameters *params, char output_dir[], char op_path[], int max_it ); // generates an optimised value for beta with kappa=0.0 // stores intermediate segmentation probability maps to enable faster optimization of k int optimize_beta( float *h_img, float *h_seed_indicator, unsigned char *h_gt, float *h_v0, struct image_dimensions *dims, struct segmentation_parameters *params, char output_dir[], float *jacc, float *haus, float *beta, int max_it ); int optimize_kappa( float *h_img, float *h_seed_indicator, unsigned char *h_gt, float *h_v0, struct image_dimensions *dims, struct segmentation_parameters *params, char output_dir[], float *jacc, float *haus, float *kappa, int max_it ); void setup_GPU(); // GPU setup for segmentation int segment_range( float *h_img, unsigned char *h_seed_img, struct image_dimensions *dims0, struct image_dimensions *dims1, struct segmentation_parameters *params, char output_dir[], char img_name_base[], float *beta, float *kappa, int b_sz, int k_sz ); int segment_paired( float *h_img, unsigned char *h_seed_img, struct image_dimensions *dims0, struct image_dimensions *dims1, struct segmentation_parameters *params, char output_dir[], char img_name_base[], float *beta, float *kappa, int b_sz ); int run_segmentation( float *h_v, float *h_w2, int *h_NR, int *h_NL, int *h_NR2, int *h_NL2, int *h_NRs, int *h_NLs, float *h_seed_indicator, struct segmentation_parameters *params, struct image_dimensions *dims ); // method for running segmentation on GPU given preallocated device variables and copied inputs #ifdef __cplusplus } #endif #endif /* SEGMENTATION_H_ */