-
Notifications
You must be signed in to change notification settings - Fork 7
/
mainwindow.h
217 lines (165 loc) · 8.47 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*#-------------------------------------------------
#
# OpenCV Superpixels Segmentation
#
# by AbsurdePhoton - www.absurdephoton.fr
#
# v2.3 - 2019/07/08
#
#-------------------------------------------------*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <iostream>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include <opencv2/ximgproc.hpp>
#include "opencv2/opencv.hpp"
#include "opencv2/core/utility.hpp"
#include <QMainWindow>
#include <QFileDialog>
#include <QButtonGroup>
#include <QListWidgetItem>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
private slots:
//// GUI
void InitializeValues(); // well named !
void on_button_whats_this_clicked(); // What's this function
//// quit
void on_button_quit_clicked();
//// Tabs
void on_Tabs_currentChanged(int); // tabs handling
//// labels
int GetCurrentLabelNumber(); // label value for use with label_mask
QListWidgetItem *AddNewLabel(QString newLabel); // add new label - empty string creates a "rename me!" label
void on_pushButton_label_delete_clicked(); // delete label
void DeleteAllLabels(bool newLabel); // delete ALL labels and create one new if wanted
void UnselectAllLabels(); // unselect all items in list
void on_listWidget_labels_currentItemChanged(QListWidgetItem *currentItem); // show current label color when item change
void on_listWidget_labels_itemChanged(QListWidgetItem *currentItem); // show current label name used
void on_pushButton_label_add_clicked(); // add one default label
void on_pushButton_label_hide_clicked(); // set label color to 0 => transparent
void on_pushButton_label_draw_clicked(); // special mode where a new cell can be drawn
void on_pushButton_label_join_clicked(); // join two or more labels
void on_pushButton_draw_clear_clicked(); // clear the cell drawing mask
void on_pushButton_draw_grabcut_clicked(); // use GrabCut in cell drawing mode
void on_pushButton_draw_grabcut_iteration_clicked(); // repeat GrabCut in cell drawing mode
cv::Vec3b DrawColor(); // return drawing color in cell drawing mode
//// image export
void on_pushButton_psd_clicked(); // export to PSD Photoshop image
void on_pushButton_tif_clicked(); // export to TIFF image
void SavePSDorTIF(std::string type); // save image in PSD or TIFF format with background = image and layers = labels
//// load & save
void SaveDirBaseFile(); // just to keep the last open dir
void on_button_image_clicked(); // load image
void on_button_save_session_clicked(); // save and load session
void on_button_load_session_clicked();
void on_button_save_conf_clicked(); // save and load configuration
void on_button_load_conf_clicked();
//// Undo
void SaveUndo(); // save current masks for undo
void on_button_undo_clicked(); // undo the last action
void on_checkBox_mask_clicked(); // toggle mask view
void on_checkBox_image_clicked(); // toggle image view
void on_checkBox_grid_clicked(); // toggle grid view
void on_checkBox_selection_clicked(); // toggle selection view
void on_checkBox_holes_clicked(); // toggle holes view
void on_horizontalSlider_blend_image_valueChanged(); // image transparency
void on_horizontalSlider_blend_mask_valueChanged(); // mask transparency
void on_horizontalSlider_blend_grid_valueChanged(); // grid transparency
void on_pushButton_zoom_minus_clicked(); // levels of zoom
void on_pushButton_zoom_plus_clicked();
void on_pushButton_zoom_fit_clicked();
void on_pushButton_zoom_100_clicked();
void on_comboBox_grid_color_currentIndexChanged(int); // change grid color
void on_comboBox_algorithm_currentIndexChanged(int); // hide and reveal algorithms parameters
void on_horizontalScrollBar_segmentation_valueChanged(); // scroll the viewport
void on_verticalScrollBar_segmentation_valueChanged();
void ShowCurrentColor(int red, int green, int blue); // set and show color for current label
void on_pushButton_color_pick_clicked(); // pick custom color for current label
void on_pushButton_color_red_clicked(); // choose color for current label
void on_pushButton_color_green_clicked();
void on_pushButton_color_blue_clicked();
void on_pushButton_color_cyan_clicked();
void on_pushButton_color_magenta_clicked();
void on_pushButton_color_yellow_clicked();
void on_pushButton_color_orange_clicked();
void on_pushButton_color_brown_clicked();
void on_pushButton_color_olive_clicked();
void on_pushButton_color_navy_clicked();
void on_pushButton_color_emerald_clicked();
void on_pushButton_color_purple_clicked();
void on_pushButton_color_lime_clicked();
void on_pushButton_color_rose_clicked();
void on_pushButton_color_violet_clicked();
void on_pushButton_color_azure_clicked();
void on_pushButton_color_malibu_clicked();
void on_pushButton_color_laurel_clicked();
//// Image tab
void on_button_apply_clicked(); // apply corrections and filters on main image
void on_button_original_clicked(); // revert to original image
//// Segmentation tab
void on_button_compute_clicked(); // compute segmentation mask and grid
//// Keyboard & mouse events
void keyPressEvent(QKeyEvent *keyEvent); // for the create cell mode and move with <SPACE>
void keyReleaseEvent(QKeyEvent *keyEvent);
void mouseReleaseEvent(QMouseEvent *eventRelease); // when the mouse button is released
void mousePressEvent(QMouseEvent *eventPress); // mouse events = zoom, set cell color etc
void mouseMoveEvent(QMouseEvent *eventPress);
void wheelEvent(QWheelEvent *wheelEvent);
private:
// the UI object, to access the UI elements created with Qt Designer
Ui::MainWindow *ui;
//// Display
void ShowSegmentation(); // display image in viewport with grid and mask
void DisplayThumbnail(); // display thumbnail view
void WhichCell(int posX, int posY); // find and display which cell has been clicked
void ZoomPlus(); // zoom in
void ZoomMinus(); // zoom out
void ShowZoomValue(); // display current zoom level
void SetViewportXY(int x, int y); // change the origin of the viewport
void UpdateViewportDimensions(); // calculate width and height of the viewport
cv::Point Viewport2Image(cv::Point p); // calculate coordinates in the image from the viewport
//// superpixels
cv::Ptr<cv::ximgproc::SuperpixelSLIC> slic; // SLIC Segmentation pointer
cv::Ptr<cv::ximgproc::SuperpixelLSC> lsc; // LSC Segmentation pointer
cv::Ptr<cv::ximgproc::SuperpixelSEEDS> seeds; // SEEDS Segmentation pointer
//// masks & display
cv::Mat labels, labels_mask, undo_labels; // Segmentation cells and labels
int maxLabels; // max number of labels
int nb_cells; // number of labels in segmentation
cv::Mat image, image_backup, // main image
thumbnail, // thumbnail of main image
mask, undo_mask, // painted cells
grid, // grid mask
selection, // selection mask
draw_cell_mask_save, draw_cell_labels_mask_save, draw_cell_labels_save, draw_cell_grid_save, mask_line_save, // used by cell paint
grabcut_mask, grabcut_background, grabcut_foreground; // for GrabCut
cv::Mat disp_color; // Processed image display with mask and grid
cv::Rect viewport; // part of the segmentation image to display
cv::Vec3b color, gridColor; // current colors used
//// files
std::string basefile, basedir, basedirinifile; // main image filename: directory and filename without extension
//// mouse
Qt::MouseButton mouseButton; // save mouse button value when holding down a mouse button
QPoint mouse_origin; // save the mouse position when holding down a mouse button
cv::Point pos_save; // save the mouse position in image coordinates
//// zoom
int num_zooms = 22; // number of zoom values
double zooms[23] = {0, 0.05, 0.0625, 0.0833, 0.125, 0.1667, 0.25, 0.3333, 0.5, 0.6667, // reduced view
1, 1.25, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10000}; // zoomed view
double zoom, oldZoom; // zoom factor for image display
QString zoom_type; // if zoom changes indicates where it came from: button clic or mouse wheel
//// indicators
bool loaded, computed; // indicators: image loaded & segmentation computed
};
#endif // MAINWINDOW_H