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.MaskData Class Reference

A structure for storing masks and their related data in batched format. Implements basic filtering and concatenation. More...

Inheritance diagram for BioGTK.MaskData:

Public Member Functions

void Filter (float pred_iou_thresh, float stability_score_thresh)
 
float[] CalculateStabilityScore (float maskThreshold, float thresholdOffset)
 
void Cat (MaskData md)
 
int[] batched_mask_to_box ()
 
void Dispose ()
 

Public Attributes

int[] mShape
 
List< float > mMask
 
List< float > mIoU
 
List< float > mStability
 
List< int > mBox
 
List< List< float > > mfinalMask
 

Detailed Description

A structure for storing masks and their related data in batched format. Implements basic filtering and concatenation.

Definition at line 13 of file MaskData.cs.

Constructor & Destructor Documentation

◆ MaskData()

BioGTK.MaskData.MaskData ( )

Definition at line 22 of file MaskData.cs.

23 {
24 this.mShape = new int[4];
25 this.mMask = new List<float>();
26 this.mIoU = new List<float>();
27 this.mStability = new List<float>();
28 this.mBox = new List<int>();
29
30 this.mfinalMask = new List<List<float>>();
31 }

Member Function Documentation

◆ batched_mask_to_box()

int[] BioGTK.MaskData.batched_mask_to_box ( )

Definition at line 115 of file MaskData.cs.

116 {
117 int C = this.mShape[1];
118 int width = this.mShape[3];
119 int height = this.mShape[2];
120
121 int[] boxes = new int[C*4];
122
123 for (int c = 0; c < C; c++)
124 {
125 bool emptyMask = true;
126 int top = height;
127 int bottom = 0;
128 int left = width;
129 int right = 0;
130
131 for (int i = 0; i < width; i++)
132 {
133 for (int j = 0; j < height; j++)
134 {
135 //int index = c * width * height + j * width + i;
136 //if (this.mMask[index] > 0)
137 int index =j * width + i;
138 if (this.mfinalMask[c][index] > 0)
139 {
140 emptyMask = false;
141 top = Math.Min(top, j);
142 bottom = Math.Max(bottom, j);
143 left = Math.Min(left, i);
144 right = Math.Max(right, i);
145 }
146 }
147 }
148
149 if (emptyMask)
150 {
151 boxes[c*4]=0;
152 boxes[c * 4+1] = 0;
153 boxes[c * 4+2] = 0;
154 boxes[c * 4+3] = 0;
155 }
156 else
157 {
158 boxes[c * 4] = left;
159 boxes[c * 4 + 1] = top;
160 boxes[c * 4 + 2] = right;
161 boxes[c * 4 + 3] = bottom;
162 }
163 }
164
165 return boxes;
166 }

◆ CalculateStabilityScore()

float[] BioGTK.MaskData.CalculateStabilityScore ( float maskThreshold,
float thresholdOffset )

Definition at line 59 of file MaskData.cs.

60 {
61 int batchSize = this.mShape[1];
62 int width = this.mShape[3];
63 int height = this.mShape[2];
64
65 float[] intersections = new float[batchSize];
66 float[] unions = new float[batchSize];
67
68 for (int i = 0; i < batchSize; i++)
69 {
70 float intersectionSum = 0;
71 float unionSum = 0;
72
73 for (int j = 0; j < width; j++)
74 {
75 for (int k = 0; k < height; k++)
76 {
77 int index = i * width * height + k * width + j;
78 if (this.mMask[index] > maskThreshold + thresholdOffset)
79 {
80 intersectionSum++;
81 }
82 if (this.mMask[index] > maskThreshold - thresholdOffset)
83 {
84 unionSum++;
85 }
86 }
87 }
88
89 intersections[i] = intersectionSum;
90 unions[i] = unionSum;
91 }
92
93 float[] stabilityScores = new float[batchSize];
94 for (int i = 0; i < batchSize; i++)
95 {
96 stabilityScores[i] = intersections[i] / unions[i];
97 }
98
99 return stabilityScores;
100 }

◆ Cat()

void BioGTK.MaskData.Cat ( MaskData md)

Definition at line 102 of file MaskData.cs.

103 {
104 this.mShape[0] = md.mShape[0];
105 this.mShape[1] += md.mShape[1];
106 this.mShape[2] = md.mShape[2];
107 this.mShape[3] = md.mShape[3];
108 this.mBox.AddRange(md.mBox);
109 this.mMask.AddRange(md.mMask);
110 this.mStability.AddRange(md.mStability);
111 this.mIoU.AddRange(md.mIoU);
112 this.mfinalMask.AddRange(md.mfinalMask);
113 }

◆ Dispose()

void BioGTK.MaskData.Dispose ( )

Definition at line 168 of file MaskData.cs.

169 {
170 mMask.Clear();
171 mIoU.Clear();
172 mMask.Clear();
173 mStability.Clear();
174 }

◆ Filter()

void BioGTK.MaskData.Filter ( float pred_iou_thresh,
float stability_score_thresh )

Definition at line 33 of file MaskData.cs.

34 {
35 List<float> m = new List<float>();
36 List<float> i = new List<float>();
37 List<float> s = new List<float>();
38 int batch = 0;
39 for (int j = 0; j < this.mShape[1]; j++)
40 {
41 if (this.mIoU[j] > pred_iou_thresh && this.mStability[j]> stability_score_thresh)
42 {
43 this.mfinalMask.Add(this.mMask.GetRange(j * this.mShape[2] * this.mShape[3], this.mShape[2] * this.mShape[3]));
44 //m.AddRange(this.mMask.GetRange(j * this.mShape[2] * this.mShape[3], this.mShape[2] * this.mShape[3]));
45 i.Add(this.mIoU[j]);
46 s.Add(this.mStability[j]);
47 batch++;
48 }
49 }
50 this.mShape[1] = batch;
51 this.mStability.Clear();
52 this.mMask.Clear();
53 this.mIoU.Clear();
54 //this.mMask.AddRange(m);
55 this.mIoU.AddRange(i);
56 this.mStability.AddRange(s);
57 }

Member Data Documentation

◆ mBox

List<int> BioGTK.MaskData.mBox

Definition at line 19 of file MaskData.cs.

◆ mfinalMask

List<List<float> > BioGTK.MaskData.mfinalMask

Definition at line 21 of file MaskData.cs.

◆ mIoU

List<float> BioGTK.MaskData.mIoU

Definition at line 17 of file MaskData.cs.

◆ mMask

List<float> BioGTK.MaskData.mMask

Definition at line 16 of file MaskData.cs.

◆ mShape

int [] BioGTK.MaskData.mShape

Definition at line 15 of file MaskData.cs.

◆ mStability

List<float> BioGTK.MaskData.mStability

Definition at line 18 of file MaskData.cs.


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