BioGTK  6.0.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
All Classes Namespaces Functions
BioGTK.Transforms Class Reference

Public Member Functions

 Transforms (int target_length)
 
float[] ApplyImage (Bitmap b)
 
PointPromotion ApplyCoords (PointPromotion org_point, int orgw, int orgh)
 
BoxPromotion ApplyBox (BoxPromotion org_box, int orgw, int orgh)
 

Detailed Description

Definition at line 14 of file Transforms.cs.

Constructor & Destructor Documentation

◆ Transforms()

BioGTK.Transforms.Transforms ( int target_length)

Definition at line 16 of file Transforms.cs.

17 {
18 this.mTargetLength = target_length;
19 }

Member Function Documentation

◆ ApplyBox()

BoxPromotion BioGTK.Transforms.ApplyBox ( BoxPromotion org_box,
int orgw,
int orgh )

The function ApplyBox takes a BoxPromotion object, along with its original width and height, and applies coordinate transformations to return a new BoxPromotion object.

Parameters
BoxPromotionThe BoxPromotion class represents a box with coordinates for the top-left and bottom-right corners.
orgwThe orgw parameter represents the original width of the box.
orghThe parameter "orgh" represents the original height of the box.
Returns
The method is returning a BoxPromotion object.

Definition at line 148 of file Transforms.cs.

149 {
150 BoxPromotion box = new BoxPromotion();
151
152 PointPromotion left = this.ApplyCoords((org_box as BoxPromotion).mLeftUp, orgw, orgh);
153 PointPromotion lefrightt = this.ApplyCoords((org_box as BoxPromotion).mRightBottom, orgw, orgh);
154
155 box.mLeftUp = left;
156 box.mRightBottom = lefrightt;
157 return box;
158 }
PointPromotion ApplyCoords(PointPromotion org_point, int orgw, int orgh)

◆ ApplyCoords()

PointPromotion BioGTK.Transforms.ApplyCoords ( PointPromotion org_point,
int orgw,
int orgh )

The function takes in a point and its original width and height, applies a scaling factor based on a target length, and returns a new point with adjusted coordinates.

Parameters
PointPromotionPointPromotion is a class that represents a point with additional properties related to promotions. It has properties like X and Y coordinates, and an Optype property.
orgwThe original width of the shape.
orghThe parameter "orgh" represents the original height of the shape.
Returns
The method is returning a new instance of the PointPromotion class, which is assigned to the variable newpointp.

Definition at line 126 of file Transforms.cs.

127 {
128 int neww = 0;
129 int newh = 0;
130 this.GetPreprocessShape(orgw, orgh, this.mTargetLength, ref neww, ref newh);
131 PointPromotion newpointp = new PointPromotion(org_point.foreGround);
132 float scalx = (float)neww / (float)orgw;
133 float scaly = (float)newh / (float)orgh;
134 newpointp.X = (int)(org_point.X * scalx);
135 newpointp.Y = (int)(org_point.Y * scaly);
136
137 return newpointp;
138 }

◆ ApplyImage()

float[] BioGTK.Transforms.ApplyImage ( Bitmap b)

The function takes a BioImage object, resizes it, calculates the mean and standard deviation of each channel, and returns a transformed image.

Parameters
BioImageThe BioImage parameter represents an image object that contains the image data. It likely has properties such as SizeX and SizeY, which represent the width and height of the image, respectively.
Returns
The method is returning a float array called "transformedImg".

Definition at line 29 of file Transforms.cs.

30 {
31 int neww = 0;
32 int newh = 0;
33 if(SAM.SAM2 && MicroSAM.theSingleton == null)
34 {
35 neww = 1024;
36 newh = 1024;
37 }
38 else
39 this.GetPreprocessShape(b.SizeX, b.SizeY, this.mTargetLength, ref neww, ref newh);
40
41 float[,,] resizeImg = this.Resize(b,neww,newh);
42
43 float[] means = new float[resizeImg.GetLength(0)];
44 for (int i = 0; i < resizeImg.GetLength(0); i++)
45 {
46 float[] data = new float[resizeImg.GetLength(1) * resizeImg.GetLength(2)];
47 for (int j = 0; j < resizeImg.GetLength(1); j++)
48 {
49 for (int k = 0; k < resizeImg.GetLength(2); k++)
50 {
51 data[j * resizeImg.GetLength(2) + k] = resizeImg[i, j, k];
52 }
53 }
54 means[i] = (float)MathNet.Numerics.Statistics.Statistics.Mean(data);
55 }
56
57 float[] stdDev = new float[resizeImg.GetLength(0)];
58 for (int i = 0; i < resizeImg.GetLength(0); i++)
59 {
60 float[] data = new float[resizeImg.GetLength(1) * resizeImg.GetLength(2)];
61 for (int j = 0; j < resizeImg.GetLength(1); j++)
62 {
63 for (int k = 0; k < resizeImg.GetLength(2); k++)
64 {
65 data[j * resizeImg.GetLength(2) + k] = resizeImg[i, j, k];
66 }
67 }
68 stdDev[i] = (float)MathNet.Numerics.Statistics.Statistics.StandardDeviation(data);
69 }
70
71
72 float[] transformedImg = new float[3 * this.mTargetLength * this.mTargetLength];
73 for (int i = 0; i < neww; i++)
74 {
75 for (int j = 0; j < newh; j++)
76 {
77 int index = j * this.mTargetLength + i;
78 transformedImg[index] = (resizeImg[0, i, j] - means[0]) / stdDev[0];
79 transformedImg[this.mTargetLength * this.mTargetLength + index] = (resizeImg[1, i, j] - means[1]) / stdDev[1];
80 transformedImg[2 * this.mTargetLength * this.mTargetLength + index] = (resizeImg[2, i, j] - means[2]) / stdDev[2];
81 }
82 }
83
84 return transformedImg;
85 }

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