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_manuelsegmentation.h
Go to the documentation of this file.
1 /************************************
2  * added: 20.01.2020 *
3  * author: David Eilenstein *
4  * contact: D.Eilenstein@gsi.de *
5  * project: ImageD *
6  * facility: GSI Darmstadt, Ger *
7  ************************************/
8 
9 #ifndef D_MAKRO_MANUELSEGMENTATION_H
10 #define D_MAKRO_MANUELSEGMENTATION_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 <qplaintextedit.h>
35 #include <QColorDialog>
36 
37 //Qt::Charts
38 #include <QChartView>
39 #include <QChart>
40 
41 //general
42 #include <iostream>
43 #include <sstream>
44 #include <fstream>
45 #include <vector>
46 #include <algorithm>
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_ManuelSegmentation : public QMainWindow
63 {
64  Q_OBJECT
65 
66 public:
67  explicit D_MAKRO_ManuelSegmentation(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 Data_Load();
76  void Data_Clear();
77  void Data_Next();
78  void Data_Previous();
79 
80  void Data_CalcContainers_Init();
81 
82  void LoadMode_Calib();
83 
84  void Save_Analysis();
85 
86  void Update_Ui();
87 
88  void Update_Views();
89  void Update_Images();
90  void Update_Image_Draw();
91  void Update_Image_Seg();
92 
93  void Update_SB_DrawInfo();
94 
95  void Update_ImgProc_All();
96  void Update_ImgProc(int step_start);
97  void Update_ImgProc_Step(int step);
98 
99  void Update_Calc_All();
100  void Update_Calc_Current_Feats();
101  void Update_Calc_Current_Stats();
102  void Update_Calc_Pool();
103  void Update_Calc_All_Stats();
104  void Update_Calc_Selections();
105 
106  void Draw_RecieveClickLeft(int x, int y);
107  void Draw_RecieveClickRight(int x, int y);
108  void Draw_ConsecutiveLine_FG();
109  void Draw_ConsecutiveLine_BG();
110  void Draw_Floodfill();
111  void Draw_Reset();
112  void Draw_Undo();
113  void Draw_FillHoles();
114  void Draw_BackupCreate();
115  void Draw_WriteFile();
116 
117  void Update_Results();
118  void Update_Table_Current_Feat();
119  void Update_Table_Current_Stat();
120  void Update_Table_All_Feat();
121  void Update_Table_All_Stat();
122 
123  void Populate_CB_Single(QComboBox *CB, QStringList QSL, int index_init);
124  void Populate_CB_Start();
125 
126  void ShowList(QPlainTextEdit *text_edit, QStringList QSL_ParentList, vector<int> *vSelection);
127  void Edit_FeatsOfInterest();
128  void Edit_StatsOfInterest();
129 
130  void Draw_Set_Tool_LineForeground();
131  void Draw_Set_Tool_LineBackground();
132  void Draw_Set_Tool_FillFlood();
133 
134 
135  bool Scale_GetFromFile();
136  void Scale_WriteToFile();
137  void Scale_SetToDefault();
138  void Scale_ToUi();
139  void Scale_UpdateFactor();
140  void Scale_UpdateFactor_Recalculate();
141 
142  void Overlay_Set_Color();
143 
144  void on_doubleSpinBox_Intensity_Overlay_valueChanged(double arg1);
145  void on_doubleSpinBox_Intensity_Backgrouond_valueChanged(double arg1);
146 
147  void on_spinBox_Scale_Px_valueChanged(int arg1);
148  void on_doubleSpinBox_Scale_CutomUnit_valueChanged(double arg1);
149  void on_lineEdit_Scale_CustomUnit_textChanged(const QString &arg1);
150 
151 private:
152  Ui::D_MAKRO_ManuelSegmentation *ui;
153  bool ClosingPossible = false;
154 
155  //Storage
156  D_Storage *pStore;
157 
158  //Load Mode
159  int LoadMode_Current = LOAD_GRAY;
160  vector<int> vLoadMode_PagesOfInterest_Indices = {0};
161  vector<Mat> vLoadMode_PagesOfInterest;
162  vector<QColor> vLoadMode_Colors;
163  vector<int> vLoadMode_Colors_R;
164  vector<int> vLoadMode_Colors_G;
165  vector<int> vLoadMode_Colors_B;
166  vector<int> vLoadMode_Colors_A;
167  D_VisDat_Obj VD_LoadAny;
168  D_VisDat_Obj VD_LoadAny_8bit;
169 
170  //Path
171  QFileInfoList FIL_Images;
172  QFileInfoList FIL_DrawFiles;
173  QFileInfoList FIL_Param;
174  QStringList QSL_Images_Names;
175  QStringList QSL_Images_Paths;
176  QStringList QSL_Images_Suffix;
177  QDir DIR_SaveMaster;
178 
179  //Images
180  vector<Mat> vMA_ProcSteps;
181 
182  //Drawing
183  int Draw_ActiveTool = DRAW_TOOL_LINE_FG;
184  QColor Draw_OverlayColor = Qt::green;
185  vector<Point> Draw_vPoints;
186  int Draw_RememberedClicks = 0;
187  Mat Draw_MA_Backup;
188 
189  //Scaling
190  int ScaleInit_Calib_Px = 1000;
191  double ScaleInit_Calib_CustomUnit = 200;
192  double ScaleInit_Factor = 0.04;
193  QString Scale_CustomUnit = "um";
194  vector<int> Scale_vCalib_Px;
195  vector<double> Scale_vCalib_CustomUnit;
196  vector<double> Scale_vFactor;
197 
198  //Measurement selections
199  vector<int> v_FeatsOfInterest = {c_FEAT_AREA, FEAT_CUSTOM_AREA_SCALED};
201  QStringList QSL_FeatsOfInterest;
202  QStringList QSL_StatsOfInterest;
203  QStringList QSL_FeatsMaster = QSL_FeatureList;//appended in constructor
204  QString QS_AreaScaled = "Area in um";
205 
206  //Measurement
207  vector<vector<double>> vv_FeatComp_Current;
208  vector<vector<double>> vv_FeatStat_Current;
209  vector<int> v_ImgAnalysed;
210  vector<vector<vector<double>>> vvv_ImgFeatComp_All;
211  vector<vector<vector<double>>> vvv_ImgFeatStat_All;
212  vector<vector<double>> vv_FeatComp_All;
213  vector<vector<double>> vv_FeatStat_All;
214  vector<vector<double>> vv_FeatComp_Current_Selection;
215  vector<vector<double>> vv_FeatStat_Current_Selection;
216  vector<vector<double>> vv_FeatComp_All_Selection;
217  vector<vector<double>> vv_FeatStat_All_Selection;
218 
219  //Viewers
220  D_Viewer View_Draw;
221  D_Viewer View_Segments;
222 
223  //statusbar
224  QLabel *pL_SB_DrawInfo_HowTo;
225  QLabel *pL_SB_DrawInfo_Selected;
226 
227  //Tables
228  D_Table Table_Current_Feats;
229  D_Table Table_Current_Stats;
230  D_Table Table_All_Feats;
231  D_Table Table_All_Stats;
232 
233  //states
234  bool state_LoadMode_Pages_Calibrated = false;
235  bool state_Images_Loaded = false;
236  bool state_CalcContainers_CorrectSize = false;
237  bool state_Current_ImgProc_Done = false;
238  bool state_Current_Calc_Done = false;
239  bool state_All_Calc_Done = false;
240  bool state_Selections_Calc = false;
241 
242  //error handling
243  D_Error_Handler ER;
244  void ERR(int err, QString func = "no specified", QString detail = "no specified");
245 
246  //CONSTANTS
247  static const int Draw_ClickMemoryCount = 5;
248 
249  enum PARAM {
250  PARAM_SCALE_PX,
251  PARAM_SCALE_CUSTOM_UNIT,
252  PARAM_NUMBER_OF
253  };
254  const QStringList QSL_Param = {
255  "ScalePx",
256  "ScaleCustomUnit"
257  };
258 
259  enum FEAT_CUSTOM {
260  FEAT_CUSTOM_AREA_SCALED = c_FEAT_NUMBER_OF_FEATS,
261  FEAT_CUSTOM_NUMBER_OF
262  };
263 
264  enum LOAD_MODE_COLOR {
265  LOAD_GRAY,
266  LOAD_COLOR,
267  LOAD_PAGES_GRAY,
268  LOAD_PAGES_COLOR,
269  LOAD_NUMBER_OF
270  };
271  const QStringList QSL_LoadModeColor = {
272  "Grayscale Image",
273  "Color Image",
274  "Multipaged Grayscale Image",
275  "Multipaged Color Image"
276  };
277 
278  enum PROC_STEPS {
279  STEP_LOAD,
280  STEP_CONVERT_COLOR,
281  STEP_DRAW_BINARY,
282  STEP_DRAW_EDGES,
283  STEP_DRAW_OVERLAY,
284  STEP_LABELING,
285  STEP_SEGMENTATION_NUMBERS,
286  STEP_NUMBER_OF
287  };
288  const QStringList QSL_ProcSteps = {
289  "Load Image",
290  "Convert to Color",
291  "Draw Binary",
292  "Draw Edges",
293  "Draw Overlay",
294  "Labeling",
295  "Segmentation Numbers"
296  };
297 
298  enum DRAW_TOOL {
299  DRAW_TOOL_LINE_FG,
300  DRAW_TOOL_LINE_BG,
301  DRAW_TOOL_FLOODFILL,
302  DRAW_TOOL_NUMBER_OF
303  };
304  const QStringList QSL_DrawTool = {
305  "Consecutive Foreground Line",
306  "Consecutive Background Line",
307  "Floodfill"
308  };
309 
310  enum RESULTS {
311  RES_GRAPHIC_SEG,
312  RES_TAB_CUR_FEAT,
313  RES_TAB_CUR_STAT,
314  RES_TAB_ALL_FEAT,
315  RES_TAB_ALL_STAT,
316  RES_NUMBER_OF
317  };
318  const QStringList QSL_Results = {
319  "Segmentation",
320  "Current Features",
321  "Current Statistics",
322  "All Features",
323  "All Statistics"
324  };
325 };
326 
327 #endif // D_MAKRO_MANUELSEGMENTATION_H
Mat
cv::Mat Mat
Definition: d_opencv_typedefs.h:28
D_Img_Proc::Type_of_Mat
static QString Type_of_Mat(Mat *pMA_In)
Definition: d_img_proc.cpp:363
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_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
c_DIM_X
@ c_DIM_X
Definition: d_enum.h:235
d_viewer.h
d_plot.h
D_VisDat_Proc::Create_VD_SinglePaged
static int Create_VD_SinglePaged(D_VisDat_Obj *pVD_New, QString QS_Path, int DimPage=c_DIM_P, int DimImgX=c_DIM_X, int DimImgY=c_DIM_Y)
Definition: d_visdat_proc.cpp:1485
D_MAKRO_ManuelSegmentation::set_ClosingPossible
void set_ClosingPossible(bool closeable)
Definition: d_makro_manuelsegmentation.h:72
D_Viewer
The D_Viewer class Display images (Mat) in QGraphicsView in the user interface.
Definition: d_viewer.h:58
D_VisDat_Proc::Copy
static int Copy(D_VisDat_Obj *pVD_Out, D_VisDat_Obj *pVD_In)
Definition: d_visdat_proc.cpp:3406
D_Storage
The D_Storage class Used for storing data. There is only one instance in D_MainWindow .
Definition: d_storage.h:49
c_DIM_Y
@ c_DIM_Y
Definition: d_enum.h:236
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_VisDat_Proc::Read_2D_Plane
static int Read_2D_Plane(Mat *pMA_Out, D_VisDat_Obj *pVD_In, D_VisDat_Slice_2D InPlane)
Definition: d_visdat_proc.cpp:2946
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_makro_manuelsegmentation.h
D_MAKRO_ManuelSegmentation::closeEvent
void closeEvent(QCloseEvent *event)
Definition: d_makro_manuelsegmentation.cpp:109
D_Table::set_TW
void set_TW(QTableWidget *TW)
Definition: d_table.cpp:16
D_Error_Handler::ERR
void ERR(int err, QString sender, QString func, QString detail)
D_Error_Handler::ERR pops an error message if an error occured and/or streams it to a csv file.
Definition: d_error_handler.cpp:23
QSL_FeatureList
const QStringList QSL_FeatureList
Definition: d_enum.h:1457
c_STAT_SEM_ABS_SAMPLE
@ c_STAT_SEM_ABS_SAMPLE
Definition: d_enum.h:790
D_VisDat_Obj
The D_VisDat_Obj class Represents a 6D image.
Definition: d_visdat_obj.h:51
D_Img_Proc::Duplicate
static int Duplicate(Mat *pMA_Out, Mat *pMA_In)
Definition: d_img_proc.cpp:2397
D_Img_Proc::Draw_Label_Numbers
static int Draw_Label_Numbers(Mat *pMA_Out, Mat *pMA_In, Mat *pMA_Label, double scale, double thickness, bool center)
Definition: d_img_proc.cpp:19012
Point
cv::Point Point
Definition: d_opencv_typedefs.h:35
D_VisDat_Obj::pMA_full
Mat * pMA_full()
Definition: d_visdat_obj.h:61
D_Img_Proc::OverlayOverwrite
static int OverlayOverwrite(Mat *pMA_Out, Mat *pMA_In, Mat *pMA_Overlay, double intensity_overlay=1.0, double intensity_backgr=1.0)
Definition: d_img_proc.cpp:19556
D_Storage::dir_M_ManualSegmentation
QDir * dir_M_ManualSegmentation()
Definition: d_storage.h:86
D_VisDat_Dim::size_P
int size_P()
Definition: d_visdat_dim.h:64
D_Img_Proc::Load_From_Path_Gray
static int Load_From_Path_Gray(Mat *pMA_Out, QFileInfo FI_path)
Definition: d_img_proc.cpp:51
D_Table
The D_Table class Display tables in QTableWidget in the user interface.
Definition: d_table.h:42
D_MAKRO_ManuelSegmentation::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: d_makro_manuelsegmentation.cpp:123
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
ER_channel_bad
@ ER_channel_bad
Definition: d_enum.h:144
D_MAKRO_ManuelSegmentation::~D_MAKRO_ManuelSegmentation
~D_MAKRO_ManuelSegmentation()
Definition: d_makro_manuelsegmentation.cpp:104
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
Scalar
cv::Scalar Scalar
Definition: d_opencv_typedefs.h:30
c_STAT_SUM
@ c_STAT_SUM
Definition: d_enum.h:737
D_VisDat_Slice_2D
The D_VisDat_Slice_2D class Represents a 2D slice through a D_VisDat_Obj.
Definition: d_visdat_slice_2d.h:18
D_Storage::get_VD
D_VisDat_Obj get_VD(size_t pos)
Definition: d_storage.h:56
d_popup_listedit.h
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
D_MAKRO_ManuelSegmentation::D_MAKRO_ManuelSegmentation
D_MAKRO_ManuelSegmentation(D_Storage *pStorage, QWidget *parent=0)
Definition: d_makro_manuelsegmentation.cpp:12
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
c_DIM_P
@ c_DIM_P
Definition: d_enum.h:240
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
c_STAT_STAN_DEV_SAMPLE
@ c_STAT_STAN_DEV_SAMPLE
Definition: d_enum.h:751
D_Img_Proc::Math_ImgImg_BitOr
static int Math_ImgImg_BitOr(Mat *pMA_Out, Mat *pMA_In1, Mat *pMA_In2)
Definition: d_img_proc.cpp:13202
d_opencv_typedefs.h
D_VisDat_Obj::pDim
D_VisDat_Dim * pDim()
Definition: d_visdat_obj.h:73
D_Img_Proc::Convert_Color
static int Convert_Color(Mat *pMA_Out, Mat *pMA_In, int cvt_mode)
Definition: d_img_proc.cpp:2524
QSL_StatList
const QStringList QSL_StatList
Definition: d_enum.h:797
d_enum.h
c_STAT_NUMBER_OF_STATS
@ c_STAT_NUMBER_OF_STATS
Definition: d_enum.h:795
D_Viewer::Save_Image
QString Save_Image()
D_Viewer::Save_Image Saves the image at FI_LastSaved.
Definition: d_viewer.cpp:2157
d_error_handler.h
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
D_Storage::get_Adress
Mat * get_Adress(size_t pos)
Definition: d_storage.h:54
D_Storage::set_dir_M_ManualSegmentation
void set_dir_M_ManualSegmentation(QString path)
Definition: d_storage.h:114
D_MAKRO_ManuelSegmentation
Definition: d_makro_manuelsegmentation.h:63
D_VisDat_Proc::Normalize
static int Normalize(D_VisDat_Obj *pVD_Out, D_VisDat_Obj *pVD_In, int norm, int type, double min, double max)
Definition: d_visdat_proc.cpp:4647
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
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