MorphoGraphX  2.0-1-227
MeshProcessSegmentation.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef MESH_PROCESS_SEGMENTATION_HPP
12 #define MESH_PROCESS_SEGMENTATION_HPP
13 
14 #include <Process.hpp>
15 
16 class Ui_LoadHeatMap;
17 
18 namespace mgx
19 {
22 
30  class mgxBase_EXPORT SegmentMesh : public Process
31  {
32  public:
33  SegmentMesh(const Process& process) : Process(process)
34  {
35  setName("Mesh/Segmentation/Watershed Segmentation");
36  setDesc("Propagate labels on mesh using the watershed algorithm.");
37  setIcon(QIcon(":/images/SegmentMesh.png"));
38 
39  addParm("Steps","Number of propagation steps performed before updating display. Increase value to run faster.","50000");
40  }
41 
42  bool run()
43  {
44  if(!checkState().mesh())
45  return false;
46  return run(currentMesh(), parm("Steps").toUInt(), currentMesh()->activeVertices());
47  }
48 
49  bool run(Mesh* mesh, uint maxsteps, const std::vector<vertex>& to_segment);
50 
51  };
52 
58  class mgxBase_EXPORT SegmentClear : public Process
59  {
60  public:
61  SegmentClear(const Process& process) : Process(process)
62  {
63  setName("Mesh/Segmentation/Segmentation Clear");
64  setDesc("Clean all mesh labels.");
65  setIcon(QIcon(":/images/SegmentClear.png"));
66  }
67 
68  bool run()
69  {
70  if(!checkState().mesh())
71  return false;
72  return run(currentMesh());
73  }
74 
75  bool run(Mesh* mesh);
76 
77  };
78 
87  class mgxBase_EXPORT MeshRelabel : public Process
88  {
89  public:
90  MeshRelabel(const Process& process) : Process(process)
91  {
92  setName("Mesh/Segmentation/Relabel");
93  setDesc("Relabel a mesh randomly to use consecutive labels.");
94  setIcon(QIcon(":/images/Relabel.png"));
95 
96  addParm("Label Start","Starting label.","1");
97  addParm("Label Step","Increment step.","1");
98 
99  }
100 
101  bool run()
102  {
103  if(!checkState().mesh(MESH_NON_EMPTY | MESH_LABEL))
104  return false;
105  Mesh* m = currentMesh();
106  int start = parm("Label Start").toInt();
107  int step = parm("Label Step").toInt();
108  return run(m, start, step);
109  }
110 
111  bool run(Mesh* m, int start, int step);
112 
113  };
114 
120  class mgxBase_EXPORT GrabLabelsSegment : public Process
121  {
122  public:
123  GrabLabelsSegment(const Process& process) : Process(process)
124  {
125  setName("Mesh/Segmentation/3D Grab Labels");
126  setDesc("Grab labels from other mesh (3D meshes).");
127  setIcon(QIcon(":/images/GrabLabels.png"));
128 
129  addParm("Tolerance (µm)","Maximal distance between matching cells. ","5.0"); // 0
130  }
131 
132  bool run()
133  {
134  if(!checkState().mesh(MESH_NON_EMPTY, 0).mesh(MESH_NON_EMPTY, 1))
135  return false;
136 
137  Mesh* mesh1, *mesh2;
138  if(currentMesh() == mesh(0)) {
139  mesh1 = mesh(0);
140  mesh2 = mesh(1);
141  } else if(currentMesh() == mesh(1)) {
142  mesh2 = mesh(0);
143  mesh1 = mesh(1);
144  } else
145  return false;
146 
147  bool res = run(mesh1, mesh2, parm("Tolerance (µm)").toFloat());
148  return res;
149  }
150 
151  bool run(Mesh* mesh1, Mesh* mesh2, float tolerance);
152 
153  };
154 
160  class mgxBase_EXPORT LabelSelected : public Process
161  {
162  public:
163  LabelSelected(const Process& process) : Process(process)
164  {
165  setName("Mesh/Segmentation/Label Selected Vertices");
166  setDesc("Label selected vertices with the same value, which can be a new label");
167  setIcon(QIcon(":/images/LabelSelected.png"));
168 
169  addParm("Label","Asign this label to all selected vertices.","0"); // 0
170  }
171 
172  bool run()
173  {
174  if(!checkState().mesh(MESH_LABEL))
175  return false;
176  return run(currentMesh(), parm("Label").toInt());
177  }
178 
179  bool run(Mesh* mesh, int label);
180 
181  };
182 
188  class mgxBase_EXPORT RelabelCells3D : public Process
189  {
190  public:
191  RelabelCells3D(const Process& process) : Process(process)
192  {
193  setName("Mesh/Segmentation/Relabel 3D Cells");
194  setDesc("Relabel 3D cells (connected regions). A start label of -1 is used to indicate continuing using current labels.");
195  setIcon(QIcon(":/images/CellFiles3D.png"));
196 
197  addParm("Label start","Starting label. Use -1 to continue from last current label.","-1");
198  addParm("Label step","Increment step.","1");
199  }
200 
201  bool run()
202  {
203  if(!checkState().mesh(MESH_NON_EMPTY))
204  return false;
205  Mesh* mesh = currentMesh();
206  bool res = run(mesh, parm("Label start").toInt(), parm("Label step").toInt());
207  if(res)
208  mesh->setShowLabel("Label");
209  return res;
210  }
211 
212  bool run(Mesh* mesh, int label_start, int label_step);
213 
214  };
215 
221  class mgxBase_EXPORT MeshCombineRegions : public Process
222  {
223  public:
224  MeshCombineRegions(const Process& process) : Process(process)
225  {
226  setName("Mesh/Segmentation/Combine Labels");
227  setDesc("Combine over-segmented regions, based on mesh signal.");
228  setIcon(QIcon(":/images/Merge.png"));
229 
230  addParm("Border Distance (µm)","Half of the cell border width on the mesh.","1"); // 0
231  addParm("Threshold","Ratio of border signal over internal signal. If a border between 2 cells has a ratio below the threshold, the cells are fused.","1.5"); // 1
232  }
233 
234  bool run()
235  {
236  if(!checkState().mesh(MESH_NON_EMPTY))
237  return false;
238  return run(currentMesh(), parm("Border Distance (µm)").toFloat(), parm("Threshold").toFloat());
239  }
240 
241  bool run(Mesh* mesh, float borderDist, float Difference);
242 
243  };
244 
251  class mgxBase_EXPORT MeshAutoSegment : public Process
252  {
253  public:
254  MeshAutoSegment(const Process& process) : Process(process)
255  {
256  setName("Mesh/Segmentation/Auto Segmentation");
257  setDesc("Auto-Segmentation of the mesh surface based on signal. Combines blurring, auto-seeding, label propagation by watershed and fusion of over-segmented cells.");
258  setIcon(QIcon(":/images/SegmentMesh.png"));
259 
260  addParm("Update","Option to update mesh drawing while running processes.","Yes",booleanChoice());
261  addParm("Normalize","Option to normalize mesh signal before merging the cells. Most useful in case of low contrast mesh signal.","Yes",booleanChoice());
262  addParm("Blur Cell Radius (µm)","Radius used for gaussian blur of mesh signal. In normal cases, should be equal to auto-seed radius.","2.0");
263  addParm("Auto-Seed Radius (µm)","Radius used for auto-seeding the mesh, based on local minima of signal. Should be equal to radius of smallest cells.","2.0");
264  addParm("Blur Borders Radius (µm)","Radius used for gaussian blur of signal on cell borders before watershed segmentation. Use small values (roughly, half the border width) to avoid border signal distortion.","1");
265  addParm("Normalization Radius (µm)","Radius used for local normalization of signal. Roughly, radius of largest cells.","5.0");
266  addParm("Border Distance (µm)","Half of the cell border width after blurring. Used for fusion of over-segmented cells.","1.0");
267  addParm("Combine Threshold","Ratio of border signal over internal signal. If a borders between 2 cells have a ratio below the threshold, the cells are fused.","1.8");
268  }
269 
270  bool run()
271  {
272  if(!checkState().mesh(MESH_NON_EMPTY))
273  return false;
274  return run(currentMesh(), stringToBool(parm("Update")), stringToBool(parm("Normalize")),
275  parm("Blur Cell Radius (µm)").toFloat(), parm("Auto-Seed Radius (µm)").toFloat(), parm("Blur Borders Radius (µm)").toFloat(), parm("Normalization Radius (µm)").toFloat(),
276  parm("Border Distance (µm)").toFloat(), parm("Combine Threshold").toFloat());
277  }
278 
279  bool run(Mesh* mesh, bool updateView, bool normalize, float gaussianRadiusCell,
280  float localMinimaRadius, float gaussianRadiusWall, float normalizeRadius, float borderDist,
281  float threshold);
282 
283  };
285 }
286 
287 #endif
mgx::GrabLabelsSegment
Definition: MeshProcessSegmentation.hpp:120
mgx::MeshAutoSegment
Definition: MeshProcessSegmentation.hpp:251
mgx::uint
unsigned int uint
Definition: Geometry.hpp:41
Process.hpp
mgx::SegmentMesh
Definition: MeshProcessSegmentation.hpp:30
mgx::MeshCombineRegions
Definition: MeshProcessSegmentation.hpp:221
mgx::Mesh::setShowLabel
void setShowLabel(const QString &s="", bool setView=true)
Set the surface label display.
Definition: Mesh.hpp:621
mgx::LabelSelected
Definition: MeshProcessSegmentation.hpp:160
mgx::GrabLabelsSegment::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:132
mgx::MeshCombineRegions::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:234
mgx::SegmentMesh::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:42
mgx::MeshAutoSegment::MeshAutoSegment
MeshAutoSegment(const Process &process)
Definition: MeshProcessSegmentation.hpp:254
mgx::MeshRelabel::MeshRelabel
MeshRelabel(const Process &process)
Definition: MeshProcessSegmentation.hpp:90
mgx::SegmentClear
Definition: MeshProcessSegmentation.hpp:58
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::LabelSelected::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:172
mgx::SegmentClear::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:68
mgx::Process
Definition: Process.hpp:219
mgx::stringToBool
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
mgx::MeshRelabel
Definition: MeshProcessSegmentation.hpp:87
mgx::MeshCombineRegions::MeshCombineRegions
MeshCombineRegions(const Process &process)
Definition: MeshProcessSegmentation.hpp:224
mgx::SegmentMesh::SegmentMesh
SegmentMesh(const Process &process)
Definition: MeshProcessSegmentation.hpp:33
mgx::Mesh
Definition: Mesh.hpp:54
mgx::RelabelCells3D::RelabelCells3D
RelabelCells3D(const Process &process)
Definition: MeshProcessSegmentation.hpp:191
mgx::LabelSelected::LabelSelected
LabelSelected(const Process &process)
Definition: MeshProcessSegmentation.hpp:163
mgx::SegmentClear::SegmentClear
SegmentClear(const Process &process)
Definition: MeshProcessSegmentation.hpp:61
mgx::GrabLabelsSegment::GrabLabelsSegment
GrabLabelsSegment(const Process &process)
Definition: MeshProcessSegmentation.hpp:123
mgx::MeshRelabel::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:101
mgx::MeshAutoSegment::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:270
mgx::RelabelCells3D::run
bool run()
Runs the process.
Definition: MeshProcessSegmentation.hpp:201
mgx::RelabelCells3D
Definition: MeshProcessSegmentation.hpp:188