11 #ifndef BRAINRAT_DATA_SLICES_H
12 #define BRAINRAT_DATA_SLICES_H
15 #include <cartobase/type/string_conversion.h>
16 #include <aims/io/process.h>
17 #include <aims/io/io_g.h>
18 #include <aims/data/data_g.h>
19 #include <aims/math/mathelem.h>
21 #include <aims/utility/converter_g.h>
27 #define MAX_INT16_T 32767
33 #define BORDER_LOCAL 10
34 #define BORDER_GLOBAL 50
35 #define PERCENT_SURFACE .2
191 float slice_min_surface = 1.,
192 float slice_median_variation = 1. /
FRACTION,
195 bool check_slices =
true);
200 const std::vector<Component> & components);
202 std::vector<Component>
analyze(carto::VolumeRef<int16_t> & vol,
203 const int32_t slices_number = 6,
204 const int32_t scan_resolution = 0,
205 const int32_t threshold_lowerbound = 0,
206 const int32_t threshold_upperbound = 0);
211 const int32_t slices_number,
212 const int32_t slices_min_voxels,
215 int32_t & slices_mode_lowerbound,
216 int32_t & slices_mode_upperbound);
219 carto::VolumeRef<int16_t> & vol,
220 const int32_t slices_number,
221 const int32_t threshold_lowerbound,
222 const int32_t threshold_upperbound);
225 carto::VolumeRef<int16_t> & vol,
226 std::vector<Component> &components,
227 const int32_t slices_number);
230 std::vector<Component> &components,
231 carto::VolumeRef<int16_t> &vol,
232 const int32_t slices_number);
235 const std::vector<Component> & components,
236 const int32_t component,
237 carto::VolumeRef<int16_t> &vol);
240 const std::vector<Component> & components,
241 const int32_t component,
242 carto::VolumeRef<int16_t> &vol,
253 float _slice_min_surface;
254 float _slice_median_variation;
255 int32_t _histogram_modes;
256 int32_t _histogram_bins;
269 int32_t pos, int32_t extr);
295 const carto::VolumeRef<int16_t> &vol,
299 std::vector<AimsVector<int32_t, 3> > &vdm);
302 const carto::VolumeRef<int16_t> &vol,
303 const int16_t threshold_lower_bound,
304 const int16_t threshold_upper_bound,
311 carto::VolumeRef<int16_t> &vol);
319 const std::vector<Component> & cpnt,
320 const std::vector<Component> & to_remove);
324 std::vector<Component> cpnt2slices,
331 const carto::VolumeRef<int16_t> &vol);
350 std::vector<Component> cpnt,
354 std::vector<Component> &cpnt,
float variation, int32_t mid_window = 0);
359 carto::VolumeRef<int32_t>
projectData(carto::VolumeRef<int16_t> &X);
362 carto::VolumeRef<int16_t> &vol);
365 const std::vector<Component> & to_remove);
368 const carto::VolumeRef<int16_t> &vol,
373 const int32_t old_label,
374 const int32_t new_label);
377 carto::VolumeRef<int16_t> &destvol,
382 const int32_t old_label,
383 const int32_t new_label);
387 carto::VolumeRef<int16_t> vol,
392 carto::VolumeRef<int16_t> vol,
398 const float min_surface);
401 const int32_t slices_number);
404 const std::vector<Component> & cpnt,
405 const float min_surface);
408 std::vector<Component> &cpnt,
409 int32_t slices_number);
412 carto::VolumeRef<int16_t> &vol,
414 int32_t slices_number,
423 std::vector<Component>& components,
424 std::vector<int32_t> dimensionsizes,
425 std::vector<int32_t> dimensionorders,
426 int32_t offset = 1, int32_t step = 1);
431 std::vector<int32_t> dimensionsizes);
437 carto::VolumeRef<int16_t> vol);
442 template<
class T>
bool
443 detectSlices(aims::Process & p,
const std::string &, aims::Finder &);
451 void rescale(carto::VolumeRef<T> &in, carto::RescalerInfo & info);
457 std::vector<Component> &cpnt,
458 carto::VolumeRef<T> &vol,
459 std::string outputfile,
466 std::vector<Component> &cpnt,
467 carto::VolumeRef<T> &vol,
468 std::string outputdir,
469 std::string outputname,
489 inline T
background(std::vector<Component> & cpnt, carto::VolumeRef<T> &vol)
494 for (int32_t i = 0; i <(int32_t)cpnt.size(); i++)
524 return (T)(bg / count);
529 carto::VolumeRef<AimsRGB> &vol)
532 AimsVector<double, 3> s(0,0,0);
535 for (int32_t i = 0; i <(int32_t)cpnt.size(); i++)
546 for (int32_t v = 0; v <3; v++)
561 for (int32_t v = 0; v <3; v++)
571 bg[0] = (uint8_t)(s[0] / count);
572 bg[1] = (uint8_t)(s[1] / count);
573 bg[2] = (uint8_t)(s[2] / count);
575 return (AimsRGB)(bg);
580 carto::VolumeRef<AimsRGBA> &vol)
582 AimsRGBA bg(0,0,0,0);
583 AimsVector<double, 4> s(0,0,0,0);
586 for (int32_t i = 0; i <(int32_t)cpnt.size(); i++)
597 for (int32_t v = 0; v <4; v++)
611 for (int32_t v = 0; v <4; v++)
621 bg[0] = (uint8_t)(bg[0] / count);
622 bg[1] = (uint8_t)(bg[1] / count);
623 bg[2] = (uint8_t)(bg[2] / count);
624 bg[3] = (uint8_t)(bg[3] / count);
626 return (AimsRGBA)(bg);
carto::Object boundingBoxes(const carto::VolumeRef< int16_t > &vol, const std::vector< Component > &components)
HistologyScanSlicesDetector(float slice_min_surface=1., float slice_median_variation=1./FRACTION, int32_t histogram_modes=NB_MODES, int32_t histogram_bins=MAX_HISTO, bool check_slices=true)
bool detectHistogramModes(const carto::VolumeRef< int32_t > &histogram, const int32_t slices_number, const int32_t slices_min_voxels, const HistoAnalysisFunction analysis_function, int32_t &background, int32_t &slices_mode_lowerbound, int32_t &slices_mode_upperbound)
std::vector< Component > checkComponents(carto::VolumeRef< int16_t > &vol, std::vector< Component > &components, const int32_t slices_number)
std::vector< Component > analyze(carto::VolumeRef< int16_t > &vol, const int32_t slices_number=6, const int32_t scan_resolution=0, const int32_t threshold_lowerbound=0, const int32_t threshold_upperbound=0)
std::vector< Component > processOutlierComponents(std::vector< Component > &components, carto::VolumeRef< int16_t > &vol, const int32_t slices_number)
std::vector< Component > detectComponents(carto::VolumeRef< int16_t > &vol, const int32_t slices_number, const int32_t threshold_lowerbound, const int32_t threshold_upperbound)
std::vector< Component > openComponent(const std::vector< Component > &components, const int32_t component, carto::VolumeRef< int16_t > &vol)
std::vector< Component > separateComponent(const std::vector< Component > &components, const int32_t component, carto::VolumeRef< int16_t > &vol, const Direction dir)
void writeTestsWarnings(const Tests &t)
std::vector< int32_t > dimensionsizes
std::vector< int32_t > dimensionorders
carto::VolumeRef< int16_t > computeConnexComponent(carto::VolumeRef< int16_t > &vol)
float getVoxelLebesgue(const carto::VolumeRef< T > &vol)
std::vector< Component > sortComponent(std::vector< Component > &cpnt, std::vector< int32_t > dimensionsizes)
std::vector< Component > processOutlierComponent(std::vector< Component > &cpnt, carto::VolumeRef< int16_t > &vol, int32_t min_surface, int32_t slices_number, float fraction)
Maxima affectMaxima(int32_t iter, int32_t num, int32_t val, int32_t pos, int32_t extr)
std::vector< Component > processMedianConsistencyParameters(std::vector< Component > &cpnt, float variation, int32_t mid_window=0)
bool detectSlices(aims::Process &p, const std::string &, aims::Finder &)
void writeMaxima(std::vector< Maxima > &mxm)
void displayStatus(const Tests &t)
carto::VolumeRef< int16_t > applyNewLabelling(std::vector< Component > cpnt, carto::VolumeRef< int16_t > vol)
carto::VolumeRef< int16_t > extractFromVolume(const carto::VolumeRef< int16_t > &vol, const int32_t x, const int32_t X, const int32_t y, const int32_t Y, const int32_t old_label, const int32_t new_label)
bool writeNumberedSlices(int32_t dx, int32_t dy, int32_t res, float z, T background, std::vector< Component > &cpnt, carto::VolumeRef< T > &vol, std::string outputdir, std::string outputname, std::string format, uint8_t slicemin)
AimsRGBA background< AimsRGBA >(std::vector< Component > &cpnt, carto::VolumeRef< AimsRGBA > &vol)
bool removeComponentsInVolume(carto::VolumeRef< int16_t > &vol, const std::vector< Component > &to_remove)
std::vector< Component > getOutliersByWeight(const std::vector< Component > &cpnt, const int32_t slices_number)
std::vector< int32_t > getComponentLabels(const std::vector< Component > &cpnt)
bool compareComponentsByLabelM(const Component &c1, const Component &c2)
float computeHistogramRatio(const carto::VolumeRef< T > &vol, const int32_t bins)
ContinuityParameterTested
struct Component * ComponentPtr
std::vector< Component > changeComponentsIndex(std::vector< Component > &components, std::vector< int32_t > dimensionsizes, std::vector< int32_t > dimensionorders, int32_t offset=1, int32_t step=1)
carto::VolumeRef< int32_t > generateHistogram(const carto::VolumeRef< int16_t > &vol, const int32_t bins=MAX_HISTO)
void writeVectorInt32_t(std::vector< int32_t > &vect)
std::vector< Component > getOutliersBySurface(const std::vector< Component > &cpnt, const float min_surface)
bool isValid(const Tests &t)
carto::VolumeRef< int16_t > transposeVolume(carto::VolumeRef< int16_t > &vol)
AimsRGB background< AimsRGB >(std::vector< Component > &cpnt, carto::VolumeRef< AimsRGB > &vol)
void rescale(carto::VolumeRef< T > &in, carto::RescalerInfo &info)
std::vector< Component > insertComponent(std::vector< Component > cpnt, int32_t comp, std::vector< Component > cpnt2slices, int32_t l)
void displayComponentsStrategy(const std::vector< Component > &cpnt)
void writeComponents(std::vector< Component > &comp)
int32_t extractMaxima(std::vector< int32_t > vctr)
std::vector< Component > removeComponent(std::vector< Component > cpnt, int32_t l)
carto::VolumeRef< int16_t > applyThreshold(const carto::VolumeRef< int16_t > &vol, const int16_t threshold_lower_bound, const int16_t threshold_upper_bound, const int16_t new_value=MAX_INT16_T)
T background(std::vector< Component > &cpnt, carto::VolumeRef< T > &vol)
void writeAimsInt32_t(carto::VolumeRef< int32_t > &vol)
std::vector< AimsVector< int32_t, 3 > > updateVDM(std::vector< AimsVector< int32_t, 3 > > &vdm)
carto::VolumeRef< int32_t > projectData(carto::VolumeRef< int16_t > &X)
std::vector< Component >::iterator CompIterator
void writeAimsFloat(carto::VolumeRef< float > &vol)
void writeVector3int32_t(std::vector< AimsVector< int32_t, 3 > > &vect)
int32_t getDimensionCount(std::vector< int32_t > dimensionsizes)
Tests testComponents(const std::vector< Component > &cpnt, int32_t number_cpnt)
std::vector< Component > filterComponentsBySurface(const std::vector< Component > &cpnt, const float min_surface)
std::vector< Component > extractInformationFromComponent(const carto::VolumeRef< int16_t > &vol)
std::vector< Component > weightedRemoveComponents(std::vector< Component > &cpnt, int32_t slices_number)
std::vector< Component > separateComponent(std::vector< Component > &cpnt, int32_t comp, carto::VolumeRef< int16_t > vol, int32_t min_surface, Direction dir, float fraction)
std::vector< Component > removeComponents(const std::vector< Component > &cpnt, const std::vector< Component > &to_remove)
std::vector< Component > openingComponent(std::vector< Component > &cpnt, int32_t comp, carto::VolumeRef< int16_t > vol, float fraction)
void writeMaximaIter(std::vector< Maxima > &mxm, int32_t iter)
struct Maxima * MaximaPtr
int32_t getVoxelCount(const carto::VolumeRef< T > &vol, float value)
bool copyToVolume(const carto::VolumeRef< int16_t > &vol, carto::VolumeRef< int16_t > &destvol, const int32_t x, const int32_t X, const int32_t y, const int32_t Y, const int32_t old_label, const int32_t new_label)
std::vector< int32_t > extractVectorFromComponent(std::vector< Component > cpnt, ContinuityParameterTested param)
bool writeStackedSlices(int32_t dx, int32_t dy, int32_t res, float z, T background, std::vector< Component > &cpnt, carto::VolumeRef< T > &vol, std::string outputfile, std::string format)
std::vector< Maxima >::iterator MaxIterator
bool individStackSlices(aims::Process &p, const std::string &, aims::Finder &)
float diff_median_bounding_vt
int32_t test_median_surface
int32_t ref_median_bounding_hz
int32_t ref_median_surface
float diff_median_bounding_hz
int32_t test_median_bounding_vt
float diff_median_surface
int32_t ref_median_bounding_vt
int32_t test_median_bounding_hz
bool test_vertical_continuity
bool test_size_continuity
bool test_horizontal_continuity