Skip to content

Commit 6b22df3

Browse files
committed
fixing merge conflict adding new files
2 parents 848a1ab + 37bc1f7 commit 6b22df3

File tree

2 files changed

+84
-68
lines changed

2 files changed

+84
-68
lines changed

src/algorithm/APRConverter.hpp

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
template<typename ImageType>
2323
class APRConverter: public LocalIntensityScale, public ComputeGradient, public LocalParticleCellSet, public PullingScheme {
2424

25-
2625
public:
2726
APRParameters par;
2827
APRTimer fine_grained_timer;
@@ -57,31 +56,18 @@ class APRConverter: public LocalIntensityScale, public ComputeGradient, public L
5756
//pointer to the APR structure so member functions can have access if they need
5857
const APR<ImageType> *apr;
5958

60-
MeshData<ImageType> image_temp; // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image)
61-
MeshData<ImageType> grad_temp; // should be a down-sampled image
62-
MeshData<float> local_scale_temp; // Used as down-sampled images for some averaging steps where it is useful to not lose precision, or get over-flow errors
63-
MeshData<float> local_scale_temp2; // Used as down-sampled images for some averaging steps where it is useful to not lose precision, or get over-flow errors
64-
65-
//assuming uint16, the total memory cost shoudl be approximately (1 + 1 + 1/8 + 2/8 + 2/8) = 2 5/8 original image size in u16bit
66-
//storage of the particle cell tree for computing the pulling scheme
67-
6859
template<typename T>
69-
void init_apr(APR<ImageType>& aAPR,MeshData<T>& input_image);
60+
void init_apr(APR<ImageType>& aAPR, MeshData<T>& input_image);
7061

7162
template<typename T>
72-
void auto_parameters(const MeshData<T>& input_img);
63+
void auto_parameters(const MeshData<T> &input_img);
7364

7465
template<typename T>
7566
bool get_apr_method_from_file(APR<ImageType> &aAPR, const TiffUtils::TiffInfo &aTiffFile);
7667

77-
template<typename T,typename S>
78-
void get_gradient(const MeshData<T>& input_img,MeshData<S>& gradient, float bspline_offset);
79-
80-
template<typename T,typename S>
81-
void get_local_intensity_scale(const MeshData<T>& input_img,MeshData<S>& local_intensity_scale);
82-
83-
template<typename T,typename S>
84-
void get_local_particle_cell_set(MeshData<T>& grad_image_ds,MeshData<S>& local_intensity_scale_ds);
68+
void get_gradient(MeshData<ImageType> &image_temp, MeshData<ImageType> &grad_temp, MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2, float bspline_offset);
69+
void get_local_intensity_scale(MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2);
70+
void get_local_particle_cell_set(MeshData<ImageType> &grad_temp, MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2);
8571
};
8672

8773

@@ -116,6 +102,13 @@ bool APRConverter<ImageType>::get_apr_method(APR<ImageType> &aAPR, MeshData<T>&
116102
/// Memory allocation of variables
117103
////////////////////////////////////////
118104

105+
//assuming uint16, the total memory cost shoudl be approximately (1 + 1 + 1/8 + 2/8 + 2/8) = 2 5/8 original image size in u16bit
106+
//storage of the particle cell tree for computing the pulling scheme
107+
MeshData<ImageType> image_temp; // global image variable useful for passing between methods, or re-using memory (should be the only full sized copy of the image)
108+
MeshData<ImageType> grad_temp; // should be a down-sampled image
109+
MeshData<float> local_scale_temp; // Used as down-sampled images for some averaging steps where it is useful to not lose precision, or get over-flow errors
110+
MeshData<float> local_scale_temp2;
111+
119112
allocation_timer.start_timer("init and copy image");
120113
image_temp.init(input_image);
121114
grad_temp.initDownsampled(input_image.y_num, input_image.x_num, input_image.z_num, 0);
@@ -131,7 +124,7 @@ bool APRConverter<ImageType>::get_apr_method(APR<ImageType> &aAPR, MeshData<T>&
131124

132125
fine_grained_timer.start_timer("offset image");
133126
//offset image by factor (this is required if there are zero areas in the background with uint16_t and uint8_t images, as the Bspline co-efficients otherwise may be negative!)
134-
// Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set this->image_type = "", i.e. uncomment the following line)
127+
// Warning both of these could result in over-flow (if your image is non zero, with a 'buffer' and has intensities up to uint16_t maximum value then set image_type = "", i.e. uncomment the following line)
135128
float bspline_offset = 0;
136129
if(std::is_same<uint16_t, ImageType>::value){
137130
bspline_offset = 100;
@@ -142,25 +135,22 @@ bool APRConverter<ImageType>::get_apr_method(APR<ImageType> &aAPR, MeshData<T>&
142135
} else {
143136
image_temp.copyFromMesh(input_image);
144137
}
145-
146138
fine_grained_timer.stop_timer();
147139

148140
method_timer.start_timer("compute_gradient_magnitude_using_bsplines");
149-
MeshData<T> gradient;
150-
this->get_gradient(input_image,gradient,bspline_offset); //note in the current pipeline don't actually use these variables, but here for interface (Use shared member allocated above variables)
141+
get_gradient(image_temp, grad_temp, local_scale_temp, local_scale_temp2, bspline_offset);
151142
method_timer.stop_timer();
152143

153-
MeshData<T> local_scale;
154144
method_timer.start_timer("compute_local_intensity_scale");
155-
this->get_local_intensity_scale(input_image,local_scale); //note in the current pipeline don't actually use these variables, but here for interface (Use shared member allocated above variables)
145+
get_local_intensity_scale(local_scale_temp, local_scale_temp2);
156146
method_timer.stop_timer();
157147

158148
method_timer.start_timer("initialize_particle_cell_tree");
159149
initialize_particle_cell_tree(aAPR);
160150
method_timer.stop_timer();
161151

162152
method_timer.start_timer("compute_local_particle_set");
163-
this->get_local_particle_cell_set(local_scale,gradient); //note in the current pipeline don't actually use these variables, but here for interface (Use shared member allocated above variables)
153+
get_local_particle_cell_set(grad_temp, local_scale_temp, local_scale_temp2);
164154
method_timer.stop_timer();
165155

166156
method_timer.start_timer("compute_pulling_scheme");
@@ -190,8 +180,8 @@ bool APRConverter<ImageType>::get_apr_method(APR<ImageType> &aAPR, MeshData<T>&
190180
return true;
191181
}
192182

193-
template<typename ImageType> template<typename T,typename S>
194-
void APRConverter<ImageType>::get_local_particle_cell_set(MeshData<T>& grad_image_ds,MeshData<S>& local_intensity_scale_ds) {
183+
template<typename ImageType>
184+
void APRConverter<ImageType>::get_local_particle_cell_set(MeshData<ImageType> &grad_temp, MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2) {
195185
//
196186
// Computes the Local Particle Cell Set from a down-sampled local intensity scale (\sigma) and gradient magnitude
197187
//
@@ -208,15 +198,15 @@ void APRConverter<ImageType>::get_local_particle_cell_set(MeshData<T>& grad_imag
208198
}
209199
fine_grained_timer.stop_timer();
210200

211-
float min_dim = std::min(this->par.dy,std::min(this->par.dx,this->par.dz));
201+
float min_dim = std::min(par.dy,std::min(par.dx,par.dz));
212202
float level_factor = pow(2,(*apr).level_max())*min_dim;
213203

214204
int l_max = (*apr).level_max() - 1;
215205
int l_min = (*apr).level_min();
216206

217207
fine_grained_timer.start_timer("compute_level_second");
218208
//incorporate other factors and compute the level of the Particle Cell, effectively construct LPC L_n
219-
compute_level_for_array(local_scale_temp,level_factor,this->par.rel_error);
209+
compute_level_for_array(local_scale_temp,level_factor,par.rel_error);
220210
fill(l_max,local_scale_temp);
221211
fine_grained_timer.stop_timer();
222212

@@ -235,8 +225,8 @@ void APRConverter<ImageType>::get_local_particle_cell_set(MeshData<T>& grad_imag
235225
fine_grained_timer.stop_timer();
236226
}
237227

238-
template<typename ImageType> template<typename T,typename S>
239-
void APRConverter<ImageType>::get_gradient(const MeshData<T>& input_img,MeshData<S>& gradient, float bspline_offset){
228+
template<typename ImageType>
229+
void APRConverter<ImageType>::get_gradient(MeshData<ImageType> &image_temp, MeshData<ImageType> &grad_temp, MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2, float bspline_offset) {
240230
//
241231
// Bevan Cheeseman 2018
242232
//
@@ -251,7 +241,7 @@ void APRConverter<ImageType>::get_gradient(const MeshData<T>& input_img,MeshData
251241

252242
fine_grained_timer.start_timer("smooth_bspline");
253243
if(par.lambda > 0) {
254-
get_smooth_bspline_3D(image_temp, this->par);
244+
get_smooth_bspline_3D(image_temp, par);
255245
}
256246
fine_grained_timer.stop_timer();
257247

@@ -279,8 +269,8 @@ void APRConverter<ImageType>::get_gradient(const MeshData<T>& input_img,MeshData
279269

280270
fine_grained_timer.start_timer("load_and_apply_mask");
281271
// Apply mask if given
282-
if(this->par.mask_file != ""){
283-
mask_gradient(grad_temp,local_scale_temp2,image_temp, this->par);
272+
if(par.mask_file != ""){
273+
mask_gradient(grad_temp,local_scale_temp2,image_temp, par);
284274
}
285275
fine_grained_timer.stop_timer();
286276

@@ -289,8 +279,8 @@ void APRConverter<ImageType>::get_gradient(const MeshData<T>& input_img,MeshData
289279
fine_grained_timer.stop_timer();
290280
}
291281

292-
template<typename ImageType> template<typename T,typename S>
293-
void APRConverter<ImageType>::get_local_intensity_scale(const MeshData<T>& input_img,MeshData<S>& local_intensity_scale){
282+
template<typename ImageType>
283+
void APRConverter<ImageType>::get_local_intensity_scale(MeshData<float> &local_scale_temp, MeshData<float> &local_scale_temp2) {
294284
//
295285
// Calculate the Local Intensity Scale (You could replace this method with your own)
296286
//
@@ -306,7 +296,7 @@ void APRConverter<ImageType>::get_local_intensity_scale(const MeshData<T>& input
306296

307297
float var_rescale;
308298
std::vector<int> var_win;
309-
get_window(var_rescale,var_win,this->par);
299+
get_window(var_rescale,var_win,par);
310300

311301
size_t win_y = var_win[0];
312302
size_t win_x = var_win[1];
@@ -334,7 +324,7 @@ void APRConverter<ImageType>::get_local_intensity_scale(const MeshData<T>& input
334324
calc_sat_mean_y(local_scale_temp,win_y2);
335325
calc_sat_mean_x(local_scale_temp,win_x2);
336326
calc_sat_mean_z(local_scale_temp,win_z2);
337-
rescale_var_and_threshold( local_scale_temp, var_rescale,this->par);
327+
rescale_var_and_threshold( local_scale_temp, var_rescale,par);
338328
fine_grained_timer.stop_timer();
339329
}
340330

@@ -360,7 +350,6 @@ void APRConverter<ImageType>::init_apr(APR<ImageType>& aAPR,MeshData<T>& input_i
360350
aAPR.apr_access.level_max = levelMax;
361351
}
362352

363-
364353
template<typename ImageType> template<typename T>
365354
void APRConverter<ImageType>::auto_parameters(const MeshData<T>& input_img){
366355
//
@@ -563,22 +552,22 @@ void APRConverter<ImageType>::auto_parameters(const MeshData<T>& input_img){
563552
//
564553
if((proportion_flat > 1.0f) && (proportion_next > 0.00001f)){
565554
std::cout << "AUTOPARAMTERS:**Warning** Detected that there is likely noisy background, instead assuming background subtracted and minimum signal of 5 (absolute), if this is not the case please set parameters manually" << std::endl;
566-
this->par.Ip_th = 1;
567-
this->par.sigma_th = 5;
568-
this->par.lambda = 0.5;
569-
this->par.sigma_th_max = 2;
570-
this->par.rel_error = 0.125;
571-
this->par.min_signal = 5;
572-
this->par.SNR_min = 1;
555+
par.Ip_th = 1;
556+
par.sigma_th = 5;
557+
par.lambda = 0.5;
558+
par.sigma_th_max = 2;
559+
par.rel_error = 0.125;
560+
par.min_signal = 5;
561+
par.SNR_min = 1;
573562
} else {
574563
std::cout << "AUTOPARAMTERS: **Assuming image has atleast 5% dark background" << std::endl;
575564
}
576565

577566

578567
float min_snr = 6;
579568

580-
if(this->par.SNR_min > 0){
581-
min_snr = this->par.SNR_min;
569+
if(par.SNR_min > 0){
570+
min_snr = par.SNR_min;
582571
} else {
583572
std::cout << "**Assuming a minimum SNR of 6" << std::endl;
584573
}
@@ -588,37 +577,37 @@ void APRConverter<ImageType>::auto_parameters(const MeshData<T>& input_img){
588577

589578
float var_th_max = sd*min_snr*.5f;
590579

591-
if(this->par.Ip_th < 0 ){
592-
this->par.Ip_th = Ip_th;
580+
if(par.Ip_th < 0 ){
581+
par.Ip_th = Ip_th;
593582
}
594583

595-
if(this->par.lambda < 0){
596-
this->par.lambda = 3.0;
584+
if(par.lambda < 0){
585+
par.lambda = 3.0;
597586
}
598587

599-
this->par.background_intensity_estimate = estimated_first_mode;
588+
par.background_intensity_estimate = estimated_first_mode;
600589

601-
if(this->par.min_signal < 0) {
602-
this->par.sigma_th = var_th;
603-
this->par.sigma_th_max = var_th_max;
604-
} else if (this->par.sigma_th > 0){
590+
if(par.min_signal < 0) {
591+
par.sigma_th = var_th;
592+
par.sigma_th_max = var_th_max;
593+
} else if (par.sigma_th > 0){
605594
//keep the defaults
606595
} else{
607-
this->par.sigma_th_max = this->par.min_signal*0.5f;
608-
this->par.sigma_th = this->par.min_signal;
596+
par.sigma_th_max = par.min_signal*0.5f;
597+
par.sigma_th = par.min_signal;
609598
}
610599

611-
if(this->par.lambda < 0.05){
612-
this->par.lambda = 0;
600+
if(par.lambda < 0.05){
601+
par.lambda = 0;
613602
std::cout << "setting lambda to zero" << std::endl;
614603
}
615604

616605

617-
std::cout << "I_th: " << this->par.Ip_th << std::endl;
618-
std::cout << "sigma_th: " << this->par.sigma_th << std::endl;
619-
std::cout << "sigma_th_max: " << this->par.sigma_th_max << std::endl;
620-
std::cout << "relative error (E): " << this->par.rel_error << std::endl;
621-
std::cout << "lambda: " << this->par.lambda << std::endl;
606+
std::cout << "I_th: " << par.Ip_th << std::endl;
607+
std::cout << "sigma_th: " << par.sigma_th << std::endl;
608+
std::cout << "sigma_th_max: " << par.sigma_th_max << std::endl;
609+
std::cout << "relative error (E): " << par.rel_error << std::endl;
610+
std::cout << "lambda: " << par.lambda << std::endl;
622611
}
623612

624613

src/data_structures/Mesh/MeshData.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ public :
176176
return mesh[idx];
177177
}
178178

179+
/**
180+
* access element at provided indices without boundary checking
181+
* @param y
182+
* @param x
183+
* @param z
184+
* @return element @(y, x, z)
185+
*/
186+
const T& at(size_t y, size_t x, size_t z) const {
187+
size_t idx = z * x_num * y_num + x * y_num + y;
188+
return mesh[idx];
189+
}
190+
179191
/**
180192
* Copies data from aInputMesh utilizing parallel copy, requires prior initialization
181193
* of 'this' object (size and number of elements)
@@ -224,7 +236,6 @@ public :
224236
mesh.set(array, size);
225237

226238
// Fill values of new buffer in parallel
227-
// TODO: set dynamically number of threads
228239
#ifdef HAVE_OPENMP
229240
#pragma omp parallel
230241
{
@@ -357,6 +368,22 @@ public :
357368
return outputStr.str();
358369
}
359370

371+
/**
372+
* Prints X-Y planes of mesh (for debug/test purposses - use only on small meshes)
373+
*/
374+
void printMesh() const {
375+
for (size_t z = 0; z < z_num; ++z) {
376+
std::cout << "z=" << z << "\n";
377+
for (size_t y = 0; y < y_num; ++y) {
378+
for (size_t x = 0; x < x_num; ++x) {
379+
std::cout << at(y, x, z) << " ";
380+
}
381+
std::cout << "\n";
382+
}
383+
std::cout << std::endl;
384+
}
385+
}
386+
360387
friend std::ostream & operator<<(std::ostream &os, const MeshData<T> &obj) {
361388
os << "MeshData: size(Y/X/Z)=" << obj.y_num << "/" << obj.x_num << "/" << obj.z_num << " vSize:" << obj.mesh.size() << " vCapacity:" << obj.mesh.capacity() << " elementSize:" << sizeof(T);
362389
return os;

0 commit comments

Comments
 (0)