BioGTK  5.1.1
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images.
Loading...
Searching...
No Matches
Bio.SlideImage Class Reference

openslide wrapper More...

Inheritance diagram for Bio.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, 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()

Bio.SlideImage.SlideImage ( )
inline
Parameters
handle
isOwnerclose handle when disposed
Exceptions
OpenSlideException
50 {
51
52 }

Member Function Documentation

◆ CalculateBaseFactor()

static double Bio.SlideImage.CalculateBaseFactor ( int  originalResolution,
int  lastLevelResolution,
int  totalLevels 
)
inlinestatic

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

◆ Close()

void Bio.SlideImage.Close ( )
inline
257 {
258
259 }

◆ DetectVendor()

static string Bio.SlideImage.DetectVendor ( string  filename)
inlinestatic

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.
40 {
41 return filename;
42 }

◆ Dispose() [1/2]

void Bio.SlideImage.Dispose ( )
inline
292 {
293 Dispose(disposing: true);
294 GC.SuppressFinalize(this);
295 }
void Dispose()
Definition SlideImage.cs:291

◆ Dispose() [2/2]

virtual void Bio.SlideImage.Dispose ( bool  disposing)
inlineprotectedvirtual

Dispose.

Parameters
disposing
270 {
271 if (!disposedValue)
272 {
273 if (disposing)
274 {
275 }
276
277 Close();
278 disposedValue = true;
279 }
280 }
void Close()
Definition SlideImage.cs:256

◆ GetLevelDimension()

ImageDimension Bio.SlideImage.GetLevelDimension ( int  level)
inline

Get the dimensions of a level.

Parameters
levelThe desired level.
Exceptions
OpenSlideException
128 {
129 return new ImageDimension(BioImage.Resolutions[level].SizeX, BioImage.Resolutions[level].SizeY);
130 }
Definition Bio.cs:2008
List< Resolution > Resolutions
Definition Bio.cs:2101

◆ GetLevelDimensions()

IEnumerable< ImageDimension > Bio.SlideImage.GetLevelDimensions ( )
inline

Get all level dimensions.

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

◆ GetLevelDownsamples()

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

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.
174 {
175 var levelDownsamples = new List<double>();
176
177 for (int level = 0; level < totalLevels; level++)
178 {
179 // Calculate the downsample factor for the current level.
180 // Math.Pow is used to raise the baseDownsampleFactor to the power of the level.
181 double downsampleFactorAtLevel = Math.Pow(baseDownsampleFactor, level);
182 levelDownsamples.Add(downsampleFactorAtLevel);
183 }
184
185 return levelDownsamples;
186 }

◆ Initialize()

static void Bio.SlideImage.Initialize ( string  path = null)
inlinestatic

Add .dll directory to PATH.

Parameters
path
Exceptions
OpenSlideException
60 {
61
62 }

◆ Open()

static SlideImage Bio.SlideImage.Open ( BioImage  b)
inlinestatic

Open.

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

◆ ReadRegion()

unsafe byte[] Bio.SlideImage.ReadRegion ( int  level,
long  x,
long  y,
long  width,
long  height 
)
inline

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
226 {
227 return BioImage.GetTile(BioImage, App.viewer.GetCoordinate(), level, (int)x, (int)y, (int)width, (int)height).Bytes;
228 }
static Bitmap GetTile(BioImage b, ZCT coord, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
Definition Bio.cs:6976

◆ ReadRegionAsync()

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

◆ TryReadRegion()

unsafe bool Bio.SlideImage.TryReadRegion ( int  level,
long  x,
long  y,
long  width,
long  height,
out byte[]  data,
ZCT  zct 
)
inline

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 Bio.SlideImage.BioImage
getset
21{ get; set; }

◆ Dimensions

ImageDimension Bio.SlideImage.Dimensions
get

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

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

◆ LevelCount

int Bio.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
87 {
88 get
89 {
90 if (BioImage.MacroResolution.HasValue)
91 {
92 return BioImage.Resolutions.Count - 2;
93 }
94 else
95 return BioImage.Resolutions.Count;
96 }
97 }
int? MacroResolution
Definition Bio.cs:3174

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