BioLib  3.7.0
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
268 {
269 try
270 {
271 return JsonConvert.DeserializeObject<QuPath.Project>(File.ReadAllText("D:\\QuPath\\project.qpproj"));
272 }
273 catch (Exception e)
274 {
275 Console.WriteLine(e.Message);
276 }
277 return null;
278 }

◆ ReadROI()

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

◆ 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 }

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