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

Classes

class  Mask
 Represents a Mask layer. More...
 

Public Types

enum  Type {
  Rectangle , Point , Line , Polygon ,
  Polyline , Freeform , Ellipse , Label ,
  Mask
}
 
enum  CoordinateSystem { pixel , micron }
 

Public Member Functions

void Validate (bool convertPixelSpace=false, double physX=1, double physY=1)
 
bool Contains (PointD p)
 
ROI Copy ()
 
ROI Copy (ZCT cord)
 
RectangleD GetSelectBound (double scaleX, double scaleY)
 
SKBitmap ByteArrayToBitmap (byte[] imageBytes)
 
PointD[] ImagePoints (Resolution res)
 The function "ImagePoints" takes a Resolution object as input and returns an array of PointD objects that have been converted to image space using the provided resolution values.
 
RectangleD[] GetSelectBoxes (double s)
 
RectangleD[] GetSelectBoxes ()
 
PointD GetCenter ()
 
double DistanceTo (PointD point)
 
void UpdatePoint (PointD p, int i)
 
PointD GetPoint (int i)
 
PointD[] GetPoints ()
 
PointF[] GetPointsF ()
 
void ConvertToMicron (double physX, double physY)
 
void AddPoint (PointD p, bool convertPixelSpace=false, double physX=1, double physY=1)
 
void AddPoints (PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
 
void AddPoints (int[] xp, int[] yp, bool convertPixelSpace=false, double physX=1, double physY=1)
 
void AddPoints (float[] xp, float[] yp, bool convertPixelSpace=false, double physX=1, double physY=1)
 
void RemovePoints (int[] indexs)
 
void ClearPoints ()
 
int GetPointCount ()
 
PointD[] stringToPoints (string s)
 
string PointsToString (BioImage b)
 
void UpdateBoundingBox ()
 
override string ToString ()
 
void Dispose ()
 

Static Public Member Functions

static ROI CreatePoint (ZCT coord, double x, double y)
 
static ROI CreateLine (ZCT coord, PointD x1, PointD x2)
 
static ROI CreateRectangle (ZCT coord, double x, double y, double w, double h)
 
static ROI CreateEllipse (ZCT coord, double x, double y, double w, double h)
 
static ROI CreatePolygon (ZCT coord, PointD[] pts)
 
static ROI CreateFreeform (ZCT coord, PointD[] pts)
 
static ROI CreateMask (ZCT coord, float[] mask, int width, int height, PointD loc, double physicalX, double physicalY, bool useFloatStorage=false, bool absolutePosition=false)
 
static ROI CreateMask (ZCT coord, Byte[] mask, int width, int height, PointD loc, double physicalX, double physicalY, bool absolutePosition=false, bool preserveDimensions=false)
 
static int AddROIsToOMERO (long imageId, long user, BioImage b)
 
static java.util.List BioPointToOmeroPoint (ROI r, BioImage b)
 

Public Attributes

Type type
 
List< int > selectedPoints = new List<int>()
 
float fontSize = 12
 
Cairo.FontSlant slant
 
Cairo.FontWeight weight
 
string family = "Times New Roman"
 
ZCT coord
 
Color strokeColor
 
Color fillColor
 
bool isFilled = false
 
string id = ""
 
string roiID = ""
 
string roiName = ""
 
string properties = ""
 
int serie = 0
 
double strokeWidth = 1
 
int shapeIndex = 0
 
bool closed = false
 
bool subPixel = false
 

Static Public Attributes

static SKPaint SelectBoxColor = new() { Style = SKPaintStyle.Stroke, Color = new SKColor(255, 0, 0) }
 
static float selectBoxSize = 14f
 

Properties

RectangleD BoundingBox [get, set]
 
double X [get]
 
double Y [get]
 
double W [get]
 
double H [get]
 
int Resolution [get, set]
 
PointD Point [get]
 
CoordinateSystem CoordSpace = CoordinateSystem.micron [get, set]
 
List< PointD > Points [get, set]
 
bool Selected [get, set]
 
Mask roiMask [get, set]
 
string Text [get, set]
 

Member Enumeration Documentation

◆ CoordinateSystem

enum BioLib.ROI.CoordinateSystem
102 {
103 pixel,
104 micron
105 }

◆ Type

enum BioLib.ROI.Type
30 {
31 Rectangle,
32 Point,
33 Line,
34 Polygon,
35 Polyline,
36 Freeform,
37 Ellipse,
38 Label,
39 Mask
40 }
Represents a Mask layer.
Definition ROI.cs:218

Constructor & Destructor Documentation

◆ ROI()

BioLib.ROI.ROI ( )
1001 {
1002 coord = new ZCT(0, 0, 0);
1003 strokeColor = Color.Yellow;
1004 BoundingBox = new RectangleD(0, 0, 1, 1);
1005 }

Member Function Documentation

◆ AddPoint()

void BioLib.ROI.AddPoint ( PointD p,
bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )
1644 {
1645 if(Points == null)
1646 Points = new List<PointD>();
1647 Points.Add(p);
1649 }
void UpdateBoundingBox()
Definition ROI.cs:1764

◆ AddPoints() [1/3]

void BioLib.ROI.AddPoints ( float[] xp,
float[] yp,
bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )

‍Adds a range of float points to the Points collection and updates the bounding box

Parameters
pThe points to add to the polygon
1682 {
1683 if (Points == null)
1684 Points = new List<PointD>();
1685 for (int i = 0; i < xp.Length; i++)
1686 {
1687 Points.Add(new PointD(xp[i], yp[i]));
1688 }
1690 }

◆ AddPoints() [2/3]

void BioLib.ROI.AddPoints ( int[] xp,
int[] yp,
bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )

‍Adds a range of integer points to the Points collection and updates the bounding box

Parameters
pThe points to add to the polygon
1669 {
1670 if (Points == null)
1671 Points = new List<PointD>();
1672 for (int i = 0; i < xp.Length; i++)
1673 {
1674 Points.Add(new PointD(xp[i], yp[i]));
1675 }
1677 }

◆ AddPoints() [3/3]

void BioLib.ROI.AddPoints ( PointD[] p,
bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )

‍Adds a range of points to the Points collection and updates the bounding box

Parameters
pThe points to add to the polygon
1654 {
1655 if (Points == null)
1656 Points = new List<PointD>();
1657 if (convertPixelSpace)
1658 {
1659 ConvertToMicron(physX, physY);
1660 }
1661 else
1662 Points.AddRange(p);
1664 }
void ConvertToMicron(double physX, double physY)
Definition ROI.cs:1634

◆ AddROIsToOMERO()

static int BioLib.ROI.AddROIsToOMERO ( long imageId,
long user,
BioImage b )
static
1202 {
1203 try
1204 {
1205 var gateway = OMERO.gateway;
1206 var roiService = gateway.getFacility(typeof(ROIFacility)) as ROIFacility;
1207 var browse = gateway.getFacility(typeof(BrowseFacility)) as BrowseFacility;
1208 var ctx = OMERO.sc;
1209 ImageData image = browse.getImage(ctx, imageId);
1210 int count = 0;
1211 ROI[] rois = b.Annotations.ToArray();
1212
1213 foreach (ROI an in rois)
1214 {
1215 ROIData roi = new ROIData();
1216 ShapeData shape = null;
1217
1218 switch (an.type)
1219 {
1220 case ROI.Type.Point:
1221 {
1222 var pt = new omero.gateway.model.PointData(
1223 b.ToImageSpaceX(an.X),
1224 b.ToImageSpaceY(an.Y)
1225 );
1226 pt.setZ(an.coord.Z);
1227 pt.setC(an.coord.C);
1228 pt.setT(an.coord.T);
1229 pt.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1230 shape = pt;
1231 break;
1232 }
1233
1234 case ROI.Type.Rectangle:
1235 {
1236 var r = new RectangleData(
1237 b.ToImageSpaceX(an.BoundingBox.X),
1238 b.ToImageSpaceY(an.BoundingBox.Y),
1239 b.ToImageSizeX(an.W),
1240 b.ToImageSizeY(an.H)
1241 );
1242 r.setZ(an.coord.Z);
1243 r.setC(an.coord.C);
1244 r.setT(an.coord.T);
1245 r.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1246 shape = r;
1247 break;
1248 }
1249
1250 case ROI.Type.Ellipse:
1251 {
1252 double rx = b.ToImageSizeX(an.W / 2.0);
1253 double ry = b.ToImageSizeY(an.H / 2.0);
1254 double cx = b.ToImageSpaceX(an.Points[0].X + an.W / 2.0);
1255 double cy = b.ToImageSpaceY(an.Points[0].Y + an.H / 2.0);
1256
1257 var e = new EllipseData(cx, cy, rx, ry);
1258 e.setZ(an.coord.Z);
1259 e.setC(an.coord.C);
1260 e.setT(an.coord.T);
1261 e.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1262 shape = e;
1263 break;
1264 }
1265
1266 case ROI.Type.Line:
1267 {
1268 var l = new LineData(
1269 b.ToImageSpaceX(an.GetPoint(0).X),
1270 b.ToImageSpaceY(an.GetPoint(0).Y),
1271 b.ToImageSpaceX(an.GetPoint(1).X),
1272 b.ToImageSpaceY(an.GetPoint(1).Y)
1273 );
1274 l.setZ(an.coord.Z);
1275 l.setC(an.coord.C);
1276 l.setT(an.coord.T);
1277 l.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1278 shape = l;
1279 break;
1280 }
1281
1282 case ROI.Type.Polygon:
1283 case ROI.Type.Freeform:
1284 {
1285 var pts = new List<PointD>();
1286 foreach (var p in an.Points)
1287 pts.Add(new PointD(
1288 b.ToImageSpaceX(p.X),
1289 b.ToImageSpaceY(p.Y)
1290 ));
1291
1292 var poly = new PolygonData(BioPointToOmeroPoint(an,b));
1293 poly.setZ(an.coord.Z);
1294 poly.setC(an.coord.C);
1295 poly.setT(an.coord.T);
1296 poly.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1297 shape = poly;
1298 break;
1299 }
1300
1301 case ROI.Type.Polyline:
1302 {
1303 var pts = new List<PointD>();
1304 foreach (var p in an.Points)
1305 pts.Add(new PointD(
1306 b.ToImageSpaceX(p.X),
1307 b.ToImageSpaceY(p.Y)
1308 ));
1309
1310 var pl = new PolylineData(BioPointToOmeroPoint(an, b));
1311 pl.setZ(an.coord.Z);
1312 pl.setC(an.coord.C);
1313 pl.setT(an.coord.T);
1314 pl.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1315 shape = pl;
1316 break;
1317 }
1318
1319 case ROI.Type.Label:
1320 {
1321 var t = new TextData(
1322 string.IsNullOrEmpty(an.Text) ? "Label" : an.Text,
1323 b.ToImageSpaceX(an.BoundingBox.X),
1324 b.ToImageSpaceY(an.BoundingBox.Y)
1325 );
1326 //t.setFontSize(new omero.model.LengthI(an.fontSize, omero.model.enums.UnitsLength.PIXEL));
1327 t.setZ(an.coord.Z);
1328 t.setC(an.coord.C);
1329 t.setT(an.coord.T);
1330 shape = t;
1331 break;
1332 }
1333
1334 case ROI.Type.Mask:
1335 {
1336 if (an.roiMask == null)
1337 continue;
1338
1339 var m = new MaskData(
1340 an.roiMask.X,
1341 an.roiMask.Y,
1342 an.roiMask.Width,
1343 an.roiMask.Height,
1344 an.roiMask.GetBytes()
1345 );
1346
1347 m.setZ(an.coord.Z);
1348 m.setC(an.coord.C);
1349 m.setT(an.coord.T);
1350 m.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1351 shape = m;
1352 break;
1353 }
1354 }
1355
1356 if (shape == null)
1357 continue;
1358 // Apply stroke/fill
1359 shape.getShapeSettings().setStroke(new java.awt.Color(
1360 an.strokeColor.A,
1361 an.strokeColor.R,
1362 an.strokeColor.G,
1363 an.strokeColor.B
1364 ));
1365
1366 shape.getShapeSettings().setFill(new java.awt.Color(
1367 an.fillColor.A,
1368 an.fillColor.R,
1369 an.fillColor.G,
1370 an.fillColor.B
1371 ));
1372
1373 shape.getShapeSettings().setStrokeWidth(
1374 new omero.model.LengthI(an.strokeWidth, omero.model.enums.UnitsLength.PIXEL)
1375 );
1376
1377 roi.addShapeData(shape);
1378
1379 // ----- Save ROI to OMERO -----
1380 java.util.List roiList = new java.util.ArrayList();
1381 roiList.add(roi);
1382
1383 var saved = roiService.saveROIs(ctx, imageId, user, roiList);
1384 count++;
1385
1386 }
1387
1388 Console.WriteLine($"Added {count} ROIs to OMERO image {imageId}");
1389 return count;
1390 }
1391 catch (Exception ex)
1392 {
1393 Console.WriteLine("Error adding ROIs: " + ex);
1394 return 0;
1395 }
1396 }
Definition OMERO.cs:34
Definition ROI.cs:27
PointD GetPoint(int i)
Definition ROI.cs:1605

◆ BioPointToOmeroPoint()

static java.util.List BioLib.ROI.BioPointToOmeroPoint ( ROI r,
BioImage b )
static
1398 {
1399 // Create Java list, NOT C# list
1400 java.util.List javaPts = new java.util.ArrayList();
1401 foreach (var p in r.Points)
1402 {
1403 // Create Java Point2D.Double for OMERO
1404 var jp = new java.awt.geom.Point2D.Double(
1405 b.ToImageSpaceX(p.X),
1406 b.ToImageSpaceY(p.Y)
1407 );
1408 javaPts.add(jp);
1409 }
1410 return javaPts;
1411 }

◆ ByteArrayToBitmap()

SKBitmap BioLib.ROI.ByteArrayToBitmap ( byte[] imageBytes)
1007 {
1008 if (imageBytes == null || imageBytes.Length == 0)
1009 return null;
1010
1011 using var ms = new SKMemoryStream(imageBytes);
1012 return SKBitmap.Decode(ms);
1013 }

◆ ClearPoints()

void BioLib.ROI.ClearPoints ( )
1712 {
1713 Points.Clear();
1714 }

◆ Contains()

bool BioLib.ROI.Contains ( PointD p)
172 {
173 return (p.X >= X &&
174 p.X <= X + W &&
175 p.Y >= Y &&
176 p.Y <= Y + H);
177 }

◆ ConvertToMicron()

void BioLib.ROI.ConvertToMicron ( double physX,
double physY )

‍Adds a point to the list of points and updates the bounding box

Parameters
PointD
1635 {
1636 List<PointD> points = new List<PointD>();
1637 for (int i = 0; i < Points.Count; i++)
1638 {
1639 points.Add(new PointD(Points[i].X * physX, Points[i].Y * physY));
1640 }
1641 Points = points;
1642 }

◆ Copy() [1/2]

ROI BioLib.ROI.Copy ( )
888 {
889 ROI copy = new ROI();
890 copy.type = type;
891 copy.id = id;
892 copy.roiID = roiID;
893 copy.roiName = roiName;
894 copy.text = text;
895 copy.strokeWidth = strokeWidth;
896 copy.strokeColor = strokeColor;
897 copy.fillColor = fillColor;
898 copy.Points.AddRange(Points);
899 copy.Selected = Selected;
900 copy.shapeIndex = shapeIndex;
901 copy.closed = closed;
902 copy.family = family;
903 copy.fontSize = fontSize;
904 copy.slant = slant;
905 copy.selectBoxs.AddRange(selectBoxs);
906 copy.BoundingBox = BoundingBox;
907 copy.isFilled = isFilled;
908 copy.coord = coord;
909 copy.selectedPoints = selectedPoints;
910 if (roiMask != null)
911 {
912 copy.roiMask = new Mask(
913 roiMask.GetBytes(),
914 roiMask.Width,
915 roiMask.Height,
916 roiMask.PhysicalSizeX,
917 roiMask.PhysicalSizeY,
918 roiMask.X * roiMask.PhysicalSizeX,
919 roiMask.Y * roiMask.PhysicalSizeY,
920 preserveDimensions: true);
921 }
922
923 return copy;
924 }

◆ Copy() [2/2]

ROI BioLib.ROI.Copy ( ZCT cord)
926 {
927 ROI copy = new ROI();
928 copy.type = type;
929 copy.id = id;
930 copy.roiID = roiID;
931 copy.roiName = roiName;
932 copy.text = text;
933 copy.strokeWidth = strokeWidth;
934 copy.strokeColor = strokeColor;
935 copy.fillColor = fillColor;
936 copy.Points.AddRange(Points);
937 copy.Selected = Selected;
938 copy.shapeIndex = shapeIndex;
939 copy.closed = closed;
940 copy.family = family;
941 copy.fontSize = fontSize;
942 copy.slant = slant;
943 copy.selectBoxs.AddRange(selectBoxs);
944 copy.BoundingBox = BoundingBox;
945 copy.isFilled = isFilled;
946 copy.coord = cord;
947 copy.selectedPoints = selectedPoints;
948 if (roiMask != null)
949 {
950 copy.roiMask = new Mask(
951 roiMask.GetBytes(),
952 roiMask.Width,
953 roiMask.Height,
954 roiMask.PhysicalSizeX,
955 roiMask.PhysicalSizeY,
956 roiMask.X * roiMask.PhysicalSizeX,
957 roiMask.Y * roiMask.PhysicalSizeY,
958 preserveDimensions: true);
959 }
960 return copy;
961 }

◆ CreateEllipse()

static ROI BioLib.ROI.CreateEllipse ( ZCT coord,
double x,
double y,
double w,
double h )
static

Create an ellipse ROI at the specified ZCT coordinate with the specified width and height

Parameters
ZCTThe ZCT coordinates of the image you want to create the ROI on.
xx-coordinate of the top-left corner of the rectangle
yThe y-coordinate of the upper-left corner of the rectangle to create.
wwidth
hheight
Returns
A new ROI object.
1138 {
1139 ROI an = new ROI();
1140 an.coord = coord;
1141 an.type = Type.Ellipse;
1142 an.BoundingBox = new RectangleD(x, y, w, h);
1143 return an;
1144 }

◆ CreateFreeform()

static ROI BioLib.ROI.CreateFreeform ( ZCT coord,
PointD[] pts )
static

‍Create a new ROI object of type Freeform, with the specified ZCT coordinate and points

Parameters
ZCTA class that contains the Z, C, and T coordinates of the ROI.
ptsan array of PointD objects, which are just a pair of doubles (x,y)
Returns
A new ROI object.
1168 {
1169 ROI an = new ROI();
1170 an.coord = coord;
1171 an.type = Type.Freeform;
1172 an.AddPoints(pts);
1173 an.closed = true;
1174 return an;
1175 }
void AddPoints(PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1653

◆ CreateLine()

static ROI BioLib.ROI.CreateLine ( ZCT coord,
PointD x1,
PointD x2 )
static

Create a new ROI object, set its type to Line, add two points to it, and return it

Parameters
ZCTZ is the Z-axis, C is the color channel, and T is the time frame.
PointDX,Y
PointDX,Y
Returns
A new ROI object.
1101 {
1102 ROI an = new ROI();
1103 an.Points = new List<PointD>();
1104 an.coord = coord;
1105 an.type = Type.Line;
1106 an.Points.Add(x1);
1107 an.Points.Add(x2);
1108 an.UpdateBoundingBox();
1109 return an;
1110 }

◆ CreateMask() [1/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
Byte[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY,
bool absolutePosition = false,
bool preserveDimensions = false )
static
1187 {
1188 ROI an = new ROI();
1189 an.coord = coord;
1190 an.type = Type.Mask;
1191 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y, absolutePosition, preserveDimensions);
1192 an.AddPoint(loc);
1193 an.BoundingBox = new RectangleD(loc.X, loc.Y, width * physicalX, height * physicalY);
1194 return an;
1195 }

◆ CreateMask() [2/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
float[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY,
bool useFloatStorage = false,
bool absolutePosition = false )
static
1177 {
1178 ROI an = new ROI();
1179 an.coord = coord;
1180 an.type = Type.Mask;
1181 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y, useFloatStorage, absolutePosition);
1182 an.AddPoint(loc);
1183 an.BoundingBox = new RectangleD(loc.X, loc.Y, width * physicalX, height * physicalY);
1184 return an;
1185 }

◆ CreatePoint()

static ROI BioLib.ROI.CreatePoint ( ZCT coord,
double x,
double y )
static

Create a new ROI object, add a point to it, and return it

Parameters
ZCTa class that contains the Z, C, and T coordinates of the image.
xx coordinate of the point
yThe y coordinate of the point
Returns
A new ROI object
1084 {
1085 ROI an = new ROI();
1086 an.coord = coord;
1087 an.AddPoint(new PointD(x, y));
1088 an.type = Type.Point;
1089 an.BoundingBox = new RectangleD(x, y, selectBoxSize, selectBoxSize);
1090 return an;
1091 }

◆ CreatePolygon()

static ROI BioLib.ROI.CreatePolygon ( ZCT coord,
PointD[] pts )
static

‍Create a new ROI object of type Polygon, with the given coordinate system and points

Parameters
ZCTThe ZCT coordinate of the ROI.
ptsan array of PointD objects, which are just a pair of doubles (x,y)
Returns
A ROI object
1152 {
1153 ROI an = new ROI();
1154 an.coord = coord;
1155 an.type = Type.Polygon;
1156 an.Points = new List<PointD>();
1157 an.AddPoints(pts);
1158 an.closed = true;
1159 return an;
1160 }

◆ CreateRectangle()

static ROI BioLib.ROI.CreateRectangle ( ZCT coord,
double x,
double y,
double w,
double h )
static

Create a new ROI object with a rectangle shape, and add a line to the recorder

Parameters
ZCTThe ZCT coordinates of the image you want to create the ROI on.
xx coordinate of the top left corner of the rectangle
yy-coordinate of the top-left corner of the rectangle
wwidth
hheight
Returns
A new ROI object.
1121 {
1122 ROI an = new ROI();
1123 an.coord = coord;
1124 an.type = Type.Rectangle;
1125 an.BoundingBox = new RectangleD(x, y, w, h);
1126 return an;
1127 }

◆ Dispose()

void BioLib.ROI.Dispose ( )
1844 {
1845 if (roiMask != null)
1846 {
1847 roiMask.Dispose();
1848 }
1849 }

◆ DistanceTo()

double BioLib.ROI.DistanceTo ( PointD point)
1584 {
1585 var center = GetCenter();
1586 return (float)Math.Sqrt(Math.Pow(center.X - point.X, 2) + Math.Pow(center.Y - point.Y, 2));
1587 }

◆ GetCenter()

PointD BioLib.ROI.GetCenter ( )
1198 {
1199 return new PointD(BoundingBox.X + (BoundingBox.W / 2.0), BoundingBox.Y + (BoundingBox.H / 2.0));
1200 }

◆ GetPoint()

PointD BioLib.ROI.GetPoint ( int i)

This function returns the point at the specified index

Parameters
iThe index of the point to get.
Returns
The point at index i in the Points array.
1606 {
1607 if (i < 0 || Points.Count == 0)
1608 return new PointD();
1609 return Points[i];
1610 }

◆ GetPointCount()

int BioLib.ROI.GetPointCount ( )

This function returns the number of points in the polygon

Returns
The number of points in the list.
1719 {
1720 return Points.Count;
1721 }

◆ GetPoints()

PointD[] BioLib.ROI.GetPoints ( )

It returns an array of PointD objects

Returns
An array of PointD objects.
1615 {
1616 return Points.ToArray();
1617 }

◆ GetPointsF()

PointF[] BioLib.ROI.GetPointsF ( )

It converts a list of points to an array of points

Returns
A PointF array.
1622 {
1623 PointF[] pfs = new PointF[Points.Count];
1624 for (int i = 0; i < Points.Count; i++)
1625 {
1626 pfs[i].X = (float)Points[i].X;
1627 pfs[i].Y = (float)Points[i].Y;
1628 }
1629 return pfs;
1630 }

◆ GetSelectBound()

RectangleD BioLib.ROI.GetSelectBound ( double scaleX,
double scaleY )

‍This function returns a rectangle that is the bounding box of the object, but with a border of half the scale

Parameters
scalethe scale of the image
Returns
A rectangle with the following properties:
984 {
985 if (type == Type.Mask)
986 return BoundingBox;
987 double fx = scaleX / 2;
988 double fy = scaleY / 2;
989 return new RectangleD(BoundingBox.X - fx, BoundingBox.Y - fy, BoundingBox.W + scaleX, BoundingBox.H + scaleY);
990 }

◆ GetSelectBoxes() [1/2]

RectangleD[] BioLib.ROI.GetSelectBoxes ( )

It returns an array of RectangleF objects that are used to draw the selection boxes around the points of the polygon

Parameters
sthe size of the select box
Returns
A list of RectangleF objects.
1067 {
1068 double f = ROI.selectBoxSize / 2;
1069 selectBoxs.Clear();
1070 for (int i = 0; i < Points.Count; i++)
1071 {
1072 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)ROI.selectBoxSize, (float)ROI.selectBoxSize));
1073 }
1074 return selectBoxs.ToArray();
1075 }

◆ GetSelectBoxes() [2/2]

RectangleD[] BioLib.ROI.GetSelectBoxes ( double s)

It returns an array of RectangleF objects that are used to draw the selection boxes around the points of the polygon

Parameters
sthe size of the select box
Returns
A list of RectangleF objects.
1046 {
1047
1048 double f = s / 2;
1049 selectBoxs.Clear();
1050 int c = Points.Count;
1051 if (type != Type.Mask)
1052 {
1053 for (int i = 0; i < c; i++)
1054 {
1055 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)s, (float)s));
1056 }
1057 }
1058 return selectBoxs.ToArray();
1059 }

◆ ImagePoints()

PointD[] BioLib.ROI.ImagePoints ( Resolution res)

The function "ImagePoints" takes a Resolution object as input and returns an array of PointD objects that have been converted to image space using the provided resolution values.

Parameters
ResolutionThe "Resolution" parameter is an object that contains information about the resolution of an image. It typically includes properties such as the stage size (width and height), physical size (width and height), and possibly other properties related to the image resolution.
Returns
The method is returning an array of PointD objects.
1026 {
1027 if (type == Type.Rectangle || type == Type.Mask)
1028 {
1029 PointD[] pts = new PointD[4];
1030 pts[0] = Points[0];
1031 pts[1] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y);
1032 pts[2] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y + BoundingBox.H);
1033 pts[3] = new PointD(Points[0].X, Points[0].Y + BoundingBox.H);
1034 return BioImage.ToImageSpace(pts.ToList(), res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
1035 }
1036 else
1037 return BioImage.ToImageSpace(Points, res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
1038 }
Definition Bio.cs:1872
PointD ToImageSpace(PointD p)
Convert a point in the stage coordinate system to a point in the image coordinate system.
Definition Bio.cs:3624

◆ PointsToString()

string BioLib.ROI.PointsToString ( BioImage b)

This function takes a BioImage object and returns a string of the points in the image space

Parameters
BioImageThe image that the ROI is on
Returns
The points of the polygon in the image space.
1750 {
1751 string pts = "";
1752 PointD[] ps = b.ToImageSpace(Points);
1753 for (int j = 0; j < ps.Length; j++)
1754 {
1755 if (j == ps.Length - 1)
1756 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture);
1757 else
1758 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
1759 }
1760 return pts;
1761 }

◆ RemovePoints()

void BioLib.ROI.RemovePoints ( int[] indexs)

It removes points from a list of points based on an array of indexes

Parameters
indexsan array of integers that represent the indexes of the points to be removed
1695 {
1696 List<PointD> inds = new List<PointD>();
1697 for (int i = 0; i < Points.Count; i++)
1698 {
1699 bool found = false;
1700 for (int ind = 0; ind < indexs.Length; ind++)
1701 {
1702 if (indexs[ind] == i)
1703 found = true;
1704 }
1705 if (!found)
1706 inds.Add(Points[i]);
1707 }
1708 Points = inds;
1710 }

◆ stringToPoints()

PointD[] BioLib.ROI.stringToPoints ( string s)

It takes a string of points and returns an array of points

Parameters
sThe string to convert to points.
Returns
A list of points.
1728 {
1729 List<PointD> pts = new List<PointD>();
1730 string[] ints = s.Split(' ');
1731 for (int i = 0; i < ints.Length; i++)
1732 {
1733 string[] sints;
1734 if (s.Contains("\t"))
1735 sints = ints[i].Split('\t');
1736 else
1737 sints = ints[i].Split(',');
1738 double x = double.Parse(sints[0], CultureInfo.InvariantCulture);
1739 double y = double.Parse(sints[1], CultureInfo.InvariantCulture);
1740 pts.Add(new PointD(x, y));
1741 }
1742 return pts.ToArray();
1743 }

◆ ToString()

override string BioLib.ROI.ToString ( )
1840 {
1841 return type + " X:" + W + " Y:" + H + " W:" + W + " H:" + H + ", ZCT:" + coord.Z + "," + coord.C + "," + coord.T + " Text: " + Text;
1842 }

◆ UpdateBoundingBox()

void BioLib.ROI.UpdateBoundingBox ( )

It takes a list of points and returns a rectangle that contains all of the points

1765 {
1766 // Safety check
1767 if ((Points == null || Points.Count == 0) && type != Type.Mask)
1768 {
1769 BoundingBox = new RectangleD(0, 0, 0, 0);
1770 return;
1771 }
1772
1773 // -----------------------------
1774 // 1) MASK ROI MODE
1775 // -----------------------------
1776 if (type == Type.Mask && roiMask != null)
1777 {
1778 double minX = double.PositiveInfinity;
1779 double minY = double.PositiveInfinity;
1780 double maxX = double.NegativeInfinity;
1781 double maxY = double.NegativeInfinity;
1782
1783 for (int y = 0; y < roiMask.Height; y++)
1784 {
1785 for (int x = 0; x < roiMask.Width; x++)
1786 {
1787 if (!roiMask.IsSelected(x, y))
1788 continue;
1789
1790 if (x < minX) minX = x;
1791 if (y < minY) minY = y;
1792 if (x > maxX) maxX = x;
1793 if (y > maxY) maxY = y;
1794 }
1795 }
1796
1797 // No selected pixels
1798 if (double.IsInfinity(minX))
1799 {
1800 BoundingBox = new RectangleD(0, 0, 0, 0);
1801 return;
1802 }
1803
1804 // Mask bounding box IN PHYSICAL COORDINATES
1805 double physX = (roiMask.X * roiMask.PhysicalSizeX) + minX * roiMask.PhysicalSizeX;
1806 double physY = (roiMask.Y * roiMask.PhysicalSizeY) + minY * roiMask.PhysicalSizeY;
1807
1808 double physW = (maxX - minX + 1) * roiMask.PhysicalSizeX;
1809 double physH = (maxY - minY + 1) * roiMask.PhysicalSizeY;
1810
1811 BoundingBox = new RectangleD(physX, physY, physW, physH);
1812 return;
1813 }
1814
1815 // -----------------------------
1816 // 2) POINT-BASED ROI MODE
1817 // -----------------------------
1818 double minPX = double.PositiveInfinity;
1819 double minPY = double.PositiveInfinity;
1820 double maxPX = double.NegativeInfinity;
1821 double maxPY = double.NegativeInfinity;
1822
1823 foreach (var p in Points)
1824 {
1825 if (p.X < minPX) minPX = p.X;
1826 if (p.Y < minPY) minPY = p.Y;
1827 if (p.X > maxPX) maxPX = p.X;
1828 if (p.Y > maxPY) maxPY = p.Y;
1829 }
1830
1831 // Build bounding rectangle
1832 BoundingBox = new RectangleD(
1833 minPX,
1834 minPY,
1835 maxPX - minPX,
1836 maxPY - minPY
1837 );
1838 }

◆ UpdatePoint()

void BioLib.ROI.UpdatePoint ( PointD p,
int i )

This function updates the point at the specified index

Parameters
PointDA class that contains an X and Y coordinate.
iThe index of the point to update
1594 {
1595 if (i < Points.Count)
1596 {
1597 Points[i] = p;
1598 }
1599 }

◆ Validate()

void BioLib.ROI.Validate ( bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )
137 {
138 // Ensure pos exists
139 if (pos == null)
140 pos = new List<PointD>();
141 else
142 pos.Clear();
143 if(convertPixelSpace)
144 {
145 ConvertToMicron(physX, physY);
146 }
147 switch (type)
148 {
149 case Type.Rectangle:
150 case Type.Ellipse:
151 // 4 corners derived from the bounding box
152 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y));
153 pos.Add(new PointD(BoundingBox.X + BoundingBox.W, BoundingBox.Y));
154 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y + BoundingBox.H));
155 pos.Add(new PointD(BoundingBox.X + BoundingBox.W, BoundingBox.Y + BoundingBox.H));
156 break;
157
158 case Type.Point:
159 case Type.Label:
160 // Only the anchor point (top-left of bounding box)
161 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y));
162 break;
163 default:
164 // Other ROI types keep their existing point data
165 // (Freeform, Polyline, Polygon, Mask, etc.)
166 break;
167 }
168
169 }

Member Data Documentation

◆ SelectBoxColor

SKPaint BioLib.ROI.SelectBoxColor = new() { Style = SKPaintStyle.Stroke, Color = new SKColor(255, 0, 0) }
static
118{ Style = SKPaintStyle.Stroke, Color = new SKColor(255, 0, 0) };

Property Documentation

◆ BoundingBox

RectangleD BioLib.ROI.BoundingBox
getset
43 {
44 get; set;
45 }

◆ CoordSpace

CoordinateSystem BioLib.ROI.CoordSpace = CoordinateSystem.micron
getset
120{ get; set; } = CoordinateSystem.micron;

◆ H

double BioLib.ROI.H
get
83 {
84 get
85 {
86 if (type == Type.Mask)
87 {
88 return roiMask.Height * roiMask.PhysicalSizeY;
89 }
90 if (type == Type.Point)
91 return ROI.selectBoxSize;
92 else
93 return BoundingBox.H;
94 }
95 }

◆ Point

PointD BioLib.ROI.Point
get
108 {
109 get
110 {
111 if (Points.Count > 0)
112 return Points[0];
113 else
114 return new PointD(X, Y);
115
116 }
117 }

◆ Points

List<PointD> BioLib.ROI.Points
getset
123 {
124 get
125 {
126 if (pos.Count == 0)
127 Validate(false,0,0);
128 return pos;
129 }
130 set
131 {
132 pos = value;
134 }
135 }

◆ Resolution

int BioLib.ROI.Resolution
getset
97 {
98 get { return resolution; }
99 set { resolution = value; }
100 }

◆ roiMask

Mask BioLib.ROI.roiMask
getset
213{ get; set; }

◆ Selected

bool BioLib.ROI.Selected
getset
201 {
202 get { return selected; }
203 set
204 {
205 if (roiMask != null)
206 roiMask.Selected = value;
207 selected = value;
208 if (!selected)
209 selectedPoints.Clear();
210 }
211 }

◆ Text

string BioLib.ROI.Text
getset
963 {
964 get
965 {
966 return text;
967 }
968 set
969 {
970 text = value;
971 if (type == Type.Label)
972 {
974 }
975 }
976 }

◆ W

double BioLib.ROI.W
get
69 {
70 get
71 {
72 if (type == Type.Mask)
73 {
74 return roiMask.Width * roiMask.PhysicalSizeX;
75 }
76 if (type == Type.Point)
77 return ROI.selectBoxSize;
78 else
79 return BoundingBox.W;
80 }
81 }

◆ X

double BioLib.ROI.X
get
47 {
48 get
49 {
50 if (type == Type.Mask)
51 {
52 return roiMask.X * roiMask.PhysicalSizeX;
53 }
54 return BoundingBox.X;
55 }
56 }

◆ Y

double BioLib.ROI.Y
get
58 {
59 get
60 {
61 if (type == Type.Mask)
62 {
63 return roiMask.Y * roiMask.PhysicalSizeY;
64 }
65 return BoundingBox.Y;
66 }
67 }

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