ImageD  v2_7_5 (24.06.22)
ImageD is an image processing software designed for rapid prototyping and implementing algorithms and solutions for science, research and teaching.
d_makro_cerebralorganoids.h
Go to the documentation of this file.
1 /************************************
2  * added: 13.11.2019 *
3  * author: David Eilenstein *
4  * contact: D.Eilenstein@gsi.de *
5  * project: ImageD *
6  * facility: GSI Darmstadt, Ger *
7  ************************************/
8 
9 #ifndef D_MAKRO_CEREBRALORGANOIDS_H
10 #define D_MAKRO_CEREBRALORGANOIDS_H
11 
12 //own
13 #include <d_enum.h>
14 #include <d_error_handler.h>
15 #include <d_visdat_proc.h>
16 #include <d_plot.h>
17 #include <d_stat.h>
18 #include <d_viewer.h>
19 #include <d_storage.h>
20 #include <d_table.h>
21 #include <d_popup_listedit.h>
22 
23 //Qt
24 #include <QMainWindow>
25 #include <QFileDialog>
26 #include <QFileInfo>
27 #include <QFileInfoList>
28 #include <QDir>
29 #include <QDateTime>
30 #include <QComboBox>
31 #include <QCloseEvent>
32 #include <QResizeEvent>
33 #include <QInputDialog>
34 #include <QLabel>
35 
36 //Qt::Charts
37 #include <QChartView>
38 #include <QChart>
39 
40 //general
41 #include <iostream>
42 #include <sstream>
43 #include <fstream>
44 #include <vector>
45 #include <algorithm>
46 #include <math.h>
47 
48 //openCV
49 #include <opencv2/core/core.hpp>
50 #include <opencv2/highgui/highgui.hpp>
51 #include <opencv2/imgproc/imgproc.hpp>
52 
53 //namespaces
54 using namespace std;
55 //using namespace cv; (prohibited because of abigous names with qtdatavisualization)
56 #include <d_opencv_typedefs.h>
57 
58 namespace Ui {
60 }
61 
62 class D_MAKRO_CerebralOrganoids : public QMainWindow
63 {
64  Q_OBJECT
65 
66 public:
67  explicit D_MAKRO_CerebralOrganoids(D_Storage *pStorage, QWidget *parent = 0);
69 
70  void closeEvent(QCloseEvent *event);
71  void resizeEvent(QResizeEvent *event);
72  void set_ClosingPossible(bool closeable) {ClosingPossible = closeable;}
73 
74 private slots:
75  void Populate_CB_Single(QComboBox *CB, QStringList QSL, int index_init = 0);
76  void Populate_CB_Init();
77  bool Populate_CB_LoadExp();
78 
79  void Load_Exp();
80 
81  void UpdateViews();
82  void UpdateView_Proc();
83  void UpdateView_Vis();
84  void UpdateImages();
85  void UpdateImage_Proc();
86  void UpdateImage_Vis();
87 
88  void UpdateUi();
89 
90  void UpdateProc_Stack();
91 
92  void UpdateImgProc(int step_start);
93  void UpdateImgProc_Step(int step);
94 
95  bool Calc_Single_All();
96  bool Calc_Single_Feats();
97  bool Calc_Single_Stats();
98 
99  void Calc_Stack_All();
100  void Calc_Stack_TD_Comps();
101  void Calc_Stack_Flask_Stats();
102  void Calc_Stack_TD_Stats();
103 
104  void UpdateResults();
105  void UpdateResults_Visualization();
106  void UpdateResults_Flask();
107  void UpdateResults_TD();
108  void UpdateResults_Exp();
109  void UpdateTable_Flask_Comp();
110  void UpdateTable_Flask_Stat();
111  void UpdateTable_TD_Comp();
112  void UpdateTable_TD_Stat();
113  void UpdatePlot_Exp_Stat_Line();
114  void UpdatePlot_Exp_Stat_Line_Errors();
115 
116  void Save_Image(D_Viewer *pViewer, QString name_default);
117  void Save_Plot(QChartView *pCV_Save, QString name_default);
118  void Save_Table(D_Table *pTable, QString name_default);
119  void Save_Image_Processing();
120  void Save_Image_Visualization();
121  void Save_Table_Flask();
122  void Save_Table_TD();
123  void Save_Plot_Experiment();
124 
125  bool Save_Analysis_DoAgainQuestion();
126  void Save_Analysis();
127  void Save_Analysis_Save();
128  void Save_Analysis_Update();
129 
130 
131 
132  void Update_SettingsMM();
133 
134  void on_comboBox_Data_Time_currentIndexChanged(int index);
135  void on_comboBox_Data_Dose_currentIndexChanged(int index);
136  void on_comboBox_Data_Flask_currentIndexChanged(int index);
137 
138  void on_doubleSpinBox_ProcSet_PixelSize_valueChanged(double arg1);
139 
140  void on_spinBox_ProcSet_BlurSize_valueChanged(int arg1);
141 
142  void on_doubleSpinBox_ProcSet_BlurSigma_valueChanged(double arg1);
143 
144  void on_spinBox_ProcSet_ColorSelect_H_Min_valueChanged(int arg1);
145 
146  void on_spinBox_ProcSet_ColorSelect_H_Max_valueChanged(int arg1);
147 
148  void on_spinBox_ProcSet_ColorSelect_S_Min_valueChanged(int arg1);
149 
150  void on_spinBox_ProcSet_ColorSelect_S_Max_valueChanged(int arg1);
151 
152  void on_spinBox_ProcSet_ColorSelect_V_Min_valueChanged(int arg1);
153 
154  void on_spinBox_ProcSet_ColorSelect_V_Max_valueChanged(int arg1);
155 
156  void on_spinBox_ProcSet_ClosingSize_valueChanged(int arg1);
157 
158  void on_spinBox_ProcSet_OpeningSize_valueChanged(int arg1);
159 
160  void on_doubleSpinBox_ProcSet_SelectArea_Min_valueChanged(double arg1);
161 
162  void on_doubleSpinBox_ProcSet_SelectArea_Max_valueChanged(double arg1);
163 
164  void on_doubleSpinBox_ProcSet_SelectRoundness_Min_valueChanged(double arg1);
165 
166  void on_doubleSpinBox_ProcSet_SelectRoundness_Max_valueChanged(double arg1);
167 
168  void on_tabWidget_Results_currentChanged(int index);
169 
170  void on_comboBox_ResFlask_Mode_currentIndexChanged(int index);
171 
172  void on_comboBox_ResTD_Mode_currentIndexChanged(int index);
173 
174  void on_comboBox_ResExp_Mode_currentIndexChanged(int index);
175 
176  void on_doubleSpinBox_ProcSet_Thresh_valueChanged(double arg1);
177 
178  void on_spinBox_ProcSet_ROI_Close_valueChanged(int arg1);
179 
180  void on_spinBox_ProcSet_ROI_Open_valueChanged(int arg1);
181 
182  void on_spinBox_ProcSet_ROI_Area_valueChanged(int arg1);
183 
184  void on_spinBox_ProcSet_ROI_Dilate_valueChanged(int arg1);
185 
186 private:
187  Ui::D_MAKRO_CerebralOrganoids *ui;
188  bool ClosingPossible = false;
189 
190  //Storage
191  D_Storage *pStore;
192 
193  //Viewer
194  D_Viewer ViewProc;
195  D_Viewer ViewRes;
196 
197  //Table
198  D_Table Table_Flask;
199  D_Table Table_TD;
200 
201 
202  //Plot
203  QChartView *pChartView;
204 
205  //Files and Paths
206  //Experiment
207  QString QS_ExpName;
208  QDir DIR_Experiment;
209  //Time
210  vector<QDir> vDIR_Times;
211  QStringList QSL_Times;
212  vector<double> vVAL_Times;
213  //Dose
214  vector<vector<QDir>> vvDIR_Dose;
215  vector<QStringList> vQSL_Dose;
216  vector<vector<double>> vvVAL_Dose;
217  //Flask
218  vector<vector<vector<QFileInfo>>> vvvFI_Flask;
219  vector<vector<QStringList>> vvQSL_Flask;
220  //Reference
221  QFileInfo FIL_Reference;
222 
223  //Save
224  QDir DIR_Save_Main;
225  QDir DIR_Save_Images;
226  QDir DIR_Save_Tables;
227  QDir DIR_Save_Plots;
228  ofstream OS_comps;
229  vector<vector<ofstream>> vvOS_stats;
230  vector<int> vFeatsOfInterest = {FEAT_CUSTOM_AREA_MM, c_FEAT_AREA, c_FEAT_ROUNDNESS};
231  vector<int> vStatsOfInterest_Line = {c_STAT_MEAN_ARITMETIC};
232  vector<int> vStatsOfInterest_Errors = {c_STAT_STAN_DEV_TOTAL, c_STAT_SEM_ABS_TOTAL};
233  vector<int> vStatsOfInterest_All = {c_STAT_MEAN_ARITMETIC, c_STAT_STAN_DEV_TOTAL, c_STAT_SEM_ABS_TOTAL};
234 
235  //Style
236  QString StyleDefault;
237 
238 
239  //states
240  bool state_exp_loaded = false;
241  bool state_img_loaded_current = false;
242  bool state_img_proc_up2date_current = false;
243  bool state_stack_analysed = false;
244  bool state_stack_processing = false;
245  bool state_calced_stack = false;
246  bool state_calced_stack_comps = false;
247  bool state_calced_stack_stats = false;
248  bool state_calced_current = false;
249  bool state_calced_current_feats = false;
250  bool state_calced_current_stats = false;
251 
252  //Data
253  vector<vector<double>> vvFeatComp_current;
254  vector<vector<double>> vvFeatStat_current;
255  vector<vector<vector<vector<vector<double>>>>> vvvvvTimeDoseFlaskFeatComp;
256  vector<vector<vector<vector<vector<double>>>>> vvvvvTimeDoseFlaskFeatStat;
257  vector<vector<vector<vector<double>>>> vvvvTimeDoseFeatComp;
258  vector<vector<vector<vector<double>>>> vvvvTimeDoseFeatStat;
259 
260  //pixel size
261  double px_scale;//mm
262 
263  //Img Proc
264  vector<Mat> vMA_ProcSteps;
265  vector<vector<int>> vvProcSteps_up2date;
266 
267  //Visualization
268  Mat MA_Vis;
269 
270  //mouse hover pixel value display
271  QLabel *pL_SB_PxVal;
272 
273  //Error handler
274  D_Error_Handler ER;
275  void ERR(int err, QString func = "not specified", QString detail = "not specified");
276 
277  //CONSTANTS
278  enum PROC_STEP {
279  STEP_LOAD,
280  STEP_BLUR,
281  STEP_COLOR_HSV,
282  STEP_COLOR_HUE,
283  STEP_COLOR_SAT,
284  STEP_COLOR_VAL,
285  STEP_COLOR_GRAB,
286  STEP_OBJ_CLOSING,
287  STEP_OBJ_OPENING,
288  STEP_OBJ_SELECT_AREA,
289  STEP_OBJ_SELECT_ROUNDNESS,
290  STEP_GRAY,
291  STEP_ROI_THRES,
292  STEP_ROI_CLOSING,
293  STEP_ROI_OPENING,
294  STEP_ROI_AREA,
295  STEP_ROI_DILATION,
296  STEP_ROI_CONVEX_HULL,
297  STEP_OBJECTS_ACCEPTED,
298  STEP_NUMBER_OF
299  };
300  const QStringList QSL_ProcStep = {
301  "00 Load",
302  "01 Blur",
303  "02 Color HSV",
304  "03 Color Hue",
305  "04 Color Saturation",
306  "05 Color Value",
307  "06 Color Grab",
308  "07 Objects Closing",
309  "08 Objects Opening",
310  "09 Objects Select by Area",
311  "10 Objects Select by Roundness",
312  "11 Gray",
313  "12 Roi Binary",
314  "13 Roi Closing",
315  "14 Roi Opening",
316  "15 Roi Area",
317  "16 Roi Margin",
318  "17 Roi Convex Hull",
319  "18 Objects Accepted",
320  };
321 
322  enum FEAT_CUSTOM {
323  FEAT_CUSTOM_AREA_MM = c_FEAT_NUMBER_OF_FEATS,
324  FEAT_CUSTOM_NUMBER_OF
325  };
326  const QStringList QSL_FeatCustom = {
327  "Area(mm^2)"
328  };
329  QStringList QSL_FeatAll;
330 
331 
332  enum RES_TYPE {
333  RES_VIS,
334  RES_FLASK,
335  RES_TD,
336  RES_EXP,
337  RES_NUMBER_OF
338  };
339 
340  enum RES_TYPE_FLASK {
341  RES_TYPE_FLASK_COMP,
342  RES_TYPE_FLASK_STAT,
343  RES_TYPE_FLASK_NUMBER_OF
344  };
345  const QStringList QSL_ResType_Flask = {
346  "Features of Components in Flask",
347  "Statistics of Features in Components in Flask"
348  };
349 
350  enum RES_TYPE_TD {
351  RES_TYPE_TD_COMP,
352  RES_TYPE_TD_STAT,
353  RES_TYPE_TD_NUMBER_OF
354  };
355  const QStringList QSL_ResType_TD = {
356  "Features of Components at Time and Dose",
357  "Statistics of Features in Components at Time and Dose"
358  };
359 
360  enum RES_TYPE_EXP {
361  RES_TYPE_EXP_STATS_LINE_ERR,
362  RES_TYPE_EXP_STATS_LINE,
363  RES_TYPE_EXP_NUMBER_OF
364  };
365  const QStringList QSL_ResType_Exp = {
366  "Statistics of Features vs Time and Dose with Errors",
367  "Statistics of Features vs Time and Dose"
368  };
369 };
370 
371 #endif // D_MAKRO_CEREBRALORGANOIDS_H
Mat
cv::Mat Mat
Definition: d_opencv_typedefs.h:28
D_MAKRO_CerebralOrganoids::closeEvent
void closeEvent(QCloseEvent *event)
Definition: d_makro_cerebralorganoids.cpp:94
ER_okay
@ ER_okay
Definition: d_enum.h:133
D_Img_Proc::Fill_Holes
static int Fill_Holes(Mat *pMA_Out, Mat *pMA_In)
Definition: d_img_proc.cpp:12257
D_Popup_ListEdit
The D_Popup_ListEdit class Lets the user choose any number of entries from a QStringList
Definition: d_popup_listedit.h:37
D_MAKRO_CerebralOrganoids::~D_MAKRO_CerebralOrganoids
~D_MAKRO_CerebralOrganoids()
Definition: d_makro_cerebralorganoids.cpp:89
D_Viewer::Update_View
void Update_View()
D_Viewer::Update_View Starts the workflow to show an image.
Definition: d_viewer.cpp:2096
c_STAT_SEM_ABS_TOTAL
@ c_STAT_SEM_ABS_TOTAL
Definition: d_enum.h:789
QSl_AlphabetAll
const QStringList QSl_AlphabetAll
Definition: d_enum.h:2263
D_Component_List::size
size_t size()
Definition: d_component_list.h:94
d_viewer.h
d_plot.h
D_Img_Proc::Feature_Select
static int Feature_Select(Mat *pMA_Out, Mat *pMA_In, int feature, double f_min, double f_max, int connectivity=4)
Definition: d_img_proc.cpp:15710
D_Img_Proc::Load_From_Path
static int Load_From_Path(Mat *pMA_Out, QFileInfo FI_path)
Definition: d_img_proc.cpp:16
D_Viewer
The D_Viewer class Display images (Mat) in QGraphicsView in the user interface.
Definition: d_viewer.h:58
D_Storage
The D_Storage class Used for storing data. There is only one instance in D_MainWindow .
Definition: d_storage.h:49
D_Table::set_data_d_2D_qsl_count
void set_data_d_2D_qsl_count(vector< vector< double >> vv_data, QStringList qsl_col_names)
Definition: d_table.cpp:98
D_Viewer::Update_Image
void Update_Image(Mat *MA_new)
D_Viewer::Update_Image Set and show image.
Definition: d_viewer.cpp:2079
d_table.h
D_Table::Save_Table
QString Save_Table()
Definition: d_table.cpp:186
D_Img_Proc::Labeling
static int Labeling(Mat *pMA_Out, Mat *pMA_In, int connectivity, int out_depth)
Definition: d_img_proc.cpp:12350
D_Table::set_TW
void set_TW(QTableWidget *TW)
Definition: d_table.cpp:16
D_Storage::set_dir_M_CerebralOrganoids
void set_dir_M_CerebralOrganoids(QString path)
Definition: d_storage.h:113
QSL_FeatureList
const QStringList QSL_FeatureList
Definition: d_enum.h:1457
D_Viewer::Save_Image_Dialog
QString Save_Image_Dialog()
D_Viewer::Save_Image_Dialog Opens a dialog to save the show image (generated default path)
Definition: d_viewer.cpp:2105
MORPH_CLOSE
const int MORPH_CLOSE
Definition: d_opencv_typedefs.h:92
D_Img_Proc::Mask
static int Mask(Mat *pMA_Out, Mat *pMA_In, Mat *pMA_Mask)
Definition: d_img_proc.cpp:14098
c_FEAT_ROUNDNESS
@ c_FEAT_ROUNDNESS
Definition: d_enum.h:1322
c_STAT_STAN_DEV_TOTAL
@ c_STAT_STAN_DEV_TOTAL
Definition: d_enum.h:750
MORPH_RECT
const int MORPH_RECT
Definition: d_opencv_typedefs.h:86
D_Table
The D_Table class Display tables in QTableWidget in the user interface.
Definition: d_table.h:42
D_Img_Proc::Draw_Label_Numbers_LUT
static int Draw_Label_Numbers_LUT(Mat *pMA_Out, Mat *pMA_In, Mat *pMA_Label, vector< double > v_LUT, bool border, double scale, double thickness, bool center, int precision, uchar r=0, uchar g=0, uchar b=0)
Definition: d_img_proc.cpp:18727
D_Error_Handler
The D_Error_Handler class takes error codes from D_ERROR_ENUM and shows a popup if an error occures.
Definition: d_error_handler.h:38
D_Img_Proc::Split
static int Split(Mat *pMA_Out, Mat *pMA_In, unsigned int channel)
Definition: d_img_proc.cpp:4007
D_Plot::Plot_Line_XY_Multi
static int Plot_Line_XY_Multi(QChartView *pChartView, vector< vector< double >> vv_XY_Data, QString name_title, QString name_series, QString name_x, QString name_y, int x_trans=c_AXE_TRANS_LIN, int y_trans=c_AXE_TRANS_LIN, bool dots_visible=false, bool heat_color=false, bool heat_color_AllColors=false, Qt::Alignment legend_pos=Qt::AlignTop)
D_Table::set_data_d_2D_qsl_qsl
void set_data_d_2D_qsl_qsl(vector< vector< double >> vv_data, QStringList qsl_col_names, QStringList qsl_row_names)
Definition: d_table.cpp:74
MORPH_OPEN
const int MORPH_OPEN
Definition: d_opencv_typedefs.h:91
D_Storage::dir_M_CerebralOrganoids
QDir * dir_M_CerebralOrganoids()
Definition: d_storage.h:85
MORPH_DILATE
const int MORPH_DILATE
Definition: d_opencv_typedefs.h:88
c_FEAT_LABEL
@ c_FEAT_LABEL
Definition: d_enum.h:1314
D_Img_Proc::Color_Grab
static int Color_Grab(Mat *pMA_Out, Mat *pMA_In, int color_space, int out_mode, vector< uchar > min, vector< uchar > max)
Definition: d_img_proc.cpp:6950
D_MAKRO_CerebralOrganoids::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: d_makro_cerebralorganoids.cpp:108
d_popup_listedit.h
D_Viewer::set_GV
void set_GV(QGraphicsView *GV_ui)
Definition: d_viewer.cpp:49
D_Component_List::set_Mat
int set_Mat(Mat *pMA_BinaryOrLabel, int connectivity=8)
Definition: d_component_list.cpp:22
Ui
Definition: d_analysiswindow.h:58
D_Img_Proc::Morphology_Elemental
static int Morphology_Elemental(Mat *pMA_Out, Mat *pMA_In, int morph_type, int elem_type, unsigned int elem_size_X, unsigned int elem_size_Y, int border_type, unsigned int iterations)
Definition: d_img_proc.cpp:7041
D_Component_List
The D_Component_List class is a list of D_Component representing the blobs in a binary image.
Definition: d_component_list.h:46
D_MAKRO_CerebralOrganoids::set_ClosingPossible
void set_ClosingPossible(bool closeable)
Definition: d_makro_cerebralorganoids.h:72
d_storage.h
c_COL2MONO_GRAY
@ c_COL2MONO_GRAY
Definition: d_enum.h:651
MORPH_ELLIPSE
const int MORPH_ELLIPSE
Definition: d_opencv_typedefs.h:87
c_GEO_CONVEX_HULL
@ c_GEO_CONVEX_HULL
Definition: d_enum.h:2054
d_opencv_typedefs.h
D_MAKRO_CerebralOrganoids::D_MAKRO_CerebralOrganoids
D_MAKRO_CerebralOrganoids(D_Storage *pStorage, QWidget *parent=0)
Definition: d_makro_cerebralorganoids.cpp:12
D_Img_Proc::Convert_Color
static int Convert_Color(Mat *pMA_Out, Mat *pMA_In, int cvt_mode)
Definition: d_img_proc.cpp:2524
D_Viewer::connect_Zoom
void connect_Zoom(D_Viewer *viewer)
Definition: d_viewer.cpp:128
QSL_StatList
const QStringList QSL_StatList
Definition: d_enum.h:797
d_enum.h
D_Component_List::get_Feature
double get_Feature(int comp, int feat)
Definition: d_component_list.h:60
D_Img_Proc::Reduce_Geometric
static int Reduce_Geometric(Mat *pMA_Out, Mat *pMA_In, int geometric, int connectivity=8, int thickness=1, uchar value=255)
Definition: d_img_proc.cpp:16215
D_Viewer::Save_Image
QString Save_Image()
D_Viewer::Save_Image Saves the image at FI_LastSaved.
Definition: d_viewer.cpp:2157
D_MAKRO_CerebralOrganoids
Definition: d_makro_cerebralorganoids.h:63
d_error_handler.h
D_Img_Proc::Math_Add
static int Math_Add(Mat *pMA_Out, Mat *pMA_In1, double summand)
Definition: d_img_proc.cpp:12364
BORDER_DEFAULT
const int BORDER_DEFAULT
Definition: d_opencv_typedefs.h:78
D_Table::Save_Table_Dialog
QString Save_Table_Dialog()
Definition: d_table.cpp:158
D_Storage::get_Adress
Mat * get_Adress(size_t pos)
Definition: d_storage.h:54
D_Img_Proc::Filter_Gauss
static int Filter_Gauss(Mat *pMA_Out, Mat *pMA_In, int size_x, int size_y, int border, double sigma_x, double sigma_y)
Definition: d_img_proc.cpp:9083
d_makro_cerebralorganoids.h
D_Img_Proc::Convert_Color_RGBA
static int Convert_Color_RGBA(Mat *pMA_Out, Mat *pMA_In, double r, double g, double b, double a, double range_rgba=255.0)
Definition: d_img_proc.cpp:2552
D_Img_Proc::Convert_Color2Mono
static int Convert_Color2Mono(Mat *pMA_Out, Mat *pMA_In, int col2mono_code)
Definition: d_img_proc.cpp:2662
d_visdat_proc.h
D_Stat::Calc_Stats
static int Calc_Stats(vector< double > *v_stats, vector< double > v_data, bool calc_sorted)
Definition: d_stat.cpp:16
c_FEAT_NUMBER_OF_FEATS
@ c_FEAT_NUMBER_OF_FEATS
Definition: d_enum.h:1455
D_Img_Proc::Threshold_Absolute
static int Threshold_Absolute(Mat *pMA_Out, Mat *pMA_In, double thres_abs)
Definition: d_img_proc.cpp:6440
c_FEAT_AREA
@ c_FEAT_AREA
Definition: d_enum.h:1347
c_STAT_MEAN_ARITMETIC
@ c_STAT_MEAN_ARITMETIC
Definition: d_enum.h:740
d_stat.h