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_osteoclasts.h
Go to the documentation of this file.
1 /************************************
2  * added: ??.??.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_OSTEOCLASTS_H
10 #define D_MAKRO_OSTEOCLASTS_H
11 
12 //own
13 #include <d_enum.h>
14 #include <d_error_handler.h>
15 #include <d_img_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_component.h>
21 #include <d_component_list.h>
23 #include <d_table.h>
24 
25 //Qt
26 #include <QMainWindow>
27 #include <QFileDialog>
28 #include <QFileInfo>
29 #include <QFileInfoList>
30 #include <QDir>
31 #include <QDateTime>
32 #include <QComboBox>
33 #include <QCloseEvent>
34 #include <QResizeEvent>
35 #include <QMouseEvent>
36 #include <QInputDialog>
37 
38 //Qt::Charts
39 #include <QChartView>
40 #include <QChart>
41 
42 //general
43 #include <iostream>
44 #include <sstream>
45 #include <fstream>
46 #include <vector>
47 #include <algorithm>
48 
49 //openCV
50 #include <opencv2/core/core.hpp>
51 #include <opencv2/highgui/highgui.hpp>
52 #include <opencv2/imgproc/imgproc.hpp>
53 
54 //namespaces
55 using namespace std;
56 //using namespace cv; (prohibited because of abigous names with qtdatavisualization)
57 #include <d_opencv_typedefs.h>
58 
59 namespace Ui {
61 }
62 
63 class D_MAKRO_Osteoclasts : public QMainWindow
64 {
65  Q_OBJECT
66 
67 public:
68  explicit D_MAKRO_Osteoclasts(D_Storage *pStorage, QWidget *parent = 0);
70 
71  void closeEvent(QCloseEvent *event);
72  void resizeEvent(QResizeEvent *event);
73  void mousePressEvent(QMouseEvent *event);
74  void set_ClosingPossible(bool closeable) {ClosingPossible = closeable;}
75 
76 private slots:
77 
78  void Update_Views();
79  void Update_View_Proc();
80 
81  void Update_Images();
82  void Update_Image_ProcView();
83  void Update_Image_ProcView_Visualize();
84  void Update_Image_ProcView_SegmentationAuto();
85  void Update_Image_ProcView_SegmentationManual();
86 
87  void Update_newViewport();
88 
89  void Update_NucleiSegmentation_Auto();
90  void Update_NucleiSegmentation_Auto_Steps(int start_step);
91 
92  void Populate_CB_Single(QComboBox *CB, QStringList QSL, int index_init = 0);
93  void Populate_CB_All_onStartUp();
94  void Populate_CB_All_onImgInit();
95  void Populate_CB_Stats();
96  void Populate_CB_AxeTrans();
97  void Populate_CB_Dimensions();
98  void Populate_CB_Draw();
99  void Populate_CB_ProcSteps();
100  void Populate_CB_Segmentations();
101 
102  void Images_NucleiSegmentation_Init();
103  void Images_VisVPin_init();
104 
105  void Load_Platelet();
106 
107  void Visualize_DataSet();
108 
109  void Segmentation_Next();
110 
111  void SegmentationManual_DIR_Init();
112  void SegmentationManual_Scan();
113  void SegmentationManual_Load(int seg_type);
114  void SegmentationManual_Init(int seg_type);
115  void SegmentationManual_Save(int seg_type);
116  void SegmentationManual_Reset();
117  void SegmentationManual_Backup();
118  void SegmentationManual_Undo();
119  void SegmentationManual_AdaptUi2BackupState();
120  void SegmentationManual_TriggerDraw(int x, int y);
121  void Segmentations_Combine();
122  void Segmentations_Combine(int seg_type);
123 
124  void Extrema_Init();
125  void Extrema_Viewport();
126  void Extrema_2ui();
127 
128  void VisVP_MouseMovedOnScene(int x, int y);
129 
130  void on_comboBox_Viewport_currentIndexChanged(int index);
131 
132 
133  void on_spinBox_SegAuto_Blur_Size_valueChanged(int arg1);
134 
135  void on_doubleSpinBox_SegAuto_Blur_Sigma_valueChanged(double arg1);
136 
137  void on_spinBox_SegAuto_Thres_Size_valueChanged(int arg1);
138 
139  void on_doubleSpinBox_SegAuto_Thres_Offset_valueChanged(double arg1);
140 
141  void on_doubleSpinBox_SegAuto_Distance_Thres_valueChanged(double arg1);
142 
143  void on_checkBox_SegAuto_Watershed_Bordered_stateChanged(int arg1);
144 
145  void on_checkBox_SegAuto_Watershed_nSeeded_stateChanged(int arg1);
146 
147  void on_spinBox_SegAuto_Area_Min_valueChanged(int arg1);
148 
149  void on_spinBox_SegAuto_Area_Max_valueChanged(int arg1);
150 
151  void on_doubleSpinBox_SegAuto_Roundness_Thres_valueChanged(double arg1);
152 
153  void on_comboBox_SegMan_SegmentationType_currentIndexChanged(int index);
154 
155  void on_comboBox_SegMan_Draw_Type_currentIndexChanged(int index);
156 
157 
158 private:
159  Ui::D_MAKRO_Osteoclasts *ui;
160  bool ClosingPossible = false;
161  const bool MessageOnFunctionStart = true;
162  const bool MessageOnBreakFromState = false;
163 
164  //Paths
165  QDir DIR_InputPlatelet;
166  QDir DIR_Segmentations;
167  QStringList QSL_Viewport_Path;
168  QString QS_PlateletName;
169  QFileInfoList FIL_Segmentations_current;
170  //bool segmentations_DirFil_init = false;
171  //bool segmentations_DirFil_scanned = false;
172 
173  //States
174  bool state_Startup = true;
175 
176  bool state_Platelet_New = true;
177  bool state_Platelet_Loaded = false;
178 
179  bool state_SegPath_Init = false;
180 
181  bool state_Viewport_New = true;
182  bool state_Viewport_Loaded = false;
183 
184  bool state_VisVP_Init = false;
185  bool state_VisVP_Updating = false;
186  bool state_VisVp_Done = false;
187 
188  bool state_SegAuto_Init = false;
189  bool state_SegAuto_Updating = false;
190  bool state_SegAuto_Done = false;
191 
192  bool state_SegMan_Init = false;
193  bool state_SegMan_Scanned = false;
194  bool state_SegMan_Combined = false;
195  bool state_SegMan_Draw_Active = false;
196  bool state_SegMan_Draw_NewLine = true;
197 
198 
199 
200  //Images
201 
202  //Original Data
203  vector<vector<vector<Mat>>> vvvMA_VpZCh_Stacks; //Base Data
204  //bool loaded_PlateletImages = false;
205 
206  //Visualizer
207  vector<Mat> vMA_Ch_VisVP_in; //used for displaying Viewport (color)
208  Mat MA_VisVP_3ch; //displayed visVP image
209  //bool proced_visVP = false;
210 
211  //Nuclei segmentation (auto)
212  vector<vector<Mat>> vvMA_VpStep_NucAutoSeg; //Automatic Nuclei Segmentation
213  //bool proced_NucSegAuto = false;
214 
215  //Segmnentations (manual)
216  vector<vector<Mat>> vvMA_VpSeg_Manual_Saved; //Saved Segmentations
217  vector<vector<Mat>> vvMA_VpSeg_Manual_Combined; //Displayed Combined
218  vector<vector<vector<Mat>>> vvvMA_VpSegStep_Manual_Backup; //Backups
219  vector<vector<unsigned int>> vvI_VpSeg_ActionsCount; //Draw Action Counter
220  vector<vector<unsigned int>> vvI_VpSeg_UndoCount; //Undo Counter
221  static const int c_SEG_MAN_BACKUPS = 10; //Max count of Backups
222 
223 
224 
225  //Ranges
226  vector<vector<vector<double>>> vvvd_ProjExtCh_Extrema;
227 
228  //Dimensions
229  QStringList QSL_Viewport_Names;
230  QStringList QSL_Depths;
231  int Dim_Viewports = 0;
232  int DIM_Depths = 0;
233  int VP_current = 0;
234 
235  //Drawing tool
236  Point PT_Draw_Last = Point(0, 0);
237  Point PT_Draw_Current = Point(0, 0);
238  //bool Draw_New_Line = true;
239 
240  //Storage
241  D_Storage *pStore;
242 
243  //Viewer
244  D_Viewer View_Proc;
245  D_Viewer View_Results;
246 
247  //Plot
248  QChartView *pChartView_Plot;
249 
250  //Table
251  D_Table Table_Results;
252 
253  //Error handler
254  D_Error_Handler ER;
255  void ERR(int err, QString func = "not specified", QString detail = "not specified");
256  void ERR_StatesCheck(QString func);
257 
258  //CONSTANTS
259 
260  enum ProcViews
261  {
262  c_PROC_VIEW_STACK,
263  c_PROC_VIEW_SEG_AUTO,
264  c_PROC_VIEW_SEG_MANUAL
265  };
266 
267  enum VisualizeParameters
268  {
269  c_VIS_PAR_DISPLAY,
270  c_VIS_PAR_PROJECT,
271  c_VIS_PAR_Z_LAYER,
272  c_VIS_PAR_RANGE_MIN,
273  c_VIS_PAR_RANGE_MAX,
274  c_VIS_PAR_GAMMA,
275  c_VIS_PAR_NUMBER_OF
276  };
277 
278  enum Projected
279  {
280  c_PROJ_SINGLE_IMAGES,
281  c_PROJ_CURRENT_PROJECTION,
282  c_PROJ_NUMBER_OF
283  };
284 
285  enum Extrema
286  {
287  c_EXTREMA_MIN,
288  c_EXTREMA_MAX,
289  c_EXTREMA_NUMBER_OF
290  };
291 
292  enum Channels
293  {
294  c_CH_B_DAPI,
295  c_CH_G_FACTIN,
296  c_CH_R_TRAP,
297  c_CH_NUMBER_OF
298  };
299  QStringList QSL_Channels =
300  {
301  "Dapi",
302  "F-Actin",
303  "Trap"
304  };
305 
306  enum Segmentations
307  {
308  c_SEG_CELLS,
309  c_SEG_ZONES,
310  c_SEG_NUCLEI,
311  c_SEG_NUMBER_OF
312  };
313  QStringList QSL_Segmentations =
314  {
315  "1_Cells",
316  "2_Zones",
317  "3_Nuclei"
318  };
319 
320  enum SegmentationsSave
321  {
322  c_SEG_SAVE_CELLS,
323  c_SEG_SAVE_ZONES,
324  c_SEG_SAVE_NUCLEI_FG,
325  c_SEG_SAVE_NUCLEI_BG,
326  c_SEG_SAVE_NUMBER_OF
327  };
328  QStringList QSL_SegmentationsSave =
329  {
330  "Cells",
331  "Zones",
332  "NucleiFG",
333  "NucleiBG"
334  };
335 
336  enum SegmentationColor
337  {
338  c_SEG_COLOR_FOREGROUND,
339  c_SEG_COLOR_BACKGROUND,
340  c_SEG_COLOR_NUMBER_OF
341  };
342  QStringList QSL_SegmentationColor =
343  {
344  "Pencil",
345  "Rubber"
346  };
347 
348  enum SegmentationPen
349  {
350  c_SEG_PEN_LINE,
351  c_SEG_PEN_FILL,
352  c_SEG_PEN_NUMBER_OF
353  };
354  QStringList QSL_SegmentationPen =
355  {
356  "Line",
357  "Floodfill"
358  };
359 
360  enum ProcSteps
361  {
362  c_STEP_PROJECT,
363  c_STEP_8BIT,
364  c_STEP_BLUR,
365  c_STEP_THRES,
366  c_STEP_DISTANCE,
367  c_STEP_SEEDS,
368  c_STEP_WATERSHED,
369  c_STEP_AREA,
370  c_STEP_ROUNDNESS,
371  c_STEP_OUTLINES,
372  c_STEP_CONTROL,
373  c_STEP_NUMBER_OF
374  };
375  QStringList QSL_ProcSteps =
376  {
377  "00 - Nuclei Projection",
378  "01 - Convert 8bit",
379  "02 - Blur",
380  "03 - Threshold",
381  "04 - Distance Transform",
382  "05 - Seeds",
383  "06 - Watershed Transform",
384  "07 - Area Filter",
385  "08 - Roundness Filter",
386  "09 - Outlines",
387  "10 - Control"
388  };
389 
390 
391 };
392 
393 #endif // D_MAKRO_OSTEOCLASTS_H
Mat
cv::Mat Mat
Definition: d_opencv_typedefs.h:28
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_Viewer::Update_View
void Update_View()
D_Viewer::Update_View Starts the workflow to show an image.
Definition: d_viewer.cpp:2096
D_Img_Proc::Draw_Line
static int Draw_Line(Mat *pMA_Target, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int thickness=1, double value=255)
Definition: d_img_proc.cpp:17134
d_component.h
D_Img_Proc::Math_ImgImg_Diff
static int Math_ImgImg_Diff(Mat *pMA_Out, Mat *pMA_In1, Mat *pMA_In2)
Definition: d_img_proc.cpp:13125
D_MAKRO_Osteoclasts::set_ClosingPossible
void set_ClosingPossible(bool closeable)
Definition: d_makro_osteoclasts.h:74
D_Img_Proc::Threshold_Adaptive
static int Threshold_Adaptive(Mat *pMA_Out, Mat *pMA_In, int out_mode, double max_val, int adapt_mode, unsigned int mask_size, double offset)
Definition: d_img_proc.cpp:6669
d_viewer.h
d_plot.h
D_Img_Proc::Math_ImgImg_AddWeighted
static int Math_ImgImg_AddWeighted(Mat *pMA_Out, Mat *pMA_In1, Mat *pMA_In2, double weight_1, double weight_2, double weight_sum)
Definition: d_img_proc.cpp:13107
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_value_distribution_list.h
D_Storage
The D_Storage class Used for storing data. There is only one instance in D_MainWindow .
Definition: d_storage.h:49
D_Img_Proc::Normalize
static int Normalize(Mat *pMA_Out, Mat *pMA_In, unsigned int norm, unsigned int type, double min, double max)
Definition: d_img_proc.cpp:3814
d_makro_osteoclasts.h
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_Img_Proc::Transformation_Distance
static int Transformation_Distance(Mat *pMA_Out, Mat *pMA_In, int metric, int precision)
Definition: d_img_proc.cpp:7486
c_GEO_OUTLINE
@ c_GEO_OUTLINE
Definition: d_enum.h:2053
D_MAKRO_Osteoclasts::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: d_makro_osteoclasts.cpp:107
Point
cv::Point Point
Definition: d_opencv_typedefs.h:35
c_FEAT_ROUNDNESS
@ c_FEAT_ROUNDNESS
Definition: d_enum.h:1322
d_img_proc.h
D_Table
The D_Table class Display tables in QTableWidget in the user interface.
Definition: d_table.h:42
D_Img_Proc::ValAtPix
static int ValAtPix(vector< double > *v_value, Mat *pMA_In, size_t x_pos, size_t y_pos)
Definition: d_img_proc.cpp:2192
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_Img_Proc::MinMax_of_Mat
static int MinMax_of_Mat(Mat *pMA_In, double *min_ext, double *max_ext)
Definition: d_img_proc.cpp:2052
Scalar
cv::Scalar Scalar
Definition: d_opencv_typedefs.h:30
D_MAKRO_Osteoclasts
Definition: d_makro_osteoclasts.h:64
D_Img_Proc::Transformation_Watershed_Auto
static int Transformation_Watershed_Auto(Mat *pMA_Out, Mat *pMA_In, Mat *pMA_Marker, bool include_not_seeded, bool conv_8bit, bool exclude_border)
Definition: d_img_proc.cpp:7573
D_Img_Proc::GammaSpread_1C
static int GammaSpread_1C(Mat *pMA_Out, Mat *pMA_In, double gamma, double in_min, double in_max, double out_min=0, double out_max=255, bool force_8bit=false)
Definition: d_img_proc.cpp:4649
D_Img_Proc::Math_ImgStack_Project
static int Math_ImgStack_Project(Mat *pMA_Out, vector< Mat > *pvMA_In, int stat=c_STAT_MEAN_ARITMETIC)
Definition: d_img_proc.cpp:13436
d_component_list.h
D_MAKRO_Osteoclasts::D_MAKRO_Osteoclasts
D_MAKRO_Osteoclasts(D_Storage *pStorage, QWidget *parent=0)
Definition: d_makro_osteoclasts.cpp:12
D_Viewer::set_GV
void set_GV(QGraphicsView *GV_ui)
Definition: d_viewer.cpp:49
D_Img_Proc::Floodfill
static int Floodfill(Mat *pMA_Out, Mat *pMA_In, unsigned int seed_x, unsigned int seed_y, double new_val)
Definition: d_img_proc.cpp:16690
Ui
Definition: d_analysiswindow.h:58
ER_other
@ ER_other
Definition: d_enum.h:134
D_MAKRO_Osteoclasts::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition: d_makro_osteoclasts.cpp:115
D_Img_Proc::Reduce_Outlines
static int Reduce_Outlines(Mat *pMA_Out, Mat *pMA_In, int neighborhood=8, int thickness=1)
Definition: d_img_proc.cpp:16469
d_storage.h
D_Img_Proc::Threshold_Absolute_1C
static int Threshold_Absolute_1C(Mat *pMA_Out, Mat *pMA_In, double thres_abs)
Definition: d_img_proc.cpp:6553
d_opencv_typedefs.h
QSL_StatList
const QStringList QSL_StatList
Definition: d_enum.h:797
D_Img_Proc::Convert_Mat_to_QImage
static int Convert_Mat_to_QImage(QImage *pQI_Out, Mat *pMA_In, bool use_custom_range_for_spread_non_8bit=false, double in_min=0, double in_max=1)
Definition: d_img_proc.cpp:973
d_enum.h
D_MAKRO_Osteoclasts::~D_MAKRO_Osteoclasts
~D_MAKRO_Osteoclasts()
Definition: d_makro_osteoclasts.cpp:85
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_error_handler.h
D_Img_Proc::Math_ImgImg_Add
static int Math_ImgImg_Add(Mat *pMA_Out, Mat *pMA_In1, Mat *pMA_In2)
Definition: d_img_proc.cpp:13092
D_Img_Proc::Merge
static int Merge(Mat *pMA_Out, Mat *pMA_In0, Mat *pMA_In1, Mat *pMA_In2, Mat *pMA_In3, unsigned int channels, bool channel_use[4])
Definition: d_img_proc.cpp:4060
BORDER_DEFAULT
const int BORDER_DEFAULT
Definition: d_opencv_typedefs.h:78
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_Storage::dir_M_Osteoclasts
QDir * dir_M_Osteoclasts()
Definition: d_storage.h:81
D_Storage::set_dir_M_Osteoclasts
void set_dir_M_Osteoclasts(QString path)
Definition: d_storage.h:109
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
D_Img_Proc::Draw_Boundaries
static int Draw_Boundaries(Mat *pMA_Target, int width=1, int val=255)
Definition: d_img_proc.cpp:18238
D_MAKRO_Osteoclasts::closeEvent
void closeEvent(QCloseEvent *event)
Definition: d_makro_osteoclasts.cpp:91