BioLib  3.7.0
A GUI-less version of Bio .NET library for editing & annotating various microscopy image formats.
Loading...
Searching...
No Matches
BioLib.SlideImage Class Reference

openslide wrapper More...

Inheritance diagram for BioLib.SlideImage:

Public Member Functions

 SlideImage ()
 
ImageDimension GetLevelDimension (int level)
 Get the dimensions of a level.
 
IEnumerable< ImageDimension > GetLevelDimensions ()
 Get all level dimensions.
 
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.
 
unsafe 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.
 
void Close ()
 
void Dispose ()
 
async Task< byte[]> ReadRegionAsync (int level, long curLevelOffsetXPixel, long curLevelOffsetYPixel, int curTileWidth, int curTileHeight, ZCT coord)
 

Static Public Member Functions

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.
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Dispose.
 

Properties

BioImage BioImage [get, set]
 
int LevelCount [get]
 Get the number of levels in the whole slide image.
 
ImageDimension Dimensions [get]
 Get the dimensions of level 0 (the largest level). Exactly equivalent to calling GetLevelDimensions(0).
 

Detailed Description

openslide wrapper

Constructor & Destructor Documentation

◆ SlideImage()

BioLib.SlideImage.SlideImage ( )
Parameters
handle
isOwnerclose handle when disposed
Exceptions
OpenSlideException
49 {
50
51 }

Member Function Documentation

◆ 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
originalDimensionThe dimension (width or height) of the original level.
nextLevelDimensionThe dimension (width or height) of the next level.
Returns
The base downsampling factor.
151 {
152 if (totalLevels <= 1)
153 {
154 throw new ArgumentException("Total levels must be greater than 1 to calculate a base factor.");
155 }
156 if (lastLevelResolution <= 0 || originalResolution <= 0)
157 {
158 throw new ArgumentException("Resolutions must be greater than 0.");
159 }
160
161 // Calculate the base downsampling factor
162 double baseFactor = Math.Pow((double)originalResolution / lastLevelResolution, 1.0 / (totalLevels - 1));
163 return baseFactor;
164 }

◆ Close()

void BioLib.SlideImage.Close ( )
256 {
257
258 }

◆ 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
filenameThe filename to check. On Windows, this must be in UTF-8.
Returns
An identification of the format vendor for this file, or NULL.
39 {
40 return filename;
41 }

◆ Dispose() [1/2]

void BioLib.SlideImage.Dispose ( )
291 {
292 Dispose(disposing: true);
293 GC.SuppressFinalize(this);
294 }
virtual void Dispose(bool disposing)
Dispose.
Definition SlideImage.cs:268

◆ Dispose() [2/2]

virtual void BioLib.SlideImage.Dispose ( bool disposing)
protectedvirtual

Dispose.

Parameters
disposing
269 {
270 if (!disposedValue)
271 {
272 if (disposing)
273 {
274 }
275
276 Close();
277 disposedValue = true;
278 }
279 }

◆ GetLevelDimension()

ImageDimension BioLib.SlideImage.GetLevelDimension ( int level)

Get the dimensions of a level.

Parameters
levelThe desired level.
Exceptions
OpenSlideException
127 {
128 return new ImageDimension(BioImage.Resolutions[level].SizeX, BioImage.Resolutions[level].SizeY);
129 }

◆ GetLevelDimensions()

IEnumerable< ImageDimension > BioLib.SlideImage.GetLevelDimensions ( )

Get all level dimensions.

Returns
Exceptions
OpenSlideException
137 {
138 var count = LevelCount;
139 for (int i = 0; i < count; i++)
140 {
141 yield return GetLevelDimension(i);
142 }
143 }
int LevelCount
Get the number of levels in the whole slide image.
Definition SlideImage.cs:86
ImageDimension GetLevelDimension(int level)
Get the dimensions of a level.
Definition SlideImage.cs:126

◆ GetLevelDownsamples()

static List< double > BioLib.SlideImage.GetLevelDownsamples ( double baseDownsampleFactor,
int totalLevels )
static

Calculates the downsample factors for each level of a slide.

Parameters
baseDownsampleFactorThe downsample factor between each level.
totalLevelsTotal number of levels in the slide.
Returns
A list of downsample factors for each level.
173 {
174 var levelDownsamples = new List<double>();
175
176 for (int level = 0; level < totalLevels; level++)
177 {
178 // Calculate the downsample factor for the current level.
179 // Math.Pow is used to raise the baseDownsampleFactor to the power of the level.
180 double downsampleFactorAtLevel = Math.Pow(baseDownsampleFactor, level);
181 levelDownsamples.Add(downsampleFactorAtLevel);
182 }
183
184 return levelDownsamples;
185 }

◆ Initialize()

static void BioLib.SlideImage.Initialize ( string path = null)
static

Add .dll directory to PATH.

Parameters
path
Exceptions
OpenSlideException
59 {
60
61 }

◆ Open()

static SlideImage BioLib.SlideImage.Open ( BioImage b)
static

Open.

Parameters
filename
Returns
Exceptions
OpenSlideException
74 {
75 SlideImage im = new SlideImage();
76 im.BioImage = b;
77 return im;
78 }
SlideImage()
Definition SlideImage.cs:48

◆ 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
levelThe desired level.
xThe top left x-coordinate, in the level 0 reference frame.
yThe top left y-coordinate, in the level 0 reference frame.
widthThe width of the region. Must be non-negative.
heightThe height of the region. Must be non-negative.
Returns
The pixel data of this region.
Exceptions
ArgumentOutOfRangeException
Exceptions
OpenSlideException
225 {
226 return BioImage.GetTile(BioImage, BioImage.GetFrameIndex(zct.Z, zct.C, zct.T), level, (int)x, (int)y, (int)width, (int)height).Bytes;
227 }
static Bitmap GetTile(BioImage b, int index, int level, int tilex, int tiley, int tileSizeX, int tileSizeY)
It reads a tile from a file, and returns a bitmap.
Definition Bio.cs:7202

◆ ReadRegionAsync()

async Task< byte[]> BioLib.SlideImage.ReadRegionAsync ( int level,
long curLevelOffsetXPixel,
long curLevelOffsetYPixel,
int curTileWidth,
int curTileHeight,
ZCT coord )
297 {
298 try
299 {
300 byte[] bts;
301 TryReadRegion(level, curLevelOffsetXPixel, curLevelOffsetYPixel, curTileWidth, curTileHeight,out bts,coord);
302 return bts;
303 }
304 catch (Exception e)
305 {
306 return null;
307 }
308 }
unsafe 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.
Definition SlideImage.cs:239

◆ TryReadRegion()

unsafe 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
levelThe desired level.
xThe top left x-coordinate, in the level 0 reference frame.
yThe top left y-coordinate, in the level 0 reference frame.
widthThe width of the region. Must be non-negative.
heightThe height of the region. Must be non-negative.
dataThe 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>

Property Documentation

◆ BioImage

BioImage BioLib.SlideImage.BioImage
getset
20{ get; set; }

◆ Dimensions

ImageDimension BioLib.SlideImage.Dimensions
get

Get the dimensions of level 0 (the largest level). Exactly equivalent to calling GetLevelDimensions(0).

Exceptions
OpenSlideException
107 {
108 get
109 {
110 if (_dimensionsRef == null)
111 {
112 lock (_dimensionsSynclock)
113 {
114 if (_dimensionsRef == null)
115 _dimensionsRef = GetLevelDimension(0);
116 }
117 }
118 return _dimensionsRef.Value;
119 }
120 }

◆ 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
OpenSlideException
86 {
87 get
88 {
89 if (BioImage.MacroResolution.HasValue)
90 {
91 return BioImage.Resolutions.Count - 2;
92 }
93 else
94 return BioImage.Resolutions.Count;
95 }
96 }

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