00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SEGMENTATION_H
00022 #define SEGMENTATION_H
00023
00024 #include "molfile_plugin.h"
00025 #include "GaussianBlur.h"
00026 #include "ScaleSpaceFilter.h"
00027 #include "VolumetricData.h"
00028
00029 #define TIMER
00030
00031
00036 class Segmentation {
00037
00038 public:
00041 Segmentation(const VolumetricData *map, bool cuda=true);
00042
00045 Segmentation(float* data,
00046 molfile_volumetric_t* metatdata,
00047 bool cuda=true);
00048
00049 Segmentation(unsigned short* data,
00050 molfile_volumetric_t* metatdata,
00051 bool cuda=true);
00052
00053 Segmentation(unsigned char* data,
00054 molfile_volumetric_t* metatdata,
00055 bool cuda=true);
00056
00057 ~Segmentation();
00058
00061 double segment(int num_final_groups,
00062 float watershed_blur_sigma,
00063 float blur_initial_sigma,
00064 float blur_multiple,
00065 MERGE_POLICY policy,
00066 const bool verbose=true);
00067
00070 template <typename OUT_T>
00071 void get_results(OUT_T* results);
00072
00074 unsigned long get_num_groups();
00075
00076 private:
00077
00078
00079
00080 enum Datatype {
00081 DT_LONG,
00082 DT_INT,
00083 DT_SHORT,
00084 DT_CHAR,
00085 DT_ULONG,
00086 DT_UINT,
00087 DT_USHORT,
00088 DT_UCHAR,
00089 DT_FLOAT,
00090 DT_DOUBLE,
00091 DT_ERROR
00092 };
00093
00094 unsigned long height;
00095 unsigned long width;
00096 unsigned long depth;
00097 unsigned long nVoxels;
00098 unsigned long nGroups;
00099 Datatype group_type;
00100 Datatype image_type;
00101 GaussianBlur<float>* gaussian_f;
00102 GaussianBlur<unsigned short>* gaussian_us;
00103 GaussianBlur<unsigned char>* gaussian_uc;
00104 unsigned long* segments_ul;
00105 unsigned int* segments_ui;
00106 unsigned short* segments_us;
00107 bool verbose;
00108
00109
00110
00111
00112
00113 bool use_cuda;
00114
00116 void init(unsigned long w,
00117 unsigned long h,
00118 unsigned long d,
00119 bool cuda);
00120
00123 void update_type();
00124
00125 void switch_to_cpu();
00126
00128 Datatype get_new_group_type();
00129
00133 template <typename IN_T, typename OUT_T>
00134 void copy_and_convert_type(IN_T* in, OUT_T* out, unsigned long num_elems,
00135 bool copy_from_gpu=false);
00136
00139 template <typename GROUP_T>
00140 void get_watershed_segmentation(float watershed_blur_sigma,
00141 GROUP_T* segments);
00142
00145 template <typename GROUP_T>
00146 void merge_groups(unsigned long num_final_groups,
00147 float blur_initial_sigma,
00148 float blur_multiple,
00149 MERGE_POLICY policy,
00150 GROUP_T* segments);
00151
00152 template <typename GROUP_T, typename IMAGE_T>
00153 void merge_groups_helper(unsigned long num_final_groups,
00154 float blur_initial_sigma,
00155 float blur_multiple,
00156 GROUP_T* segments,
00157 MERGE_POLICY policy,
00158 GaussianBlur<IMAGE_T>* gaussian);
00159
00160 template <typename GROUP_T>
00161 void sequentialize_groups(GROUP_T* segments,
00162 GROUP_T* group_map);
00163
00164 template <typename GROUP_T>
00165 unsigned long sequentialize_groups_cpu(GROUP_T* segments,
00166 GROUP_T* group_map);
00167
00171 template <typename GROUP_T>
00172 GROUP_T* allocate_array(unsigned long num_elements);
00173
00174 template <typename GROUP_T>
00175 void free_array(GROUP_T*& arr);
00176
00177 };
00178
00179 #endif