BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
BioImager.SlideSourceBase Class Referenceabstract
Inheritance diagram for BioImager.SlideSourceBase:
BioImager.ISlideSource BioImager.ISliceProvider BioImager.ISlideExternInfo BioImager.SlideBase

Public Member Functions

async Task< byte[]> GetSlice (SliceInfo sliceInfo)
 Get slice. More...
 
byte[] GetRgb24Bytes (Image< Rgb24 > image)
 
abstract IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image. More...
 
void Dispose ()
 
async Task< byte[]> GetTileAsync (TileInformation tileInfo)
 
async Task< byte[]> GetTileAsync (BruTile.TileInfo tileInfo)
 
Task< byte[]> GetSlice (SliceInfo sliceInfo)
 Get slice. More...
 
IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image. More...
 

Static Public Member Functions

static void Resister (string extensionUpper, Func< string, bool, ISlideSource > factory)
 resister decode for Specific format More...
 
static ISlideSource Create (BioImage source, SlideImage im, bool enableCache=true)
 
static byte[] ConvertRgbaToRgb (byte[] rgbaArray)
 

Public Attributes

TileCache cache = null
 

Static Public Attributes

static byte[] LastSlice
 
static Extent destExtent
 
static Extent sourceExtent
 
static double curUnitsPerPixel = 1
 
static bool UseVips = true
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Properties

static bool UseRealResolution = true [get, set]
 
double MinUnitsPerPixel [get, protected set]
 um/pixel More...
 
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. More...
 
string Source [get, protected set]
 File path. More...
 
- Properties inherited from BioImager.ISliceProvider
double MinUnitsPerPixel [get]
 um/pixel More...
 
- Properties inherited from BioImager.ISlideExternInfo
string Source [get]
 File path. More...
 
IReadOnlyDictionary< string, object > ExternInfo [get]
 Extern info. More...
 

Detailed Description

Definition at line 122 of file ISlideSource.cs.

Member Function Documentation

◆ ConvertRgbaToRgb()

static byte[] BioImager.SlideSourceBase.ConvertRgbaToRgb ( byte[]  rgbaArray)
static

Definition at line 318 of file ISlideSource.cs.

319 {
320 // Initialize a new byte array for RGB24 format
321 byte[] rgbArray = new byte[(rgbaArray.Length / 4) * 3];
322
323 for (int i = 0, j = 0; i < rgbaArray.Length; i += 4, j += 3)
324 {
325 // Copy the R, G, B values, skip the A value
326 rgbArray[j] = rgbaArray[i + 2]; // B
327 rgbArray[j + 1] = rgbaArray[i + 1]; // G
328 rgbArray[j + 2] = rgbaArray[i]; // R
329 }
330
331 return rgbArray;
332 }

◆ Create()

static ISlideSource BioImager.SlideSourceBase.Create ( BioImage  source,
SlideImage  im,
bool  enableCache = true 
)
static

Definition at line 140 of file ISlideSource.cs.

141 {
142
143 var ext = Path.GetExtension(source.file).ToUpper();
144 try
145 {
146 if (keyValuePairs.TryGetValue(ext, out var factory) && factory != null)
147 return factory.Invoke(source.file, enableCache);
148
149 if (!string.IsNullOrEmpty(SlideBase.DetectVendor(source.file)))
150 {
151 SlideBase b = new SlideBase(source, im, enableCache);
152
153 }
154 }
155 catch (Exception e)
156 {
157 Console.WriteLine(e.Message);
158 }
159 return null;
160 }

◆ Dispose() [1/2]

void BioImager.SlideSourceBase.Dispose ( )

Definition at line 276 of file ISlideSource.cs.

277 {
278 Dispose(disposing: true);
279 GC.SuppressFinalize(this);
280 }

◆ Dispose() [2/2]

virtual void BioImager.SlideSourceBase.Dispose ( bool  disposing)
protectedvirtual

Definition at line 259 of file ISlideSource.cs.

260 {
261 if (!disposedValue)
262 {
263 if (disposing)
264 {
265 //_bgraCache.Dispose();
266 }
267 disposedValue = true;
268 }
269 }

◆ GetExternImages()

abstract IReadOnlyDictionary< string, byte[]> BioImager.SlideSourceBase.GetExternImages ( )
pure virtual

Extern image.

Returns

Implements BioImager.ISlideExternInfo.

Implemented in BioImager.SlideBase.

◆ GetRgb24Bytes()

byte[] BioImager.SlideSourceBase.GetRgb24Bytes ( Image< Rgb24 >  image)

Definition at line 221 of file ISlideSource.cs.

222 {
223 int width = image.Width;
224 int height = image.Height;
225 byte[] rgbBytes = new byte[width * height * 3]; // 3 bytes per pixel (RGB)
226
227 int byteIndex = 0;
228 for (int y = 0; y < height; y++)
229 {
230 for (int x = 0; x < width; x++)
231 {
232 Rgb24 pixel = image[x, y];
233 rgbBytes[byteIndex++] = pixel.R;
234 rgbBytes[byteIndex++] = pixel.G;
235 rgbBytes[byteIndex++] = pixel.B;
236 }
237 }
238
239 return rgbBytes;
240 }

◆ GetSlice()

async Task< byte[]> BioImager.SlideSourceBase.GetSlice ( SliceInfo  sliceInfo)

Get slice.

Parameters
sliceInfoSlice info
Returns

Implements BioImager.ISliceProvider.

Definition at line 169 of file ISlideSource.cs.

170 {
171 if (cache == null)
172 cache = new TileCache(this);
173 var curLevel = Image.BioImage.LevelFromResolution(sliceInfo.Resolution);
174 var curUnitsPerPixel = Schema.Resolutions[curLevel].UnitsPerPixel;
175 var tileInfos = Schema.GetTileInfos(sliceInfo.Extent, curLevel);
176 List<Tuple<Extent, byte[]>> tiles = new List<Tuple<Extent, byte[]>>();
177 foreach (BruTile.TileInfo t in tileInfos)
178 {
179 TileInformation tf = new TileInformation();
180 tf.Extent = t.Extent;
181 tf.Coordinate = App.viewer.GetCoordinate();
182 tf.Index = t.Index;
183 byte[] c = await cache.GetTile(tf);
184 if(c!=null)
185 tiles.Add(Tuple.Create(t.Extent.WorldToPixelInvertedY(curUnitsPerPixel), c));
186 }
187 var srcPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(curUnitsPerPixel);
188 var dstPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(sliceInfo.Resolution);
189 var dstPixelHeight = sliceInfo.Parame.DstPixelHeight > 0 ? sliceInfo.Parame.DstPixelHeight : dstPixelExtent.Height;
190 var dstPixelWidth = sliceInfo.Parame.DstPixelWidth > 0 ? sliceInfo.Parame.DstPixelWidth : dstPixelExtent.Width;
191 destExtent = new Extent(0, 0, dstPixelWidth, dstPixelHeight);
192 sourceExtent = srcPixelExtent;
193 if (UseVips)
194 {
195 try
196 {
197 NetVips.Image im = OpenSlideGTK.ImageUtil.JoinVips(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
198 LastSlice = im.WriteToMemory();
199 return LastSlice;
200 }
201 catch (Exception e)
202 {
203 UseVips = false;
204 Console.WriteLine("Failed to use LibVips please install Libvips for your platform.");
205 Console.WriteLine(e.Message);
206 }
207 }
208 try
209 {
210 Image<Rgb24> im = OpenSlideGTK.ImageUtil.Join(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
211 LastSlice = GetRgb24Bytes(im);
212 im.Dispose();
213 }
214 catch (Exception er)
215 {
216 Console.WriteLine(er.Message);
217 return null;
218 }
219 return LastSlice;
220 }
int LevelFromResolution(double Resolution)
Returns the level of a given resolution.
Definition: Bio.cs:2589

References BioImager.SliceInfo.Extent, BioImager.ImageView.GetCoordinate(), BioImager.BioImage.LevelFromResolution(), and BioImager.SliceInfo.Resolution.

◆ GetTileAsync() [1/2]

async Task< byte[]> BioImager.SlideSourceBase.GetTileAsync ( BruTile.TileInfo  tileInfo)

Definition at line 300 of file ISlideSource.cs.

301 {
302 if (tileInfo == null)
303 return null;
304 var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
305 var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
306 var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
307 var curLevelOffsetXPixel = tileInfo.Extent.MinX / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
308 var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
309 var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
310 var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
311 var bgraData = await Image.ReadRegionAsync(tileInfo.Index.Level, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight, new ZCT());
312 //We check to see if the data is valid.
313 if (bgraData.Length != curTileWidth * curTileHeight * 4)
314 return null;
315 byte[] bm = ConvertRgbaToRgb(bgraData);
316 return bm;
317 }

◆ GetTileAsync() [2/2]

async Task< byte[]> BioImager.SlideSourceBase.GetTileAsync ( TileInformation  tileInfo)

Definition at line 282 of file ISlideSource.cs.

283 {
284 if (tileInfo == null)
285 return null;
286 var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
287 var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
288 var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
289 var curLevelOffsetXPixel = tileInfo.Extent.MinX / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
290 var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
291 var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
292 var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
293 var bgraData = await Image.ReadRegionAsync(tileInfo.Index.Level, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight,tileInfo.Coordinate);
294 //We check to see if the data is valid.
295 if (bgraData.Length != curTileWidth * curTileHeight * 4)
296 return null;
297 byte[] bm = ConvertRgbaToRgb(bgraData);
298 return bm;
299 }

◆ Resister()

static void BioImager.SlideSourceBase.Resister ( string  extensionUpper,
Func< string, bool, ISlideSource factory 
)
static

resister decode for Specific format

Parameters
extensionUpperdot and extension upper
factoryfile path,enable cache,decoder

Definition at line 134 of file ISlideSource.cs.

135 {
136 keyValuePairs.Add(extensionUpper, factory);
137 }

Member Data Documentation

◆ cache

TileCache BioImager.SlideSourceBase.cache = null

Definition at line 168 of file ISlideSource.cs.

◆ curUnitsPerPixel

double BioImager.SlideSourceBase.curUnitsPerPixel = 1
static

Definition at line 166 of file ISlideSource.cs.

◆ destExtent

Extent BioImager.SlideSourceBase.destExtent
static

Definition at line 164 of file ISlideSource.cs.

◆ LastSlice

byte [] BioImager.SlideSourceBase.LastSlice
static

Definition at line 163 of file ISlideSource.cs.

◆ sourceExtent

Extent BioImager.SlideSourceBase.sourceExtent
static

Definition at line 165 of file ISlideSource.cs.

◆ UseVips

bool BioImager.SlideSourceBase.UseVips = true
static

Definition at line 167 of file ISlideSource.cs.

Property Documentation

◆ Attribution

Attribution BioImager.SlideSourceBase.Attribution
getprotected set

Definition at line 248 of file ISlideSource.cs.

248{ get; protected set; }

◆ ExternInfo

IReadOnlyDictionary<string, object> BioImager.SlideSourceBase.ExternInfo
getprotected set

Extern info.

Implements BioImager.ISlideExternInfo.

Definition at line 250 of file ISlideSource.cs.

250{ get; protected set; }

◆ Image

SlideImage BioImager.SlideSourceBase.Image
getset

Definition at line 242 of file ISlideSource.cs.

242{ get; set; }

◆ MinUnitsPerPixel

double BioImager.SlideSourceBase.MinUnitsPerPixel
getprotected set

um/pixel

Implements BioImager.ISliceProvider.

Definition at line 162 of file ISlideSource.cs.

162{ get; protected set; }

◆ Name

string BioImager.SlideSourceBase.Name
getprotected set

Definition at line 246 of file ISlideSource.cs.

246{ get; protected set; }

◆ Schema

ITileSchema BioImager.SlideSourceBase.Schema
getprotected set

Definition at line 244 of file ISlideSource.cs.

244{ get; protected set; }

◆ Source

string BioImager.SlideSourceBase.Source
getprotected set

File path.

Implements BioImager.ISlideExternInfo.

Definition at line 252 of file ISlideSource.cs.

252{ get; protected set; }

◆ UseRealResolution

bool BioImager.SlideSourceBase.UseRealResolution = true
staticgetset

Definition at line 125 of file ISlideSource.cs.

125{ get; set; } = true;

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