BioLib  3.7.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 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 AddPoint (PointD p)
 
void AddPoints (PointD[] p)
 
void AddPoints (int[] xp, int[] yp)
 
void AddPoints (float[] xp, float[] yp)
 
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]
 
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 ( )
678 {
679 coord = new ZCT(0, 0, 0);
680 strokeColor = Color.Yellow;
681 BoundingBox = new RectangleD(0, 0, 1, 1);
682 }

Member Function Documentation

◆ AddPoint()

void BioLib.ROI.AddPoint ( PointD p)

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

Parameters
PointD
1312 {
1313 if(Points == null)
1314 Points = new List<PointD>();
1315 Points.Add(p);
1317 }
void UpdateBoundingBox()
Definition ROI.cs:1427

◆ AddPoints() [1/3]

void BioLib.ROI.AddPoints ( float[] xp,
float[] yp )

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

Parameters
pThe points to add to the polygon
1345 {
1346 if (Points == null)
1347 Points = new List<PointD>();
1348 for (int i = 0; i < xp.Length; i++)
1349 {
1350 Points.Add(new PointD(xp[i], yp[i]));
1351 }
1353 }

◆ AddPoints() [2/3]

void BioLib.ROI.AddPoints ( int[] xp,
int[] yp )

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

Parameters
pThe points to add to the polygon
1332 {
1333 if (Points == null)
1334 Points = new List<PointD>();
1335 for (int i = 0; i < xp.Length; i++)
1336 {
1337 Points.Add(new PointD(xp[i], yp[i]));
1338 }
1340 }

◆ AddPoints() [3/3]

void BioLib.ROI.AddPoints ( PointD[] p)

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

Parameters
pThe points to add to the polygon
1322 {
1323 if (Points == null)
1324 Points = new List<PointD>();
1325 Points.AddRange(p);
1327 }

◆ AddROIsToOMERO()

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

◆ BioPointToOmeroPoint()

static java.util.List BioLib.ROI.BioPointToOmeroPoint ( ROI r,
BioImage b )
static
1075 {
1076 // Create Java list, NOT C# list
1077 java.util.List javaPts = new java.util.ArrayList();
1078 foreach (var p in r.Points)
1079 {
1080 // Create Java Point2D.Double for OMERO
1081 var jp = new java.awt.geom.Point2D.Double(
1082 b.ToImageSpaceX(p.X),
1083 b.ToImageSpaceY(p.Y)
1084 );
1085 javaPts.add(jp);
1086 }
1087 return javaPts;
1088 }

◆ ByteArrayToBitmap()

SKBitmap BioLib.ROI.ByteArrayToBitmap ( byte[] imageBytes)
684 {
685 if (imageBytes == null || imageBytes.Length == 0)
686 return null;
687
688 using var ms = new SKMemoryStream(imageBytes);
689 return SKBitmap.Decode(ms);
690 }

◆ ClearPoints()

void BioLib.ROI.ClearPoints ( )
1375 {
1376 Points.Clear();
1377 }

◆ Contains()

bool BioLib.ROI.Contains ( PointD p)
157 {
158 return (p.X >= X &&
159 p.X <= X + W &&
160 p.Y >= Y &&
161 p.Y <= Y + H);
162 }

◆ Copy() [1/2]

ROI BioLib.ROI.Copy ( )
590 {
591 ROI copy = new ROI();
592 copy.id = id;
593 copy.roiID = roiID;
594 copy.roiName = roiName;
595 copy.text = text;
596 copy.strokeWidth = strokeWidth;
597 copy.strokeColor = strokeColor;
598 copy.fillColor = fillColor;
599 copy.Points = Points;
600 copy.Selected = Selected;
601 copy.shapeIndex = shapeIndex;
602 copy.closed = closed;
603 copy.family = family;
604 copy.fontSize = fontSize;
605 copy.slant = slant;
606 copy.selectBoxs = selectBoxs;
607 copy.BoundingBox = BoundingBox;
608 copy.isFilled = isFilled;
609 copy.coord = coord;
610 copy.selectedPoints = selectedPoints;
611
612 return copy;
613 }

◆ Copy() [2/2]

ROI BioLib.ROI.Copy ( ZCT cord)
615 {
616 ROI copy = new ROI();
617 copy.type = type;
618 copy.id = id;
619 copy.roiID = roiID;
620 copy.roiName = roiName;
621 copy.text = text;
622 copy.strokeWidth = strokeWidth;
623 copy.strokeColor = strokeColor;
624 copy.fillColor = fillColor;
625 copy.Points.AddRange(Points);
626 copy.Selected = Selected;
627 copy.shapeIndex = shapeIndex;
628 copy.closed = closed;
629 copy.family = family;
630 copy.fontSize = fontSize;
631 copy.slant = slant;
632 copy.selectBoxs.AddRange(selectBoxs);
633 copy.BoundingBox = BoundingBox;
634 copy.isFilled = isFilled;
635 copy.coord = cord;
636 copy.selectedPoints = selectedPoints;
637 return copy;
638 }

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

◆ 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.
845 {
846 ROI an = new ROI();
847 an.coord = coord;
848 an.type = Type.Freeform;
849 an.AddPoints(pts);
850 an.closed = true;
851 return an;
852 }
void AddPoints(PointD[] p)
Definition ROI.cs:1321

◆ 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.
778 {
779 ROI an = new ROI();
780 an.Points = new List<PointD>();
781 an.coord = coord;
782 an.type = Type.Line;
783 an.Points.Add(x1);
784 an.Points.Add(x2);
786 return an;
787 }

◆ CreateMask() [1/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
Byte[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY )
static
864 {
865 ROI an = new ROI();
866 an.coord = coord;
867 an.type = Type.Mask;
868 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y);
869 an.AddPoint(loc);
870 an.BoundingBox = new RectangleD(loc.X + (an.roiMask.X * an.roiMask.PhysicalSizeX), loc.Y + (an.roiMask.Y * an.roiMask.PhysicalSizeY), width, height);
871 return an;
872 }
void AddPoint(PointD p)
Definition ROI.cs:1311

◆ CreateMask() [2/2]

static ROI BioLib.ROI.CreateMask ( ZCT coord,
float[] mask,
int width,
int height,
PointD loc,
double physicalX,
double physicalY )
static
854 {
855 ROI an = new ROI();
856 an.coord = coord;
857 an.type = Type.Mask;
858 an.roiMask = new Mask(mask, width, height, physicalX, physicalY, loc.X, loc.Y);
859 an.AddPoint(loc);
860 an.BoundingBox = new RectangleD(loc.X + (an.roiMask.X * an.roiMask.PhysicalSizeX), loc.Y + (an.roiMask.Y * an.roiMask.PhysicalSizeY), width, height);
861 return an;
862 }

◆ 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
761 {
762 ROI an = new ROI();
763 an.coord = coord;
764 an.AddPoint(new PointD(x, y));
765 an.type = Type.Point;
766 an.BoundingBox = new RectangleD(x, y, selectBoxSize, selectBoxSize);
767 return an;
768 }

◆ 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
829 {
830 ROI an = new ROI();
831 an.coord = coord;
832 an.type = Type.Polygon;
833 an.Points = new List<PointD>();
834 an.AddPoints(pts);
835 an.closed = true;
836 return an;
837 }

◆ 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.
798 {
799 ROI an = new ROI();
800 an.coord = coord;
801 an.type = Type.Rectangle;
802 an.BoundingBox = new RectangleD(x, y, w, h);
803 return an;
804 }

◆ Dispose()

void BioLib.ROI.Dispose ( )
1507 {
1508 if (roiMask != null)
1509 {
1510 roiMask.Dispose();
1511 }
1512 }

◆ DistanceTo()

double BioLib.ROI.DistanceTo ( PointD point)
1261 {
1262 var center = GetCenter();
1263 return (float)Math.Sqrt(Math.Pow(center.X - point.X, 2) + Math.Pow(center.Y - point.Y, 2));
1264 }

◆ GetCenter()

PointD BioLib.ROI.GetCenter ( )
875 {
876 return new PointD(BoundingBox.X + (BoundingBox.W / 2.0), BoundingBox.Y + (BoundingBox.H / 2.0));
877 }

◆ 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.
1283 {
1284 if (i < 0 || Points.Count == 0)
1285 return new PointD();
1286 return Points[i];
1287 }

◆ GetPointCount()

int BioLib.ROI.GetPointCount ( )

This function returns the number of points in the polygon

Returns
The number of points in the list.
1382 {
1383 return Points.Count;
1384 }

◆ GetPoints()

PointD[] BioLib.ROI.GetPoints ( )

It returns an array of PointD objects

Returns
An array of PointD objects.
1292 {
1293 return Points.ToArray();
1294 }

◆ GetPointsF()

PointF[] BioLib.ROI.GetPointsF ( )

It converts a list of points to an array of points

Returns
A PointF array.
1299 {
1300 PointF[] pfs = new PointF[Points.Count];
1301 for (int i = 0; i < Points.Count; i++)
1302 {
1303 pfs[i].X = (float)Points[i].X;
1304 pfs[i].Y = (float)Points[i].Y;
1305 }
1306 return pfs;
1307 }

◆ 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:
661 {
662 if (type == Type.Mask)
663 return BoundingBox;
664 double fx = scaleX / 2;
665 double fy = scaleY / 2;
666 return new RectangleD(BoundingBox.X - fx, BoundingBox.Y - fy, BoundingBox.W + scaleX, BoundingBox.H + scaleY);
667 }

◆ 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.
744 {
745 double f = ROI.selectBoxSize / 2;
746 selectBoxs.Clear();
747 for (int i = 0; i < Points.Count; i++)
748 {
749 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)ROI.selectBoxSize, (float)ROI.selectBoxSize));
750 }
751 return selectBoxs.ToArray();
752 }

◆ 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.
723 {
724
725 double f = s / 2;
726 selectBoxs.Clear();
727 int c = Points.Count;
728 if (type != Type.Mask)
729 {
730 for (int i = 0; i < c; i++)
731 {
732 selectBoxs.Add(new RectangleD((float)(Points[i].X - f), (float)(Points[i].Y - f), (float)s, (float)s));
733 }
734 }
735 return selectBoxs.ToArray();
736 }

◆ 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.
703 {
704 if (type == Type.Rectangle || type == Type.Mask)
705 {
706 PointD[] pts = new PointD[4];
707 pts[0] = Points[0];
708 pts[1] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y);
709 pts[2] = new PointD(Points[0].X + BoundingBox.W, Points[0].Y + BoundingBox.H);
710 pts[3] = new PointD(Points[0].X, Points[0].Y + BoundingBox.H);
711 return BioImage.ToImageSpace(pts.ToList(), res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
712 }
713 else
714 return BioImage.ToImageSpace(Points, res.StageSizeX, res.StageSizeY, res.PhysicalSizeX, res.PhysicalSizeY);
715 }
Definition Bio.cs:1849
PointD ToImageSpace(PointD p)
Convert a point in the stage coordinate system to a point in the image coordinate system.
Definition Bio.cs:3326

◆ 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.
1413 {
1414 string pts = "";
1415 PointD[] ps = b.ToImageSpace(Points);
1416 for (int j = 0; j < ps.Length; j++)
1417 {
1418 if (j == ps.Length - 1)
1419 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture);
1420 else
1421 pts += ps[j].X.ToString(CultureInfo.InvariantCulture) + "," + ps[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
1422 }
1423 return pts;
1424 }

◆ 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
1358 {
1359 List<PointD> inds = new List<PointD>();
1360 for (int i = 0; i < Points.Count; i++)
1361 {
1362 bool found = false;
1363 for (int ind = 0; ind < indexs.Length; ind++)
1364 {
1365 if (indexs[ind] == i)
1366 found = true;
1367 }
1368 if (!found)
1369 inds.Add(Points[i]);
1370 }
1371 Points = inds;
1373 }

◆ 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.
1391 {
1392 List<PointD> pts = new List<PointD>();
1393 string[] ints = s.Split(' ');
1394 for (int i = 0; i < ints.Length; i++)
1395 {
1396 string[] sints;
1397 if (s.Contains("\t"))
1398 sints = ints[i].Split('\t');
1399 else
1400 sints = ints[i].Split(',');
1401 double x = double.Parse(sints[0], CultureInfo.InvariantCulture);
1402 double y = double.Parse(sints[1], CultureInfo.InvariantCulture);
1403 pts.Add(new PointD(x, y));
1404 }
1405 return pts.ToArray();
1406 }

◆ ToString()

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

◆ UpdateBoundingBox()

void BioLib.ROI.UpdateBoundingBox ( )

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

1428 {
1429 // Safety check
1430 if ((Points == null || Points.Count == 0) && type != Type.Mask)
1431 {
1432 BoundingBox = new RectangleD(0, 0, 0, 0);
1433 return;
1434 }
1435
1436 // -----------------------------
1437 // 1) MASK ROI MODE
1438 // -----------------------------
1439 if (type == Type.Mask && roiMask != null)
1440 {
1441 double minX = double.PositiveInfinity;
1442 double minY = double.PositiveInfinity;
1443 double maxX = double.NegativeInfinity;
1444 double maxY = double.NegativeInfinity;
1445
1446 for (int y = 0; y < roiMask.Height; y++)
1447 {
1448 for (int x = 0; x < roiMask.Width; x++)
1449 {
1450 if (!roiMask.IsSelected(x, y))
1451 continue;
1452
1453 if (x < minX) minX = x;
1454 if (y < minY) minY = y;
1455 if (x > maxX) maxX = x;
1456 if (y > maxY) maxY = y;
1457 }
1458 }
1459
1460 // No selected pixels
1461 if (double.IsInfinity(minX))
1462 {
1463 BoundingBox = new RectangleD(0, 0, 0, 0);
1464 return;
1465 }
1466
1467 // Mask bounding box IN PHYSICAL COORDINATES
1468 double physX = roiMask.X + minX * roiMask.PhysicalSizeX;
1469 double physY = roiMask.Y + minY * roiMask.PhysicalSizeY;
1470
1471 double physW = (maxX - minX + 1) * roiMask.PhysicalSizeX;
1472 double physH = (maxY - minY + 1) * roiMask.PhysicalSizeY;
1473
1474 BoundingBox = new RectangleD(physX, physY, physW, physH);
1475 return;
1476 }
1477
1478 // -----------------------------
1479 // 2) POINT-BASED ROI MODE
1480 // -----------------------------
1481 double minPX = double.PositiveInfinity;
1482 double minPY = double.PositiveInfinity;
1483 double maxPX = double.NegativeInfinity;
1484 double maxPY = double.NegativeInfinity;
1485
1486 foreach (var p in Points)
1487 {
1488 if (p.X < minPX) minPX = p.X;
1489 if (p.Y < minPY) minPY = p.Y;
1490 if (p.X > maxPX) maxPX = p.X;
1491 if (p.Y > maxPY) maxPY = p.Y;
1492 }
1493
1494 // Build bounding rectangle
1495 BoundingBox = new RectangleD(
1496 minPX,
1497 minPY,
1498 maxPX - minPX,
1499 maxPY - minPY
1500 );
1501 }

◆ 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
1271 {
1272 if (i < Points.Count)
1273 {
1274 Points[i] = p;
1275 }
1276 }

◆ Validate()

void BioLib.ROI.Validate ( )
126 {
127 // Ensure pos exists
128 if (pos == null)
129 pos = new List<PointD>();
130 else
131 pos.Clear();
132
133 switch (type)
134 {
135 case Type.Rectangle:
136 case Type.Ellipse:
137 // 4 corners derived from the bounding box
138 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y));
139 pos.Add(new PointD(BoundingBox.X + BoundingBox.W, BoundingBox.Y));
140 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y + BoundingBox.H));
141 pos.Add(new PointD(BoundingBox.X + BoundingBox.W, BoundingBox.Y + BoundingBox.H));
142 break;
143
144 case Type.Point:
145 case Type.Label:
146 // Only the anchor point (top-left of bounding box)
147 pos.Add(new PointD(BoundingBox.X, BoundingBox.Y));
148 break;
149 default:
150 // Other ROI types keep their existing point data
151 // (Freeform, Polyline, Polygon, Mask, etc.)
152 break;
153 }
154 }

Member Data Documentation

◆ SelectBoxColor

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

Property Documentation

◆ BoundingBox

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

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

◆ Points

List<PointD> BioLib.ROI.Points
getset
112 {
113 get
114 {
115 if (pos.Count == 0)
116 Validate();
117 return pos;
118 }
119 set
120 {
121 pos = value;
123 }
124 }

◆ Resolution

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

◆ roiMask

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

◆ Selected

bool BioLib.ROI.Selected
getset
186 {
187 get { return selected; }
188 set
189 {
190 if (roiMask != null)
191 roiMask.Selected = value;
192 selected = value;
193 if (!selected)
194 selectedPoints.Clear();
195 }
196 }

◆ Text

string BioLib.ROI.Text
getset
640 {
641 get
642 {
643 return text;
644 }
645 set
646 {
647 text = value;
648 if (type == Type.Label)
649 {
651 }
652 }
653 }

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