BioGTK  5.1.1
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images.
Loading...
Searching...
No Matches
BioGTK.QuPath Class Reference

Classes

class  GeoJsonFeature
 
class  GeoJsonFeatureCollection
 
class  GeoJsonGeometry
 
class  GeoJsonLineString
 
class  GeoJsonPoint
 
class  GeoJsonPolygon
 
class  Properties
 

Static Public Member Functions

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

Member Function Documentation

◆ GetPoints()

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

◆ ReadROI()

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

◆ Save()

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

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