BioLib  4.3.0
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)
 
 ROI ()
 
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

Enumerator
pixel 
micron 

◆ Type

Enumerator
Rectangle 
Point 
Line 
Polygon 
Polyline 
Freeform 
Ellipse 
Label 
Mask 
29 {
31 Point,
32 Line,
33 Polygon,
36 Ellipse,
37 Label,
38 Mask
39 }
Represents a Mask layer.
Definition ROI.cs:217
PointD Point
Definition ROI.cs:107

Constructor & Destructor Documentation

◆ ROI()

BioLib.ROI.ROI ( )
1000 {
1001 coord = new ZCT(0, 0, 0);
1002 strokeColor = Color.Yellow;
1003 BoundingBox = new RectangleD(0, 0, 1, 1);
1004 }
AForge.ZCT ZCT
Definition Bio.cs:62
AForge.Color Color
Definition Bio.cs:55
AForge.RectangleD RectangleD
Definition Fiji.cs:27
ZCT coord
Definition ROI.cs:184
RectangleD BoundingBox
Definition ROI.cs:42
Color strokeColor
Definition ROI.cs:185

Member Function Documentation

◆ AddPoint()

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

◆ 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
1681 {
1682 if (Points == null)
1683 Points = new List<PointD>();
1684 for (int i = 0; i < xp.Length; i++)
1685 {
1686 Points.Add(new PointD(xp[i], yp[i]));
1687 }
1689 }
AForge.PointD PointD
Definition Bio.cs:60

◆ 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
1668 {
1669 if (Points == null)
1670 Points = new List<PointD>();
1671 for (int i = 0; i < xp.Length; i++)
1672 {
1673 Points.Add(new PointD(xp[i], yp[i]));
1674 }
1676 }

◆ 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
1653 {
1654 if (Points == null)
1655 Points = new List<PointD>();
1656 if (convertPixelSpace)
1657 {
1658 ConvertToMicron(physX, physY);
1659 }
1660 else
1661 Points.AddRange(p);
1663 }
void ConvertToMicron(double physX, double physY)
Definition ROI.cs:1633

◆ AddROIsToOMERO()

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

◆ BioPointToOmeroPoint()

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

◆ ByteArrayToBitmap()

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

◆ ClearPoints()

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

◆ Contains()

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

◆ ConvertToMicron()

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

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

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

◆ Copy() [1/2]

ROI BioLib.ROI.Copy ( )
887 {
888 ROI copy = new ROI();
889 copy.type = type;
890 copy.id = id;
891 copy.roiID = roiID;
892 copy.roiName = roiName;
893 copy.text = text;
894 copy.strokeWidth = strokeWidth;
895 copy.strokeColor = strokeColor;
896 copy.fillColor = fillColor;
897 copy.Points.AddRange(Points);
898 copy.Selected = Selected;
899 copy.shapeIndex = shapeIndex;
900 copy.closed = closed;
901 copy.family = family;
902 copy.fontSize = fontSize;
903 copy.slant = slant;
904 copy.selectBoxs.AddRange(selectBoxs);
905 copy.BoundingBox = BoundingBox;
906 copy.isFilled = isFilled;
907 copy.coord = coord;
908 copy.selectedPoints = selectedPoints;
909 if (roiMask != null)
910 {
911 copy.roiMask = new Mask(
919 preserveDimensions: true);
920 }
921
922 return copy;
923 }
double PhysicalSizeY
Definition ROI.cs:228
double PhysicalSizeX
Definition ROI.cs:227
string roiName
Definition ROI.cs:190
int shapeIndex
Definition ROI.cs:196
bool closed
Definition ROI.cs:197
string family
Definition ROI.cs:183
bool isFilled
Definition ROI.cs:187
ROI()
Definition ROI.cs:999
List< int > selectedPoints
Definition ROI.cs:179
string roiID
Definition ROI.cs:189
float fontSize
Definition ROI.cs:180
Cairo.FontSlant slant
Definition ROI.cs:181
bool Selected
Definition ROI.cs:200

◆ Copy() [2/2]

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

◆ 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.
1137 {
1138 ROI an = new ROI();
1139 an.coord = coord;
1140 an.type = Type.Ellipse;
1141 an.BoundingBox = new RectangleD(x, y, w, h);
1142 return an;
1143 }

◆ 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.
1167 {
1168 ROI an = new ROI();
1169 an.coord = coord;
1170 an.type = Type.Freeform;
1171 an.AddPoints(pts);
1172 an.closed = true;
1173 return an;
1174 }
void AddPoints(PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1652

◆ 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.
1100 {
1101 ROI an = new ROI();
1102 an.Points = new List<PointD>();
1103 an.coord = coord;
1104 an.type = Type.Line;
1105 an.Points.Add(x1);
1106 an.Points.Add(x2);
1107 an.UpdateBoundingBox();
1108 return an;
1109 }

◆ 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
1186 {
1187 ROI an = new ROI();
1188 an.coord = coord;
1189 an.type = Type.Mask;
1190 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y, absolutePosition, preserveDimensions);
1191 an.AddPoint(loc);
1192 an.BoundingBox = new RectangleD(loc.X, loc.Y, width * physicalX, height * physicalY);
1193 return an;
1194 }
void AddPoint(PointD p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1642

◆ 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
1176 {
1177 ROI an = new ROI();
1178 an.coord = coord;
1179 an.type = Type.Mask;
1180 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y, useFloatStorage, absolutePosition);
1181 an.AddPoint(loc);
1182 an.BoundingBox = new RectangleD(loc.X, loc.Y, width * physicalX, height * physicalY);
1183 return an;
1184 }

◆ 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
1083 {
1084 ROI an = new ROI();
1085 an.coord = coord;
1086 an.AddPoint(new PointD(x, y));
1087 an.type = Type.Point;
1088 an.BoundingBox = new RectangleD(x, y, selectBoxSize, selectBoxSize);
1089 return an;
1090 }
static float selectBoxSize
Definition ROI.cs:118

◆ 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
1151 {
1152 ROI an = new ROI();
1153 an.coord = coord;
1154 an.type = Type.Polygon;
1155 an.Points = new List<PointD>();
1156 an.AddPoints(pts);
1157 an.closed = true;
1158 return an;
1159 }

◆ 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.
1120 {
1121 ROI an = new ROI();
1122 an.coord = coord;
1123 an.type = Type.Rectangle;
1124 an.BoundingBox = new RectangleD(x, y, w, h);
1125 return an;
1126 }

◆ Dispose()

void BioLib.ROI.Dispose ( )
1843 {
1844 if (roiMask != null)
1845 {
1846 roiMask.Dispose();
1847 }
1848 }
void Dispose()
Definition ROI.cs:867

◆ DistanceTo()

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

◆ GetCenter()

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

◆ 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.
1605 {
1606 if (i < 0 || Points.Count == 0)
1607 return new PointD();
1608 return Points[i];
1609 }

◆ GetPointCount()

int BioLib.ROI.GetPointCount ( )

This function returns the number of points in the polygon

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

◆ GetPoints()

PointD[] BioLib.ROI.GetPoints ( )

It returns an array of PointD objects

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

◆ GetPointsF()

PointF[] BioLib.ROI.GetPointsF ( )

It converts a list of points to an array of points

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

◆ 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:
983 {
984 if (type == Type.Mask)
985 return BoundingBox;
986 double fx = scaleX / 2;
987 double fy = scaleY / 2;
988 return new RectangleD(BoundingBox.X - fx, BoundingBox.Y - fy, BoundingBox.W + scaleX, BoundingBox.H + scaleY);
989 }

◆ 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.
1066 {
1067 double f = ROI.selectBoxSize / 2;
1068 selectBoxs.Clear();
1069 for (int i = 0; i < Points.Count; i++)
1070 {
1071 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)ROI.selectBoxSize, (float)ROI.selectBoxSize));
1072 }
1073 return selectBoxs.ToArray();
1074 }

◆ 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.
1045 {
1046
1047 double f = s / 2;
1048 selectBoxs.Clear();
1049 int c = Points.Count;
1050 if (type != Type.Mask)
1051 {
1052 for (int i = 0; i < c; i++)
1053 {
1054 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)s, (float)s));
1055 }
1056 }
1057 return selectBoxs.ToArray();
1058 }

◆ 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.
1025 {
1026 if (type == Type.Rectangle || type == Type.Mask)
1027 {
1028 PointD[] pts = new PointD[4];
1029 pts[0] = Points[0];
1030 pts[1] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y);
1031 pts[2] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y + BoundingBox.H);
1032 pts[3] = new PointD(Points[0].X, Points[0].Y + BoundingBox.H);
1033 return BioImage.ToImageSpace(pts.ToList(), res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
1034 }
1035 else
1037 }
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
double PhysicalSizeX
Definition Bio.cs:219
double PhysicalSizeY
Definition Bio.cs:224
double StageSizeY
Definition Bio.cs:239
double StageSizeX
Definition Bio.cs:234

◆ 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.
1749 {
1750 string pts = "";
1751 PointD[] ps = b.ToImageSpace(Points);
1752 for (int j = 0; j < ps.Length; j++)
1753 {
1754 if (j == ps.Length - 1)
1755 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture);
1756 else
1757 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
1758 }
1759 return pts;
1760 }

◆ 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
1694 {
1695 List<PointD> inds = new List<PointD>();
1696 for (int i = 0; i < Points.Count; i++)
1697 {
1698 bool found = false;
1699 for (int ind = 0; ind < indexs.Length; ind++)
1700 {
1701 if (indexs[ind] == i)
1702 found = true;
1703 }
1704 if (!found)
1705 inds.Add(Points[i]);
1706 }
1707 Points = inds;
1709 }

◆ 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.
1727 {
1728 List<PointD> pts = new List<PointD>();
1729 string[] ints = s.Split(' ');
1730 for (int i = 0; i < ints.Length; i++)
1731 {
1732 string[] sints;
1733 if (s.Contains("\t"))
1734 sints = ints[i].Split('\t');
1735 else
1736 sints = ints[i].Split(',');
1737 double x = double.Parse(sints[0], CultureInfo.InvariantCulture);
1738 double y = double.Parse(sints[1], CultureInfo.InvariantCulture);
1739 pts.Add(new PointD(x, y));
1740 }
1741 return pts.ToArray();
1742 }

◆ ToString()

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

◆ UpdateBoundingBox()

void BioLib.ROI.UpdateBoundingBox ( )

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

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

◆ 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
1593 {
1594 if (i < Points.Count)
1595 {
1596 Points[i] = p;
1597 }
1598 }

◆ Validate()

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

Member Data Documentation

◆ closed

bool BioLib.ROI.closed = false

◆ coord

ZCT BioLib.ROI.coord

◆ family

string BioLib.ROI.family = "Times New Roman"

◆ fillColor

Color BioLib.ROI.fillColor

◆ fontSize

float BioLib.ROI.fontSize = 12

◆ id

string BioLib.ROI.id = ""

◆ isFilled

bool BioLib.ROI.isFilled = false

◆ properties

string BioLib.ROI.properties = ""

◆ roiID

string BioLib.ROI.roiID = ""

◆ roiName

string BioLib.ROI.roiName = ""

◆ SelectBoxColor

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

◆ selectBoxSize

float BioLib.ROI.selectBoxSize = 14f
static

◆ selectedPoints

List<int> BioLib.ROI.selectedPoints = new List<int>()

◆ serie

int BioLib.ROI.serie = 0

◆ shapeIndex

int BioLib.ROI.shapeIndex = 0

◆ slant

Cairo.FontSlant BioLib.ROI.slant

◆ strokeColor

Color BioLib.ROI.strokeColor

◆ strokeWidth

double BioLib.ROI.strokeWidth = 1

◆ subPixel

bool BioLib.ROI.subPixel = false

◆ type

Type BioLib.ROI.type

◆ weight

Cairo.FontWeight BioLib.ROI.weight

Property Documentation

◆ BoundingBox

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

◆ CoordSpace

CoordinateSystem BioLib.ROI.CoordSpace = CoordinateSystem.micron
getset
119{ get; set; } = CoordinateSystem.micron;
CoordinateSystem
Definition ROI.cs:101

◆ H

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

◆ Point

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

◆ Points

List<PointD> BioLib.ROI.Points
getset
122 {
123 get
124 {
125 if (pos.Count == 0)
126 Validate(false,0,0);
127 return pos;
128 }
129 set
130 {
131 pos = value;
133 }
134 }
void Validate(bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:135

◆ Resolution

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

◆ roiMask

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

◆ Selected

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

◆ Text

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

◆ W

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

◆ X

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

◆ Y

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

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