openslide wrapper
More...
|
| | SlideImage () |
| |
| ImageDimension | GetLevelDimension (int level) |
| |
| IEnumerable< ImageDimension > | GetLevelDimensions () |
| | Get all level dimensions.
|
| |
| void | ResetDimensionsCache () |
| | Clears the cached level-0 dimensions so Dimensions is re-derived from the active well field on the next access. Call this whenever BioImage.WellIndex changes for a well image.
|
| |
| unsafe byte[] | ReadRegion (int level, ZCT zct, long x, long y, long width, long height) |
| | Copy pre-multiplied BGRA data from a whole slide image.
|
| |
| bool | TryReadRegion (int level, long x, long y, long width, long height, out byte[] data, ZCT zct) |
| | Copy pre-multiplied BGRA data from a whole slide image.
|
| |
| async Task< byte[]> | TryReadRegionAsync (int level, long x, long y, long width, long height, ZCT zct, CancellationToken ct=default) |
| | Copy pre-multiplied BGRA data from a whole slide image.
|
| |
| void | Close () |
| |
| void | Dispose () |
| |
| async Task< byte[]> | ReadRegionAsync (int level, long curLevelOffsetXPixel, long curLevelOffsetYPixel, int curTileWidth, int curTileHeight, ZCT coord, CancellationToken ct=default) |
| |
|
| static string | DetectVendor (string filename) |
| | Quickly determine whether a whole slide image is recognized.
|
| |
| static void | Initialize (string path=null) |
| | Add .dll directory to PATH.
|
| |
| static SlideImage | Open (BioImage b) |
| | Open.
|
| |
| static double | CalculateBaseFactor (int originalResolution, int lastLevelResolution, int totalLevels) |
| | Calculates the base downsampling factor between two levels of a slide.
|
| |
| static List< double > | GetLevelDownsamples (double baseDownsampleFactor, int totalLevels) |
| | Calculates the downsample factors for each level of a slide.
|
| |
|
| virtual void | Dispose (bool disposing) |
| | Dispose.
|
| |
◆ SlideImage()
| BioLib.SlideImage.SlideImage |
( |
| ) |
|
- Parameters
-
| handle | |
| isOwner | close handle when disposed |
- Exceptions
-
◆ CalculateBaseFactor()
| static double BioLib.SlideImage.CalculateBaseFactor |
( |
int | originalResolution, |
|
|
int | lastLevelResolution, |
|
|
int | totalLevels ) |
|
static |
Calculates the base downsampling factor between two levels of a slide.
- Parameters
-
| originalDimension | The dimension (width or height) of the original level. |
| nextLevelDimension | The dimension (width or height) of the next level. |
- Returns
- The base downsampling factor.
209 {
210 if (totalLevels <= 1)
211 {
212 throw new ArgumentException("Total levels must be greater than 1 to calculate a base factor.");
213 }
214 if (lastLevelResolution <= 0 || originalResolution <= 0)
215 {
216 throw new ArgumentException("Resolutions must be greater than 0.");
217 }
218
219
220 double baseFactor = Math.Pow((double)originalResolution / lastLevelResolution, 1.0 / (totalLevels - 1));
221 return baseFactor;
222 }
◆ Close()
| void BioLib.SlideImage.Close |
( |
| ) |
|
◆ DetectVendor()
| static string BioLib.SlideImage.DetectVendor |
( |
string | filename | ) |
|
|
static |
Quickly determine whether a whole slide image is recognized.
If OpenSlide recognizes the file referenced by filename , return a string identifying the slide format vendor.This is equivalent to the value of the NativeMethods.VENDOR property. Calling Open(string) on this file will return a valid OpenSlide object or an OpenSlide object in error state.
Otherwise, return null.Calling
Open(string) on this file will also return null.
- Parameters
-
| filename | The filename to check. On Windows, this must be in UTF-8. |
- Returns
- An identification of the format vendor for this file, or NULL.
72 {
73 return filename;
74 }
◆ Dispose() [1/2]
| void BioLib.SlideImage.Dispose |
( |
| ) |
|
662 {
664 GC.SuppressFinalize(this);
665 }
void Dispose()
Definition SlideImage.cs:661
◆ Dispose() [2/2]
| virtual void BioLib.SlideImage.Dispose |
( |
bool | disposing | ) |
|
|
protectedvirtual |
Dispose.
- Parameters
-
640 {
641 if (!disposedValue)
642 {
643 if (disposing)
644 {
645 }
646
648 disposedValue = true;
649 }
650 }
void Close()
Definition SlideImage.cs:626
◆ GetLevelDimension()
| ImageDimension BioLib.SlideImage.GetLevelDimension |
( |
int | level | ) |
|
155 {
156
159 {
160 int fi = Math.Clamp(
BioImage.WellIndex, 0,
BioImage.ZarrWellLevels.Count - 1);
161 var fieldLevels =
BioImage.ZarrWellLevels[fi];
162 if (fieldLevels != null && fieldLevels.Count > 0)
163 {
164 int lev = Math.Clamp(level, 0, fieldLevels.Count - 1);
165 var shape = fieldLevels[lev].Shape;
166 var axes = fieldLevels[lev].EffectiveAxes;
167 int w = 1, h = 1;
168 for (int i = 0; i < axes.Length; i++)
169 {
170 switch (axes[i].Name.ToLowerInvariant())
171 {
172 case "x": w = (int)shape[i]; break;
173 case "y": h = (int)shape[i]; break;
174 }
175 }
176 return new ImageDimension(w, h);
177 }
178 }
180 }
ImageType
Definition Bio.cs:1961
List< Resolution > Resolutions
Definition Bio.cs:1979
ImageType Type
Definition Bio.cs:1968
BioImage BioImage
Definition SlideImage.cs:25
◆ GetLevelDimensions()
| IEnumerable< ImageDimension > BioLib.SlideImage.GetLevelDimensions |
( |
| ) |
|
Get all level dimensions.
- Returns
- Exceptions
-
188 {
190 for (int i = 0; i < count; i++)
191 {
193 }
194 }
int LevelCount
Get the number of levels in the whole slide image.
Definition SlideImage.cs:119
ImageDimension GetLevelDimension(int level)
Definition SlideImage.cs:154
◆ GetLevelDownsamples()
| static List< double > BioLib.SlideImage.GetLevelDownsamples |
( |
double | baseDownsampleFactor, |
|
|
int | totalLevels ) |
|
static |
Calculates the downsample factors for each level of a slide.
- Parameters
-
| baseDownsampleFactor | The downsample factor between each level. |
| totalLevels | Total number of levels in the slide. |
- Returns
- A list of downsample factors for each level.
231 {
232 var levelDownsamples = new List<double>();
233
234 for (int level = 0; level < totalLevels; level++)
235 {
236
237
238 double downsampleFactorAtLevel = Math.Pow(baseDownsampleFactor, level);
239 levelDownsamples.Add(downsampleFactorAtLevel);
240 }
241
242 return levelDownsamples;
243 }
◆ Initialize()
| static void BioLib.SlideImage.Initialize |
( |
string | path = null | ) |
|
|
static |
Add .dll directory to PATH.
- Parameters
-
- Exceptions
-
◆ Open()
Open.
- Parameters
-
- Returns
- Exceptions
-
107 {
110 return im;
111 }
return b
Definition Bio.cs:7393
SlideImage()
Definition SlideImage.cs:81
◆ ReadRegion()
| unsafe byte[] BioLib.SlideImage.ReadRegion |
( |
int | level, |
|
|
ZCT | zct, |
|
|
long | x, |
|
|
long | y, |
|
|
long | width, |
|
|
long | height ) |
Copy pre-multiplied BGRA data from a whole slide image.
- Parameters
-
| level | The desired level. |
| x | The top left x-coordinate, in the level 0 reference frame. |
| y | The top left y-coordinate, in the level 0 reference frame. |
| width | The width of the region. Must be non-negative. |
| height | The height of the region. Must be non-negative. |
- Returns
- The pixel data of this region.
- Exceptions
-
| ArgumentOutOfRangeException | - Exceptions
-
|
283 {
284 try
285 {
287 BioImage.GetFrameIndex(zct.Z, zct.C, zct.T),
288 level,
289 (int)x,
290 (int)y,
291 (int)width,
292 (int)height).Result;
293 if (tile == null)
294 return null;
295
296 var bytes = tile.Bytes;
297 tile.Dispose();
298 return bytes;
299 }
300 catch (Exception e)
301 {
303 Console.WriteLine("BioImage is null. ");
304 Console.WriteLine(e.Message + " " + e.StackTrace);
305 }
306 return null;
307 }
◆ ReadRegionAsync()
| async Task< byte[]> BioLib.SlideImage.ReadRegionAsync |
( |
int | level, |
|
|
long | curLevelOffsetXPixel, |
|
|
long | curLevelOffsetYPixel, |
|
|
int | curTileWidth, |
|
|
int | curTileHeight, |
|
|
ZCT | coord, |
|
|
CancellationToken | ct = default ) |
668 {
669 try
670 {
671 byte[] bts = await
TryReadRegionAsync(level, curLevelOffsetXPixel, curLevelOffsetYPixel, curTileWidth, curTileHeight, coord, ct);
672 return bts;
673 }
674 catch (Exception e)
675 {
676 return null;
677 }
678 }
async Task< byte[]> TryReadRegionAsync(int level, long x, long y, long width, long height, ZCT zct, CancellationToken ct=default)
Copy pre-multiplied BGRA data from a whole slide image.
Definition SlideImage.cs:352
◆ ResetDimensionsCache()
| void BioLib.SlideImage.ResetDimensionsCache |
( |
| ) |
|
Clears the cached level-0 dimensions so Dimensions is re-derived from the active well field on the next access. Call this whenever BioImage.WellIndex changes for a well image.
◆ TryReadRegion()
| bool BioLib.SlideImage.TryReadRegion |
( |
int | level, |
|
|
long | x, |
|
|
long | y, |
|
|
long | width, |
|
|
long | height, |
|
|
out byte[] | data, |
|
|
ZCT | zct ) |
Copy pre-multiplied BGRA data from a whole slide image.
- Parameters
-
| level | The desired level. |
| x | The top left x-coordinate, in the level 0 reference frame. |
| y | The top left y-coordinate, in the level 0 reference frame. |
| width | The width of the region. Must be non-negative. |
| height | The height of the region. Must be non-negative. |
| data | The BGRA pixel data of this region. |
- Returns
320 {
322 BioImage.GetFrameIndex(zct.Z, zct.C, zct.T),
323 level,
324 (int)x,
325 (int)y,
326 (int)width,
327 (int)height).Result;
328 if (tile == null)
329 {
330 data = null;
331 return false;
332 }
333
334 data = tile.Bytes;
335 tile.Dispose();
336 if (data == null)
337 return false;
338 else
339 return true;
340 }
◆ TryReadRegionAsync()
| async Task< byte[]> BioLib.SlideImage.TryReadRegionAsync |
( |
int | level, |
|
|
long | x, |
|
|
long | y, |
|
|
long | width, |
|
|
long | height, |
|
|
ZCT | zct, |
|
|
CancellationToken | ct = default ) |
Copy pre-multiplied BGRA data from a whole slide image.
- Parameters
-
| level | The desired level. |
| x | The top left x-coordinate, in the level 0 reference frame. |
| y | The top left y-coordinate, in the level 0 reference frame. |
| width | The width of the region. Must be non-negative. |
| height | The height of the region. Must be non-negative. |
| data | The BGRA pixel data of this region. |
- Returns
summary> Close an OpenSlide object. /summary> remarks> No other threads may be using the object. After this call returns, the object cannot be used anymore. /remarks>
◆ BioImage
◆ Dimensions
| ImageDimension BioLib.SlideImage.Dimensions |
|
get |
139 {
140 get
141 {
142 if (_dimensionsRef == null)
143 {
144 lock (_dimensionsSynclock)
145 {
146 if (_dimensionsRef == null)
148 }
149 }
150 return _dimensionsRef.Value;
151 }
152 }
◆ LevelCount
| int BioLib.SlideImage.LevelCount |
|
get |
Get the number of levels in the whole slide image.
<return>The number of levels, or -1 if an error occurred.</return>
- Exceptions
-
119 {
120 get
121 {
122
125 {
126 int fi = Math.Clamp(
BioImage.WellIndex, 0,
BioImage.ZarrWellLevels.Count - 1);
127 return BioImage.ZarrWellLevels[fi]?.Count ?? 1;
128 }
130 return BioImage.Resolutions.Count - 2;
132 }
133 }
int? MacroResolution
Definition Bio.cs:3349
The documentation for this class was generated from the following file: