BioLib  3.9.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)
 
static ROI CreateMask (ZCT coord, Byte[] mask, int width, int height, PointD loc, double physicalX, double physicalY)
 
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 }

Constructor & Destructor Documentation

◆ ROI()

BioLib.ROI.ROI ( )
693 {
694 coord = new ZCT(0, 0, 0);
695 strokeColor = Color.Yellow;
696 BoundingBox = new RectangleD(0, 0, 1, 1);
697 }

Member Function Documentation

◆ AddPoint()

void BioLib.ROI.AddPoint ( PointD p,
bool convertPixelSpace = false,
double physX = 1,
double physY = 1 )
1336 {
1337 if(Points == null)
1338 Points = new List<PointD>();
1339 Points.Add(p);
1341 }
void UpdateBoundingBox()
Definition ROI.cs:1456

◆ 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
1374 {
1375 if (Points == null)
1376 Points = new List<PointD>();
1377 for (int i = 0; i < xp.Length; i++)
1378 {
1379 Points.Add(new PointD(xp[i], yp[i]));
1380 }
1382 }

◆ 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
1361 {
1362 if (Points == null)
1363 Points = new List<PointD>();
1364 for (int i = 0; i < xp.Length; i++)
1365 {
1366 Points.Add(new PointD(xp[i], yp[i]));
1367 }
1369 }

◆ 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
1346 {
1347 if (Points == null)
1348 Points = new List<PointD>();
1349 if (convertPixelSpace)
1350 {
1351 ConvertToMicron(physX, physY);
1352 }
1353 else
1354 Points.AddRange(p);
1356 }
void ConvertToMicron(double physX, double physY)
Definition ROI.cs:1326

◆ AddROIsToOMERO()

static int BioLib.ROI.AddROIsToOMERO ( long imageId,
long user,
BioImage b )
static
894 {
895 try
896 {
897 var gateway = OMERO.gateway;
898 var roiService = gateway.getFacility(typeof(ROIFacility)) as ROIFacility;
899 var browse = gateway.getFacility(typeof(BrowseFacility)) as BrowseFacility;
900 var ctx = OMERO.sc;
901 ImageData image = browse.getImage(ctx, imageId);
902 int count = 0;
903 ROI[] rois = b.Annotations.ToArray();
904
905 foreach (ROI an in rois)
906 {
907 ROIData roi = new ROIData();
908 ShapeData shape = null;
909
910 switch (an.type)
911 {
912 case ROI.Type.Point:
913 {
914 var pt = new omero.gateway.model.PointData(
915 b.ToImageSpaceX(an.X),
916 b.ToImageSpaceY(an.Y)
917 );
918 pt.setZ(an.coord.Z);
919 pt.setC(an.coord.C);
920 pt.setT(an.coord.T);
921 pt.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
922 shape = pt;
923 break;
924 }
925
926 case ROI.Type.Rectangle:
927 {
928 var r = new RectangleData(
929 b.ToImageSpaceX(an.BoundingBox.X),
930 b.ToImageSpaceY(an.BoundingBox.Y),
931 b.ToImageSizeX(an.W),
932 b.ToImageSizeY(an.H)
933 );
934 r.setZ(an.coord.Z);
935 r.setC(an.coord.C);
936 r.setT(an.coord.T);
937 r.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
938 shape = r;
939 break;
940 }
941
942 case ROI.Type.Ellipse:
943 {
944 double rx = b.ToImageSizeX(an.W / 2.0);
945 double ry = b.ToImageSizeY(an.H / 2.0);
946 double cx = b.ToImageSpaceX(an.Points[0].X + an.W / 2.0);
947 double cy = b.ToImageSpaceY(an.Points[0].Y + an.H / 2.0);
948
949 var e = new EllipseData(cx, cy, rx, ry);
950 e.setZ(an.coord.Z);
951 e.setC(an.coord.C);
952 e.setT(an.coord.T);
953 e.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
954 shape = e;
955 break;
956 }
957
958 case ROI.Type.Line:
959 {
960 var l = new LineData(
961 b.ToImageSpaceX(an.GetPoint(0).X),
962 b.ToImageSpaceY(an.GetPoint(0).Y),
963 b.ToImageSpaceX(an.GetPoint(1).X),
964 b.ToImageSpaceY(an.GetPoint(1).Y)
965 );
966 l.setZ(an.coord.Z);
967 l.setC(an.coord.C);
968 l.setT(an.coord.T);
969 l.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
970 shape = l;
971 break;
972 }
973
974 case ROI.Type.Polygon:
975 case ROI.Type.Freeform:
976 {
977 var pts = new List<PointD>();
978 foreach (var p in an.Points)
979 pts.Add(new PointD(
980 b.ToImageSpaceX(p.X),
981 b.ToImageSpaceY(p.Y)
982 ));
983
984 var poly = new PolygonData(BioPointToOmeroPoint(an,b));
985 poly.setZ(an.coord.Z);
986 poly.setC(an.coord.C);
987 poly.setT(an.coord.T);
988 poly.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
989 shape = poly;
990 break;
991 }
992
993 case ROI.Type.Polyline:
994 {
995 var pts = new List<PointD>();
996 foreach (var p in an.Points)
997 pts.Add(new PointD(
998 b.ToImageSpaceX(p.X),
999 b.ToImageSpaceY(p.Y)
1000 ));
1001
1002 var pl = new PolylineData(BioPointToOmeroPoint(an, b));
1003 pl.setZ(an.coord.Z);
1004 pl.setC(an.coord.C);
1005 pl.setT(an.coord.T);
1006 pl.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1007 shape = pl;
1008 break;
1009 }
1010
1011 case ROI.Type.Label:
1012 {
1013 var t = new TextData(
1014 string.IsNullOrEmpty(an.Text) ? "Label" : an.Text,
1015 b.ToImageSpaceX(an.BoundingBox.X),
1016 b.ToImageSpaceY(an.BoundingBox.Y)
1017 );
1018 //t.setFontSize(new omero.model.LengthI(an.fontSize, omero.model.enums.UnitsLength.PIXEL));
1019 t.setZ(an.coord.Z);
1020 t.setC(an.coord.C);
1021 t.setT(an.coord.T);
1022 shape = t;
1023 break;
1024 }
1025
1026 case ROI.Type.Mask:
1027 {
1028 if (an.roiMask == null)
1029 continue;
1030
1031 var m = new MaskData(
1032 an.roiMask.X,
1033 an.roiMask.Y,
1034 an.roiMask.Width,
1035 an.roiMask.Height,
1036 an.roiMask.GetBytes()
1037 );
1038
1039 m.setZ(an.coord.Z);
1040 m.setC(an.coord.C);
1041 m.setT(an.coord.T);
1042 m.setText(string.IsNullOrEmpty(an.Text) ? an.id : an.Text);
1043 shape = m;
1044 break;
1045 }
1046 }
1047
1048 if (shape == null)
1049 continue;
1050 // Apply stroke/fill
1051 shape.getShapeSettings().setStroke(new java.awt.Color(
1052 an.strokeColor.A,
1053 an.strokeColor.R,
1054 an.strokeColor.G,
1055 an.strokeColor.B
1056 ));
1057
1058 shape.getShapeSettings().setFill(new java.awt.Color(
1059 an.fillColor.A,
1060 an.fillColor.R,
1061 an.fillColor.G,
1062 an.fillColor.B
1063 ));
1064
1065 shape.getShapeSettings().setStrokeWidth(
1066 new omero.model.LengthI(an.strokeWidth, omero.model.enums.UnitsLength.PIXEL)
1067 );
1068
1069 roi.addShapeData(shape);
1070
1071 // ----- Save ROI to OMERO -----
1072 java.util.List roiList = new java.util.ArrayList();
1073 roiList.add(roi);
1074
1075 var saved = roiService.saveROIs(ctx, imageId, user, roiList);
1076 count++;
1077
1078 }
1079
1080 Console.WriteLine($"Added {count} ROIs to OMERO image {imageId}");
1081 return count;
1082 }
1083 catch (Exception ex)
1084 {
1085 Console.WriteLine("Error adding ROIs: " + ex);
1086 return 0;
1087 }
1088 }
double ToImageSpaceY(double y)
Definition Bio.cs:3381
double ToImageSizeX(double d)
Convert a physical size to an image size.
Definition Bio.cs:3351
double ToImageSizeY(double d)
Convert a physical size in Y direction to an image size in Y direction.
Definition Bio.cs:3361
double ToImageSpaceX(double x)
Definition Bio.cs:3370
Definition OMERO.cs:32
Definition ROI.cs:27
PointD GetPoint(int i)
Definition ROI.cs:1297

◆ BioPointToOmeroPoint()

static java.util.List BioLib.ROI.BioPointToOmeroPoint ( ROI r,
BioImage b )
static
1090 {
1091 // Create Java list, NOT C# list
1092 java.util.List javaPts = new java.util.ArrayList();
1093 foreach (var p in r.Points)
1094 {
1095 // Create Java Point2D.Double for OMERO
1096 var jp = new java.awt.geom.Point2D.Double(
1097 b.ToImageSpaceX(p.X),
1098 b.ToImageSpaceY(p.Y)
1099 );
1100 javaPts.add(jp);
1101 }
1102 return javaPts;
1103 }

◆ ByteArrayToBitmap()

SKBitmap BioLib.ROI.ByteArrayToBitmap ( byte[] imageBytes)
699 {
700 if (imageBytes == null || imageBytes.Length == 0)
701 return null;
702
703 using var ms = new SKMemoryStream(imageBytes);
704 return SKBitmap.Decode(ms);
705 }

◆ ClearPoints()

void BioLib.ROI.ClearPoints ( )
1404 {
1405 Points.Clear();
1406 }

◆ 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
1327 {
1328 List<PointD> points = new List<PointD>();
1329 for (int i = 0; i < Points.Count; i++)
1330 {
1331 points.Add(new PointD(Points[i].X * physX, Points[i].Y * physY));
1332 }
1333 Points = points;
1334 }

◆ Copy() [1/2]

ROI BioLib.ROI.Copy ( )
605 {
606 ROI copy = new ROI();
607 copy.id = id;
608 copy.roiID = roiID;
609 copy.roiName = roiName;
610 copy.text = text;
611 copy.strokeWidth = strokeWidth;
612 copy.strokeColor = strokeColor;
613 copy.fillColor = fillColor;
614 copy.Points = Points;
615 copy.Selected = Selected;
616 copy.shapeIndex = shapeIndex;
617 copy.closed = closed;
618 copy.family = family;
619 copy.fontSize = fontSize;
620 copy.slant = slant;
621 copy.selectBoxs = selectBoxs;
622 copy.BoundingBox = BoundingBox;
623 copy.isFilled = isFilled;
624 copy.coord = coord;
625 copy.selectedPoints = selectedPoints;
626
627 return copy;
628 }

◆ Copy() [2/2]

ROI BioLib.ROI.Copy ( ZCT cord)
630 {
631 ROI copy = new ROI();
632 copy.type = type;
633 copy.id = id;
634 copy.roiID = roiID;
635 copy.roiName = roiName;
636 copy.text = text;
637 copy.strokeWidth = strokeWidth;
638 copy.strokeColor = strokeColor;
639 copy.fillColor = fillColor;
640 copy.Points.AddRange(Points);
641 copy.Selected = Selected;
642 copy.shapeIndex = shapeIndex;
643 copy.closed = closed;
644 copy.family = family;
645 copy.fontSize = fontSize;
646 copy.slant = slant;
647 copy.selectBoxs.AddRange(selectBoxs);
648 copy.BoundingBox = BoundingBox;
649 copy.isFilled = isFilled;
650 copy.coord = cord;
651 copy.selectedPoints = selectedPoints;
652 return copy;
653 }

◆ 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.
830 {
831 ROI an = new ROI();
832 an.coord = coord;
833 an.type = Type.Ellipse;
834 an.BoundingBox = new RectangleD(x, y, w, h);
835 return an;
836 }

◆ 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.
860 {
861 ROI an = new ROI();
862 an.coord = coord;
863 an.type = Type.Freeform;
864 an.AddPoints(pts);
865 an.closed = true;
866 return an;
867 }
void AddPoints(PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1345

◆ 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.
793 {
794 ROI an = new ROI();
795 an.Points = new List<PointD>();
796 an.coord = coord;
797 an.type = Type.Line;
798 an.Points.Add(x1);
799 an.Points.Add(x2);
801 return an;
802 }

◆ CreateMask() [1/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
Byte[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY )
static
879 {
880 ROI an = new ROI();
881 an.coord = coord;
882 an.type = Type.Mask;
883 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y);
884 an.AddPoint(loc);
885 an.BoundingBox = new RectangleD(loc.X + (an.roiMask.X * an.roiMask.PhysicalSizeX), loc.Y + (an.roiMask.Y * an.roiMask.PhysicalSizeY), width, height);
886 return an;
887 }

◆ CreateMask() [2/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
float[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY )
static
869 {
870 ROI an = new ROI();
871 an.coord = coord;
872 an.type = Type.Mask;
873 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y);
874 an.AddPoint(loc);
875 an.BoundingBox = new RectangleD(loc.X + (an.roiMask.X * an.roiMask.PhysicalSizeX), loc.Y + (an.roiMask.Y * an.roiMask.PhysicalSizeY), width, height);
876 return an;
877 }

◆ 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
776 {
777 ROI an = new ROI();
778 an.coord = coord;
779 an.AddPoint(new PointD(x, y));
780 an.type = Type.Point;
781 an.BoundingBox = new RectangleD(x, y, selectBoxSize, selectBoxSize);
782 return an;
783 }

◆ 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
844 {
845 ROI an = new ROI();
846 an.coord = coord;
847 an.type = Type.Polygon;
848 an.Points = new List<PointD>();
849 an.AddPoints(pts);
850 an.closed = true;
851 return an;
852 }

◆ 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.
813 {
814 ROI an = new ROI();
815 an.coord = coord;
816 an.type = Type.Rectangle;
817 an.BoundingBox = new RectangleD(x, y, w, h);
818 return an;
819 }

◆ Dispose()

void BioLib.ROI.Dispose ( )
1536 {
1537 if (roiMask != null)
1538 {
1539 roiMask.Dispose();
1540 }
1541 }

◆ DistanceTo()

double BioLib.ROI.DistanceTo ( PointD point)
1276 {
1277 var center = GetCenter();
1278 return (float)Math.Sqrt(Math.Pow(center.X - point.X, 2) + Math.Pow(center.Y - point.Y, 2));
1279 }

◆ GetCenter()

PointD BioLib.ROI.GetCenter ( )
890 {
891 return new PointD(BoundingBox.X + (BoundingBox.W / 2.0), BoundingBox.Y + (BoundingBox.H / 2.0));
892 }

◆ 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.
1298 {
1299 if (i < 0 || Points.Count == 0)
1300 return new PointD();
1301 return Points[i];
1302 }

◆ GetPointCount()

int BioLib.ROI.GetPointCount ( )

This function returns the number of points in the polygon

Returns
The number of points in the list.
1411 {
1412 return Points.Count;
1413 }

◆ GetPoints()

PointD[] BioLib.ROI.GetPoints ( )

It returns an array of PointD objects

Returns
An array of PointD objects.
1307 {
1308 return Points.ToArray();
1309 }

◆ GetPointsF()

PointF[] BioLib.ROI.GetPointsF ( )

It converts a list of points to an array of points

Returns
A PointF array.
1314 {
1315 PointF[] pfs = new PointF[Points.Count];
1316 for (int i = 0; i < Points.Count; i++)
1317 {
1318 pfs[i].X = (float)Points[i].X;
1319 pfs[i].Y = (float)Points[i].Y;
1320 }
1321 return pfs;
1322 }

◆ 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:
676 {
677 if (type == Type.Mask)
678 return BoundingBox;
679 double fx = scaleX / 2;
680 double fy = scaleY / 2;
681 return new RectangleD(BoundingBox.X - fx, BoundingBox.Y - fy, BoundingBox.W + scaleX, BoundingBox.H + scaleY);
682 }

◆ 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.
759 {
760 double f = ROI.selectBoxSize / 2;
761 selectBoxs.Clear();
762 for (int i = 0; i < Points.Count; i++)
763 {
764 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)ROI.selectBoxSize, (float)ROI.selectBoxSize));
765 }
766 return selectBoxs.ToArray();
767 }

◆ 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.
738 {
739
740 double f = s / 2;
741 selectBoxs.Clear();
742 int c = Points.Count;
743 if (type != Type.Mask)
744 {
745 for (int i = 0; i < c; i++)
746 {
747 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)s, (float)s));
748 }
749 }
750 return selectBoxs.ToArray();
751 }

◆ 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.
718 {
719 if (type == Type.Rectangle || type == Type.Mask)
720 {
721 PointD[] pts = new PointD[4];
722 pts[0] = Points[0];
723 pts[1] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y);
724 pts[2] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y + BoundingBox.H);
725 pts[3] = new PointD(Points[0].X, Points[0].Y + BoundingBox.H);
726 return BioImage.ToImageSpace(pts.ToList(), res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
727 }
728 else
729 return BioImage.ToImageSpace(Points, res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
730 }
Definition Bio.cs:1861
PointD ToImageSpace(PointD p)
Convert a point in the stage coordinate system to a point in the image coordinate system.
Definition Bio.cs:3392

◆ 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.
1442 {
1443 string pts = "";
1444 PointD[] ps = b.ToImageSpace(Points);
1445 for (int j = 0; j < ps.Length; j++)
1446 {
1447 if (j == ps.Length - 1)
1448 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture);
1449 else
1450 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
1451 }
1452 return pts;
1453 }

◆ 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
1387 {
1388 List<PointD> inds = new List<PointD>();
1389 for (int i = 0; i < Points.Count; i++)
1390 {
1391 bool found = false;
1392 for (int ind = 0; ind < indexs.Length; ind++)
1393 {
1394 if (indexs[ind] == i)
1395 found = true;
1396 }
1397 if (!found)
1398 inds.Add(Points[i]);
1399 }
1400 Points = inds;
1402 }

◆ 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.
1420 {
1421 List<PointD> pts = new List<PointD>();
1422 string[] ints = s.Split(' ');
1423 for (int i = 0; i < ints.Length; i++)
1424 {
1425 string[] sints;
1426 if (s.Contains("\t"))
1427 sints = ints[i].Split('\t');
1428 else
1429 sints = ints[i].Split(',');
1430 double x = double.Parse(sints[0], CultureInfo.InvariantCulture);
1431 double y = double.Parse(sints[1], CultureInfo.InvariantCulture);
1432 pts.Add(new PointD(x, y));
1433 }
1434 return pts.ToArray();
1435 }

◆ ToString()

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

◆ UpdateBoundingBox()

void BioLib.ROI.UpdateBoundingBox ( )

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

1457 {
1458 // Safety check
1459 if ((Points == null || Points.Count == 0) && type != Type.Mask)
1460 {
1461 BoundingBox = new RectangleD(0, 0, 0, 0);
1462 return;
1463 }
1464
1465 // -----------------------------
1466 // 1) MASK ROI MODE
1467 // -----------------------------
1468 if (type == Type.Mask && roiMask != null)
1469 {
1470 double minX = double.PositiveInfinity;
1471 double minY = double.PositiveInfinity;
1472 double maxX = double.NegativeInfinity;
1473 double maxY = double.NegativeInfinity;
1474
1475 for (int y = 0; y < roiMask.Height; y++)
1476 {
1477 for (int x = 0; x < roiMask.Width; x++)
1478 {
1479 if (!roiMask.IsSelected(x, y))
1480 continue;
1481
1482 if (x < minX) minX = x;
1483 if (y < minY) minY = y;
1484 if (x > maxX) maxX = x;
1485 if (y > maxY) maxY = y;
1486 }
1487 }
1488
1489 // No selected pixels
1490 if (double.IsInfinity(minX))
1491 {
1492 BoundingBox = new RectangleD(0, 0, 0, 0);
1493 return;
1494 }
1495
1496 // Mask bounding box IN PHYSICAL COORDINATES
1497 double physX = roiMask.X + minX * roiMask.PhysicalSizeX;
1498 double physY = roiMask.Y + minY * roiMask.PhysicalSizeY;
1499
1500 double physW = (maxX - minX + 1) * roiMask.PhysicalSizeX;
1501 double physH = (maxY - minY + 1) * roiMask.PhysicalSizeY;
1502
1503 BoundingBox = new RectangleD(physX, physY, physW, physH);
1504 return;
1505 }
1506
1507 // -----------------------------
1508 // 2) POINT-BASED ROI MODE
1509 // -----------------------------
1510 double minPX = double.PositiveInfinity;
1511 double minPY = double.PositiveInfinity;
1512 double maxPX = double.NegativeInfinity;
1513 double maxPY = double.NegativeInfinity;
1514
1515 foreach (var p in Points)
1516 {
1517 if (p.X < minPX) minPX = p.X;
1518 if (p.Y < minPY) minPY = p.Y;
1519 if (p.X > maxPX) maxPX = p.X;
1520 if (p.Y > maxPY) maxPY = p.Y;
1521 }
1522
1523 // Build bounding rectangle
1524 BoundingBox = new RectangleD(
1525 minPX,
1526 minPY,
1527 maxPX - minPX,
1528 maxPY - minPY
1529 );
1530 }

◆ 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
1286 {
1287 if (i < Points.Count)
1288 {
1289 Points[i] = p;
1290 }
1291 }

◆ 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
655 {
656 get
657 {
658 return text;
659 }
660 set
661 {
662 text = value;
663 if (type == Type.Label)
664 {
666 }
667 }
668 }

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