BioLib  4.1.1
A GUI-less version of Bio .NET library for editing & annotating various microscopy image formats.
Loading...
Searching...
No Matches
BioLib.QuPath Class Reference

Classes

class  Channel
 
class  GeoJsonFeature
 
class  GeoJsonFeatureCollection
 
class  GeoJsonGeometry
 
class  GeoJsonLineString
 
class  GeoJsonPoint
 
class  GeoJsonPolygon
 
class  Image
 
class  Level
 
class  Metadata
 
class  PixelCalibration
 
class  PixelDimension
 
class  Project
 
class  Properties
 
class  ServerBuilder
 
class  ZSpacing
 

Static Public Member Functions

static PointD[] GetPoints (GeoJsonGeometry p, BioImage b)
 
static void SaveROI (string file, BioImage b)
 
static ROI[] ReadROI (string filePath, BioImage b)
 
static Project OpenProject (string file)
 

Member Function Documentation

◆ GetPoints()

static PointD[] BioLib.QuPath.GetPoints ( GeoJsonGeometry p,
BioImage b )
static
75 {
76 if (p.type == "Point")
77 {
78 List<PointD> points = new List<PointD>();
79 double[] gs = JsonConvert.DeserializeObject<double[]>(p.coordinates.ToString());
80 points.Add(new PointD(gs[0], gs[1]));
81 for (int i = 0; i < points.Count; i++)
82 {
83 points[i] = new PointD(b.StageSizeX + (points[i].X / b.SizeX) * b.Volume.Width, b.StageSizeY + (points[i].Y / b.SizeY) * b.Volume.Height);
84 }
85 return points.ToArray();
86 }
87 else if (p.type == "Polygon")
88 {
89 List<PointD> points = new List<PointD>();
90 double[][][] gs = JsonConvert.DeserializeObject<double[][][]>(p.coordinates.ToString());
91 foreach (double[] item in gs[0])
92 {
93 points.Add(new PointD(item[0], item[1]));
94 }
95 for (int i = 0; i < points.Count; i++)
96 {
97 points[i] = new PointD(b.StageSizeX + (points[i].X / b.SizeX) * b.Volume.Width, b.StageSizeY + (points[i].Y / b.SizeY) * b.Volume.Height);
98 }
99 return points.ToArray();
100 }
101 else
102 {
103 List<PointD> points = new List<PointD>();
104 double[][] gs = JsonConvert.DeserializeObject<double[][]>(p.coordinates.ToString());
105 foreach (double[] item in gs)
106 {
107 points.Add(new PointD(item[0], item[1]));
108 }
109 for (int i = 0; i < points.Count; i++)
110 {
111 points[i] = new PointD(b.StageSizeX + (points[i].X / b.SizeX) * b.Volume.Width, b.StageSizeY + (points[i].Y / b.SizeY) * b.Volume.Height);
112 }
113 return points.ToArray();
114 }
115 }

◆ OpenProject()

static Project BioLib.QuPath.OpenProject ( string file)
static
270 {
271 try
272 {
273 Project project = JsonConvert.DeserializeObject<QuPath.Project>(File.ReadAllText("D:\\QuPath\\project.qpproj"));
274 Recorder.Record($"QuPath.OpenProject(\"{file}\");");
275 return project;
276 }
277 catch (Exception e)
278 {
279 Console.WriteLine(e.Message);
280 }
281 return null;
282 }

◆ ReadROI()

static ROI[] BioLib.QuPath.ReadROI ( string filePath,
BioImage b )
static
231 {
232 List<ROI> rois = new List<ROI>();
233 string st = File.ReadAllText(filePath);
234 GeoJsonFeatureCollection gs = JsonConvert.DeserializeObject<GeoJsonFeatureCollection>(st);
235
236 foreach (GeoJsonFeature f in gs.features)
237 {
238 ROI r = new ROI();
239 if (f.geometry.type == "Polygon")
240 {
241 r.type = ROI.Type.Polygon;
242 r.closed = true;
243 r.AddPoints(GetPoints(f.geometry, b));
244 if (f.geometry.plane != null)
245 r.coord = f.geometry.GetZCT();
246 }
247 else if (f.geometry.type == "LineString")
248 {
249 r.type = ROI.Type.Line;
250 r.AddPoints(GetPoints(f.geometry, b));
251 if (r.Points.Count > 2)
252 r.type = ROI.Type.Polyline;
253 if (f.geometry.plane != null)
254 r.coord = f.geometry.GetZCT();
255 }
256 else
257 {
258 r.type = ROI.Type.Point;
259 r.AddPoints(GetPoints(f.geometry, b));
260 if (f.geometry.plane != null)
261 r.coord = f.geometry.GetZCT();
262 }
263 rois.Add(r);
264 }
265 Recorder.Record($"QuPath.ReadROI(\"{filePath}\", {b});");
266 return rois.ToArray();
267 }

◆ SaveROI()

static void BioLib.QuPath.SaveROI ( string file,
BioImage b )
static
197 {
198 string j = "{ \"type\":\"FeatureCollection\",\"features\":[";
199 int i = 0;
200 foreach (ROI roi in b.Annotations)
201 {
202 if (i == 0)
203 j += "{\"type\":\"Feature\",\"geometry\":";
204 else
205 j += ",{\"type\":\"Feature\",\"geometry\":";
206 if (roi.type == ROI.Type.Point)
207 {
208 GeoJsonPoint p = GeoJsonPoint.FromROI(roi, b);
209 j += JsonConvert.SerializeObject(p);
210 }
211 else if (roi.type == ROI.Type.Rectangle || (roi.type == ROI.Type.Polygon && roi.closed) || roi.type == ROI.Type.Freeform)
212 {
213 GeoJsonPolygon p = GeoJsonPolygon.FromROI(roi, b);
214 j += JsonConvert.SerializeObject(p);
215 }
216 else if (roi.type == ROI.Type.Polyline || roi.type == ROI.Type.Line || roi.type == ROI.Type.Polygon)
217 {
218 GeoJsonLineString p = GeoJsonLineString.FromROI(roi, b);
219 j += JsonConvert.SerializeObject(p);
220 }
221
222 j += ",\"properties\":{\"object_type\":\"annotation\",\"isLocked\":false}}";
223 i++;
224 }
225 j += "]}";
226 File.WriteAllText(file, j);
227 Recorder.Record($"QuPath.SaveROI(\"{file}\", {b});");
228 }

The documentation for this class was generated from the following file: