BioLib  3.6.2
A GUI-less version of Bio .NET library for editing & annotating various microscopy image formats.
Loading...
Searching...
No Matches
BioLib.SlideBase Class Reference
Inheritance diagram for BioLib.SlideBase:
BioLib.SlideSourceBase BioLib.ISlideSource BioLib.ISliceProvider BioLib.ISlideExternInfo

Public Member Functions

 SlideBase (BioImage source, SlideImage im, bool enableCache=true)
 
override IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image.
 
byte[] GetTile (TileInfo tileInfo, ZCT coord)
 
- Public Member Functions inherited from BioLib.SlideSourceBase
async Task< byte[]> GetSlice (SliceInfo sliceInfo)
 Get slice.
 
byte[] Get8BitBytes (Image< L8 > image)
 
byte[] GetRgb24Bytes (Image< Rgb24 > image)
 
byte[] Get16Bytes (Image< L16 > image)
 
IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image.
 
void Dispose ()
 
async Task< byte[]> GetTileAsync (TileInformation tileInfo)
 
async Task< byte[]> GetTileAsync (BruTile.TileInfo tileInfo)
 
- Public Member Functions inherited from BioLib.ISliceProvider
- Public Member Functions inherited from BioLib.ISlideExternInfo

Static Public Member Functions

static string DetectVendor (string source)
 
static byte[] ConvertRgbaToRgb (byte[] rgbaArray)
 
- Static Public Member Functions inherited from BioLib.SlideSourceBase
static void Resister (string extensionUpper, Func< string, bool, ISlideSource > factory)
 resister decode for Specific format
 
static ISlideSource Create (BioImage source, SlideImage im, bool enableCache=true)
 
static byte[] ConvertRgbaToRgb (byte[] rgbaArray)
 

Public Attributes

readonly SlideImage SlideImage
 
- Public Attributes inherited from BioLib.SlideSourceBase
TileCache cache = null
 

Protected Member Functions

void InitResolutions (IDictionary< int, BruTile.Resolution > resolutions, int tileWidth, int tileHeight)
 
override void Dispose (bool disposing)
 
- Protected Member Functions inherited from BioLib.SlideSourceBase

Additional Inherited Members

- Static Public Attributes inherited from BioLib.SlideSourceBase
static Extent destExtent
 
static Extent sourceExtent
 
static double curUnitsPerPixel = 1
 
static bool UseVips = true
 
- Properties inherited from BioLib.SlideSourceBase
static bool UseRealResolution = true [get, set]
 
double MinUnitsPerPixel [get, protected set]
 um/pixel
 
SlideImage Image [get, set]
 
ITileSchema Schema [get, protected set]
 
string Name [get, protected set]
 
Attribution Attribution [get, protected set]
 
IReadOnlyDictionary< string, object > ExternInfo [get, protected set]
 Extern info.
 
string Source [get, protected set]
 File path.
 
- Properties inherited from BioLib.ISliceProvider
- Properties inherited from BioLib.ISlideExternInfo

Detailed Description

Definition at line 14 of file SlideBase.cs.

Constructor & Destructor Documentation

◆ SlideBase()

BioLib.SlideBase.SlideBase ( BioImage source,
SlideImage im,
bool enableCache = true )

Definition at line 17 of file SlideBase.cs.

18 {
19 Source = source.file;
20 SlideImage = im;
21 Image = im;
22 double minUnitsPerPixel;
23 if (source.PhysicalSizeX < source.PhysicalSizeY) minUnitsPerPixel = source.PhysicalSizeX; else minUnitsPerPixel = source.PhysicalSizeY;
24 MinUnitsPerPixel = UseRealResolution ? minUnitsPerPixel : 1;
26 var height = SlideImage.Dimensions.Height;
27 var width = SlideImage.Dimensions.Width;
28 //ExternInfo = GetInfo();
29 Schema = new TileSchema
30 {
31 YAxis = YAxis.OSM,
32 Format = "jpg",
33 Extent = new Extent(0, -height, width, 0),
34 OriginX = 0,
35 OriginY = 0,
36 };
37 InitResolutions(Schema.Resolutions, 256, 256);
38 }
ImageDimension Dimensions
Get the dimensions of level 0 (the largest level). Exactly equivalent to calling GetLevelDimensions(0...
string Source
File path.
double MinUnitsPerPixel
um/pixel

Member Function Documentation

◆ ConvertRgbaToRgb()

static byte[] BioLib.SlideBase.ConvertRgbaToRgb ( byte[] rgbaArray)
static

Definition at line 97 of file SlideBase.cs.

98 {
99 // Initialize a new byte array for RGB24 format
100 byte[] rgbArray = new byte[(rgbaArray.Length / 4) * 3];
101
102 for (int i = 0, j = 0; i < rgbaArray.Length; i += 4, j += 3)
103 {
104 // Copy the R, G, B values, skip the A value
105 rgbArray[j] = rgbaArray[i]; // B
106 rgbArray[j + 1] = rgbaArray[i + 1]; // G
107 rgbArray[j + 2] = rgbaArray[i + 2]; // R
108 }
109
110 return rgbArray;
111 }

◆ DetectVendor()

static string BioLib.SlideBase.DetectVendor ( string source)
static

Definition at line 40 of file SlideBase.cs.

41 {
42 return SlideImage.DetectVendor(source);
43 }
static string DetectVendor(string filename)
Quickly determine whether a whole slide image is recognized.
Definition SlideImage.cs:38

◆ Dispose()

override void BioLib.SlideBase.Dispose ( bool disposing)
protectedvirtual

Reimplemented from BioLib.SlideSourceBase.

Definition at line 132 of file SlideBase.cs.

133 {
134 if (!disposedValue)
135 {
136 if (disposing)
137 {
138 SlideImage.Dispose();
139 }
140 disposedValue = true;
141 }
142 base.Dispose(disposing);
143 }
virtual void Dispose(bool disposing)
Dispose.

◆ GetExternImages()

override IReadOnlyDictionary< string, byte[]> BioLib.SlideBase.GetExternImages ( )

Extern image.

Returns

Implements BioLib.ISlideExternInfo.

Definition at line 46 of file SlideBase.cs.

47 {
48 throw new NotImplementedException();
49 /*
50 Dictionary<string, byte[]> images = new Dictionary<string, byte[]>();
51 var r = Math.Max(Schema.Extent.Height, Schema.Extent.Width) / 512;
52 images.Add("preview", GetSlice(new SliceInfo { Extent = Schema.Extent, Resolution = r }));
53 foreach (var item in SlideImage.GetAssociatedImages())
54 {
55 var dim = item.Value.Dimensions;
56 images.Add(item.Key, ImageUtil.GetJpeg(item.Value.Data, 4, 4 * (int)dim.Width, (int)dim.Width, (int)dim.Height));
57 }
58 return images;
59 */
60 }

◆ GetTile()

byte[] BioLib.SlideBase.GetTile ( TileInfo tileInfo,
ZCT coord )

Definition at line 81 of file SlideBase.cs.

82 {
83 var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
84 var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
85 var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
86 var curLevelOffsetXPixel = tileInfo.Extent.MinX / MinUnitsPerPixel;
87 var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / MinUnitsPerPixel;
88 var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
89 var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
90 var bgraData = SlideImage.ReadRegion(tileInfo.Index.Level, coord, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight);
91 //We check to see if the data is valid.
92 if (bgraData.Length != curTileWidth * curTileHeight * 4)
93 return null;
94 byte[] bm = ConvertRgbaToRgb(bgraData);
95 return bm;
96 }
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.

◆ InitResolutions()

void BioLib.SlideBase.InitResolutions ( IDictionary< int, BruTile.Resolution > resolutions,
int tileWidth,
int tileHeight )
protected

Definition at line 113 of file SlideBase.cs.

114 {
115 for (int i = 0; i < SlideImage.LevelCount; i++)
116 {
117 /*
118 bool useInternalWidth = int.TryParse(ExternInfo.TryGetValue($"openslide.level[{i}].tile-width", out var _w) ? (string)_w : null, out var w) && w >= tileWidth;
119 bool useInternalHeight = int.TryParse(ExternInfo.TryGetValue($"openslide.level[{i}].tile-height", out var _h) ? (string)_h : null, out var h) && h >= tileHeight;
120
121 bool useInternalSize = useInternalHeight && useInternalWidth;
122 var tw = useInternalSize ? w : tileWidth;
123 var th = useInternalSize ? h : tileHeight;
124 resolutions.Add(i, new Resolution(i, MinUnitsPerPixel * SlideImage.GetLevelDownsample(i), tw, th));
125 */
126 resolutions.Add(i, new BruTile.Resolution(i, SlideImage.BioImage.GetUnitPerPixel(i), tileWidth, tileHeight));
127 }
128 }
double GetUnitPerPixel(int level)
Get Unit Per Pixel for pyramidal images.
Definition Bio.cs:3292
int LevelCount
Get the number of levels in the whole slide image.
Definition SlideImage.cs:86

Member Data Documentation

◆ SlideImage

readonly SlideImage BioLib.SlideBase.SlideImage

Definition at line 16 of file SlideBase.cs.


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