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

Classes

class  ImageJDesc
 
class  WellPlate
 

Public Types

enum  ImageType { stack , pyramidal , well }
 

Public Member Functions

BioImage Copy (bool rois)
 
BioImage Copy ()
 
double GetLevelDownsample (int level)
 Get the downsampling factor of a given level.
 
double[] GetLevelDownsamples ()
 
int LevelFromResolution (double Resolution)
 Returns the level of a given resolution.
 
double GetUnitPerPixel (int level)
 Get Unit Per Pixel for pyramidal images.
 
void To8Bit ()
 Converts a 16-bit image to an 8-bit image.
 
void To16Bit ()
 Converts the image to 16 bit.
 
void To24Bit ()
 Converts the image to 24 bit.
 
void To32Bit ()
 Converts the image to 32 bit.
 
void To48Bit ()
 
void RotateFlip (AForge.RotateFlipType rot)
 
void Bake (int rmin, int rmax, int gmin, int gmax, int bmin, int bmax)
 
void Bake (IntRange rf, IntRange gf, IntRange bf)
 
void UpdateCoords ()
 It takes a list of images and assigns them to a 3D array of coordinates.
 
void UpdateCoords (int sz, int sc, int st)
 
void UpdateCoords (int sz, int sc, int st, string order)
 
double ToImageSizeX (double d)
 
double ToImageSizeY (double d)
 
double ToImageSpaceX (double x)
 
double ToImageSpaceY (double y)
 
PointD ToImageSpace (PointD p)
 
PointD[] ToImageSpace (List< PointD > p)
 
PointF[] ToImageSpace (PointF[] p)
 
RectangleF ToImageSpace (RectangleD p)
 
PointD ToStageSpace (PointD p)
 
PointD ToStageSpace (PointD p, int resolution)
 
RectangleD ToStageSpace (RectangleD p)
 
PointD[] ToStageSpace (PointD[] p)
 
 BioImage (string file)
 
BioImage[] SplitChannels ()
 
Bitmap GetImageByCoord (int z, int c, int t)
 
Bitmap GetBitmap (int z, int c, int t)
 
int GetIndex (int ix, int iy)
 
int GetIndexRGB (int ix, int iy, int index)
 
ushort GetValue (ZCTXY coord)
 
ushort GetValueRGB (ZCTXY coord, int index)
 
ushort GetValue (ZCT coord, int x, int y)
 
ushort GetValue (int z, int c, int t, int x, int y)
 
ushort GetValueRGB (ZCT coord, int x, int y, int RGBindex)
 
ushort GetValueRGB (int z, int c, int t, int x, int y, int RGBindex)
 
void SetValue (ZCTXY coord, ushort value)
 
void SetValue (int x, int y, int ind, ushort value)
 
void SetValue (int x, int y, ZCT coord, ushort value)
 
void SetValueRGB (ZCTXY coord, int RGBindex, ushort value)
 
Bitmap GetBitmap (ZCT coord)
 
Bitmap GetFiltered (ZCT coord, IntRange r, IntRange g, IntRange b)
 
Bitmap GetFiltered (int ind, IntRange r, IntRange g, IntRange b)
 
UnmanagedImage GetChannelImage (int ind, short s)
 
Bitmap GetEmission (ZCT coord, IntRange rf, IntRange gf, IntRange bf)
 
Bitmap GetRGBBitmap (ZCT coord, IntRange rf, IntRange gf, IntRange bf)
 
List< ROIGetAnnotations (ZCT coord)
 
List< ROIGetAnnotations (int Z, int C, int T)
 
void StackThreshold (bool bit16)
 
async void UpdateBuffersPyramidal ()
 Updates the Buffers based on current pyramidal origin and resolution.
 
void Update ()
 

‍Update() is a function that calls the Update() function of the parent class


 
void Dispose ()
 
override string ToString ()
 

Static Public Member Functions

static BioImage Copy (BioImage b, bool rois)
 
static BioImage Copy (BioImage b)
 
static BioImage CopyInfo (BioImage b, bool copyAnnotations, bool copyChannels)
 
static PointD ToStageSpace (PointD p, double physicalSizeX, double physicalSizeY, double volumeX, double volumeY)
 
static RectangleD ToStageSpace (RectangleD p, double physicalSizeX, double physicalSizeY, double volumeX, double volumeY)
 
static PointD[] ToStageSpace (PointD[] p, double physicalSizeX, double physicalSizeY, double volumeX, double volumeY)
 
static BioImage Substack (BioImage orig, int ser, int zs, int ze, int cs, int ce, int ts, int te)
 
static BioImage MergeChannels (BioImage b2, BioImage b)
 
static BioImage MergeChannels (string bname, string b2name)
 
static BioImage MergeZ (BioImage b)
 
static BioImage MergeT (BioImage b)
 
static BioImage[] SplitChannels (BioImage bb)
 
static BioImage[] SplitChannels (string name)
 
static unsafe Bitmap GetBitmapRGB (int w, int h, PixelFormat px, byte[] bts)
 
static void Initialize ()
 
static int GetSeriesCount (string file)
 
static void SaveFile (string file, string ID)
 
static void SaveSeries (string[] IDs, string file)
 
static BioImage[] OpenSeries (string file, bool tab)
 
static BioImage OpenFile (string file)
 
static BioImage OpenFile (string file, bool tab)
 
static BioImage OpenFile (string file, int series, bool tab, bool addToImages)
 
static BioImage OpenFile (string file, int series, bool tab, bool addToImages, bool tile, int tileX, int tileY, int tileSizeX, int tileSizeY)
 
static bool isTiffSeries (string file)
 
static bool isOME (string file)
 
static bool isOMESeries (string file)
 
static void SaveOME (string file, string ID)
 
static void SaveOME (BioImage image, string file)
 
static void SaveOMESeries (BioImage[] files, string f, bool planes)
 
static void SaveOMEPyramidal (BioImage[] bms, string file, Enums.ForeignTiffCompression compression, int compressionLevel)
 The function SaveOMEPyramidal saves a collection of BioImages as a pyramidal OME-TIFF file.
 
static BioImage OpenOME (string file, bool tab)
 
static BioImage OpenOME (string file, int serie)
 
static BioImage FilesToStack (string[] files, int sizeZ, int sizeC, int sizeT)
 
static BioImage FolderToStack (string path, bool tab)
 
static void OpenVips (BioImage b, int pagecount)
 
static Bitmap ExtractRegionFromTiledTiff (BioImage b, int x, int y, int width, int height, int res)
 
static BioImage OpenOME (string file, int serie, bool tab, bool addToImages, bool tile, int tilex, int tiley, int tileSizeX, int tileSizeY, bool useOpenSlide=true)
 The function "OpenOME" opens a bioimage file, with options to specify the series, whether to.
 
static Bitmap GetTile (BioImage b, ZCT coord, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
 
static Bitmap GetTile (BioImage b, int index, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
 
static int GetBitsPerPixel (int bt)
 
static int GetBitMaxValue (int bt)
 
static PixelFormat GetPixelFormat (int rgbChannelCount, int bitsPerPixel)
 
static PixelFormat GetPixelFormat (int rgbChannelCount, ome.xml.model.enums.PixelType px)
 
static BioImage[] OpenOMESeries (string file, bool tab, bool addToImages)
 
static async Task OpenAsync (string file, bool OME, bool newtab, bool images, int series)
 
static async Task OpenAsync (string[] files, bool OME, bool tab, bool images)
 
static void Open (string file)
 
static void Open (string[] files)
 
static BioImage ImagesToStack (string[] files, bool tab)
 
static void Update (BioImage b)
 
static async Task SaveAsync (string file, string id, int serie, bool ome)
 The SaveAsync function saves data to a file asynchronously.
 
static async Task SaveSeriesAsync (BioImage[] imgs, string file, bool ome)
 The function SaveSeriesAsync saves a series of BioImage objects to a file asynchronously.
 
static async Task SavePyramidalAsync (BioImage[] imgs, string file, Enums.ForeignTiffCompression com, int compLevel)
 The function SavePyramidalAsync saves an array of BioImage objects as a pyramidal TIFF file asynchronously.
 
static bool VipsSupport (string file)
 
static string OpenXML (string file)
 
static List< ROIOpenOMEROIs (string file, int series)
 
static string ROIsToString (List< ROI > Annotations)
 
static string ROIToString (ROI an)
 
static ROI StringToROI (string sts)
 
static void ExportROIsCSV (string filename, List< ROI > Annotations)
 
static List< ROIImportROIsCSV (string filename)
 
static void ExportROIFolder (string path, string filename)
 
static void AutoThreshold (BioImage b, bool updateImageStats)
 
static void AutoThreshold ()
 It takes the current image, and finds the best threshold value for it.
 
static void AutoThresholdThread (BioImage b)
 
static int FindFocus (BioImage im, int Channel, int Time)
 
static BioImage operator/ (BioImage a, float b)
 
static BioImage operator* (BioImage a, float b)
 
static BioImage operator+ (BioImage a, float b)
 
static BioImage operator- (BioImage a, float b)
 
static BioImage operator/ (BioImage a, ColorS b)
 
static BioImage operator* (BioImage a, ColorS b)
 
static BioImage operator+ (BioImage a, ColorS b)
 
static BioImage operator- (BioImage a, ColorS b)
 

Public Attributes

WellPlate Plate = null
 
int[,,] Coords
 
List< Channel > Channels = new List<Channel>()
 
List< ResolutionResolutions = new List<Resolution>()
 
List< AForge.Bitmap > Buffers = new List<AForge.Bitmap>()
 
List< NetVips.Image > vipPages = new List<NetVips.Image>()
 
VolumeD Volume
 
List< ROIAnnotations = new List<ROI>()
 
string filename = ""
 
string script = ""
 
int[] rgbChannels = new int[3]
 
int bitsPerPixel
 
int imagesPerSeries = 0
 
int seriesCount = 1
 
double frameInterval = 0
 
bool littleEndian = false
 
bool isGroup = false
 
long loadTimeMS = 0
 
long loadTimeTicks = 0
 
bool selected = false
 
Stopwatch watch = new Stopwatch()
 
string file
 
bool Loading = false
 
ImageReader imRead
 
Tiff tifRead
 
OpenSlideImage openSlideImage
 

Static Public Attributes

static bool Planes = false
 
static string status
 
static string progFile
 
static LevelsLinear filter8 = new LevelsLinear()
 
static LevelsLinear16bpp filter16 = new LevelsLinear16bpp()
 
static Stopwatch swatch = new Stopwatch()
 
const char NewLine = '\n'
 
const string columns = "ROIID,ROINAME,TYPE,ID,SHAPEINDEX,TEXT,S,C,Z,T,X,Y,W,H,POINTS,STROKECOLOR,STROKECOLORW,FILLCOLOR,FONTSIZE\n"
 

Properties

ZCT Coordinate [get, set]
 
ImageType Type [get, set]
 
int Level [get, set]
 
string Filename [get, set]
 
int RGBChannelCount [get]
 
Statistics Statistics [get, set]
 
double Resolution [get, set]
 
string ID [get, set]
 
int ImageCount [get]
 
double PhysicalSizeX [get]
 
double PhysicalSizeY [get]
 
double PhysicalSizeZ [get]
 
double StageSizeX [get, set]
 
double StageSizeY [get, set]
 
double StageSizeZ [get, set]
 
Size PyramidalSize [get, set]
 
PointD PyramidalOrigin [get, set]
 
int series [get, set]
 
OpenSlideBase OpenSlideBase [get]
 
SlideBase SlideBase [get]
 
Channel RChannel [get]
 
Channel GChannel [get]
 
Channel BChannel [get]
 
List< ROIAnnotationsR [get]
 
List< ROIAnnotationsG [get]
 
List< ROIAnnotationsB [get]
 
List< ROIAnnotationsRGB [get]
 
int SizeX [get]
 
int SizeY [get]
 
int SizeZ [get]
 
int SizeC [get]
 
int SizeT [get]
 
object Tag [get, set]
 
IntRange RRange [get]
 
IntRange GRange [get]
 
IntRange BRange [get]
 
Bitmap SelectedBuffer [get]
 
bool isRGB [get]
 
bool isTime [get]
 
bool isSeries [get]
 
bool isPyramidal [get]
 
static double progressValue [get, set]
 
static bool Initialized [get]
 
int? MacroResolution [get, set]
 
int? LabelResolution [get, set]
 

Member Enumeration Documentation

◆ ImageType

Enumerator
stack 
pyramidal 
well 

Constructor & Destructor Documentation

◆ BioImage()

BioGTK.BioImage.BioImage ( string  file)
inline
3635 {
3636 id = file;
3637 this.file = file;
3638 filename = Images.GetImageName(id);
3639 Coordinate = new ZCT();
3640 rgbChannels[0] = 0;
3641 rgbChannels[1] = 0;
3642 rgbChannels[2] = 0;
3643 }
string file
Definition Bio.cs:2721
string filename
Definition Bio.cs:2141
ZCT Coordinate
Definition Bio.cs:2082
int[] rgbChannels
Definition Bio.cs:2154

Member Function Documentation

◆ AutoThreshold() [1/2]

static void BioGTK.BioImage.AutoThreshold ( )
inlinestatic

It takes the current image, and finds the best threshold value for it.

8347 {
8348 AutoThreshold(bstats, update);
8349 }
static void AutoThreshold()
It takes the current image, and finds the best threshold value for it.
Definition Bio.cs:8346

◆ AutoThreshold() [2/2]

static void BioGTK.BioImage.AutoThreshold ( BioImage  b,
bool  updateImageStats 
)
inlinestatic

It takes a BioImage object, and calculates the mean histogram for each channel, and for the entire image.

The BioImage object is a class that contains a list of buffers, each of which contains a byte array of pixel data.

The function also calculates the mean histogram for each buffer, and stores it in the buffer's stats property.

The function also calculates the mean histogram for each channel, and stores it in the channel's stats property.

The function also calculates the mean histogram for the entire image, and stores it in the image's statistics property.

The mean histogram is calculated by adding up the histograms of each buffer, and then dividing by the number of buffers.

The histogram is calculated by looping through the byte array of pixel data, and incrementing the value of the histogram at the index of the pixel value.

The histogram

Parameters
BioImageThis is the image object that contains the image data.
updateImageStatsif true, the image stats will be updated.
8273 {
8274 bstats = b;
8275 Statistics statistics = null;
8276 if (b.bitsPerPixel > 8)
8277 statistics = new Statistics(true);
8278 else
8279 statistics = new Statistics(false);
8280 for (int i = 0; i < b.Buffers.Count; i++)
8281 {
8282 if (b.Buffers[i].Stats == null || updateImageStats)
8283 b.Buffers[i].Stats = Statistics.FromBytes(b.Buffers[i]);
8284 if (b.Buffers[i].RGBChannelsCount == 1)
8285 statistics.AddStatistics(b.Buffers[i].Stats[0]);
8286 else
8287 {
8288 for (int r = 0; r < b.Buffers[i].RGBChannelsCount; r++)
8289 {
8290 statistics.AddStatistics(b.Buffers[i].Stats[r]);
8291 }
8292 }
8293 }
8294 for (int c = 0; c < b.Channels.Count; c++)
8295 {
8296 Statistics[] sts = new Statistics[b.Buffers[0].RGBChannelsCount];
8297 for (int i = 0; i < b.Buffers[0].RGBChannelsCount; i++)
8298 {
8299 if (b.bitsPerPixel > 8)
8300 {
8301 sts[i] = new Statistics(true);
8302 }
8303 else
8304 sts[i] = new Statistics(false);
8305 }
8306 for (int z = 0; z < b.SizeZ; z++)
8307 {
8308 for (int t = 0; t < b.SizeT; t++)
8309 {
8310 int ind;
8311 if(b.Channels.Count > b.SizeC)
8312 {
8313 ind = b.Coords[z, 0, t];
8314 }
8315 else
8316 ind = b.Coords[z, c, t];
8317 if (b.Buffers[ind].RGBChannelsCount == 1)
8318 sts[0].AddStatistics(b.Buffers[ind].Stats[0]);
8319 else
8320 {
8321 sts[0].AddStatistics(b.Buffers[ind].Stats[0]);
8322 sts[1].AddStatistics(b.Buffers[ind].Stats[1]);
8323 sts[2].AddStatistics(b.Buffers[ind].Stats[2]);
8324 if (b.Buffers[ind].RGBChannelsCount == 4)
8325 sts[3].AddStatistics(b.Buffers[ind].Stats[3]);
8326 }
8327 }
8328 }
8329 if (b.RGBChannelCount == 1)
8330 sts[0].MeanHistogram();
8331 else
8332 {
8333 sts[0].MeanHistogram();
8334 sts[1].MeanHistogram();
8335 sts[2].MeanHistogram();
8336 if (b.Buffers[0].RGBChannelsCount == 4)
8337 sts[3].MeanHistogram();
8338 }
8339 b.Channels[c].stats = sts;
8340 }
8341 statistics.MeanHistogram();
8342 b.statistics = statistics;
8343
8344 }
Statistics Statistics
Definition Bio.cs:2172

◆ AutoThresholdThread()

static void BioGTK.BioImage.AutoThresholdThread ( BioImage  b)
inlinestatic

It creates a new thread that calls the AutoThreshold function

Parameters
BioImageThis is a class that holds the image data and some other information.
8354 {
8355 bstats = b;
8356 Thread th = new Thread(AutoThreshold);
8357 th.Start();
8358 }

◆ Bake() [1/2]

void BioGTK.BioImage.Bake ( int  rmin,
int  rmax,
int  gmin,
int  gmax,
int  bmin,
int  bmax 
)
inline

Bake(int rmin, int rmax, int gmin, int gmax, int bmin, int bmax)

Parameters
rminThe minimum value of the red channel.
rmaxThe maximum value of the red channel.
gminThe minimum value of the green channel.
gmaxThe maximum value of the green channel.
bminThe minimum value of the blue channel.
bmaxThe maximum value of the blue channel.
3226 {
3227 Bake(new IntRange(rmin, rmax), new IntRange(gmin, gmax), new IntRange(bmin, bmax));
3228 }
void Bake(int rmin, int rmax, int gmin, int gmax, int bmin, int bmax)
Definition Bio.cs:3225

◆ Bake() [2/2]

void BioGTK.BioImage.Bake ( IntRange  rf,
IntRange  gf,
IntRange  bf 
)
inline

It takes a range of values for each channel, and creates a new image with the filtered values

Parameters
IntRange
IntRange
IntRange
3236 {
3237 BioImage bm = new BioImage(Images.GetImageName(ID));
3238 bm = CopyInfo(this, true, true);
3239 for (int i = 0; i < Buffers.Count; i++)
3240 {
3241 ZCT co = Buffers[i].Coordinate;
3242 UnmanagedImage b = GetFiltered(i, rf, gf, bf);
3243 Bitmap inf = new Bitmap(bm.ID, b, co, i);
3244 Statistics.CalcStatistics(inf);
3245 bm.Coords[co.Z, co.C, co.T] = i;
3246 bm.Buffers.Add(inf);
3247 }
3248 foreach (Channel item in bm.Channels)
3249 {
3250 for (int i = 0; i < item.range.Length; i++)
3251 {
3252 item.range[i].Min = 0;
3253 if (bm.bitsPerPixel > 8)
3254 item.range[i].Max = ushort.MaxValue;
3255 else
3256 item.range[i].Max = 255;
3257 }
3258 }
3259 //We wait for threshold image statistics calculation
3260 do
3261 {
3262 Thread.Sleep(50);
3263 } while (Buffers[Buffers.Count - 1].Stats == null);
3264 AutoThreshold(bm, false);
3265 Statistics.ClearCalcBuffer();
3266 Images.AddImage(bm, true);
3267 App.tabsView.AddTab(bm);
3268 Recorder.AddLine("ImageView.SelectedImage.Bake(" + rf.Min + "," + rf.Max + "," + gf.Min + "," + gf.Max + "," + bf.Min + "," + bf.Max + ");");
3269 }
AForge.Bitmap Bitmap
Definition Bio.cs:21
Bitmap GetFiltered(ZCT coord, IntRange r, IntRange g, IntRange b)
Definition Bio.cs:4258
BioImage(string file)
Definition Bio.cs:3634
List< AForge.Bitmap > Buffers
Definition Bio.cs:2102
string ID
Definition Bio.cs:2350
static BioImage CopyInfo(BioImage b, bool copyAnnotations, bool copyChannels)
Definition Bio.cs:2268

◆ Copy() [1/4]

BioImage BioGTK.BioImage.Copy ( )
inline

‍This function copies the current BioImage object and returns a new BioImage object

Returns
A copy of the BioImage object.
2258 {
2259 return BioImage.Copy(this, true);
2260 }

◆ Copy() [2/4]

static BioImage BioGTK.BioImage.Copy ( BioImage  b)
inlinestatic

Copy a BioImage object.

Parameters
BioImageThe image to copy
Returns
A copy of the BioImage object.
2242 {
2243 return Copy(b, true);
2244 }
BioImage Copy()
Definition Bio.cs:2257

◆ Copy() [3/4]

static BioImage BioGTK.BioImage.Copy ( BioImage  b,
bool  rois 
)
inlinestatic

It copies the BioImage b and returns a new BioImage object.

Parameters
BioImageThe BioImage object to copy
roisIf true, the ROIs will be copied. If false, the ROIs will be ignored.
2202 {
2203 BioImage bi = new BioImage(b.ID);
2204 if (rois)
2205 foreach (ROI an in b.Annotations)
2206 {
2207 bi.Annotations.Add(an);
2208 }
2209 foreach (Bitmap bf in b.Buffers)
2210 {
2211 bi.Buffers.Add(bf.Copy());
2212 }
2213 foreach (Channel c in b.Channels)
2214 {
2215 bi.Channels.Add(c);
2216 }
2217 bi.Volume = b.Volume;
2218 bi.Coords = b.Coords;
2219 bi.sizeZ = b.sizeZ;
2220 bi.sizeC = b.sizeC;
2221 bi.sizeT = b.sizeT;
2222 bi.series = b.series;
2223 bi.seriesCount = b.seriesCount;
2224 bi.frameInterval = b.frameInterval;
2225 bi.littleEndian = b.littleEndian;
2226 bi.isGroup = b.isGroup;
2227 bi.imageInfo = b.imageInfo;
2228 bi.bitsPerPixel = b.bitsPerPixel;
2229 bi.file = b.file;
2230 bi.filename = b.filename;
2231 bi.Resolutions = b.Resolutions;
2232 bi.statistics = b.statistics;
2233 bi.openSlideImage = b.openSlideImage;
2234 return bi;
2235 }

◆ Copy() [4/4]

BioImage BioGTK.BioImage.Copy ( bool  rois)
inline

Copy the image and optionally the ROIs

Parameters
roisBoolean value indicating whether to copy the ROIs or not.
Returns
A copy of the BioImage object.
2251 {
2252 return BioImage.Copy(this, rois);
2253 }

◆ CopyInfo()

static BioImage BioGTK.BioImage.CopyInfo ( BioImage  b,
bool  copyAnnotations,
bool  copyChannels 
)
inlinestatic

CopyInfo() copies the information from one BioImage to another

Parameters
BioImagethe image to copy
copyAnnotationstrue
copyChannelstrue
Returns
A new BioImage object.
2269 {
2270 BioImage bi = new BioImage(b.ID);
2271 if (copyAnnotations)
2272 foreach (ROI an in b.Annotations)
2273 {
2274 bi.Annotations.Add(an);
2275 }
2276 if (copyChannels)
2277 foreach (Channel c in b.Channels)
2278 {
2279 bi.Channels.Add(c.Copy());
2280 }
2281
2282 bi.Coords = b.Coords;
2283 bi.Volume = b.Volume;
2284 bi.sizeZ = b.sizeZ;
2285 bi.sizeC = b.sizeC;
2286 bi.sizeT = b.sizeT;
2287 bi.series = b.series;
2288 bi.seriesCount = b.seriesCount;
2289 bi.frameInterval = b.frameInterval;
2290 bi.littleEndian = b.littleEndian;
2291 bi.isGroup = b.isGroup;
2292 bi.imageInfo = b.imageInfo;
2293 bi.bitsPerPixel = b.bitsPerPixel;
2294 bi.Resolutions = b.Resolutions;
2295 bi.Coordinate = b.Coordinate;
2296 bi.file = b.file;
2297 bi.Filename = b.Filename;
2298 bi.ID = Images.GetImageName(b.file);
2299 bi.statistics = b.statistics;
2300 return bi;
2301 }

◆ Dispose()

void BioGTK.BioImage.Dispose ( )
inline

It disposes of all the buffers and channels in the image, removes the image from the Images list, and then forces the garbage collector to run

8430 {
8431 for (int i = 0; i < Buffers.Count; i++)
8432 {
8433 Buffers[i].Dispose();
8434 }
8435 for (int i = 0; i < Channels.Count; i++)
8436 {
8437 Channels[i].Dispose();
8438 }
8439 for (int i = 0; i < Annotations.Count; i++)
8440 {
8441 Annotations[i].Dispose();
8442 }
8443 }
List< Channel > Channels
Definition Bio.cs:2100
List< ROI > Annotations
Definition Bio.cs:2140

◆ ExportROIFolder()

static void BioGTK.BioImage.ExportROIFolder ( string  path,
string  filename 
)
inlinestatic

ExportROIFolder(path, filename)

This function takes a folder path and a filename as input and exports all the ROIs in the folder as CSV files

Parameters
paththe path to the folder containing the OMERO ROI files
filenamethe name of the file you want to export
8233 {
8234 string[] fs = Directory.GetFiles(path);
8235 int i = 0;
8236 foreach (string f in fs)
8237 {
8238 List<ROI> annotations = OpenOMEROIs(f, 0);
8239 string ff = Path.GetFileNameWithoutExtension(f);
8240 ExportROIsCSV(path + "//" + ff + "-" + i.ToString() + ".csv", annotations);
8241 i++;
8242 }
8243 }
static List< ROI > OpenOMEROIs(string file, int series)
Definition Bio.cs:7619
static void ExportROIsCSV(string filename, List< ROI > Annotations)
Definition Bio.cs:8201

◆ ExportROIsCSV()

static void BioGTK.BioImage.ExportROIsCSV ( string  filename,
List< ROI Annotations 
)
inlinestatic

This function takes a list of ROIs and writes them to a CSV file

Parameters
filenamethe name of the file to be saved
AnnotationsList of ROI objects
8202 {
8203 string con = columns;
8204 con += ROIsToString(Annotations);
8205 File.WriteAllText(filename, con);
8206 }
static string ROIsToString(List< ROI > Annotations)
Definition Bio.cs:8002
const string columns
Definition Bio.cs:7598

◆ ExtractRegionFromTiledTiff()

static Bitmap BioGTK.BioImage.ExtractRegionFromTiledTiff ( BioImage  b,
int  x,
int  y,
int  width,
int  height,
int  res 
)
inlinestatic

The function ExtractRegionFromTiledTiff takes a BioImage object, coordinates, width, height, and resolution as input, and returns a Bitmap object representing the extracted region from the tiled TIFF image.

Parameters
BioImageThe BioImage object represents an image file that contains multiple pages or resolutions. It contains information about the image file, such as the file path, the number of pages, and the format of each page.
xThe x-coordinate of the top-left corner of the region to extract from the tiled TIFF image.
yThe parameter "y" represents the starting y-coordinate of the region to be extracted from the tiled TIFF image.
widthThe width parameter represents the width of the region to be extracted from the tiled TIFF image.
heightThe height parameter represents the height of the region to be extracted from the tiled TIFF image.
resThe parameter "res" represents the resolution level of the tiled TIFF image. It is used to specify the level of detail or zoom level at which the image is being extracted.
Returns
The method is returning a Bitmap object.
6103 {
6104 try
6105 {
6106 NetVips.Image subImage = b.vipPages[res].Crop(x, y, width, height);
6107 if (b.vipPages[res].Format == Enums.BandFormat.Uchar)
6108 {
6109 Bitmap bm;
6110 byte[] imageData = subImage.WriteToMemory();
6111 if (b.Resolutions[res].RGBChannelsCount == 3)
6112 bm = new Bitmap(width, height, PixelFormat.Format24bppRgb, imageData, new ZCT(), b.file);
6113 else
6114 bm = new Bitmap(width, height, PixelFormat.Format8bppIndexed, imageData, new ZCT(), b.file);
6115 return bm;
6116
6117 }
6118 else if (b.vipPages[res].Format == Enums.BandFormat.Ushort)
6119 {
6120 Bitmap bm;
6121 byte[] imageData = subImage.WriteToMemory();
6122 if (b.Resolutions[res].RGBChannelsCount == 3)
6123 bm = new Bitmap(width, height, PixelFormat.Format24bppRgb, imageData, new ZCT(), b.file);
6124 else
6125 bm = new Bitmap(width, height, PixelFormat.Format8bppIndexed, imageData, new ZCT(), b.file);
6126 return bm;
6127 }
6128 }
6129 catch (Exception ex)
6130 {
6131 Console.WriteLine($"Error: {ex.Message}");
6132 return null;
6133 }
6134 return null;
6135 }

◆ FilesToStack()

static BioImage BioGTK.BioImage.FilesToStack ( string[]  files,
int  sizeZ,
int  sizeC,
int  sizeT 
)
inlinestatic

It takes a list of files, and creates a new BioImage object with the first file in the list. Then it loops through the rest of the files, adding the buffers from each file to the new BioImage object. Finally, it updates the coordinates of the new BioImage object, and adds it to the Images list

Parameters
filesan array of file paths
sizeZnumber of slices in the stack
sizeCnumber of channels
sizeTnumber of time points
Returns
A BioImage object.
6008 {
6009 BioImage b = new BioImage(files[0]);
6010 for (int i = 0; i < files.Length; i++)
6011 {
6012 BioImage bb = OpenFile(files[i], false);
6013 b.Buffers.AddRange(bb.Buffers);
6014 }
6015 b.UpdateCoords(sizeZ, sizeC, sizeT);
6016 Images.AddImage(b, true);
6017 return b;
6018 }
static BioImage OpenFile(string file)
Definition Bio.cs:4874

◆ FindFocus()

static int BioGTK.BioImage.FindFocus ( BioImage  im,
int  Channel,
int  Time 
)
inlinestatic

The function finds the focus of a given BioImage at a specific channel and time by calculating the focus quality of each Z-plane and returning the coordinate with the highest focus quality.

Parameters
BioImageA BioImage object that contains the image data.
ChannelThe channel of the BioImage to analyze. A BioImage can have multiple channels, each representing a different fluorescent label or imaging modality.
TimeThe time point at which the focus is being calculated.
Returns
an integer value which represents the coordinate of the image with the highest focus quality in a given channel and time.
8371 {
8372 long mf = 0;
8373 int fr = 0;
8374 List<double> dt = new List<double>();
8375 ZCT c = new ZCT(0, 0, 0);
8376 for (int i = 0; i < im.SizeZ; i++)
8377 {
8378 long f = CalculateFocusQuality(im.Buffers[im.Coords[i, Channel, Time]]);
8379 dt.Add(f);
8380 if (f > mf)
8381 {
8382 mf = f;
8383 fr = im.Coords[i, Channel, Time];
8384 }
8385 }
8386 Plot pl = Plot.Create(dt.ToArray(), "Focus");
8387 pl.Show();
8388 return fr;
8389 }

◆ FolderToStack()

static BioImage BioGTK.BioImage.FolderToStack ( string  path,
bool  tab 
)
inlinestatic

It takes a folder of images and creates a stack from them

Parameters
paththe path to the folder containing the images
Returns
A BioImage object.
6025 {
6026 string[] files = Directory.GetFiles(path);
6027 BioImage b = new BioImage(files[0]);
6028 int z = 0;
6029 int c = 0;
6030 int t = 0;
6031 BioImage bb = null;
6032 for (int i = 0; i < files.Length; i++)
6033 {
6034 string[] st = files[i].Split('_');
6035 if (st.Length > 3)
6036 {
6037 z = int.Parse(st[1].Replace("Z", ""));
6038 c = int.Parse(st[2].Replace("C", ""));
6039 t = int.Parse(st[3].Replace("T", ""));
6040 }
6041 bb = OpenFile(files[i], tab);
6042 b.Buffers.AddRange(bb.Buffers);
6043 }
6044 if (z == 0)
6045 {
6046 /*TO DO
6047 ImagesToStack im = new ImagesToStack();
6048 if (im.ShowDialog() != DialogResult.OK)
6049 return null;
6050 b.UpdateCoords(im.SizeZ, im.SizeC, im.SizeT);
6051 */
6052 }
6053 else
6054 b.UpdateCoords(z + 1, c + 1, t + 1);
6055 Images.AddImage(b, tab);
6056 Recorder.AddLine("BioImage.FolderToStack(\"" + path + "\");");
6057 return b;
6058 }

◆ GetAnnotations() [1/2]

List< ROI > BioGTK.BioImage.GetAnnotations ( int  Z,
int  C,
int  T 
)
inline

This function returns a list of ROI objects that are associated with the specified Z, C, and T coordinates

Parameters
ZThe Z-stack index
CChannel
TTime
Returns
A list of ROI objects.
4566 {
4567 List<ROI> annotations = new List<ROI>();
4568 foreach (ROI an in Annotations)
4569 {
4570 if (an.coord.Z == Z && an.coord.Z == Z && an.coord.C == C && an.coord.T == T)
4571 annotations.Add(an);
4572 }
4573 return annotations;
4574 }

◆ GetAnnotations() [2/2]

List< ROI > BioGTK.BioImage.GetAnnotations ( ZCT  coord)
inline

‍GetAnnotations() returns a list of ROI objects that are associated with the ZCT coordinate

passed in as a parameter

Parameters
ZCTa 3D coordinate (Z, C, T)
Returns
A list of ROI objects.
4546 {
4547 List<ROI> annotations = new List<ROI>();
4548 foreach (ROI an in Annotations)
4549 {
4550 if (an == null)
4551 continue;
4552 if (an.coord == coord)
4553 annotations.Add(an);
4554 }
4555 return annotations;
4556 }

◆ GetBitmap() [1/2]

Bitmap BioGTK.BioImage.GetBitmap ( int  z,
int  c,
int  t 
)
inline

"Given a z, c, t coordinate, return the bitmap at that coordinate."

The function is called by the following code:

Parameters
zthe z-stack index
cchannel
ttime
Returns
A bitmap.
4043 {
4044 return Buffers[Coords[z, c, t]];
4045 }
int[,,] Coords
Definition Bio.cs:2079

◆ GetBitmap() [2/2]

Bitmap BioGTK.BioImage.GetBitmap ( ZCT  coord)
inline

‍This function returns a Bitmap object from the image data stored in the OME-TIFF file

Parameters
ZCTZ = Z-stack, C = channel, T = timepoint
Returns
A Bitmap object.
4247 {
4248 return (Bitmap)GetImageByCoord(coord.Z, coord.C, coord.T);
4249 }
Bitmap GetImageByCoord(int z, int c, int t)
Definition Bio.cs:4029

◆ GetBitmapRGB()

static unsafe Bitmap BioGTK.BioImage.GetBitmapRGB ( int  w,
int  h,
PixelFormat  px,
byte[]  bts 
)
inlinestatic

It takes a byte array of RGB or RGBA data and converts it to a Bitmap

Parameters
wwidth of the image
hheight of the image
PixelFormatThe pixel format of the image.
btsthe byte array of the image
Returns
A Bitmap object.
4380 {
4381 if (px == PixelFormat.Format32bppArgb)
4382 {
4383 //opening a 8 bit per pixel jpg image
4384 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4385 //creating the bitmapdata and lock bits
4386 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4387 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4388 //iterating through all the pixels in y direction
4389 for (int y = 0; y < h; y++)
4390 {
4391 //getting the pixels of current row
4392 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4393 int rowRGB = y * w * 4;
4394 //iterating through all the pixels in x direction
4395 for (int x = 0; x < w; x++)
4396 {
4397 int indexRGB = x * 4;
4398 int indexRGBA = x * 4;
4399 row[indexRGBA + 3] = bts[rowRGB + indexRGB + 3];//byte A
4400 row[indexRGBA + 2] = bts[rowRGB + indexRGB + 2];//byte R
4401 row[indexRGBA + 1] = bts[rowRGB + indexRGB + 1];//byte G
4402 row[indexRGBA] = bts[rowRGB + indexRGB];//byte B
4403 }
4404 }
4405 //unlocking bits and disposing image
4406 bmp.UnlockBits(bmd);
4407 return bmp;
4408 }
4409 else if (px == PixelFormat.Format24bppRgb)
4410 {
4411 //opening a 8 bit per pixel jpg image
4412 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4413 //creating the bitmapdata and lock bits
4414 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4415 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4416 //iterating through all the pixels in y direction
4417 for (int y = 0; y < h; y++)
4418 {
4419 //getting the pixels of current row
4420 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4421 int rowRGB = y * w * 3;
4422 //iterating through all the pixels in x direction
4423 for (int x = 0; x < w; x++)
4424 {
4425 int indexRGB = x * 3;
4426 int indexRGBA = x * 4;
4427 row[indexRGBA + 3] = byte.MaxValue;//byte A
4428 row[indexRGBA + 2] = bts[rowRGB + indexRGB + 2];//byte R
4429 row[indexRGBA + 1] = bts[rowRGB + indexRGB + 1];//byte G
4430 row[indexRGBA] = bts[rowRGB + indexRGB];//byte B
4431 }
4432 }
4433 //unlocking bits and disposing image
4434 bmp.UnlockBits(bmd);
4435 return bmp;
4436 }
4437 else
4438 if (px == PixelFormat.Format48bppRgb)
4439 {
4440 //opening a 8 bit per pixel jpg image
4441 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4442 //creating the bitmapdata and lock bits
4443 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4444 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4445 unsafe
4446 {
4447 //iterating through all the pixels in y direction
4448 for (int y = 0; y < h; y++)
4449 {
4450 //getting the pixels of current row
4451 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4452 int rowRGB = y * w * 6;
4453 //iterating through all the pixels in x direction
4454 for (int x = 0; x < w; x++)
4455 {
4456 int indexRGB = x * 6;
4457 int indexRGBA = x * 4;
4458 int b = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB) / 255);
4459 int g = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB + 2) / 255);
4460 int r = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB + 4) / 255);
4461 row[indexRGBA + 3] = 255;//byte A
4462 row[indexRGBA + 2] = (byte)(b);//byte R
4463 row[indexRGBA + 1] = (byte)(g);//byte G
4464 row[indexRGBA] = (byte)(r);//byte B
4465 }
4466 }
4467 }
4468 bmp.UnlockBits(bmd);
4469 return bmp;
4470 }
4471 else
4472 if (px == PixelFormat.Format8bppIndexed)
4473 {
4474 //opening a 8 bit per pixel jpg image
4475 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4476 //creating the bitmapdata and lock bits
4477 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4478 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4479 unsafe
4480 {
4481 //iterating through all the pixels in y direction
4482 for (int y = 0; y < h; y++)
4483 {
4484 //getting the pixels of current row
4485 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4486 int rowRGB = y * w;
4487 //iterating through all the pixels in x direction
4488 for (int x = 0; x < w; x++)
4489 {
4490 int indexRGB = x;
4491 int indexRGBA = x * 4;
4492 byte b = bts[rowRGB + indexRGB];
4493 row[indexRGBA + 3] = 255;//byte A
4494 row[indexRGBA + 2] = (byte)(b);//byte R
4495 row[indexRGBA + 1] = (byte)(b);//byte G
4496 row[indexRGBA] = (byte)(b);//byte B
4497 }
4498 }
4499 }
4500 bmp.UnlockBits(bmd);
4501 return bmp;
4502 }
4503 else
4504 if (px == PixelFormat.Format16bppGrayScale)
4505 {
4506 //opening a 8 bit per pixel jpg image
4507 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4508 //creating the bitmapdata and lock bits
4509 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4510 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4511 unsafe
4512 {
4513 //iterating through all the pixels in y direction
4514 for (int y = 0; y < h; y++)
4515 {
4516 //getting the pixels of current row
4517 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4518 int rowRGB = y * w * 2;
4519 //iterating through all the pixels in x direction
4520 for (int x = 0; x < w; x++)
4521 {
4522 int indexRGB = x * 2;
4523 int indexRGBA = x * 4;
4524 ushort b = (ushort)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB) / 255);
4525 row[indexRGBA + 3] = 255;//byte A
4526 row[indexRGBA + 2] = (byte)(b);//byte R
4527 row[indexRGBA + 1] = (byte)(b);//byte G
4528 row[indexRGBA] = (byte)(b);//byte B
4529 }
4530 }
4531 }
4532 bmp.UnlockBits(bmd);
4533 return bmp;
4534 }
4535
4536 throw new NotSupportedException("Pixelformat " + px + " is not supported.");
4537 }

◆ GetBitMaxValue()

static int BioGTK.BioImage.GetBitMaxValue ( int  bt)
inlinestatic

It returns the maximum value of a bit.

Parameters
btbit depth
Returns
The maximum value of a bit.
7191 {
7192 if (bt == 8)
7193 return 255;
7194 if (bt == 9)
7195 return 512;
7196 else if (bt == 10)
7197 return 1023;
7198 else if (bt == 11)
7199 return 2047;
7200 else if (bt == 12)
7201 return 4095;
7202 else if (bt == 13)
7203 return 8191;
7204 else if (bt == 14)
7205 return 16383;
7206 else if (bt == 15)
7207 return 32767;
7208 else
7209 return 65535;
7210 }

◆ GetBitsPerPixel()

static int BioGTK.BioImage.GetBitsPerPixel ( int  bt)
inlinestatic

‍If the number is less than or equal to 255, then it's 8 bits. If it's less than or equal

to 512, then it's 9 bits. If it's less than or equal to 1023, then it's 10 bits. If it's less than or equal to 2047, then it's 11 bits. If it's less than or equal to 4095, then it's 12 bits. If it's less than or equal to 8191, then it's 13 bits. If it's less than or equal to 16383, then it's 14 bits. If it's less than or equal to 32767, then it's 15 bits. If it's less than or equal to 65535, then it's 16 bits

Parameters
btThe number of bits per pixel.
Returns
The number of bits per pixel.
7165 {
7166 if (bt <= 255)
7167 return 8;
7168 if (bt <= 512)
7169 return 9;
7170 else if (bt <= 1023)
7171 return 10;
7172 else if (bt <= 2047)
7173 return 11;
7174 else if (bt <= 4095)
7175 return 12;
7176 else if (bt <= 8191)
7177 return 13;
7178 else if (bt <= 16383)
7179 return 14;
7180 else if (bt <= 32767)
7181 return 15;
7182 else
7183 return 16;
7184 }

◆ GetChannelImage()

UnmanagedImage BioGTK.BioImage.GetChannelImage ( int  ind,
short  s 
)
inline

It takes an image, and returns a channel of that image

Parameters
indthe index of the buffer
s0, 1, 2
4295 {
4296 Bitmap bf = Buffers[ind];
4297 if (bf.isRGB)
4298 {
4299 if (s == 0)
4300 return extractR.Apply(Buffers[ind].Image);
4301 else
4302 if (s == 1)
4303 return extractG.Apply(Buffers[ind].Image);
4304 else
4305 return extractB.Apply(Buffers[ind].Image);
4306 }
4307 else
4308 throw new InvalidOperationException();
4309 }
SixLabors.ImageSharp.Image Image
Definition ISlideSource.cs:11

◆ GetEmission()

Bitmap BioGTK.BioImage.GetEmission ( ZCT  coord,
IntRange  rf,
IntRange  gf,
IntRange  bf 
)
inline

‍GetEmission() returns an UnmanagedImage object that is a composite of the emission

channels

Parameters
ZCTZ, C, T coordinates
IntRange
IntRange
IntRange
Returns
A Bitmap or an UnmanagedImage.
4320 {
4321 if (RGBChannelCount == 1)
4322 {
4323 Bitmap[] bs = new Bitmap[Channels.Count];
4324 for (int c = 0; c < Channels.Count; c++)
4325 {
4326 int index = Coords[coord.Z, c, coord.T];
4327 bs[c] = Buffers[index];
4328 }
4329 Bitmap bm = (Bitmap)Bitmap.GetEmissionBitmap(bs, Channels.ToArray());
4330 return bm;
4331 }
4332 else
4333 {
4334 int index = Coords[coord.Z, coord.C, coord.T];
4335 return Buffers[index];
4336 }
4337 }
int RGBChannelCount
Definition Bio.cs:2156

◆ GetFiltered() [1/2]

Bitmap BioGTK.BioImage.GetFiltered ( int  ind,
IntRange  r,
IntRange  g,
IntRange  b 
)
inline

It takes an image, and returns a filtered version of that image

Parameters
indthe index of the buffer to be filtered
IntRange
IntRange
IntRange
Returns
A filtered image.
4272 {
4273 if (Buffers[ind].BitsPerPixel > 8)
4274 {
4275 BioImage.filter16.InRed = r;
4276 BioImage.filter16.InGreen = g;
4277 BioImage.filter16.InBlue = b;
4278 Bitmap bm = BioImage.filter16.Apply(Buffers[ind]);
4279 return bm;
4280 }
4281 else
4282 {
4283 // set ranges
4284 BioImage.filter8.InRed = r;
4285 BioImage.filter8.InGreen = g;
4286 BioImage.filter8.InBlue = b;
4287 return BioImage.filter8.Apply(Buffers[ind]);
4288 }
4289 }

◆ GetFiltered() [2/2]

Bitmap BioGTK.BioImage.GetFiltered ( ZCT  coord,
IntRange  r,
IntRange  g,
IntRange  b 
)
inline

‍Get the image at the specified ZCT coordinate, and return a filtered version of it

Parameters
ZCTa 3-tuple of integers (z, c, t)
IntRange
IntRange
IntRange
Returns
An UnmanagedImage object.
4259 {
4260 int index = Coords[coord.Z, coord.C, coord.T];
4261 return GetFiltered(index, r, g, b);
4262 }

◆ GetImageByCoord()

Bitmap BioGTK.BioImage.GetImageByCoord ( int  z,
int  c,
int  t 
)
inline

‍Get the image at the specified coordinates

Parameters
zthe z-stack index
cchannel
ttime
Returns
A Bitmap object.
4030 {
4031 return Buffers[Coords[z, c, t]];
4032 }

◆ GetIndex()

int BioGTK.BioImage.GetIndex ( int  ix,
int  iy 
)
inline

‍GetIndex(x,y) = (y * stridex + x) * 2

The stridex is the width of the image in bytes.

The stridey is the height of the image in bytes.

Parameters
ixx coordinate of the pixel
iyThe y coordinate of the pixel
Returns
The index of the pixel in the array.
4057 {
4058 if (ix > SizeX || iy > SizeY || ix < 0 || iy < 0)
4059 return 0;
4060 int stridex = SizeX;
4061 int x = ix;
4062 int y = iy;
4063 if (bitsPerPixel > 8)
4064 {
4065 return (y * stridex + x) * 2;
4066 }
4067 else
4068 {
4069 return (y * stridex + x);
4070 }
4071 }
int bitsPerPixel
Definition Bio.cs:2162
int SizeY
Definition Bio.cs:2630
int SizeX
Definition Bio.cs:2621

◆ GetIndexRGB()

int BioGTK.BioImage.GetIndexRGB ( int  ix,
int  iy,
int  index 
)
inline

‍The function returns the index of the pixel in the buffer

Parameters
ixx coordinate of the pixel
iyThe y coordinate of the pixel
index0 = Red, 1 = Green, 2 = Blue
Returns
The index of the pixel in the buffer.
4080 {
4081 int stridex = SizeX;
4082 //For 16bit (2*8bit) images we multiply buffer index by 2
4083 int x = ix;
4084 int y = iy;
4085 if (bitsPerPixel > 8)
4086 {
4087 return (y * stridex + x) * 2 * index;
4088 }
4089 else
4090 {
4091 return (y * stridex + x) * index;
4092 }
4093 }

◆ GetLevelDownsample()

double BioGTK.BioImage.GetLevelDownsample ( int  level)
inline

Get the downsampling factor of a given level.

Parameters
levelThe desired level.

<return> The downsampling factor for this level. </return>

Exceptions
OpenSlideException
2311 {
2312 int originalWidth = Resolutions[0].SizeX; // Width of the original level
2313 int nextLevelWidth = Resolutions[level].SizeX; // Width of the next level (downsampled)
2314 return (double)originalWidth / (double)nextLevelWidth;
2315 }
List< Resolution > Resolutions
Definition Bio.cs:2101

◆ GetLevelDownsamples()

double[] BioGTK.BioImage.GetLevelDownsamples ( )
inline
2317 {
2318 double[] ds = new double[Resolutions.Count];
2319 for (int i = 0; i < Resolutions.Count; i++)
2320 {
2321 ds[i] = Resolutions[0].PhysicalSizeX * GetLevelDownsample(i);
2322 }
2323 return ds;
2324 }
double GetLevelDownsample(int level)
Get the downsampling factor of a given level.
Definition Bio.cs:2310

◆ GetPixelFormat() [1/2]

static PixelFormat BioGTK.BioImage.GetPixelFormat ( int  rgbChannelCount,
int  bitsPerPixel 
)
inlinestatic

If the bits per pixel is 8, then the pixel format is either 8bppIndexed, 24bppRgb, or 32bppArgb. If the bits per pixel is 16, then the pixel format is either 16bppGrayScale or 48bppRgb

Parameters
rgbChannelCountThe number of channels in the image. For example, a grayscale image has 1 channel, a color image has 3 channels (red, green, blue).
bitsPerPixel8 or 16
Returns
The PixelFormat of the image.
7221 {
7222 if (bitsPerPixel == 8)
7223 {
7224 if (rgbChannelCount == 1)
7225 return PixelFormat.Format8bppIndexed;
7226 else if (rgbChannelCount == 3)
7227 return PixelFormat.Format24bppRgb;
7228 else if (rgbChannelCount == 4)
7229 return PixelFormat.Format32bppArgb;
7230 }
7231 else
7232 {
7233 if (rgbChannelCount == 1)
7234 return PixelFormat.Format16bppGrayScale;
7235 if (rgbChannelCount == 3)
7236 return PixelFormat.Format48bppRgb;
7237 }
7238 throw new NotSupportedException("Not supported pixel format.");
7239 }

◆ GetPixelFormat() [2/2]

static PixelFormat BioGTK.BioImage.GetPixelFormat ( int  rgbChannelCount,
ome::xml::model::enums::PixelType  px 
)
inlinestatic

The function returns the appropriate PixelFormat based on the number of RGB channels and the pixel type.

Parameters
rgbChannelCountThe rgbChannelCount parameter represents the number of channels in the RGB color model. It can have a value of either 1 (for grayscale images) or 3 (for RGB color images).
pxThe parameter "px" is of type ome.xml.model.enums.PixelType. It represents the pixel type of the image, such as INT8, UINT8, INT16, or UINT16.
Returns
The method returns a PixelFormat value based on the input parameters.
7251 {
7252 if (rgbChannelCount == 1)
7253 {
7254 if (px == ome.xml.model.enums.PixelType.INT8 || px == ome.xml.model.enums.PixelType.UINT8)
7255 return PixelFormat.Format8bppIndexed;
7256 else if (px == ome.xml.model.enums.PixelType.INT16 || px == ome.xml.model.enums.PixelType.UINT16)
7257 return PixelFormat.Format16bppGrayScale;
7258 }
7259 else if (rgbChannelCount == 3)
7260 {
7261 if (px == ome.xml.model.enums.PixelType.INT8 || px == ome.xml.model.enums.PixelType.UINT8)
7262 return PixelFormat.Format24bppRgb;
7263 else if (px == ome.xml.model.enums.PixelType.INT16 || px == ome.xml.model.enums.PixelType.UINT16)
7264 return PixelFormat.Format48bppRgb;
7265 }
7266 else
7267 return PixelFormat.Format32bppArgb;
7268 throw new InvalidDataException("RGBChannels Count of " + rgbChannelCount + " not supported.");
7269 }

◆ GetRGBBitmap()

Bitmap BioGTK.BioImage.GetRGBBitmap ( ZCT  coord,
IntRange  rf,
IntRange  gf,
IntRange  bf 
)
inline

‍Get the RGB bitmap for the specified ZCT coordinate

Parameters
ZCTZ, C, T coordinates
IntRange
IntRange
IntRange
Returns
A Bitmap object.
4347 {
4348 int index = Coords[coord.Z, coord.C, coord.T];
4349 if (Buffers[0].RGBChannelsCount == 1)
4350 {
4351 if (Channels.Count >= 3)
4352 {
4353 Bitmap[] bs = new Bitmap[3];
4354 bs[2] = Buffers[index + RChannel.Index];
4355 bs[1] = Buffers[index + GChannel.Index];
4356 bs[0] = Buffers[index + BChannel.Index];
4357 return Bitmap.GetRGBBitmap(bs, rf, gf, bf);
4358 }
4359 else
4360 {
4361 Bitmap[] bs = new Bitmap[3];
4362 bs[2] = Buffers[index + RChannel.Index];
4363 bs[1] = Buffers[index + RChannel.Index + 1];
4364 bs[0] = Buffers[index + RChannel.Index + 2];
4365 return Bitmap.GetRGBBitmap(bs, rf, gf, bf);
4366 }
4367 }
4368 else
4369 return Buffers[index];
4370 }
Channel RChannel
Definition Bio.cs:2420
Channel BChannel
Definition Bio.cs:2440
Channel GChannel
Definition Bio.cs:2430

◆ GetSeriesCount()

static int BioGTK.BioImage.GetSeriesCount ( string  file)
inlinestatic
4710 {
4711 reader.setId(file);
4712 int i = reader.getSeriesCount();
4713 int prs = GetPyramidCount();
4714 reader.close();
4715 if (prs > 0)
4716 return prs;
4717 else
4718 return i;
4719 }

◆ GetTile() [1/2]

static Bitmap BioGTK.BioImage.GetTile ( BioImage  b,
int  index,
int  serie,
int  tilex,
int  tiley,
int  tileSizeX,
int  tileSizeY 
)
inlinestatic
7050 {
7051 if ((b.file.EndsWith("ome.tif") && vips) || (b.file.EndsWith(".tif") && vips))
7052 {
7053 //We can get a tile faster with libvips rather than bioformats.
7054 return ExtractRegionFromTiledTiff(b, tilex, tiley, tileSizeX, tileSizeY, serie);
7055 }
7056 //We check if we can open this with OpenSlide as this is faster than Bioformats with IKVM.
7057 if (b.openSlideImage != null && !b.file.EndsWith("ome.tif"))
7058 {
7059 return new Bitmap(tileSizeX, tileSizeY, AForge.PixelFormat.Format32bppArgb, b.openSlideImage.ReadRegion(serie, tilex, tiley, tileSizeX, tileSizeY), new ZCT(), "");
7060 }
7061
7062 string curfile = b.imRead.getCurrentFile();
7063 if (curfile == null)
7064 {
7065 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
7066 b.imRead.close();
7067 b.imRead.setMetadataStore(b.meta);
7068 Console.WriteLine(b.file);
7069 b.imRead.setId(b.file);
7070 }
7071 else
7072 {
7073 string fi = b.file.Replace("\\", "/");
7074 string cf = curfile.Replace("\\", "/");
7075 if (cf != fi)
7076 {
7077 b.imRead.close();
7078 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
7079 b.imRead.setMetadataStore(b.meta);
7080 b.imRead.setId(b.file);
7081 }
7082 }
7083 if (b.imRead.getSeries() != serie)
7084 b.imRead.setSeries(serie);
7085 int SizeX = b.imRead.getSizeX();
7086 int SizeY = b.imRead.getSizeY();
7087 bool flat = b.imRead.hasFlattenedResolutions();
7088 bool littleEndian = b.imRead.isLittleEndian();
7089 bool interleaved = b.imRead.isInterleaved();
7090 PixelFormat PixelFormat = b.Resolutions[serie].PixelFormat;
7091 if (tilex < 0)
7092 tilex = 0;
7093 if (tiley < 0)
7094 tiley = 0;
7095 if (tilex >= SizeX)
7096 tilex = SizeX;
7097 if (tiley >= SizeY)
7098 tiley = SizeY;
7099 int sx = tileSizeX;
7100 if (tilex + tileSizeX > SizeX)
7101 sx -= (tilex + tileSizeX) - (SizeX);
7102 int sy = tileSizeY;
7103 if (tiley + tileSizeY > SizeY)
7104 sy -= (tiley + tileSizeY) - (SizeY);
7105 //For some reason calling openBytes with 1x1px area causes an exception.
7106 if (sx <= 1)
7107 return null;
7108 if (sy <= 1)
7109 return null;
7110 try
7111 {
7112 byte[] bytesr = b.imRead.openBytes(index, tilex, tiley, sx, sy);
7113 return new Bitmap(b.file, sx, sy, PixelFormat, bytesr, new ZCT(), index, null, littleEndian, interleaved);
7114 }
7115 catch (Exception e)
7116 {
7117 Console.WriteLine(e.Message);
7118 return null;
7119 }
7120 }
static Bitmap ExtractRegionFromTiledTiff(BioImage b, int x, int y, int width, int height, int res)
Definition Bio.cs:6102
bool littleEndian
Definition Bio.cs:2166

◆ GetTile() [2/2]

static Bitmap BioGTK.BioImage.GetTile ( BioImage  b,
ZCT  coord,
int  serie,
int  tilex,
int  tiley,
int  tileSizeX,
int  tileSizeY 
)
inlinestatic

It reads a tile from a file, and returns a bitmap

Parameters
BioImageThis is a class that contains the image file name, the image reader, and the coordinates of the image.
ZCTZ, C, T
seriethe series number (0-based)
tilexthe x coordinate of the tile
tileythe y coordinate of the tile
tileSizeXthe width of the tile
tileSizeYthe height of the tile
Returns
A Bitmap object.
6977 {
6978 if ((b.file.EndsWith("ome.tif") && vips) || (b.file.EndsWith(".tif") && vips))
6979 {
6980 //We can get a tile faster with libvips rather than bioformats.
6981 return ExtractRegionFromTiledTiff(b, tilex, tiley, tileSizeX, tileSizeY, serie);
6982 }
6983 //We check if we can open this with OpenSlide as this is faster than Bioformats with IKVM.
6984 if (b.openSlideImage != null && !b.file.EndsWith("ome.tif"))
6985 {
6986 return new Bitmap(tileSizeX, tileSizeY, AForge.PixelFormat.Format32bppArgb, b.openSlideImage.ReadRegion(serie, tilex, tiley, tileSizeX, tileSizeY), new ZCT(), "");
6987 }
6988
6989 string curfile = b.imRead.getCurrentFile();
6990 if (curfile == null)
6991 {
6992 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
6993 b.imRead.close();
6994 b.imRead.setMetadataStore(b.meta);
6995 Console.WriteLine(b.file);
6996 b.imRead.setId(b.file);
6997 }
6998 else
6999 {
7000 string fi = b.file.Replace("\\", "/");
7001 string cf = curfile.Replace("\\", "/");
7002 if (cf != fi)
7003 {
7004 b.imRead.close();
7005 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
7006 b.imRead.setMetadataStore(b.meta);
7007 b.imRead.setId(b.file);
7008 }
7009 }
7010 if (b.imRead.getSeries() != serie)
7011 b.imRead.setSeries(serie);
7012 int SizeX = b.imRead.getSizeX();
7013 int SizeY = b.imRead.getSizeY();
7014 bool flat = b.imRead.hasFlattenedResolutions();
7015 int p = b.Coords[coord.Z, coord.C, coord.T];
7016 bool littleEndian = b.imRead.isLittleEndian();
7017 PixelFormat PixelFormat = b.Resolutions[serie].PixelFormat;
7018 bool interleaved = b.imRead.isInterleaved();
7019 if (tilex < 0)
7020 tilex = 0;
7021 if (tiley < 0)
7022 tiley = 0;
7023 if (tilex >= SizeX)
7024 tilex = SizeX;
7025 if (tiley >= SizeY)
7026 tiley = SizeY;
7027 int sx = tileSizeX;
7028 if (tilex + tileSizeX > SizeX)
7029 sx -= (tilex + tileSizeX) - (SizeX);
7030 int sy = tileSizeY;
7031 if (tiley + tileSizeY > SizeY)
7032 sy -= (tiley + tileSizeY) - (SizeY);
7033 //For some reason calling openBytes with 1x1px area causes an exception.
7034 if (sx <= 1)
7035 return null;
7036 if (sy <= 1)
7037 return null;
7038 try
7039 {
7040 byte[] bytesr = b.imRead.openBytes(b.Coords[coord.Z, coord.C, coord.T], tilex, tiley, sx, sy);
7041 return new Bitmap(b.file, sx, sy, PixelFormat, bytesr, coord, p, null, littleEndian, interleaved);
7042 }
7043 catch (Exception e)
7044 {
7045 Console.WriteLine(e.Message);
7046 return null;
7047 }
7048 }

◆ GetUnitPerPixel()

double BioGTK.BioImage.GetUnitPerPixel ( int  level)
inline

Get Unit Per Pixel for pyramidal images.

Parameters
level
Returns
2346 {
2347 return Resolutions[0].PhysicalSizeX * GetLevelDownsample(level);
2348 }

◆ GetValue() [1/3]

ushort BioGTK.BioImage.GetValue ( int  z,
int  c,
int  t,
int  x,
int  y 
)
inline

‍This function returns the value of the pixel at the specified ZCTXY coordinates

Parameters
zThe Z-plane of the image.
cchannel
ttime
xx coordinate of the pixel
ythe y coordinate of the pixel
Returns
The value of the pixel at the given coordinates.
4165 {
4166 return GetValue(new ZCTXY(z, c, t, x, y));
4167 }
ushort GetValue(ZCTXY coord)
Definition Bio.cs:4100

◆ GetValue() [2/3]

ushort BioGTK.BioImage.GetValue ( ZCT  coord,
int  x,
int  y 
)
inline

‍Get the value of the pixel at the given coordinates

Parameters
ZCTZ is the Z-plane, C is the channel, T is the timepoint
xx coordinate of the pixel
yThe y coordinate of the pixel
Returns
The value of the pixel at the given coordinates.
4152 {
4153 return GetValueRGB(new ZCTXY(coord.Z, coord.C, coord.T, x, y), 0);
4154 }
ushort GetValueRGB(ZCTXY coord, int index)
Definition Bio.cs:4125

◆ GetValue() [3/3]

ushort BioGTK.BioImage.GetValue ( ZCTXY  coord)
inline

If the coordinate is within the bounds of the image, then return the value of the pixel at that coordinate

Parameters
ZCTXYa struct that contains the X, Y, Z, C, and T coordinates of the pixel.
Returns
The value of the pixel at the given coordinate.
4101 {
4102 if (coord.X < 0 || coord.Y < 0 || coord.X > SizeX || coord.Y > SizeY)
4103 {
4104 return 0;
4105 }
4106 if (isRGB)
4107 {
4108 if (coord.C == 0)
4109 return GetValueRGB(coord, 0);
4110 else if (coord.C == 1)
4111 return GetValueRGB(coord, 1);
4112 else if (coord.C == 2)
4113 return GetValueRGB(coord, 2);
4114 }
4115 else
4116 return GetValueRGB(coord, 0);
4117 return 0;
4118 }
bool isRGB
Definition Bio.cs:2682

◆ GetValueRGB() [1/3]

ushort BioGTK.BioImage.GetValueRGB ( int  z,
int  c,
int  t,
int  x,
int  y,
int  RGBindex 
)
inline

This function returns the value of the pixel at the specified coordinates in the specified channel, frame, and RGB index

Parameters
zThe Z-plane index
cchannel
ttime index
xx coordinate of the pixel
yThe y coordinate of the pixel
RGBindex0 = Red, 1 = Green, 2 = Blue
Returns
The value of the pixel at the given coordinates.
4198 {
4199 return GetValueRGB(new ZCT(z, c, t), x, y, RGBindex);
4200 }

◆ GetValueRGB() [2/3]

ushort BioGTK.BioImage.GetValueRGB ( ZCT  coord,
int  x,
int  y,
int  RGBindex 
)
inline

‍Get the value of a pixel at a given coordinate, x, y, and RGB index

Parameters
ZCTThe ZCT coordinate of the image.
xx coordinate of the pixel
ythe y coordinate of the pixel
RGBindex0 = Red, 1 = Green, 2 = Blue
Returns
The value of the pixel at the given coordinates.
4177 {
4178 ZCTXY c = new ZCTXY(coord.Z, coord.C, coord.T, x, y);
4179 if (isRGB)
4180 {
4181 return GetValueRGB(c, RGBindex);
4182 }
4183 else
4184 return GetValue(coord, x, y);
4185 }

◆ GetValueRGB() [3/3]

ushort BioGTK.BioImage.GetValueRGB ( ZCTXY  coord,
int  index 
)
inline

It takes a coordinate and an index and returns the value of the pixel at that coordinate

Parameters
ZCTXYa struct that contains the Z, C, T, X, and Y coordinates of the pixel.
index0, 1, 2
Returns
A ushort value.
4126 {
4127 int ind = 0;
4128 if (coord.C >= SizeC)
4129 {
4130 coord.C = 0;
4131 }
4132 ind = Coords[coord.Z, coord.C, coord.T];
4133 ColorS c = Buffers[ind].GetPixel(coord.X, coord.Y);
4134 if (index == 0)
4135 return c.R;
4136 else
4137 if (index == 1)
4138 return c.G;
4139 else
4140 if (index == 2)
4141 return c.B;
4142 throw new IndexOutOfRangeException();
4143 }
int SizeC
Definition Bio.cs:2643

◆ ImagesToStack()

static BioImage BioGTK.BioImage.ImagesToStack ( string[]  files,
bool  tab 
)
inlinestatic

It takes a list of files, opens them, and then combines them into a single BioImage object

Parameters
filesan array of file paths
Returns
A BioImage object.
7358 {
7359 BioImage[] bs = new BioImage[files.Length];
7360 int z = 0;
7361 int c = 0;
7362 int t = 0;
7363 for (int i = 0; i < files.Length; i++)
7364 {
7365 string str = Path.GetFileNameWithoutExtension(files[i]);
7366 str = str.Replace(".ome", "");
7367 string[] st = str.Split('_');
7368 if (st.Length > 3)
7369 {
7370 z = int.Parse(st[1].Replace("Z", ""));
7371 c = int.Parse(st[2].Replace("C", ""));
7372 t = int.Parse(st[3].Replace("T", ""));
7373 }
7374 if (i == 0)
7375 bs[0] = OpenOME(files[i], tab);
7376 else
7377 {
7378 bs[i] = OpenFile(files[i], 0, tab, false);
7379 }
7380 }
7381 BioImage b = BioImage.CopyInfo(bs[0], true, true);
7382 for (int i = 0; i < files.Length; i++)
7383 {
7384 for (int bc = 0; bc < bs[i].Buffers.Count; bc++)
7385 {
7386 b.Buffers.Add(bs[i].Buffers[bc]);
7387 }
7388 }
7389 b.UpdateCoords(z + 1, c + 1, t + 1);
7390 b.Volume = new VolumeD(bs[0].Volume.Location, new Point3D(bs[0].SizeX * bs[0].PhysicalSizeX, bs[0].SizeY * bs[0].PhysicalSizeY, (z + 1) * bs[0].PhysicalSizeZ));
7391 return b;
7392 }
VolumeD Volume
Definition Bio.cs:2139
double PhysicalSizeX
Definition Bio.cs:2362
double PhysicalSizeZ
Definition Bio.cs:2370
static BioImage OpenOME(string file, bool tab)
Definition Bio.cs:5979
double PhysicalSizeY
Definition Bio.cs:2366

◆ ImportROIsCSV()

static List< ROI > BioGTK.BioImage.ImportROIsCSV ( string  filename)
inlinestatic

It reads the CSV file and converts each line into a ROI object

Parameters
filenameThe path to the CSV file.
Returns
A list of ROI objects.
8213 {
8214 List<ROI> list = new List<ROI>();
8215 if (!File.Exists(filename))
8216 return list;
8217 string[] sts = File.ReadAllLines(filename);
8218 //We start reading from line 1.
8219 for (int i = 1; i < sts.Length; i++)
8220 {
8221 list.Add(StringToROI(sts[i]));
8222 }
8223 return list;
8224 }
static ROI StringToROI(string sts)
Definition Bio.cs:8042

◆ Initialize()

static void BioGTK.BioImage.Initialize ( )
inlinestatic

We initialize OME on a seperate thread so the user doesn't have to wait for initialization to view images.

4579 {
4580 //We initialize OME on a seperate thread so the user doesn't have to wait for initialization to
4581 //view images.
4582 System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(InitFactory));
4583 t.Start();
4584 System.Threading.Thread t3 = new System.Threading.Thread(new System.Threading.ThreadStart(InitReader));
4585 t3.Start();
4586 System.Threading.Thread t4 = new System.Threading.Thread(new System.Threading.ThreadStart(InitWriter));
4587 t4.Start();
4588 }

◆ isOME()

static bool BioGTK.BioImage.isOME ( string  file)
inlinestatic

If the file is a TIFF, check the ImageDescription tag for the string "OME-XML". If it's there, return true. If it's not a TIFF, return true. If it's a PNG, JPG, JPEG, or BMP, return false

Parameters
filethe path to the image file
Returns
A boolean value.
5367 {
5368 if (file.EndsWith("ome.tif") || file.EndsWith("ome.tiff"))
5369 {
5370 return true;
5371 }
5372 if (file.EndsWith(".tif") || file.EndsWith(".TIF") || file.EndsWith("tiff") || file.EndsWith("TIFF"))
5373 {
5374 Tiff image = Tiff.Open(file, "r");
5375 string desc = "";
5376 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
5377 desc = f[0].ToString();
5378 image.Close();
5379 if (desc.Contains("OME-XML"))
5380 return true;
5381 else
5382 return false;
5383 }
5384 if ((file.EndsWith("png") || file.EndsWith("PNG") || file.EndsWith("jpg") || file.EndsWith("JPG") ||
5385 file.EndsWith("jpeg") || file.EndsWith("JPEG") || file.EndsWith("bmp") || file.EndsWith("BMP")))
5386 {
5387 return false;
5388 }
5389 else return true;
5390 }

◆ isOMESeries()

static bool BioGTK.BioImage.isOMESeries ( string  file)
inlinestatic

‍If the file is an OME file and has more than one series, return true

Parameters
filethe file to be checked
Returns
A boolean value.
5397 {
5398 if (!isOME(file))
5399 return false;
5400 ImageReader reader = new ImageReader();
5401 var meta = (IMetadata)((OMEXMLService)new ServiceFactory().getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
5402 reader.setMetadataStore((MetadataStore)meta);
5403 file = file.Replace("\\", "/");
5404 reader.setId(file);
5405 bool ser = false;
5406 if (reader.getSeriesCount() > 1)
5407 ser = true;
5408 reader.close();
5409 reader = null;
5410 return ser;
5411 }
static bool isOME(string file)
Definition Bio.cs:5366

◆ isTiffSeries()

static bool BioGTK.BioImage.isTiffSeries ( string  file)
inlinestatic

‍The function checks if the image is a Tiff image and if it is, it checks if the image is a

series of images

Parameters
filethe path to the file
Returns
a boolean value.
5332 {
5333 Tiff image = Tiff.Open(file, "r");
5334 string desc = "";
5335 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
5336 image.Close();
5337 string[] sts = desc.Split('\n');
5338 int index = 0;
5339 for (int i = 0; i < sts.Length; i++)
5340 {
5341 if (sts[i].StartsWith("-ImageInfo"))
5342 {
5343 string val = sts[i].Substring(11);
5344 val = val.Substring(0, val.IndexOf(':'));
5345 int serie = int.Parse(val);
5346 if (sts[i].Length > 10)
5347 {
5348 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
5349 ImageInfo info = JsonConvert.DeserializeObject<ImageInfo>(cht);
5350 if (info.Series > 1)
5351 return true;
5352 else
5353 return false;
5354 }
5355 }
5356 }
5357 return false;
5358 }

◆ LevelFromResolution()

int BioGTK.BioImage.LevelFromResolution ( double  Resolution)
inline

Returns the level of a given resolution.

Parameters
Resolution
Returns
2331 {
2332 double[] ds = GetLevelDownsamples();
2333 for (int i = 0; i < ds.Length; i++)
2334 {
2335 if (ds[i] > Resolution)
2336 return i - 1;
2337 }
2338 return Resolutions.Count-1;
2339 }
double[] GetLevelDownsamples()
Definition Bio.cs:2316
double Resolution
Definition Bio.cs:2186

◆ MergeChannels() [1/2]

static BioImage BioGTK.BioImage.MergeChannels ( BioImage  b2,
BioImage  b 
)
inlinestatic

This function takes two images and merges them together

Parameters
BioImageThe image to be merged
BioImageThe image to be merged
Returns
A new BioImage object.
3708 {
3709 BioImage res = new BioImage(b2.ID);
3710 res.ID = Images.GetImageName(b2.ID);
3711 res.series = b2.series;
3712 res.sizeZ = b2.SizeZ;
3713 int cOrig = b2.SizeC;
3714 res.sizeC = b2.SizeC + b.SizeC;
3715 res.sizeT = b2.SizeT;
3716 res.bitsPerPixel = b2.bitsPerPixel;
3717 res.imageInfo = b2.imageInfo;
3718 res.littleEndian = b2.littleEndian;
3719 res.seriesCount = b2.seriesCount;
3720 res.imagesPerSeries = res.ImageCount / res.seriesCount;
3721 res.Coords = new int[res.SizeZ, res.SizeC, res.SizeT];
3722
3723 int i = 0;
3724 int cc = 0;
3725 for (int ti = 0; ti < res.SizeT; ti++)
3726 {
3727 for (int zi = 0; zi < res.SizeZ; zi++)
3728 {
3729 for (int ci = 0; ci < res.SizeC; ci++)
3730 {
3731 ZCT co = new ZCT(zi, ci, ti);
3732 if (ci < cOrig)
3733 {
3734 //If this channel is part of the image b1 we add planes from it.
3735 Bitmap copy = new Bitmap(b2.id, b2.SizeX, b2.SizeY, b2.Buffers[0].PixelFormat, b2.Buffers[i].Bytes, co, i);
3736 if (b2.littleEndian)
3737 copy.RotateFlip(AForge.RotateFlipType.Rotate180FlipNone);
3738 res.Coords[zi, ci, ti] = i;
3739 res.Buffers.Add(b2.Buffers[i]);
3740 res.Buffers.Add(copy);
3741 //Lets copy the ROI's from the original image.
3742 List<ROI> anns = b2.GetAnnotations(zi, ci, ti);
3743 if (anns.Count > 0)
3744 res.Annotations.AddRange(anns);
3745 }
3746 else
3747 {
3748 //This plane is not part of b1 so we add the planes from b2 channels.
3749 Bitmap copy = new Bitmap(b.id, b.SizeX, b.SizeY, b.Buffers[0].PixelFormat, b.Buffers[i].Bytes, co, i);
3750 if (b2.littleEndian)
3751 copy.RotateFlip(AForge.RotateFlipType.Rotate180FlipNone);
3752 res.Coords[zi, ci, ti] = i;
3753 res.Buffers.Add(b.Buffers[i]);
3754 res.Buffers.Add(copy);
3755
3756 //Lets copy the ROI's from the original image.
3757 List<ROI> anns = b.GetAnnotations(zi, cc, ti);
3758 if (anns.Count > 0)
3759 res.Annotations.AddRange(anns);
3760 }
3761 i++;
3762 }
3763 }
3764 }
3765 for (int ci = 0; ci < res.SizeC; ci++)
3766 {
3767 if (ci < cOrig)
3768 {
3769 res.Channels.Add(b2.Channels[ci].Copy());
3770 }
3771 else
3772 {
3773 res.Channels.Add(b.Channels[cc].Copy());
3774 res.Channels[cOrig + cc].Index = ci;
3775 cc++;
3776 }
3777 }
3778 Images.AddImage(res, true);
3779 //We wait for threshold image statistics calculation
3780 do
3781 {
3782 Thread.Sleep(100);
3783 } while (res.Buffers[res.Buffers.Count - 1].Stats == null);
3784 AutoThreshold(res, false);
3785 if (res.bitsPerPixel > 8)
3786 res.StackThreshold(true);
3787 else
3788 res.StackThreshold(false);
3789 Recorder.AddLine("BioGTK.BioImage.MergeChannels(" + '"' + b.ID + '"' + "," + '"' + b2.ID + '"' + ");");
3790 return res;
3791 }

◆ MergeChannels() [2/2]

static BioImage BioGTK.BioImage.MergeChannels ( string  bname,
string  b2name 
)
inlinestatic

MergeChannels(b, b2) takes two images, b and b2, and merges the channels of b2 into b

Parameters
bnameThe name of the first image
b2nameThe name of the image to merge with the first image.
Returns
A BioImage object.
3799 {
3800 BioImage b = Images.GetImage(bname);
3801 BioImage b2 = Images.GetImage(b2name);
3802 return MergeChannels(b, b2);
3803 }
static BioImage MergeChannels(BioImage b2, BioImage b)
Definition Bio.cs:3707

◆ MergeT()

static BioImage BioGTK.BioImage.MergeT ( BioImage  b)
inlinestatic

It takes a 3D image and merges the time dimension into a single image

Parameters
BioImageThe image to be processed
Returns
A new BioImage object.
3855 {
3856 BioImage bi = BioImage.CopyInfo(b, true, true);
3857 int ind = 0;
3858 for (int c = 0; c < b.SizeC; c++)
3859 {
3860 for (int z = 0; z < b.sizeZ; z++)
3861 {
3862 Merge m = new Merge(b.Buffers[b.Coords[z, c, 0]]);
3863 Bitmap bm = new Bitmap(b.SizeX, b.SizeY, b.Buffers[0].PixelFormat);
3864 for (int i = 1; i < b.sizeT; i++)
3865 {
3866 m.OverlayImage = bm;
3867 bm = m.Apply(b.Buffers[b.Coords[z, c, i]]);
3868 }
3869 Bitmap bf = new Bitmap(b.file, bm, new ZCT(z, c, 0), ind);
3870 bi.Buffers.Add(bf);
3871 Statistics.CalcStatistics(bf);
3872 ind++;
3873 }
3874 }
3875 Images.AddImage(bi, true);
3876 bi.UpdateCoords(1, b.SizeC, b.SizeT);
3877 bi.Coordinate = new ZCT(0, 0, 0);
3878 //We wait for threshold image statistics calculation
3879 do
3880 {
3881 Thread.Sleep(100);
3882 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3883 Statistics.ClearCalcBuffer();
3884 bi.Resolutions.Add(new BioGTK.Resolution(b.Buffers[0].SizeX, b.Buffers[0].SizeY, b.Buffers[0].PixelFormat, b.PhysicalSizeX, b.PhysicalSizeY, b.PhysicalSizeZ, b.StageSizeX, b.StageSizeY, b.StageSizeZ));
3885 AutoThreshold(bi, false);
3886 if (bi.bitsPerPixel > 8)
3887 bi.StackThreshold(true);
3888 else
3889 bi.StackThreshold(false);
3890 Recorder.AddLine("BioGTK.BioImage.MergeT(" + '"' + b.ID + '"' + ");");
3891 return bi;
3892 }
Definition About.cs:11
Definition Bio.cs:181

◆ MergeZ()

static BioImage BioGTK.BioImage.MergeZ ( BioImage  b)
inlinestatic

It takes a 3D image and merges the Z-stack into a single 2D image

Parameters
BioImageThe image to be merged
Returns
A new BioImage object.
3810 {
3811 BioImage bi = BioImage.CopyInfo(b, true, true);
3812 int ind = 0;
3813 for (int c = 0; c < b.SizeC; c++)
3814 {
3815 for (int t = 0; t < b.sizeT; t++)
3816 {
3817 Merge m = new Merge(b.Buffers[b.Coords[0, c, t]]);
3818 Bitmap bm = new Bitmap(b.SizeX, b.SizeY, b.Buffers[0].PixelFormat);
3819 for (int i = 1; i < b.sizeZ; i++)
3820 {
3821 m.OverlayImage = bm;
3822 bm = m.Apply(b.Buffers[b.Coords[i, c, t]]);
3823 }
3824 Bitmap bf = new Bitmap(b.file, bm, new ZCT(0, c, t), ind);
3825 bi.Buffers.Add(bf);
3826 Statistics.CalcStatistics(bf);
3827 ind++;
3828 }
3829 }
3830 Images.AddImage(bi, true);
3831 bi.UpdateCoords(1, b.SizeC, b.SizeT);
3832 bi.Coordinate = new ZCT(0, 0, 0);
3833 //We wait for threshold image statistics calculation
3834 do
3835 {
3836 Thread.Sleep(100);
3837 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3838 Statistics.ClearCalcBuffer();
3839 bi.Resolutions.Add(new BioGTK.Resolution(b.Buffers[0].SizeX, b.Buffers[0].SizeY, b.Buffers[0].PixelFormat, b.PhysicalSizeX, b.PhysicalSizeY, b.PhysicalSizeZ, b.StageSizeX, b.StageSizeY, b.StageSizeZ));
3840
3841 AutoThreshold(bi, false);
3842 if (bi.bitsPerPixel > 8)
3843 bi.StackThreshold(true);
3844 else
3845 bi.StackThreshold(false);
3846 Recorder.AddLine("BioGTK.BioImage.MergeZ(" + '"' + b.ID + '"' + ");");
3847 return bi;
3848 }

◆ Open() [1/2]

static void BioGTK.BioImage.Open ( string  file)
inlinestatic

It opens a file

Parameters
fileThe file to open.
7339 {
7340 OpenFile(file);
7341 }

◆ Open() [2/2]

static void BioGTK.BioImage.Open ( string[]  files)
inlinestatic

It opens a file

Parameters
filesThe files to open.
7346 {
7347 foreach (string file in files)
7348 {
7349 Open(file);
7350 }
7351 }
static void Open(string file)
Definition Bio.cs:7338

◆ OpenAsync() [1/2]

static async Task BioGTK.BioImage.OpenAsync ( string  file,
bool  OME,
bool  newtab,
bool  images,
int  series 
)
inlinestatic

It opens a file in a new thread.

Parameters
fileThe file to open
7317 {
7318 openfile = file;
7319 omes = OME;
7320 tab = newtab;
7321 add = images;
7322 serie = series;
7323 await Task.Run(OpenThread);
7324 }
int series
Definition Bio.cs:2403

◆ OpenAsync() [2/2]

static async Task BioGTK.BioImage.OpenAsync ( string[]  files,
bool  OME,
bool  tab,
bool  images 
)
inlinestatic

It opens a file asynchronously

Parameters
filesThe file(s) to open.
7329 {
7330 foreach (string file in files)
7331 {
7332 await OpenAsync(file, OME, tab, images,0);
7333 }
7334 }
static async Task OpenAsync(string file, bool OME, bool newtab, bool images, int series)
Definition Bio.cs:7316

◆ OpenFile() [1/4]

static BioImage BioGTK.BioImage.OpenFile ( string  file)
inlinestatic

This function opens a file and returns a BioImage object

Parameters
fileThe path to the file to open.
Returns
A BioImage object.
4875 {
4876 Recorder.AddLine("BioGTK.BioImage.OpenFile(\"" + file + "\");");
4877 return OpenFile(file, 0, true, true);
4878 }

◆ OpenFile() [2/4]

static BioImage BioGTK.BioImage.OpenFile ( string  file,
bool  tab 
)
inlinestatic
4880 {
4881 Recorder.AddLine("BioGTK.BioImage.OpenFile(\"" + file + "\"," + tab.ToString() + ");");
4882 return OpenFile(file, 0, tab, true);
4883 }

◆ OpenFile() [3/4]

static BioImage BioGTK.BioImage.OpenFile ( string  file,
int  series,
bool  tab,
bool  addToImages 
)
inlinestatic

It opens a TIFF file and returns a BioImage object

Parameters
filethe file path
seriesthe series number of the image to open
Returns
A BioImage object.
4891 {
4892 return OpenFile(file, series, tab, addToImages, false, 0, 0, 0, 0);
4893 }

◆ OpenFile() [4/4]

static BioImage BioGTK.BioImage.OpenFile ( string  file,
int  series,
bool  tab,
bool  addToImages,
bool  tile,
int  tileX,
int  tileY,
int  tileSizeX,
int  tileSizeY 
)
inlinestatic

The OpenFile function opens a BioImage file, reads its metadata, and loads the image data into a BioImage object.

Parameters
fileThe file path of the bioimage to be opened.
seriesThe series parameter is an integer that specifies the series number of the image to open.
tabThe "tab" parameter is a boolean value that determines whether the BioImage should be opened in a new tab or not. If set to true, the BioImage will be opened in a new tab. If set to false, the BioImage will be opened in the current tab.
addToImagesA boolean value indicating whether the BioImage should be added to the Images collection.
tileThe "tile" parameter is a boolean value that determines whether the image should be opened as a tiled image or not. If set to true, the image will be opened as a tiled image. If set to false, the image will be opened as a regular image.
tileXThe tileX parameter is an integer that represents the starting X coordinate of the tile. It is used when opening a tiled image to specify the position of the tile within the image.
tileYThe tileY parameter is used to specify the starting Y coordinate of the tile when opening a tiled image. It determines the position of the tile within the image.
tileSizeXThe tileSizeX parameter is the width of each tile in pixels. It is used when opening a tiled TIFF image to specify the size of the tiles.
tileSizeYThe tileSizeY parameter is the height of each tile in pixels when the image is tiled.
Returns
The method is returning a BioImage object.
5024 {
5025 string fs = file.Replace("\\", "/");
5026 vips = VipsSupport(file);
5027 Console.WriteLine("Opening BioImage: " + file);
5028 bool ome = isOME(file);
5029 if (ome) return OpenOME(file, series, tab, addToImages, tile, tileX, tileY, tileSizeX, tileSizeY);
5030 bool tiled = IsTiffTiled(file);
5031 Console.WriteLine("IsTiled=" + tiled.ToString());
5032 tile = tiled;
5033
5034 Stopwatch st = new Stopwatch();
5035 st.Start();
5036 status = "Opening Image";
5037 progFile = file;
5038 progressValue = 0;
5039 BioImage b = new BioImage(file);
5040 if(tiled && file.EndsWith(".tif") && !file.EndsWith(".ome.tif"))
5041 {
5042 //To open this we need libvips
5043 vips = VipsSupport(b.file);
5044 }
5045 b.series = series;
5046 b.file = file;
5047 if (tiled)
5048 b.Type = ImageType.pyramidal;
5049 string fn = Path.GetFileNameWithoutExtension(file);
5050 string dir = Path.GetDirectoryName(file);
5051 if (File.Exists(fn + ".csv"))
5052 {
5053 string f = dir + "//" + fn + ".csv";
5054 b.Annotations = BioImage.ImportROIsCSV(f);
5055 }
5056 if (file.EndsWith("tif") || file.EndsWith("tiff") || file.EndsWith("TIF") || file.EndsWith("TIFF"))
5057 {
5058 Tiff image = Tiff.Open(file, "r");
5059 b.tifRead = image;
5060 int SizeX = image.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
5061 int SizeY = image.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
5062 b.bitsPerPixel = image.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
5063 b.littleEndian = image.IsBigEndian();
5064 int RGBChannelCount = image.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
5065 string desc = "";
5066
5067 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
5068 desc = f[0].ToString();
5069 ImageJDesc imDesc = null;
5070 b.sizeC = 1;
5071 b.sizeT = 1;
5072 b.sizeZ = 1;
5073 int pages = image.NumberOfDirectories() / b.seriesCount;
5074 if (f != null && !tile)
5075 {
5076 imDesc = new ImageJDesc();
5077 desc = f[0].ToString();
5078 if (desc.StartsWith("ImageJ"))
5079 {
5080 imDesc.SetString(desc);
5081 if (imDesc.channels != 0)
5082 b.sizeC = imDesc.channels;
5083 else
5084 b.sizeC = 1;
5085 if (imDesc.slices != 0)
5086 b.sizeZ = imDesc.slices;
5087 else
5088 b.sizeZ = pages;
5089 if (imDesc.frames != 0)
5090 b.sizeT = imDesc.frames;
5091 else
5092 b.sizeT = 1;
5093 if (imDesc.finterval != 0)
5094 b.frameInterval = imDesc.finterval;
5095 else
5096 b.frameInterval = 1;
5097 if (imDesc.spacing != 0)
5098 b.imageInfo.PhysicalSizeZ = imDesc.spacing;
5099 else
5100 b.imageInfo.PhysicalSizeZ = 1;
5101 }
5102 else
5103 {
5104 b.sizeZ = pages;
5105 b.sizeT = 1;
5106 b.sizeC = 1;
5107 }
5108 }
5109 int stride = 0;
5110 PixelFormat PixelFormat;
5111
5112 if (RGBChannelCount == 1)
5113 {
5114 if (b.bitsPerPixel > 8)
5115 {
5116 PixelFormat = PixelFormat.Format16bppGrayScale;
5117 stride = SizeX * 2;
5118 }
5119 else
5120 {
5121 PixelFormat = PixelFormat.Format8bppIndexed;
5122 stride = SizeX;
5123 }
5124 }
5125 else
5126 if (RGBChannelCount == 3)
5127 {
5128 b.sizeC = 1;
5129 if (b.bitsPerPixel > 8)
5130 {
5131 PixelFormat = PixelFormat.Format48bppRgb;
5132 stride = SizeX * 2 * 3;
5133 }
5134 else
5135 {
5136 PixelFormat = PixelFormat.Format24bppRgb;
5137 stride = SizeX * 3;
5138 }
5139 }
5140 else
5141 {
5142 PixelFormat = PixelFormat.Format32bppArgb;
5143 stride = SizeX * 4;
5144 }
5145
5146 string[] sts = desc.Split('\n');
5147 int index = 0;
5148 for (int i = 0; i < sts.Length; i++)
5149 {
5150 if (sts[i].StartsWith("-Channel"))
5151 {
5152 string val = sts[i].Substring(9);
5153 val = val.Substring(0, val.IndexOf(':'));
5154 int serie = int.Parse(val);
5155 if (serie == series && sts[i].Length > 7)
5156 {
5157 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
5158 Channel.ChannelInfo info = JsonConvert.DeserializeObject<Channel.ChannelInfo>(cht);
5159 Channel ch = new Channel(index, b.bitsPerPixel, info.SamplesPerPixel);
5160 ch.info = info;
5161 b.Channels.Add(ch);
5162 if (index == 0)
5163 {
5164 b.rgbChannels[0] = 0;
5165 }
5166 else
5167 if (index == 1)
5168 {
5169 b.rgbChannels[1] = 1;
5170 }
5171 else
5172 if (index == 2)
5173 {
5174 b.rgbChannels[2] = 2;
5175 }
5176 index++;
5177 }
5178 }
5179 else
5180 if (sts[i].StartsWith("-ROI"))
5181 {
5182 string val = sts[i].Substring(5);
5183 val = val.Substring(0, val.IndexOf(':'));
5184 int serie = int.Parse(val);
5185 if (serie == series && sts[i].Length > 7)
5186 {
5187 string s = sts[i].Substring(sts[i].IndexOf("ROI:") + 4, sts[i].Length - (sts[i].IndexOf("ROI:") + 4));
5188 string ro = s.Substring(s.IndexOf(":") + 1, s.Length - (s.IndexOf(':') + 1));
5189 ROI roi = StringToROI(ro);
5190 b.Annotations.Add(roi);
5191 }
5192 }
5193 else
5194 if (sts[i].StartsWith("-ImageInfo"))
5195 {
5196 string val = sts[i].Substring(11);
5197 val = val.Substring(0, val.IndexOf(':'));
5198 int serie = int.Parse(val);
5199 if (serie == series && sts[i].Length > 10)
5200 {
5201 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
5202 b.imageInfo = JsonConvert.DeserializeObject<ImageInfo>(cht);
5203 }
5204 }
5205 }
5206 b.Coords = new int[b.SizeZ, b.SizeC, b.SizeT];
5207 if (tiled && tileSizeX == 0 && tileSizeY == 0)
5208 {
5209 tileSizeX = 1920;
5210 tileSizeY = 1080;
5211 }
5212
5213 //If this is a tiff file not made by Bio we init channels based on RGBChannels.
5214 if (b.Channels.Count == 0)
5215 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
5216
5217 //Lets check to see the channels are correctly defined in this file
5218 for (int ch = 0; ch < b.Channels.Count; ch++)
5219 {
5220 if (b.Channels[ch].SamplesPerPixel != RGBChannelCount)
5221 {
5222 b.Channels[ch].SamplesPerPixel = RGBChannelCount;
5223 }
5224 }
5225
5226 b.Buffers = new List<Bitmap>();
5227
5228 int str = image.ScanlineSize();
5229 bool inter = true;
5230 if (stride != str)
5231 inter = false;
5232 InitDirectoryResolution(b, image, imDesc);
5233 if (tiled)
5234 {
5235 Console.WriteLine("Opening tiles.");
5236 if (vips)
5237 OpenVips(b, b.Resolutions.Count);
5238 for (int t = 0; t < b.SizeT; t++)
5239 {
5240 for (int c = 0; c < b.SizeC; c++)
5241 {
5242 for (int z = 0; z < b.SizeZ; z++)
5243 {
5244 Bitmap bmp = GetTile(b, new ZCT(z, c, t), series, tileX, tileY, tileSizeX, tileSizeY);
5245 b.Buffers.Add(bmp);
5246 Statistics.CalcStatistics(bmp);
5247 }
5248 }
5249 }
5250 Console.WriteLine("Calculating statisitics.");
5251 }
5252 else
5253 {
5254 for (int p = series * pages; p < (series + 1) * pages; p++)
5255 {
5256 image.SetDirectory((short)p);
5257
5258 byte[] bytes = new byte[stride * SizeY];
5259 for (int im = 0, offset = 0; im < SizeY; im++)
5260 {
5261 image.ReadScanline(bytes, offset, im, 0);
5262 offset += stride;
5263 }
5264 Bitmap inf = new Bitmap(file, SizeX, SizeY, b.Resolutions[series].PixelFormat, bytes, new ZCT(0, 0, 0), p, null, b.littleEndian, inter);
5265 b.Buffers.Add(inf);
5266 Statistics.CalcStatistics(inf);
5267 progressValue = (float)p / (float)(series + 1) * pages;
5268 }
5269 }
5270 image.Close();
5271 b.UpdateCoords();
5272 }
5273 else
5274 {
5275 Gdk.Pixbuf pf = new Gdk.Pixbuf(file);
5276 b.littleEndian = BitConverter.IsLittleEndian;
5277 PixelFormat px = GetPixelFormat(pf.NChannels, pf.BitsPerSample);
5278 b.Resolutions.Add(new Resolution(pf.Width, pf.Height,px,96 * (1/2.54) / 1000, 96 * (1 / 2.54) / 1000, 96 * (1 / 2.54) / 1000,0,0,0));
5279 b.bitsPerPixel = pf.BitsPerSample;
5280 b.Buffers.Add(new Bitmap(pf.Width, pf.Height, pf.Width * pf.NChannels, px, pf.Pixels));
5281 b.Buffers.Last().ID = Bitmap.CreateID(file, 0);
5282 Statistics.CalcStatistics(b.Buffers.Last());
5283 b.Channels.Add(new Channel(0, b.bitsPerPixel, b.RGBChannelCount));
5284 b.Coords = new int[1, 1, 1];
5285 b.sizeC = 1;
5286 b.sizeT = 1;
5287 b.sizeZ = 1;
5288 }
5289 if (b.StageSizeX == -1)
5290 {
5291 b.imageInfo.Series = 0;
5292 b.StageSizeX = 0;
5293 b.StageSizeY = 0;
5294 b.StageSizeZ = 0;
5295 }
5296 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.PhysicalSizeX * b.SizeX, b.PhysicalSizeY * b.SizeY, b.PhysicalSizeZ * b.SizeZ));
5297
5298 //If file is ome and we have OME support then check for annotation in metadata.
5299 if (ome)
5300 {
5301 b.Annotations.AddRange(OpenOMEROIs(file, series));
5302 }
5303
5304 //We wait for histogram image statistics calculation
5305 do
5306 {
5307 Thread.Sleep(50);
5308 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
5309 Statistics.ClearCalcBuffer();
5310 AutoThreshold(b, false);
5311 if (b.bitsPerPixel > 8)
5312 b.StackThreshold(true);
5313 else
5314 b.StackThreshold(false);
5315 Recorder.AddLine("BioGTK.BioImage.OpenFile(" + '"' + file + '"' + ");");
5316 if (addToImages)
5317 Images.AddImage(b, tab);
5318 //pr.Close();
5319 //pr.Dispose();
5320 st.Stop();
5321 b.loadTimeMS = st.ElapsedMilliseconds;
5322 Console.WriteLine("BioImage loaded " + b.ToString());
5323 return b;
5324 }
static string progFile
Definition Bio.cs:2744
static void OpenVips(BioImage b, int pagecount)
Definition Bio.cs:6068
static Bitmap GetTile(BioImage b, ZCT coord, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
Definition Bio.cs:6976
static string status
Definition Bio.cs:2743
static PixelFormat GetPixelFormat(int rgbChannelCount, int bitsPerPixel)
Definition Bio.cs:7220
static double progressValue
Definition Bio.cs:2723
static bool VipsSupport(string file)
Definition Bio.cs:7570
ImageType
Image type.
Definition ISlideSource.cs:525

◆ OpenOME() [1/3]

static BioImage BioGTK.BioImage.OpenOME ( string  file,
bool  tab 
)
inlinestatic

The function "OpenOME" opens a bioimage file in the OME format and returns the first image in the series.

Parameters
fileThe "file" parameter is a string that represents the file path or name of the OME file that you want to open.
tabThe "tab" parameter is a boolean value that determines whether the image is opened in a new tab.
Returns
The method is returning a BioImage object.
5980 {
5981 return OpenOMESeries(file, tab, true)[0];
5982 }
static BioImage[] OpenOMESeries(string file, bool tab, bool addToImages)
Definition Bio.cs:7277

◆ OpenOME() [2/3]

static BioImage BioGTK.BioImage.OpenOME ( string  file,
int  serie 
)
inlinestatic

‍OpenOME(string file, int serie)

The first parameter is a string, the second is an integer

Parameters
filethe path to the file
seriethe image series to open
Returns
A BioImage object.
5992 {
5993 Recorder.AddLine("BioGTK.BioImage.OpenOME(\"" + file + "\"," + serie + ");");
5994 return OpenOME(file, serie, true, false, false, 0, 0, 0, 0);
5995 }

◆ OpenOME() [3/3]

static BioImage BioGTK.BioImage.OpenOME ( string  file,
int  serie,
bool  tab,
bool  addToImages,
bool  tile,
int  tilex,
int  tiley,
int  tileSizeX,
int  tileSizeY,
bool  useOpenSlide = true 
)
inlinestatic

The function "OpenOME" opens a bioimage file, with options to specify the series, whether to.

The function "OpenOME" opens a bioimage file, with options to specify the series, whether to display it in a tab, whether to add it to existing images, whether to tile the image, and the tile size.

Parameters
fileThe file parameter is a string that represents the file path or name of the OME (Open Microscopy Environment) file that you want to open.
serieThe "serie" parameter is an integer that represents the series number of the image to be opened.
tabThe "tab" parameter is a boolean value that determines whether the image should be opened in a new tab or not. If set to true, the image will be opened in a new tab. If set to false, the image will be opened in the current tab.
addToImagesThe "addToImages" parameter is a boolean value that determines whether the opened image should be added to a collection of images. If set to true, the image will be added to the collection. If set to false, the image will not be added.
tileThe "tile" parameter is a boolean value that determines whether or not to tile the images. If set to true, the images will be tiled according to the specified tilex, tiley, tileSizeX, and tileSizeY parameters. If set to false, the images will not be tiled.
tilexThe parameter "tilex" is an integer that represents the starting x-coordinate of the tile.
tileyThe parameter "tiley" is used to specify the number of tiles in the y-direction when tiling the image.
tileSizeXThe tileSizeX parameter specifies the width of each tile in pixels when tiling the images.
tileSizeYThe tileSizeY parameter is the height of each tile in pixels when tiling the images.
6163 {
6164 if (file == null || file == "")
6165 throw new InvalidDataException("File is empty or null");
6166 //We wait incase OME has not initialized.
6167 do
6168 {
6169 Thread.Sleep(10);
6170 } while (!initialized);
6171 Console.WriteLine("OpenOME " + file);
6172 reader = new ImageReader();
6173 Progress pr = Progress.Create(file, "Opening OME", "Opening OME file.");
6174 // update ui on main UI thread
6175 Application.Invoke(delegate
6176 {
6177 pr.Show();
6178 pr.Present();
6179 });
6180 if (tileSizeX == 0)
6181 tileSizeX = 1920;
6182 if (tileSizeY == 0)
6183 tileSizeY = 1080;
6184 progressValue = 0;
6185 progFile = file;
6186 BioImage b = new BioImage(file);
6187 b.Type = ImageType.stack;
6188 b.Loading = true;
6189 if (b.meta == null)
6190 b.meta = service.createOMEXMLMetadata();
6191 string f = file.Replace("\\", "/");
6192 string cf = reader.getCurrentFile();
6193 if (cf != null)
6194 cf = cf.Replace("\\", "/");
6195 if (cf != f)
6196 {
6197 reader.close();
6198 reader.setMetadataStore(b.meta);
6199 try
6200 {
6201 reader.setId(f);
6202 }
6203 catch (Exception e)
6204 {
6205 Console.WriteLine(e.Message);
6206 return null;
6207 }
6208
6209 pr.Status = "Reading Metadata";
6210 }
6211
6212 //status = "Reading OME Metadata.";
6213 reader.setSeries(serie);
6214 int RGBChannelCount = reader.getRGBChannelCount();
6215 //OME reader.getBitsPerPixel(); sometimes returns incorrect bits per pixel, like when opening ImageJ images.
6216 //So we check the pixel type from xml metadata and if it fails we use the readers value.
6217 PixelFormat PixelFormat;
6218 try
6219 {
6220 PixelFormat = GetPixelFormat(RGBChannelCount, b.meta.getPixelsType(serie));
6221 }
6222 catch (Exception)
6223 {
6224 PixelFormat = GetPixelFormat(RGBChannelCount, reader.getBitsPerPixel());
6225 }
6226
6227 b.id = file;
6228 b.file = file;
6229 int SizeX, SizeY;
6230 SizeX = reader.getSizeX();
6231 SizeY = reader.getSizeY();
6232 int SizeZ = reader.getSizeZ();
6233 b.sizeC = reader.getSizeC();
6234 b.sizeZ = reader.getSizeZ();
6235 b.sizeT = reader.getSizeT();
6236 b.littleEndian = reader.isLittleEndian();
6237 b.seriesCount = reader.getSeriesCount();
6238 b.imagesPerSeries = reader.getImageCount();
6239 b.bitsPerPixel = reader.getBitsPerPixel();
6240 b.series = serie;
6241 string order = reader.getDimensionOrder();
6242
6243 //Lets get the channels and initialize them
6244 int i = 0;
6245 pr.Status = "Reading Channels";
6246 int sumSamples = 0;
6247 while (true)
6248 {
6249 Channel ch = new Channel(i, b.bitsPerPixel, 1);
6250 bool def = false;
6251 try
6252 {
6253 if (b.meta.getChannelSamplesPerPixel(serie, i) != null)
6254 {
6255 int s = b.meta.getChannelSamplesPerPixel(serie, i).getNumberValue().intValue();
6256 ch.SamplesPerPixel = s;
6257 sumSamples += s;
6258 def = true;
6259 }
6260 if (b.meta.getChannelName(serie, i) != null)
6261 ch.Name = b.meta.getChannelName(serie, i);
6262 if (b.meta.getChannelAcquisitionMode(serie, i) != null)
6263 ch.AcquisitionMode = b.meta.getChannelAcquisitionMode(serie, i).ToString();
6264 if (b.meta.getChannelID(serie, i) != null)
6265 ch.info.ID = b.meta.getChannelID(serie, i);
6266 if (b.meta.getChannelFluor(serie, i) != null)
6267 ch.Fluor = b.meta.getChannelFluor(serie, i);
6268 if (b.meta.getChannelColor(serie, i) != null)
6269 {
6270 ome.xml.model.primitives.Color cc = b.meta.getChannelColor(serie, i);
6271 ch.Color = Color.FromArgb(cc.getRed(), cc.getGreen(), cc.getBlue());
6272 }
6273 if (b.meta.getChannelIlluminationType(serie, i) != null)
6274 ch.IlluminationType = b.meta.getChannelIlluminationType(serie, i).ToString();
6275 if (b.meta.getChannelContrastMethod(serie, i) != null)
6276 ch.ContrastMethod = b.meta.getChannelContrastMethod(serie, i).ToString();
6277 if (b.meta.getChannelEmissionWavelength(serie, i) != null)
6278 ch.Emission = b.meta.getChannelEmissionWavelength(serie, i).value().intValue();
6279 if (b.meta.getChannelExcitationWavelength(serie, i) != null)
6280 ch.Excitation = b.meta.getChannelExcitationWavelength(serie, i).value().intValue();
6281 if (b.meta.getLightEmittingDiodePower(serie, i) != null)
6282 ch.LightSourceIntensity = b.meta.getLightEmittingDiodePower(serie, i).value().doubleValue();
6283 if (b.meta.getLightEmittingDiodeID(serie, i) != null)
6284 ch.DiodeName = b.meta.getLightEmittingDiodeID(serie, i);
6285 if (b.meta.getChannelLightSourceSettingsAttenuation(serie, i) != null)
6286 ch.LightSourceAttenuation = b.meta.getChannelLightSourceSettingsAttenuation(serie, i).toString();
6287
6288 }
6289 catch (Exception e)
6290 {
6291 Console.WriteLine(e.Message);
6292 }
6293 //If this channel is not defined we have loaded all the channels in the file.
6294 if (!def)
6295 break;
6296 else
6297 b.Channels.Add(ch);
6298 if (i == 0)
6299 {
6300 b.rgbChannels[0] = 0;
6301 }
6302 else
6303 if (i == 1)
6304 {
6305 b.rgbChannels[1] = 1;
6306 }
6307 else
6308 if (i == 2)
6309 {
6310 b.rgbChannels[2] = 2;
6311 }
6312 i++;
6313 }
6314 //If the file doens't have channels we initialize them.
6315 if (b.Channels.Count == 0)
6316 {
6317 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
6318 }
6319
6320 //Bioformats gives a size of 3 for C when saved in ImageJ as RGB. We need to correct for this as C should be 1 for RGB.
6321 if (RGBChannelCount >= 3)
6322 {
6323 b.sizeC = sumSamples / b.Channels[0].SamplesPerPixel;
6324 }
6325 b.Coords = new int[b.SizeZ, b.SizeC, b.SizeT];
6326
6327 int resc = reader.getResolutionCount();
6328
6329 try
6330 {
6331 int wells = b.meta.getWellCount(0);
6332 if(wells>0)
6333 {
6334 b.Type = ImageType.well;
6335 b.Plate = new WellPlate(b);
6336 tile = false;
6337 }
6338 }
6339 catch (Exception)
6340 {
6341
6342 }
6343 List<Resolution> rss = new List<Resolution>();
6344 for (int s = 0; s < b.seriesCount; s++)
6345 {
6346 reader.setSeries(s);
6347 for (int r = 0; r < reader.getResolutionCount(); r++)
6348 {
6349 Resolution res = new Resolution();
6350 try
6351 {
6352 int rgbc = reader.getRGBChannelCount();
6353 int bps = reader.getBitsPerPixel();
6354 PixelFormat px;
6355 try
6356 {
6357 px = GetPixelFormat(rgbc, b.meta.getPixelsType(r));
6358 }
6359 catch (Exception)
6360 {
6361 px = GetPixelFormat(rgbc, bps);
6362 }
6363 res.PixelFormat = px;
6364 res.SizeX = reader.getSizeX();
6365 res.SizeY = reader.getSizeY();
6366 if (b.meta.getPixelsPhysicalSizeX(r) != null)
6367 {
6368 res.PhysicalSizeX = b.meta.getPixelsPhysicalSizeX(r).value().doubleValue();
6369 }
6370 else
6371 res.PhysicalSizeX = (96 / 2.54) / 1000;
6372 if (b.meta.getPixelsPhysicalSizeY(r) != null)
6373 {
6374 res.PhysicalSizeY = b.meta.getPixelsPhysicalSizeY(r).value().doubleValue();
6375 }
6376 else
6377 res.PhysicalSizeY = (96 / 2.54) / 1000;
6378
6379 if (b.meta.getStageLabelX(r) != null)
6380 res.StageSizeX = b.meta.getStageLabelX(r).value().doubleValue();
6381 if (b.meta.getStageLabelY(r) != null)
6382 res.StageSizeY = b.meta.getStageLabelY(r).value().doubleValue();
6383 if (b.meta.getStageLabelZ(r) != null)
6384 res.StageSizeZ = b.meta.getStageLabelZ(r).value().doubleValue();
6385 else
6386 res.StageSizeZ = 1;
6387 if (b.meta.getPixelsPhysicalSizeZ(r) != null)
6388 {
6389 res.PhysicalSizeZ = b.meta.getPixelsPhysicalSizeZ(r).value().doubleValue();
6390 }
6391 else
6392 {
6393 res.PhysicalSizeZ = 1;
6394 }
6395 }
6396 catch (Exception e)
6397 {
6398 Console.WriteLine("No Stage Coordinates. PhysicalSize:(" + res.PhysicalSizeX + "," + res.PhysicalSizeY + "," + res.PhysicalSizeZ + ")");
6399 }
6400 rss.Add(res);
6401 }
6402 }
6403 reader.setSeries(serie);
6404
6405 int pyramidCount = 0;
6406 int pyramidResolutions = 0;
6407 List<Tuple<int, int>> prs = new List<Tuple<int, int>>();
6408 //We need to determine if this image is pyramidal or not.
6409 //We do this by seeing if the resolutions are downsampled or not.
6410 if (rss.Count > 1 && b.Type != ImageType.well)
6411 {
6412 if (rss[0].SizeX > rss[1].SizeX)
6413 {
6414 b.Type = ImageType.pyramidal;
6415 tile = true;
6416 //We need to determine number of pyramids in this image and which belong to the series we are opening.
6417 int? sr = null;
6418 for (int r = 0; r < rss.Count - 1; r++)
6419 {
6420 if (rss[r].SizeX > rss[r + 1].SizeX && rss[r].PixelFormat == rss[r + 1].PixelFormat)
6421 {
6422 if (sr == null)
6423 {
6424 sr = r;
6425 prs.Add(new Tuple<int, int>(r, 0));
6426 }
6427 }
6428 else
6429 {
6430 if(rss[prs[prs.Count - 1].Item1].PixelFormat == rss[r].PixelFormat)
6431 prs[prs.Count - 1] = new Tuple<int, int>(prs[prs.Count - 1].Item1, r);
6432 sr = null;
6433 }
6434 }
6435 pyramidCount = prs.Count;
6436 for (int p = 0; p < prs.Count; p++)
6437 {
6438 pyramidResolutions += (prs[p].Item2 - prs[p].Item1)+1;
6439 }
6440
6441 if (prs[serie].Item2 == 0)
6442 {
6443 prs[serie] = new Tuple<int, int>(prs[serie].Item1, rss.Count);
6444 }
6445 for (int r = prs[serie].Item1; r < prs[serie].Item2; r++)
6446 {
6447 b.Resolutions.Add(rss[r]);
6448 }
6449 }
6450 else
6451 {
6452 b.Resolutions.AddRange(rss);
6453 }
6454 }
6455 else
6456 b.Resolutions.AddRange(rss);
6457
6458 //If we have 2 resolutions that we're not added they are the label & macro resolutions so we add them to the image.
6459 if(rss.Count - pyramidResolutions == 2)
6460 {
6461 b.Resolutions.Add(rss[rss.Count - 2]);
6462 b.Resolutions.Add(rss[rss.Count - 1]);
6463 }
6464
6465 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.PhysicalSizeX * SizeX, b.PhysicalSizeY * SizeY, b.PhysicalSizeZ * SizeZ));
6466 pr.Status = "Reading ROIs";
6467 int rc = b.meta.getROICount();
6468 for (int im = 0; im < rc; im++)
6469 {
6470 string roiID = b.meta.getROIID(im);
6471 string roiName = b.meta.getROIName(im);
6472 ZCT co = new ZCT(0, 0, 0);
6473 int scount = 1;
6474 try
6475 {
6476 scount = b.meta.getShapeCount(im);
6477 }
6478 catch (Exception e)
6479 {
6480 Console.WriteLine(e.Message.ToString());
6481 }
6482 for (int sc = 0; sc < scount; sc++)
6483 {
6484 string type = b.meta.getShapeType(im, sc);
6485 ROI an = new ROI();
6486 an.roiID = roiID;
6487 an.roiName = roiName;
6488 an.shapeIndex = sc;
6489 if (type == "Point")
6490 {
6491 an.type = ROI.Type.Point;
6492 an.id = b.meta.getPointID(im, sc);
6493 double dx = b.meta.getPointX(im, sc).doubleValue();
6494 double dy = b.meta.getPointY(im, sc).doubleValue();
6495 an.AddPoint(b.ToStageSpace(new PointD(dx, dy)));
6496 an.coord = new ZCT();
6497 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPointTheZ(im, sc);
6498 if (nz != null)
6499 an.coord.Z = nz.getNumberValue().intValue();
6500 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPointTheC(im, sc);
6501 if (nc != null)
6502 an.coord.C = nc.getNumberValue().intValue();
6503 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPointTheT(im, sc);
6504 if (nt != null)
6505 an.coord.T = nt.getNumberValue().intValue();
6506 an.Text = b.meta.getPointText(im, sc);
6507 ome.units.quantity.Length fl = b.meta.getPointFontSize(im, sc);
6508 if (fl != null)
6509 an.fontSize = fl.value().intValue();
6510 ome.xml.model.enums.FontFamily ff = b.meta.getPointFontFamily(im, sc);
6511 if (ff != null)
6512 an.family = ff.name();
6513 ome.xml.model.primitives.Color col = b.meta.getPointStrokeColor(im, sc);
6514 if (col != null)
6515 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6516 ome.units.quantity.Length fw = b.meta.getPointStrokeWidth(im, sc);
6517 if (fw != null)
6518 an.strokeWidth = (float)fw.value().floatValue();
6519 ome.xml.model.primitives.Color colf = b.meta.getPointStrokeColor(im, sc);
6520 if (colf != null)
6521 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6522 }
6523 else
6524 if (type == "Line")
6525 {
6526 an.type = ROI.Type.Line;
6527 an.id = b.meta.getLineID(im, sc);
6528 double px1 = b.meta.getLineX1(im, sc).doubleValue();
6529 double py1 = b.meta.getLineY1(im, sc).doubleValue();
6530 double px2 = b.meta.getLineX2(im, sc).doubleValue();
6531 double py2 = b.meta.getLineY2(im, sc).doubleValue();
6532 an.AddPoint(b.ToStageSpace(new PointD(px1, py1)));
6533 an.AddPoint(b.ToStageSpace(new PointD(px2, py2)));
6534 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLineTheZ(im, sc);
6535 if (nz != null)
6536 co.Z = nz.getNumberValue().intValue();
6537 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLineTheC(im, sc);
6538 if (nc != null)
6539 co.C = nc.getNumberValue().intValue();
6540 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLineTheT(im, sc);
6541 if (nt != null)
6542 co.T = nt.getNumberValue().intValue();
6543 an.coord = co;
6544 an.Text = b.meta.getLineText(im, sc);
6545 ome.units.quantity.Length fl = b.meta.getLineFontSize(im, sc);
6546 if (fl != null)
6547 an.fontSize = fl.value().intValue();
6548 ome.xml.model.enums.FontFamily ff = b.meta.getLineFontFamily(im, sc);
6549 if (ff != null)
6550 an.family = ff.name();
6551 ome.xml.model.primitives.Color col = b.meta.getLineStrokeColor(im, sc);
6552 if (col != null)
6553 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6554 ome.units.quantity.Length fw = b.meta.getLineStrokeWidth(im, sc);
6555 if (fw != null)
6556 an.strokeWidth = (float)fw.value().floatValue();
6557 ome.xml.model.primitives.Color colf = b.meta.getLineFillColor(im, sc);
6558 if (colf != null)
6559 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6560 }
6561 else
6562 if (type == "Rectangle")
6563 {
6564 an.type = ROI.Type.Rectangle;
6565 an.id = b.meta.getRectangleID(im, sc);
6566 double px = b.meta.getRectangleX(im, sc).doubleValue();
6567 double py = b.meta.getRectangleY(im, sc).doubleValue();
6568 double pw = b.meta.getRectangleWidth(im, sc).doubleValue();
6569 double ph = b.meta.getRectangleHeight(im, sc).doubleValue();
6570 an.Rect = b.ToStageSpace(new RectangleD(px, py, pw, ph));
6571 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getRectangleTheZ(im, sc);
6572 if (nz != null)
6573 co.Z = nz.getNumberValue().intValue();
6574 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getRectangleTheC(im, sc);
6575 if (nc != null)
6576 co.C = nc.getNumberValue().intValue();
6577 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getRectangleTheT(im, sc);
6578 if (nt != null)
6579 co.T = nt.getNumberValue().intValue();
6580 an.coord = co;
6581
6582 an.Text = b.meta.getRectangleText(im, sc);
6583 ome.units.quantity.Length fl = b.meta.getRectangleFontSize(im, sc);
6584 if (fl != null)
6585 an.fontSize = fl.value().intValue();
6586 ome.xml.model.enums.FontFamily ff = b.meta.getRectangleFontFamily(im, sc);
6587 if (ff != null)
6588 an.family = ff.name();
6589 ome.xml.model.primitives.Color col = b.meta.getRectangleStrokeColor(im, sc);
6590 if (col != null)
6591 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6592 ome.units.quantity.Length fw = b.meta.getRectangleStrokeWidth(im, sc);
6593 if (fw != null)
6594 an.strokeWidth = (float)fw.value().floatValue();
6595 ome.xml.model.primitives.Color colf = b.meta.getRectangleFillColor(im, sc);
6596 if (colf != null)
6597 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6598 ome.xml.model.enums.FillRule fr = b.meta.getRectangleFillRule(im, sc);
6599 }
6600 else
6601 if (type == "Ellipse")
6602 {
6603 an.type = ROI.Type.Ellipse;
6604 an.id = b.meta.getEllipseID(im, sc);
6605 double px = b.meta.getEllipseX(im, sc).doubleValue();
6606 double py = b.meta.getEllipseY(im, sc).doubleValue();
6607 double ew = b.meta.getEllipseRadiusX(im, sc).doubleValue();
6608 double eh = b.meta.getEllipseRadiusY(im, sc).doubleValue();
6609 //We convert the ellipse radius to Rectangle
6610 double w = ew * 2;
6611 double h = eh * 2;
6612 double x = px - ew;
6613 double y = py - eh;
6614 an.Rect = b.ToStageSpace(new RectangleD(x, y, w, h));
6615 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getEllipseTheZ(im, sc);
6616 if (nz != null)
6617 co.Z = nz.getNumberValue().intValue();
6618 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getEllipseTheC(im, sc);
6619 if (nc != null)
6620 co.C = nc.getNumberValue().intValue();
6621 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getEllipseTheT(im, sc);
6622 if (nt != null)
6623 co.T = nt.getNumberValue().intValue();
6624 an.coord = co;
6625 an.Text = b.meta.getEllipseText(im, sc);
6626 ome.units.quantity.Length fl = b.meta.getEllipseFontSize(im, sc);
6627 if (fl != null)
6628 an.fontSize = fl.value().intValue();
6629 ome.xml.model.enums.FontFamily ff = b.meta.getEllipseFontFamily(im, sc);
6630 if (ff != null)
6631 an.family = ff.name();
6632 ome.xml.model.primitives.Color col = b.meta.getEllipseStrokeColor(im, sc);
6633 if (col != null)
6634 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6635 ome.units.quantity.Length fw = b.meta.getEllipseStrokeWidth(im, sc);
6636 if (fw != null)
6637 an.strokeWidth = (float)fw.value().floatValue();
6638 ome.xml.model.primitives.Color colf = b.meta.getEllipseFillColor(im, sc);
6639 if (colf != null)
6640 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6641 }
6642 else
6643 if (type == "Polygon")
6644 {
6645 an.type = ROI.Type.Polygon;
6646 an.id = b.meta.getPolygonID(im, sc);
6647 an.closed = true;
6648 string pxs = b.meta.getPolygonPoints(im, sc);
6649 PointD[] pts = an.stringToPoints(pxs);
6650 pts = b.ToStageSpace(pts);
6651 if (pts.Length > 100)
6652 {
6653 an.type = ROI.Type.Freeform;
6654 }
6655 an.AddPoints(pts);
6656 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolygonTheZ(im, sc);
6657 if (nz != null)
6658 co.Z = nz.getNumberValue().intValue();
6659 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolygonTheC(im, sc);
6660 if (nc != null)
6661 co.C = nc.getNumberValue().intValue();
6662 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolygonTheT(im, sc);
6663 if (nt != null)
6664 co.T = nt.getNumberValue().intValue();
6665 an.coord = co;
6666 an.Text = b.meta.getPolygonText(im, sc);
6667 ome.units.quantity.Length fl = b.meta.getPolygonFontSize(im, sc);
6668 if (fl != null)
6669 an.fontSize = fl.value().intValue();
6670 ome.xml.model.enums.FontFamily ff = b.meta.getPolygonFontFamily(im, sc);
6671 if (ff != null)
6672 an.family = ff.name();
6673 ome.xml.model.primitives.Color col = b.meta.getPolygonStrokeColor(im, sc);
6674 if (col != null)
6675 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6676 ome.units.quantity.Length fw = b.meta.getPolygonStrokeWidth(im, sc);
6677 if (fw != null)
6678 an.strokeWidth = (float)fw.value().floatValue();
6679 ome.xml.model.primitives.Color colf = b.meta.getPolygonFillColor(im, sc);
6680 if (colf != null)
6681 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6682 }
6683 else
6684 if (type == "Polyline")
6685 {
6686 an.type = ROI.Type.Polyline;
6687 an.id = b.meta.getPolylineID(im, sc);
6688 string pxs = b.meta.getPolylinePoints(im, sc);
6689 PointD[] pts = an.stringToPoints(pxs);
6690 for (int pi = 0; pi < pts.Length; pi++)
6691 {
6692 pts[pi] = b.ToStageSpace(pts[pi]);
6693 }
6694 an.AddPoints(an.stringToPoints(pxs));
6695 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolylineTheZ(im, sc);
6696 if (nz != null)
6697 co.Z = nz.getNumberValue().intValue();
6698 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolylineTheC(im, sc);
6699 if (nc != null)
6700 co.C = nc.getNumberValue().intValue();
6701 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolylineTheT(im, sc);
6702 if (nt != null)
6703 co.T = nt.getNumberValue().intValue();
6704 an.coord = co;
6705 an.Text = b.meta.getPolylineText(im, sc);
6706 ome.units.quantity.Length fl = b.meta.getPolylineFontSize(im, sc);
6707 if (fl != null)
6708 an.fontSize = fl.value().intValue();
6709 ome.xml.model.enums.FontFamily ff = b.meta.getPolylineFontFamily(im, sc);
6710 if (ff != null)
6711 an.family = ff.name();
6712 ome.xml.model.primitives.Color col = b.meta.getPolylineStrokeColor(im, sc);
6713 if (col != null)
6714 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6715 ome.units.quantity.Length fw = b.meta.getPolylineStrokeWidth(im, sc);
6716 if (fw != null)
6717 an.strokeWidth = (float)fw.value().floatValue();
6718 ome.xml.model.primitives.Color colf = b.meta.getPolylineFillColor(im, sc);
6719 if (colf != null)
6720 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6721 }
6722 else
6723 if (type == "Label")
6724 {
6725 an.type = ROI.Type.Label;
6726 an.id = b.meta.getLabelID(im, sc);
6727
6728 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLabelTheZ(im, sc);
6729 if (nz != null)
6730 co.Z = nz.getNumberValue().intValue();
6731 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLabelTheC(im, sc);
6732 if (nc != null)
6733 co.C = nc.getNumberValue().intValue();
6734 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLabelTheT(im, sc);
6735 if (nt != null)
6736 co.T = nt.getNumberValue().intValue();
6737 an.coord = co;
6738
6739 ome.units.quantity.Length fl = b.meta.getLabelFontSize(im, sc);
6740 if (fl != null)
6741 an.fontSize = fl.value().intValue();
6742 ome.xml.model.enums.FontFamily ff = b.meta.getLabelFontFamily(im, sc);
6743 if (ff != null)
6744 an.family = ff.name();
6745 ome.xml.model.primitives.Color col = b.meta.getLabelStrokeColor(im, sc);
6746 if (col != null)
6747 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6748 ome.units.quantity.Length fw = b.meta.getLabelStrokeWidth(im, sc);
6749 if (fw != null)
6750 an.strokeWidth = (float)fw.value().floatValue();
6751 ome.xml.model.primitives.Color colf = b.meta.getLabelFillColor(im, sc);
6752 if (colf != null)
6753 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6754 PointD p = new PointD(b.meta.getLabelX(im, sc).doubleValue(), b.meta.getLabelY(im, sc).doubleValue());
6755 an.AddPoint(b.ToStageSpace(p));
6756 an.Text = b.meta.getLabelText(im, sc);
6757 }
6758 else
6759 if (type == "Mask")
6760 {
6761 byte[] bts = b.meta.getMaskBinData(im, sc);
6762 bool end = b.meta.getMaskBinDataBigEndian(im, sc).booleanValue();
6763 an = ROI.CreateMask(co, bts, b.Resolutions[0].SizeX, b.Resolutions[0].SizeY,new PointD(b.StageSizeX,b.StageSizeY),b.PhysicalSizeX,b.PhysicalSizeY);
6764 an.Text = b.meta.getMaskText(im, sc);
6765 an.id = b.meta.getMaskID(im, sc);
6766 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getMaskTheZ(im, sc);
6767 if (nz != null)
6768 co.Z = nz.getNumberValue().intValue();
6769 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getMaskTheC(im, sc);
6770 if (nc != null)
6771 co.C = nc.getNumberValue().intValue();
6772 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getMaskTheT(im, sc);
6773 if (nt != null)
6774 co.T = nt.getNumberValue().intValue();
6775 an.coord = co;
6776
6777 ome.units.quantity.Length fl = b.meta.getMaskFontSize(im, sc);
6778 if (fl != null)
6779 an.fontSize = fl.value().intValue();
6780 ome.xml.model.enums.FontFamily ff = b.meta.getMaskFontFamily(im, sc);
6781 if (ff != null)
6782 an.family = ff.name();
6783 ome.xml.model.primitives.Color col = b.meta.getMaskStrokeColor(im, sc);
6784 if (col != null)
6785 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6786 ome.units.quantity.Length fw = b.meta.getMaskStrokeWidth(im, sc);
6787 if (fw != null)
6788 an.strokeWidth = (float)fw.value().floatValue();
6789 ome.xml.model.primitives.Color colf = b.meta.getMaskFillColor(im, sc);
6790 if (colf != null)
6791 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6792 }
6793 b.Annotations.Add(an);
6794 }
6795 }
6796
6797 List<string> serFiles = new List<string>();
6798 serFiles.AddRange(reader.getSeriesUsedFiles());
6799
6800 b.Buffers = new List<Bitmap>();
6801 if(b.Type == ImageType.pyramidal)
6802 try
6803 {
6804 string st = OpenSlideImage.DetectVendor(file);
6805 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
6806 {
6807 b.openSlideImage = OpenSlideImage.Open(file);
6808 b.openslideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file);
6809 }
6810 else
6811 {
6812 b.slideBase = new SlideBase(b,SlideImage.Open(b));
6813 }
6814 }
6815 catch (Exception e)
6816 {
6817 Console.WriteLine(e.Message.ToString());
6818 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6819 }
6820
6821 // read the image data bytes
6822 int pages = reader.getImageCount();
6823 bool inter = reader.isInterleaved();
6824 int z = 0;
6825 int c = 0;
6826 int t = 0;
6827 pr.Status = "Reading Image Data";
6828 if (!tile)
6829 {
6830 try
6831 {
6832 for (int p = 0; p < pages; p++)
6833 {
6834 Bitmap bf;
6835 pr.ProgressValue = (float)p / (float)pages;
6836 byte[] bytes = reader.openBytes(p);
6837 bf = new Bitmap(file, SizeX, SizeY, PixelFormat, bytes, new ZCT(z, c, t), p, null, b.littleEndian, inter);
6838 b.Buffers.Add(bf);
6839 }
6840 }
6841 catch (Exception)
6842 {
6843 //If we failed to read an entire plane it is likely too large so we open as pyramidal.
6844 b.Type = ImageType.pyramidal;
6845 try
6846 {
6847 string st = OpenSlideImage.DetectVendor(file);
6848 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
6849 {
6850 b.openSlideImage = OpenSlideImage.Open(file);
6851 b.openslideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file);
6852 }
6853 else
6854 {
6855 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6856 }
6857 }
6858 catch (Exception e)
6859 {
6860 Console.WriteLine(e.Message.ToString());
6861 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6862 }
6863 b.imRead = reader;
6864 for (int p = 0; p < pages; p++)
6865 {
6866 b.Buffers.Add(GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6867 Statistics.CalcStatistics(b.Buffers.Last());
6868 }
6869 }
6870
6871 }
6872 else
6873 {
6874 b.imRead = reader;
6875 for (int p = 0; p < pages; p++)
6876 {
6877 b.Buffers.Add(GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6878 Statistics.CalcStatistics(b.Buffers.Last());
6879 }
6880 }
6881 int pls;
6882 try
6883 {
6884 pls = b.meta.getPlaneCount(serie);
6885 }
6886 catch (Exception)
6887 {
6888 pls = 0;
6889 }
6890 pr.Status = "Reading Plane Data";
6891 if (pls == b.Buffers.Count)
6892 for (int bi = 0; bi < b.Buffers.Count; bi++)
6893 {
6894 Plane pl = new Plane();
6895 pl.Coordinate = new ZCT();
6896 double px = 0; double py = 0; double pz = 0;
6897 if (b.meta.getPlanePositionX(serie, bi) != null)
6898 px = b.meta.getPlanePositionX(serie, bi).value().doubleValue();
6899 if (b.meta.getPlanePositionY(serie, bi) != null)
6900 py = b.meta.getPlanePositionY(serie, bi).value().doubleValue();
6901 if (b.meta.getPlanePositionZ(serie, bi) != null)
6902 pz = b.meta.getPlanePositionZ(serie, bi).value().doubleValue();
6903 pl.Location = new AForge.Point3D(px, py, pz);
6904 int cc = 0; int zc = 0; int tc = 0;
6905 if (b.meta.getPlaneTheC(serie, bi) != null)
6906 cc = b.meta.getPlaneTheC(serie, bi).getNumberValue().intValue();
6907 if (b.meta.getPlaneTheZ(serie, bi) != null)
6908 zc = b.meta.getPlaneTheZ(serie, bi).getNumberValue().intValue();
6909 if (b.meta.getPlaneTheT(serie, bi) != null)
6910 tc = b.meta.getPlaneTheT(serie, bi).getNumberValue().intValue();
6911 pl.Coordinate = new ZCT(zc, cc, tc);
6912 if (b.meta.getPlaneDeltaT(serie, bi) != null)
6913 pl.Delta = b.meta.getPlaneDeltaT(serie, bi).value().doubleValue();
6914 if (b.meta.getPlaneExposureTime(serie, bi) != null)
6915 pl.Exposure = b.meta.getPlaneExposureTime(serie, bi).value().doubleValue();
6916 b.Buffers[bi].Plane = pl;
6917 }
6918
6919 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, order);
6920 //We wait for histogram image statistics calculation
6921 do
6922 {
6923 Thread.Sleep(50);
6924 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
6925 b.SetLabelMacroResolutions();
6926 Statistics.ClearCalcBuffer();
6927 AutoThreshold(b, true);
6928 if (b.bitsPerPixel > 8)
6929 b.StackThreshold(true);
6930 else
6931 b.StackThreshold(false);
6932 if (!tile)
6933 {
6934 //We use a try block to close the reader as sometimes this will cause an error.
6935 bool stop = false;
6936 do
6937 {
6938 try
6939 {
6940 reader.close();
6941 stop = true;
6942 }
6943 catch (Exception e)
6944 {
6945 Console.WriteLine(e.Message);
6946 }
6947 } while (!stop);
6948 }
6949 if (addToImages)
6950 Images.AddImage(b, tab);
6951 b.Loading = false;
6952 // update ui on main UI thread
6953 Application.Invoke(delegate
6954 {
6955 pr.Hide();
6956 });
6957 Console.WriteLine("Opening complete " + file);
6958 return b;
6959 }
AForge.Color Color
Definition Bio.cs:22
openslide wrapper
Definition SlideImage.cs:20
static SlideImage Open(BioImage b)
Open.
Definition SlideImage.cs:74
SlideBase SlideBase
Definition Bio.cs:2418
OpenSlideBase OpenSlideBase
Definition Bio.cs:2416
int SizeZ
Definition Bio.cs:2639

◆ OpenOMEROIs()

static List< ROI > BioGTK.BioImage.OpenOMEROIs ( string  file,
int  series 
)
inlinestatic

It reads the OME-XML file and converts the ROIs to a list of ROI objects

Parameters
filethe path to the OME-TIFF file
seriesthe series number of the image you want to open
Returns
A list of ROI objects.
7620 {
7621 List<ROI> Annotations = new List<ROI>();
7622 // create OME-XML metadata store
7623 ServiceFactory factory = new ServiceFactory();
7624 OMEXMLService service = (OMEXMLService)factory.getInstance(typeof(OMEXMLService));
7625 loci.formats.ome.OMEXMLMetadata meta = service.createOMEXMLMetadata();
7626 // create format reader
7627 ImageReader imageReader = new ImageReader();
7628 imageReader.setMetadataStore(meta);
7629 // initialize file
7630 file = file.Replace("\\", "/");
7631 imageReader.setId(file);
7632 int imageCount = imageReader.getImageCount();
7633 int seriesCount = imageReader.getSeriesCount();
7634 double physicalSizeX = 0;
7635 double physicalSizeY = 0;
7636 double physicalSizeZ = 0;
7637 double stageSizeX = 0;
7638 double stageSizeY = 0;
7639 double stageSizeZ = 0;
7640 int SizeX = imageReader.getSizeX();
7641 int SizeY = imageReader.getSizeY();
7642 int SizeZ = imageReader.getSizeY();
7643 try
7644 {
7645 bool hasPhysical = false;
7646 if (meta.getPixelsPhysicalSizeX(series) != null)
7647 {
7648 physicalSizeX = meta.getPixelsPhysicalSizeX(series).value().doubleValue();
7649 hasPhysical = true;
7650 }
7651 if (meta.getPixelsPhysicalSizeY(series) != null)
7652 {
7653 physicalSizeY = meta.getPixelsPhysicalSizeY(series).value().doubleValue();
7654 }
7655 if (meta.getPixelsPhysicalSizeZ(series) != null)
7656 {
7657 physicalSizeZ = meta.getPixelsPhysicalSizeZ(series).value().doubleValue();
7658 }
7659 else
7660 {
7661 physicalSizeZ = 1;
7662 }
7663 if (meta.getStageLabelX(series) != null)
7664 stageSizeX = meta.getStageLabelX(series).value().doubleValue();
7665 if (meta.getStageLabelY(series) != null)
7666 stageSizeY = meta.getStageLabelY(series).value().doubleValue();
7667 if (meta.getStageLabelZ(series) != null)
7668 stageSizeZ = meta.getStageLabelZ(series).value().doubleValue();
7669 else
7670 stageSizeZ = 1;
7671 }
7672 catch (Exception e)
7673 {
7674 stageSizeX = 0;
7675 stageSizeY = 0;
7676 stageSizeZ = 1;
7677 }
7678 VolumeD volume = new VolumeD(new Point3D(stageSizeX, stageSizeY, stageSizeZ), new Point3D(physicalSizeX * SizeX, physicalSizeY * SizeY, physicalSizeZ * SizeZ));
7679 int rc = meta.getROICount();
7680 for (int im = 0; im < rc; im++)
7681 {
7682 string roiID = meta.getROIID(im);
7683 string roiName = meta.getROIName(im);
7684 ZCT co = new ZCT(0, 0, 0);
7685 int scount = 1;
7686 try
7687 {
7688 scount = meta.getShapeCount(im);
7689 }
7690 catch (Exception e)
7691 {
7692 Console.WriteLine(e.Message.ToString());
7693 }
7694 for (int sc = 0; sc < scount; sc++)
7695 {
7696 string type = meta.getShapeType(im, sc);
7697 ROI an = new ROI();
7698 an.roiID = roiID;
7699 an.roiName = roiName;
7700 an.shapeIndex = sc;
7701 if (type == "Point")
7702 {
7703 an.type = ROI.Type.Point;
7704 an.id = meta.getPointID(im, sc);
7705 double dx = meta.getPointX(im, sc).doubleValue();
7706 double dy = meta.getPointY(im, sc).doubleValue();
7707 an.AddPoint(ToStageSpace(new PointD(dx, dy), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7708 an.coord = new ZCT();
7709 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPointTheZ(im, sc);
7710 if (nz != null)
7711 an.coord.Z = nz.getNumberValue().intValue();
7712 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPointTheC(im, sc);
7713 if (nc != null)
7714 an.coord.C = nc.getNumberValue().intValue();
7715 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPointTheT(im, sc);
7716 if (nt != null)
7717 an.coord.T = nt.getNumberValue().intValue();
7718 an.Text = meta.getPointText(im, sc);
7719 ome.units.quantity.Length fl = meta.getPointFontSize(im, sc);
7720 if (fl != null)
7721 an.fontSize = fl.value().intValue();
7722 an.family = meta.getPointFontFamily(im, sc).name();
7723 ome.xml.model.primitives.Color col = meta.getPointStrokeColor(im, sc);
7724 if (col != null)
7725 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7726 ome.units.quantity.Length fw = meta.getPointStrokeWidth(im, sc);
7727 if (fw != null)
7728 an.strokeWidth = (float)fw.value().floatValue();
7729 ome.xml.model.primitives.Color colf = meta.getPointStrokeColor(im, sc);
7730 if (colf != null)
7731 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7732 }
7733 else
7734 if (type == "Line")
7735 {
7736 an.type = ROI.Type.Line;
7737 an.id = meta.getLineID(im, sc);
7738 double px1 = meta.getLineX1(im, sc).doubleValue();
7739 double py1 = meta.getLineY1(im, sc).doubleValue();
7740 double px2 = meta.getLineX2(im, sc).doubleValue();
7741 double py2 = meta.getLineY2(im, sc).doubleValue();
7742 an.AddPoint(ToStageSpace(new PointD(px1, py1), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7743 an.AddPoint(ToStageSpace(new PointD(px2, py2), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7744 ome.xml.model.primitives.NonNegativeInteger nz = meta.getLineTheZ(im, sc);
7745 if (nz != null)
7746 co.Z = nz.getNumberValue().intValue();
7747 ome.xml.model.primitives.NonNegativeInteger nc = meta.getLineTheC(im, sc);
7748 if (nc != null)
7749 co.C = nc.getNumberValue().intValue();
7750 ome.xml.model.primitives.NonNegativeInteger nt = meta.getLineTheT(im, sc);
7751 if (nt != null)
7752 co.T = nt.getNumberValue().intValue();
7753 an.coord = co;
7754 an.Text = meta.getLineText(im, sc);
7755 ome.units.quantity.Length fl = meta.getLineFontSize(im, sc);
7756 if (fl != null)
7757 an.fontSize = fl.value().intValue();
7758 an.family = meta.getPointFontFamily(im, sc).name();
7759 ome.xml.model.primitives.Color col = meta.getLineStrokeColor(im, sc);
7760 if (col != null)
7761 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7762 ome.units.quantity.Length fw = meta.getLineStrokeWidth(im, sc);
7763 if (fw != null)
7764 an.strokeWidth = (float)fw.value().floatValue();
7765 ome.xml.model.primitives.Color colf = meta.getLineFillColor(im, sc);
7766 if (colf != null)
7767 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7768 }
7769 else
7770 if (type == "Rectangle")
7771 {
7772 an.type = ROI.Type.Rectangle;
7773 an.id = meta.getRectangleID(im, sc);
7774 double px = meta.getRectangleX(im, sc).doubleValue();
7775 double py = meta.getRectangleY(im, sc).doubleValue();
7776 double pw = meta.getRectangleWidth(im, sc).doubleValue();
7777 double ph = meta.getRectangleHeight(im, sc).doubleValue();
7778 an.Rect = ToStageSpace(new RectangleD(px, py, pw, ph), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7779 ome.xml.model.primitives.NonNegativeInteger nz = meta.getRectangleTheZ(im, sc);
7780 if (nz != null)
7781 co.Z = nz.getNumberValue().intValue();
7782 ome.xml.model.primitives.NonNegativeInteger nc = meta.getRectangleTheC(im, sc);
7783 if (nc != null)
7784 co.C = nc.getNumberValue().intValue();
7785 ome.xml.model.primitives.NonNegativeInteger nt = meta.getRectangleTheT(im, sc);
7786 if (nt != null)
7787 co.T = nt.getNumberValue().intValue();
7788 an.coord = co;
7789
7790 an.Text = meta.getRectangleText(im, sc);
7791 ome.units.quantity.Length fl = meta.getRectangleFontSize(im, sc);
7792 if (fl != null)
7793 an.fontSize = fl.value().intValue();
7794 an.family = meta.getPointFontFamily(im, sc).name();
7795 ome.xml.model.primitives.Color col = meta.getRectangleStrokeColor(im, sc);
7796 if (col != null)
7797 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7798 ome.units.quantity.Length fw = meta.getRectangleStrokeWidth(im, sc);
7799 if (fw != null)
7800 an.strokeWidth = (float)fw.value().floatValue();
7801 ome.xml.model.primitives.Color colf = meta.getRectangleFillColor(im, sc);
7802 if (colf != null)
7803 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7804 ome.xml.model.enums.FillRule fr = meta.getRectangleFillRule(im, sc);
7805 }
7806 else
7807 if (type == "Ellipse")
7808 {
7809 an.type = ROI.Type.Ellipse;
7810 an.id = meta.getEllipseID(im, sc);
7811 double px = meta.getEllipseX(im, sc).doubleValue();
7812 double py = meta.getEllipseY(im, sc).doubleValue();
7813 double ew = meta.getEllipseRadiusX(im, sc).doubleValue();
7814 double eh = meta.getEllipseRadiusY(im, sc).doubleValue();
7815 //We convert the ellipse radius to Rectangle
7816 double w = ew * 2;
7817 double h = eh * 2;
7818 double x = px - ew;
7819 double y = py - eh;
7820 an.Rect = ToStageSpace(new RectangleD(px, py, w, h), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7821 ome.xml.model.primitives.NonNegativeInteger nz = meta.getEllipseTheZ(im, sc);
7822 if (nz != null)
7823 co.Z = nz.getNumberValue().intValue();
7824 ome.xml.model.primitives.NonNegativeInteger nc = meta.getEllipseTheC(im, sc);
7825 if (nc != null)
7826 co.C = nc.getNumberValue().intValue();
7827 ome.xml.model.primitives.NonNegativeInteger nt = meta.getEllipseTheT(im, sc);
7828 if (nt != null)
7829 co.T = nt.getNumberValue().intValue();
7830 an.coord = co;
7831 an.Text = meta.getEllipseText(im, sc);
7832 ome.units.quantity.Length fl = meta.getEllipseFontSize(im, sc);
7833 if (fl != null)
7834 an.fontSize = fl.value().intValue();
7835 an.family = meta.getPointFontFamily(im, sc).name();
7836 ome.xml.model.primitives.Color col = meta.getEllipseStrokeColor(im, sc);
7837 if (col != null)
7838 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7839 ome.units.quantity.Length fw = meta.getEllipseStrokeWidth(im, sc);
7840 if (fw != null)
7841 an.strokeWidth = (float)fw.value().floatValue();
7842 ome.xml.model.primitives.Color colf = meta.getEllipseFillColor(im, sc);
7843 if (colf != null)
7844 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7845 }
7846 else
7847 if (type == "Polygon")
7848 {
7849 an.type = ROI.Type.Polygon;
7850 an.id = meta.getPolygonID(im, sc);
7851 an.closed = true;
7852 string pxs = meta.getPolygonPoints(im, sc);
7853 PointD[] pts = an.stringToPoints(pxs);
7854 pts = ToStageSpace(pts, physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7855 if (pts.Length > 100)
7856 {
7857 an.type = ROI.Type.Freeform;
7858 }
7859 an.AddPoints(pts);
7860 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPolygonTheZ(im, sc);
7861 if (nz != null)
7862 co.Z = nz.getNumberValue().intValue();
7863 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPolygonTheC(im, sc);
7864 if (nc != null)
7865 co.C = nc.getNumberValue().intValue();
7866 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPolygonTheT(im, sc);
7867 if (nt != null)
7868 co.T = nt.getNumberValue().intValue();
7869 an.coord = co;
7870 an.Text = meta.getPolygonText(im, sc);
7871 ome.units.quantity.Length fl = meta.getPolygonFontSize(im, sc);
7872 if (fl != null)
7873 an.fontSize = fl.value().intValue();
7874 an.family = meta.getPointFontFamily(im, sc).name();
7875 ome.xml.model.primitives.Color col = meta.getPolygonStrokeColor(im, sc);
7876 if (col != null)
7877 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7878 ome.units.quantity.Length fw = meta.getPolygonStrokeWidth(im, sc);
7879 if (fw != null)
7880 an.strokeWidth = (float)fw.value().floatValue();
7881 ome.xml.model.primitives.Color colf = meta.getPolygonFillColor(im, sc);
7882 if (colf != null)
7883 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7884 }
7885 else
7886 if (type == "Polyline")
7887 {
7888 an.type = ROI.Type.Polyline;
7889 an.id = meta.getPolylineID(im, sc);
7890 string pxs = meta.getPolylinePoints(im, sc);
7891 PointD[] pts = an.stringToPoints(pxs);
7892 for (int pi = 0; pi < pts.Length; pi++)
7893 {
7894 pts[pi] = ToStageSpace(pts[pi], physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7895 }
7896 an.AddPoints(an.stringToPoints(pxs));
7897 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPolylineTheZ(im, sc);
7898 if (nz != null)
7899 co.Z = nz.getNumberValue().intValue();
7900 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPolylineTheC(im, sc);
7901 if (nc != null)
7902 co.C = nc.getNumberValue().intValue();
7903 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPolylineTheT(im, sc);
7904 if (nt != null)
7905 co.T = nt.getNumberValue().intValue();
7906 an.coord = co;
7907 an.Text = meta.getPolylineText(im, sc);
7908 ome.units.quantity.Length fl = meta.getPolylineFontSize(im, sc);
7909 if (fl != null)
7910 an.fontSize = fl.value().intValue();
7911 an.family = meta.getPointFontFamily(im, sc).name();
7912 ome.xml.model.primitives.Color col = meta.getPolylineStrokeColor(im, sc);
7913 if (col != null)
7914 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7915 ome.units.quantity.Length fw = meta.getPolylineStrokeWidth(im, sc);
7916 if (fw != null)
7917 an.strokeWidth = (float)fw.value().floatValue();
7918 ome.xml.model.primitives.Color colf = meta.getPolylineFillColor(im, sc);
7919 if (colf != null)
7920 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7921 }
7922 else
7923 if (type == "Label")
7924 {
7925 an.type = ROI.Type.Label;
7926 an.id = meta.getLabelID(im, sc);
7927
7928 ome.xml.model.primitives.NonNegativeInteger nz = meta.getLabelTheZ(im, sc);
7929 if (nz != null)
7930 co.Z = nz.getNumberValue().intValue();
7931 ome.xml.model.primitives.NonNegativeInteger nc = meta.getLabelTheC(im, sc);
7932 if (nc != null)
7933 co.C = nc.getNumberValue().intValue();
7934 ome.xml.model.primitives.NonNegativeInteger nt = meta.getLabelTheT(im, sc);
7935 if (nt != null)
7936 co.T = nt.getNumberValue().intValue();
7937 an.coord = co;
7938
7939 ome.units.quantity.Length fl = meta.getLabelFontSize(im, sc);
7940 if (fl != null)
7941 an.fontSize = fl.value().intValue();
7942 an.family = meta.getPointFontFamily(im, sc).name();
7943 ome.xml.model.primitives.Color col = meta.getLabelStrokeColor(im, sc);
7944 if (col != null)
7945 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7946 ome.units.quantity.Length fw = meta.getLabelStrokeWidth(im, sc);
7947 if (fw != null)
7948 an.strokeWidth = (float)fw.value().floatValue();
7949 ome.xml.model.primitives.Color colf = meta.getLabelFillColor(im, sc);
7950 if (colf != null)
7951 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7952 PointD p = new PointD(meta.getLabelX(im, sc).doubleValue(), meta.getLabelY(im, sc).doubleValue());
7953 an.AddPoint(ToStageSpace(p, physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7954 an.Text = meta.getLabelText(im, sc);
7955 }
7956 else
7957 if (type == "Mask")
7958 {
7959 byte[] bts = meta.getMaskBinData(im, sc);
7960 bool end = meta.getMaskBinDataBigEndian(im, sc).booleanValue();
7961 an = ROI.CreateMask(co, bts, SizeX, SizeY, new PointD(stageSizeX, stageSizeY),physicalSizeX,physicalSizeY);
7962 an.Text = meta.getMaskText(im, sc);
7963 an.id = meta.getMaskID(im, sc);
7964 ome.xml.model.primitives.NonNegativeInteger nz = meta.getMaskTheZ(im, sc);
7965 if (nz != null)
7966 co.Z = nz.getNumberValue().intValue();
7967 ome.xml.model.primitives.NonNegativeInteger nc = meta.getMaskTheC(im, sc);
7968 if (nc != null)
7969 co.C = nc.getNumberValue().intValue();
7970 ome.xml.model.primitives.NonNegativeInteger nt = meta.getMaskTheT(im, sc);
7971 if (nt != null)
7972 co.T = nt.getNumberValue().intValue();
7973 an.coord = co;
7974
7975 ome.units.quantity.Length fl = meta.getMaskFontSize(im, sc);
7976 if (fl != null)
7977 an.fontSize = fl.value().intValue();
7978 ome.xml.model.enums.FontFamily ff = meta.getMaskFontFamily(im, sc);
7979 if (ff != null)
7980 an.family = ff.name();
7981 ome.xml.model.primitives.Color col = meta.getMaskStrokeColor(im, sc);
7982 if (col != null)
7983 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7984 ome.units.quantity.Length fw = meta.getMaskStrokeWidth(im, sc);
7985 if (fw != null)
7986 an.strokeWidth = (float)fw.value().floatValue();
7987 ome.xml.model.primitives.Color colf = meta.getMaskFillColor(im, sc);
7988 if (colf != null)
7989 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7990 }
7991 }
7992 }
7993
7994 imageReader.close();
7995 return Annotations;
7996 }
int seriesCount
Definition Bio.cs:2164
PointD ToStageSpace(PointD p)
Definition Bio.cs:3512

◆ OpenOMESeries()

static BioImage[] BioGTK.BioImage.OpenOMESeries ( string  file,
bool  tab,
bool  addToImages 
)
inlinestatic

It opens a file, checks if it's tiled, if it is, it opens it as a tiled image, if not, it opens it as a normal image

Parameters
filethe file path
tabopen in new tab
addToImagesadd to images list.
Returns
An array of BioImage objects.
7278 {
7279 //We wait incase OME has not initialized yet.
7280 if (!initialized)
7281 do
7282 {
7283 Thread.Sleep(100);
7284 //Application.DoEvents();
7285 } while (!Initialized);
7286 var meta = (IMetadata)((OMEXMLService)new ServiceFactory().getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
7287 reader.setMetadataStore((MetadataStore)meta);
7288 file = file.Replace("\\", "/");
7289 try
7290 {
7291 if (reader.getCurrentFile() != file)
7292 {
7293 status = "Opening OME Image.";
7294 file = file.Replace("\\", "/");
7295 reader.setId(file);
7296 }
7297 }
7298 catch (Exception e)
7299 {
7300 Scripting.LogLine(e.Message);
7301 return null;
7302 }
7303 int count = reader.getSeriesCount();
7304 BioImage[] bs = new BioImage[count];
7305 for (int i = 0; i < count; i++)
7306 {
7307 bs[i] = OpenOME(file, i, tab, addToImages, false, 0, 0, 0, 0);
7308 if (bs[i] == null)
7309 return null;
7310 }
7311 return bs;
7312 }
static bool Initialized
Definition Bio.cs:2746

◆ OpenSeries()

static BioImage[] BioGTK.BioImage.OpenSeries ( string  file,
bool  tab 
)
inlinestatic

It opens a tiff file, reads the number of pages, reads the number of channels, and then reads each page into a BioImage object.

Parameters
filethe path to the file
tabopen image in new tab.
Returns
An array of BioImage objects.
4843 {
4844 Tiff image = Tiff.Open(file, "r");
4845 int pages = image.NumberOfDirectories();
4846 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
4847 int sp = image.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
4848 ImageJDesc imDesc = new ImageJDesc();
4849 int count = 1;
4850 if (f != null)
4851 {
4852 string desc = f[0].ToString();
4853 if (desc.StartsWith("ImageJ"))
4854 {
4855 imDesc.SetString(desc);
4856 if (imDesc.channels != 0)
4857 count = imDesc.channels;
4858 }
4859 }
4860 int scount = (pages * sp) / count;
4861 BioImage[] bs = new BioImage[pages];
4862 image.Close();
4863 for (int i = 0; i < pages; i++)
4864 {
4865 bs[i] = OpenFile(file, i, tab, true);
4866 }
4867 return bs;
4868 }

◆ OpenVips()

static void BioGTK.BioImage.OpenVips ( BioImage  b,
int  pagecount 
)
inlinestatic

The function "OpenVips" takes a BioImage object and an integer representing the number of pages, and adds each page of the image file to the BioImage's vipPages list using the NetVips library.

Parameters
BioImageThe BioImage parameter is an object that represents a bio image. It likely contains information about the image file, such as the file path and other metadata.
pagecountThe parameter "pagecount" represents the number of pages in the TIFF file that needs to be loaded into the "vipPages" list of the "BioImage" object.
6069 {
6070 try
6071 {
6072 for (int i = 0; i < pagecount; i++)
6073 {
6074 b.vipPages.Add(NetVips.Image.Tiffload(b.file, i));
6075 }
6076 }
6077 catch (Exception e)
6078 {
6079 Console.WriteLine(e.Message);
6080 }
6081
6082 }

◆ OpenXML()

static string BioGTK.BioImage.OpenXML ( string  file)
inlinestatic

‍Open the file, get the image description field, and return it as a string

Parameters
filethe path to the file
Returns
The image description of the tiff file.
7606 {
7607 if (!file.EndsWith(".tif"))
7608 return null;
7609 Tiff image = Tiff.Open(file, "r");
7610 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
7611 return f[0].ToString();
7612 }

◆ operator*() [1/2]

static BioImage BioGTK.BioImage.operator* ( BioImage  a,
ColorS  b 
)
inlinestatic

This function takes a BioImage object and a ColorS object and returns a BioImage object

Parameters
BioImagea class that contains a list of ColorS objects.
ColorSa struct that contains a byte for each color channel (R, G, B, A)
Returns
A BioImage object
8526 {
8527 for (int i = 0; i < a.Buffers.Count; i++)
8528 {
8529 a.Buffers[i] = a.Buffers[i] * b;
8530 }
8531 return a;
8532 }

◆ operator*() [2/2]

static BioImage BioGTK.BioImage.operator* ( BioImage  a,
float  b 
)
inlinestatic
8468 {
8469 for (int i = 0; i < a.Buffers.Count; i++)
8470 {
8471 a.Buffers[i] = a.Buffers[i] / b;
8472 }
8473 return a;
8474 }

◆ operator+() [1/2]

static BioImage BioGTK.BioImage.operator+ ( BioImage  a,
ColorS  b 
)
inlinestatic

It takes a BioImage object and a ColorS object and adds the ColorS object to each buffer in the BioImage object

Parameters
BioImagea class that contains a list of ColorS objects.
ColorSa struct that contains a byte for each color channel (R, G, B, A)
Returns
A BioImage object
8541 {
8542 for (int i = 0; i < a.Buffers.Count; i++)
8543 {
8544 a.Buffers[i] = a.Buffers[i] + b;
8545 }
8546 return a;
8547 }

◆ operator+() [2/2]

static BioImage BioGTK.BioImage.operator+ ( BioImage  a,
float  b 
)
inlinestatic

This function adds a constant value to each pixel in the image

Parameters
BioImagea class that contains a list of buffers (float[])
bthe value to add to the image
Returns
The image itself.
8482 {
8483 for (int i = 0; i < a.Buffers.Count; i++)
8484 {
8485 a.Buffers[i] = a.Buffers[i] + b;
8486 }
8487 return a;
8488 }

◆ operator-() [1/2]

static BioImage BioGTK.BioImage.operator- ( BioImage  a,
ColorS  b 
)
inlinestatic

The function subtracts a color from each pixel in the image

Parameters
BioImagea class that contains a list of ColorS objects.
ColorSa struct that contains a byte for each color channel (R, G, B, A)
Returns
The image itself.
8555 {
8556 for (int i = 0; i < a.Buffers.Count; i++)
8557 {
8558 a.Buffers[i] = a.Buffers[i] - b;
8559 }
8560 return a;
8561 }

◆ operator-() [2/2]

static BioImage BioGTK.BioImage.operator- ( BioImage  a,
float  b 
)
inlinestatic

Subtracts a scalar value from each pixel in the image

Parameters
BioImagea class that contains a list of buffers (which are 2D arrays of floats)
bthe value to subtract from the image
Returns
The BioImage object is being returned.
8496 {
8497 for (int i = 0; i < a.Buffers.Count; i++)
8498 {
8499 a.Buffers[i] = a.Buffers[i] - b;
8500 }
8501 return a;
8502 }

◆ operator/() [1/2]

static BioImage BioGTK.BioImage.operator/ ( BioImage  a,
ColorS  b 
)
inlinestatic

This function divides each pixel in the image by the value of the color

Parameters
BioImagea class that contains a list of ColorS objects.
ColorSa struct that contains a byte for each color channel (R, G, B, A)
Returns
A BioImage object.
8512 {
8513 for (int i = 0; i < a.Buffers.Count; i++)
8514 {
8515 a.Buffers[i] = a.Buffers[i] / b;
8516 }
8517 return a;
8518 }

◆ operator/() [2/2]

static BioImage BioGTK.BioImage.operator/ ( BioImage  a,
float  b 
)
inlinestatic

This function divides each pixel in the image by a constant value

Parameters
BioImagea class that contains a list of buffers (which are 2D arrays of floats)
bthe value to divide by
Returns
The image is being returned.
8460 {
8461 for (int i = 0; i < a.Buffers.Count; i++)
8462 {
8463 a.Buffers[i] = a.Buffers[i] / b;
8464 }
8465 return a;
8466 }

◆ ROIsToString()

static string BioGTK.BioImage.ROIsToString ( List< ROI Annotations)
inlinestatic

It takes a list of ROI objects and returns a string of all the ROI objects in the list

Parameters
AnnotationsList of ROI objects
Returns
A string of the ROI's
8003 {
8004 string s = "";
8005 for (int i = 0; i < Annotations.Count; i++)
8006 {
8007 s += ROIToString(Annotations[i]);
8008 }
8009 return s;
8010 }
static string ROIToString(ROI an)
Definition Bio.cs:8017

◆ ROIToString()

static string BioGTK.BioImage.ROIToString ( ROI  an)
inlinestatic

This function takes an ROI object and returns a string that contains all the information about the ROI

Parameters
ROIThe ROI object
Returns
A string
8018 {
8019 PointD[] points = an.GetPoints();
8020 string pts = "";
8021 for (int j = 0; j < points.Length; j++)
8022 {
8023 if (j == points.Length - 1)
8024 pts += points[j].X.ToString(CultureInfo.InvariantCulture) + "," + points[j].Y.ToString(CultureInfo.InvariantCulture);
8025 else
8026 pts += points[j].X.ToString(CultureInfo.InvariantCulture) + "," + points[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
8027 }
8028 char sep = (char)34;
8029 string sColor = sep.ToString() + an.strokeColor.A.ToString() + ',' + an.strokeColor.R.ToString() + ',' + an.strokeColor.G.ToString() + ',' + an.strokeColor.B.ToString() + sep.ToString();
8030 string bColor = sep.ToString() + an.fillColor.A.ToString() + ',' + an.fillColor.R.ToString() + ',' + an.fillColor.G.ToString() + ',' + an.fillColor.B.ToString() + sep.ToString();
8031
8032 string line = an.roiID + ',' + an.roiName + ',' + an.type.ToString() + ',' + an.id + ',' + an.shapeIndex.ToString() + ',' +
8033 an.Text + ',' + an.serie + ',' + an.coord.Z.ToString() + ',' + an.coord.C.ToString() + ',' + an.coord.T.ToString() + ',' + an.X.ToString(CultureInfo.InvariantCulture) + ',' + an.Y.ToString(CultureInfo.InvariantCulture) + ',' +
8034 an.W.ToString(CultureInfo.InvariantCulture) + ',' + an.H.ToString(CultureInfo.InvariantCulture) + ',' + sep.ToString() + pts + sep.ToString() + ',' + sColor + ',' + an.strokeWidth.ToString(CultureInfo.InvariantCulture) + ',' + bColor + ',' + an.fontSize.ToString(CultureInfo.InvariantCulture) + ',' + NewLine;
8035 return line;
8036 }
const char NewLine
Definition Bio.cs:7597

◆ RotateFlip()

void BioGTK.BioImage.RotateFlip ( AForge::RotateFlipType  rot)
inline
3210 {
3211 for (int i = 0; i < Buffers.Count; i++)
3212 {
3213 Buffers[i].RotateFlip(rot);
3214 }
3215 Volume = new VolumeD(new Point3D(StageSizeX, StageSizeY, StageSizeZ), new Point3D(PhysicalSizeX * SizeX, PhysicalSizeY * SizeY, PhysicalSizeZ * SizeZ));
3216 }
double StageSizeX
Definition Bio.cs:2374
double StageSizeY
Definition Bio.cs:2382
double StageSizeZ
Definition Bio.cs:2387

◆ SaveAsync()

static async Task BioGTK.BioImage.SaveAsync ( string  file,
string  id,
int  serie,
bool  ome 
)
inlinestatic

The SaveAsync function saves data to a file asynchronously.

Parameters
fileThe file parameter is a string that represents the file path or name where the data will be saved.
idThe "id" parameter is a string that represents an identifier for the save operation. It could be used to uniquely identify the saved data or to specify a specific location or format for the saved file.
serieThe "serie" parameter is an integer that represents a series or sequence number. It is used as a parameter in the SaveAsync method.
omeThe "ome" parameter is a boolean value that determines whether or not to perform a specific action in the saving process.
7478 {
7479 savefile = file;
7480 saveid = id;
7481 some = ome;
7482 await Task.Run(SaveThread);
7483 }

◆ SaveFile()

static void BioGTK.BioImage.SaveFile ( string  file,
string  ID 
)
inlinestatic

This function takes a string array of file names and a string ID and saves the files to the database

Parameters
fileThe file path to the file you want to save.
IDThe ID of the series you want to save.
4726 {
4727 string[] sts = new string[1];
4728 sts[0] = ID;
4729 SaveSeries(sts, file);
4730 }
static void SaveSeries(string[] IDs, string file)
Definition Bio.cs:4735

◆ SaveOME() [1/2]

static void BioGTK.BioImage.SaveOME ( BioImage  image,
string  file 
)
inlinestatic
5420 {
5421 BioImage[] sts = new BioImage[1];
5422 sts[0] = image;
5423 SaveOMESeries(sts, file, BioImage.Planes);
5424 }
static void SaveOMESeries(BioImage[] files, string f, bool planes)
Definition Bio.cs:5430

◆ SaveOME() [2/2]

static void BioGTK.BioImage.SaveOME ( string  file,
string  ID 
)
inlinestatic
5413 {
5414 BioImage[] sts = new BioImage[1];
5415 sts[0] = Images.GetImage(ID);
5416 SaveOMESeries(sts, file, BioImage.Planes);
5417 }

◆ SaveOMEPyramidal()

static void BioGTK.BioImage.SaveOMEPyramidal ( BioImage[]  bms,
string  file,
Enums::ForeignTiffCompression  compression,
int  compressionLevel 
)
inlinestatic

The function SaveOMEPyramidal saves a collection of BioImages as a pyramidal OME-TIFF file.

Parameters
bmsAn array of BioImage objects representing the images to be saved.
fileThe file parameter is a string that represents the file path where the OME Pyramidal TIFF file will be saved.
compressionThe compression parameter is of type Enums.ForeignTiffCompression and it specifies the compression method to be used when saving the TIFF file.
5841 {
5842 if (File.Exists(file))
5843 File.Delete(file);
5844 //We need to go through the images and find the ones belonging to each resolution.
5845 //As well we need to determine the dimensions of the tiles.
5846 Dictionary<double, List<BioImage>> bis = new Dictionary<double, List<BioImage>>();
5847 Dictionary<double, Point3D> min = new Dictionary<double, Point3D>();
5848 Dictionary<double, Point3D> max = new Dictionary<double, Point3D>();
5849 for (int i = 0; i < bms.Length; i++)
5850 {
5851 Resolution res = bms[i].Resolutions[bms[i].Level];
5852 if (bis.ContainsKey(res.PhysicalSizeX))
5853 {
5854 bis[res.PhysicalSizeX].Add(bms[i]);
5855 if (bms[i].StageSizeX < min[res.PhysicalSizeX].X || bms[i].StageSizeY < min[res.PhysicalSizeX].Y)
5856 {
5857 min[res.PhysicalSizeX] = bms[i].Volume.Location;
5858 }
5859 if (bms[i].StageSizeX > max[res.PhysicalSizeX].X || bms[i].StageSizeY > max[res.PhysicalSizeX].Y)
5860 {
5861 max[res.PhysicalSizeX] = bms[i].Volume.Location;
5862 }
5863 }
5864 else
5865 {
5866 bis.Add(res.PhysicalSizeX, new List<BioImage>());
5867 min.Add(res.PhysicalSizeX, new Point3D(double.MaxValue, double.MaxValue, double.MaxValue));
5868 max.Add(res.PhysicalSizeX, new Point3D(double.MinValue, double.MinValue, double.MinValue));
5869 if (bms[i].StageSizeX < min[res.PhysicalSizeX].X || bms[i].StageSizeY < min[res.PhysicalSizeX].Y)
5870 {
5871 min[res.PhysicalSizeX] = bms[i].Volume.Location;
5872 }
5873 if (bms[i].StageSizeX > max[res.PhysicalSizeX].X || bms[i].StageSizeY > max[res.PhysicalSizeX].Y)
5874 {
5875 max[res.PhysicalSizeX] = bms[i].Volume.Location;
5876 }
5877 bis[res.PhysicalSizeX].Add(bms[i]);
5878 }
5879 }
5880 int s = 0;
5881 //We determine the sizes of each resolution.
5882 Dictionary<double, AForge.Size> ss = new Dictionary<double, AForge.Size>();
5883 int minx = int.MaxValue;
5884 int miny = int.MaxValue;
5885 double last = 0;
5886 foreach (double px in bis.Keys)
5887 {
5888 int xs = (1 + (int)Math.Ceiling((max[px].X - min[px].X) / bis[px][0].Resolutions[0].VolumeWidth)) * bis[px][0].SizeX;
5889 int ys = (1 + (int)Math.Ceiling((max[px].Y - min[px].Y) / bis[px][0].Resolutions[0].VolumeHeight)) * bis[px][0].SizeY;
5890 if (minx > xs)
5891 minx = xs;
5892 if (miny > ys)
5893 miny = ys;
5894 ss.Add(px, new AForge.Size(xs, ys));
5895 last = px;
5896 }
5897 s = 0;
5898 string met = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
5899 "<OME xmlns=\"http://www.openmicroscopy.org/Schemas/OME/2016-06\" " +
5900 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
5901 "xsi:schemaLocation=\"http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd\">";
5902 NetVips.Image img = null;
5903 int ib = 0;
5904
5905 foreach (double px in bis.Keys)
5906 {
5907 int c = bis[px][s].SizeC;
5908 if (bis[px][s].Buffers[0].isRGB)
5909 c = 3;
5910 string endian = (bis[px][s].Buffers[0].LittleEndian).ToString().ToLower();
5911 met +=
5912 "<Image ID=\"Image:" + ib + "\">" +
5913 "<Pixels BigEndian=\"" + endian + "\" DimensionOrder= \"XYCZT\" ID= \"Pixels:0\" Interleaved=\"true\" " +
5914 "PhysicalSizeX=\"" + bis[px][s].PhysicalSizeX + "\" PhysicalSizeXUnit=\"µm\" PhysicalSizeY=\"" + bis[px][s].PhysicalSizeY + "\" PhysicalSizeYUnit=\"µm\" SignificantBits=\"" + bis[px][s].bitsPerPixel + "\" " +
5915 "SizeC = \"" + c + "\" SizeT = \"" + bis[px][s].SizeT + "\" SizeX =\"" + ss[px].Width +
5916 "\" SizeY= \"" + ss[px].Height + "\" SizeZ=\"" + bis[px][s].SizeZ;
5917 if (bis[px][s].bitsPerPixel > 8) met += "\" Type= \"uint16\">";
5918 else met += "\" Type= \"uint8\">";
5919 int i = 0;
5920 foreach (Channel ch in bis[px][s].Channels)
5921 {
5922 met += "<Channel ID=\"Channel:" + ib + ":" + i + "\" SamplesPerPixel=\"1\"></Channel>";
5923 i++;
5924 }
5925 met += "</Pixels></Image>";
5926 ib++;
5927 }
5928 met += "</OME>";
5929 foreach (double px in bis.Keys)
5930 {
5931 PixelFormat pf = bis[px][0].Buffers[0].PixelFormat;
5932 Bitmap level = new Bitmap(ss[px].Width, ss[px].Height, pf);
5933 int bands = GetBands(pf);
5934 if (bis[px][0].bitsPerPixel > 8)
5935 img = NetVips.Image.NewFromMemory(level.Data, (ulong)level.Length, level.Width, level.Height, bands, Enums.BandFormat.Ushort);
5936 else
5937 img = NetVips.Image.NewFromMemory(level.Data, (ulong)level.Length, level.Width, level.Height, bands, Enums.BandFormat.Uchar);
5938 int i = 0;
5939 foreach (BioImage b in bis[px])
5940 {
5941 AForge.Size si = ss[px];
5942 double xs = (-(min[px].X - bis[px][i].Volume.Location.X) / bis[px][i].Resolutions[0].VolumeWidth) * bis[px][i].SizeX;
5943 double ys = (-(min[px].Y - bis[px][i].Volume.Location.Y) / bis[px][i].Resolutions[0].VolumeHeight) * bis[px][i].SizeY;
5944 NetVips.Image tile;
5945 if (b.bitsPerPixel > 8)
5946 tile = NetVips.Image.NewFromMemory(bis[px][i].Buffers[0].Data, (ulong)bis[px][i].Buffers[0].Length, bis[px][i].Buffers[0].Width, bis[px][i].Buffers[0].Height, bands, Enums.BandFormat.Ushort);
5947 else
5948 tile = NetVips.Image.NewFromMemory(bis[px][i].Buffers[0].Data, (ulong)bis[px][i].Buffers[0].Length, bis[px][i].Buffers[0].Width, bis[px][i].Buffers[0].Height, bands, Enums.BandFormat.Uchar);
5949 img = img.Insert(tile, (int)xs, (int)ys);
5950 i++;
5951 };
5952 using var mutated = img.Mutate(mutable =>
5953 {
5954 // Set the ImageDescription tag
5955 mutable.Set(GValue.GStrType, "image-description", met);
5956 mutable.Set(GValue.GIntType, "page-height", ss[last].Height);
5957 });
5958 if (bis[px][0].bitsPerPixel > 8)
5959 mutated.Tiffsave(file, compression, 1, Enums.ForeignTiffPredictor.None, true, ss[px].Width, ss[px].Height, true, false, 16,
5960 Enums.ForeignTiffResunit.Cm, 1000 * bis[px][0].PhysicalSizeX, 1000 * bis[px][0].PhysicalSizeY, true, null, Enums.RegionShrink.Nearest,
5961 compressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, ss[px].Height);
5962 else
5963 mutated.Tiffsave(file, compression, 1, Enums.ForeignTiffPredictor.None, true, ss[px].Width, ss[px].Height, true, false, 8,
5964 Enums.ForeignTiffResunit.Cm, 1000 * bis[px][0].PhysicalSizeX, 1000 * bis[px][0].PhysicalSizeY, true, null, Enums.RegionShrink.Nearest,
5965 compressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, ss[px].Height);
5966 s++;
5967 }
5968
5969 }
override string ToString()
Definition Bio.cs:8448
int Level
Definition Bio.cs:2106

◆ SaveOMESeries()

static void BioGTK.BioImage.SaveOMESeries ( BioImage[]  files,
string  f,
bool  planes 
)
inlinestatic

This function takes a list of image files and saves them as a single OME-TIFF file

Parameters
filesan array of file paths to the images to be saved
fthe file name to save to
planesif true, the planes will be saved as well.
5431 {
5432 if (File.Exists(f))
5433 File.Delete(f);
5434 loci.formats.meta.IMetadata omexml = service.createOMEXMLMetadata();
5435 progressValue = 0;
5436 status = "Saving OME Image Metadata.";
5437 for (int fi = 0; fi < files.Length; fi++)
5438 {
5439 int serie = fi;
5440 BioImage b = files[fi];
5441 if (b.isPyramidal)
5442 {
5443 b = OpenOME(b.file, b.Level, false, false, true, (int)App.viewer.PyramidalOrigin.X, (int)App.viewer.PyramidalOrigin.Y, App.viewer.AllocatedWidth, App.viewer.AllocatedHeight);
5444 }
5445 // create OME-XML metadata store
5446
5447 omexml.setImageID("Image:" + serie, serie);
5448 omexml.setPixelsID("Pixels:" + serie, serie);
5449 omexml.setPixelsInterleaved(java.lang.Boolean.TRUE, serie);
5450 omexml.setPixelsDimensionOrder(ome.xml.model.enums.DimensionOrder.XYCZT, serie);
5451 if (b.bitsPerPixel > 8)
5452 omexml.setPixelsType(ome.xml.model.enums.PixelType.UINT16, serie);
5453 else
5454 omexml.setPixelsType(ome.xml.model.enums.PixelType.UINT8, serie);
5455 omexml.setPixelsSizeX(new PositiveInteger(java.lang.Integer.valueOf(b.SizeX)), serie);
5456 omexml.setPixelsSizeY(new PositiveInteger(java.lang.Integer.valueOf(b.SizeY)), serie);
5457 omexml.setPixelsSizeZ(new PositiveInteger(java.lang.Integer.valueOf(b.SizeZ)), serie);
5458 omexml.setPixelsSizeC(new PositiveInteger(java.lang.Integer.valueOf(b.SizeC)), serie);
5459 omexml.setPixelsSizeT(new PositiveInteger(java.lang.Integer.valueOf(b.SizeT)), serie);
5460 if (BitConverter.IsLittleEndian)
5461 omexml.setPixelsBigEndian(java.lang.Boolean.FALSE, serie);
5462 else
5463 omexml.setPixelsBigEndian(java.lang.Boolean.TRUE, serie);
5464 ome.units.quantity.Length p1 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeX), ome.units.UNITS.MICROMETER);
5465 omexml.setPixelsPhysicalSizeX(p1, serie);
5466 ome.units.quantity.Length p2 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeY), ome.units.UNITS.MICROMETER);
5467 omexml.setPixelsPhysicalSizeY(p2, serie);
5468 ome.units.quantity.Length p3 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeZ), ome.units.UNITS.MICROMETER);
5469 omexml.setPixelsPhysicalSizeZ(p3, serie);
5470 ome.units.quantity.Length s1 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.X), ome.units.UNITS.MICROMETER);
5471 omexml.setStageLabelX(s1, serie);
5472 ome.units.quantity.Length s2 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.Y), ome.units.UNITS.MICROMETER);
5473 omexml.setStageLabelY(s2, serie);
5474 ome.units.quantity.Length s3 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.Z), ome.units.UNITS.MICROMETER);
5475 omexml.setStageLabelZ(s3, serie);
5476 omexml.setStageLabelName("StageLabel:" + serie, serie);
5477
5478 for (int channel = 0; channel < b.Channels.Count; channel++)
5479 {
5480 Channel c = b.Channels[channel];
5481 for (int r = 0; r < c.range.Length; r++)
5482 {
5483 omexml.setChannelID("Channel:" + channel + ":" + serie, serie, channel + r);
5484 omexml.setChannelSamplesPerPixel(new PositiveInteger(java.lang.Integer.valueOf(1)), serie, channel + r);
5485 if (c.LightSourceWavelength != 0)
5486 {
5487 omexml.setChannelLightSourceSettingsID("LightSourceSettings:" + channel, serie, channel + r);
5488 ome.units.quantity.Length lw = new ome.units.quantity.Length(java.lang.Double.valueOf(c.LightSourceWavelength), ome.units.UNITS.NANOMETER);
5489 omexml.setChannelLightSourceSettingsWavelength(lw, serie, channel + r);
5490 omexml.setChannelLightSourceSettingsAttenuation(PercentFraction.valueOf(c.LightSourceAttenuation), serie, channel + r);
5491 }
5492 omexml.setChannelName(c.Name, serie, channel + r);
5493 if (c.Color != null)
5494 {
5495 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(c.Color.Value.R, c.Color.Value.G, c.Color.Value.B, c.Color.Value.A);
5496 omexml.setChannelColor(col, serie, channel + r);
5497 }
5498 if (c.Emission != 0)
5499 {
5500 ome.units.quantity.Length em = new ome.units.quantity.Length(java.lang.Double.valueOf(c.Emission), ome.units.UNITS.NANOMETER);
5501 omexml.setChannelEmissionWavelength(em, serie, channel + r);
5502 ome.units.quantity.Length ex = new ome.units.quantity.Length(java.lang.Double.valueOf(c.Excitation), ome.units.UNITS.NANOMETER);
5503 omexml.setChannelExcitationWavelength(ex, serie, channel + r);
5504 }
5505 /*
5506 if (c.ContrastMethod != null)
5507 {
5508 ome.xml.model.enums.ContrastMethod cm = (ome.xml.model.enums.ContrastMethod)Enum.Parse(typeof(ome.xml.model.enums.ContrastMethod), c.ContrastMethod);
5509 omexml.setChannelContrastMethod(cm, serie, channel + r);
5510 }
5511 if (c.IlluminationType != null)
5512 {
5513 ome.xml.model.enums.IlluminationType il = (ome.xml.model.enums.IlluminationType)Enum.Parse(typeof(ome.xml.model.enums.IlluminationType), c.IlluminationType.ToUpper());
5514 omexml.setChannelIlluminationType(il, serie, channel + r);
5515 }
5516 if (c.AcquisitionMode != null)
5517 {
5518 ome.xml.model.enums.AcquisitionMode am = (ome.xml.model.enums.AcquisitionMode)Enum.Parse(typeof(ome.xml.model.enums.AcquisitionMode), c.AcquisitionMode.ToUpper());
5519 omexml.setChannelAcquisitionMode(am, serie, channel + r);
5520 }
5521 */
5522 omexml.setChannelFluor(c.Fluor, serie, channel + r);
5523 if (c.LightSourceIntensity != 0)
5524 {
5525 ome.units.quantity.Power pw = new ome.units.quantity.Power(java.lang.Double.valueOf(c.LightSourceIntensity), ome.units.UNITS.VOLT);
5526 omexml.setLightEmittingDiodePower(pw, serie, channel + r);
5527 omexml.setLightEmittingDiodeID(c.DiodeName, serie, channel + r);
5528 }
5529 }
5530 }
5531
5532 int i = 0;
5533 foreach (ROI an in b.Annotations)
5534 {
5535 if (an.roiID == "")
5536 omexml.setROIID("ROI:" + i.ToString() + ":" + serie, i);
5537 else
5538 omexml.setROIID(an.roiID, i);
5539 omexml.setROIName(an.roiName, i);
5540 if (an.type == ROI.Type.Point)
5541 {
5542 if (an.id != "")
5543 omexml.setPointID(an.id, i, serie);
5544 else
5545 omexml.setPointID("Shape:" + i + ":" + serie, i, serie);
5546 omexml.setPointX(java.lang.Double.valueOf(b.ToImageSpaceX(an.X)), i, serie);
5547 omexml.setPointY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Y)), i, serie);
5548 omexml.setPointTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5549 omexml.setPointTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5550 omexml.setPointTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5551 if (an.Text != "")
5552 omexml.setPointText(an.Text, i, serie);
5553 else
5554 omexml.setPointText(i.ToString(), i, serie);
5555 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5556 omexml.setPointFontSize(fl, i, serie);
5557 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5558 omexml.setPointStrokeColor(col, i, serie);
5559 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5560 omexml.setPointStrokeWidth(sw, i, serie);
5561 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5562 omexml.setPointFillColor(colf, i, serie);
5563 }
5564 else
5565 if (an.type == ROI.Type.Polygon || an.type == ROI.Type.Freeform)
5566 {
5567 if (an.id != "")
5568 omexml.setPolygonID(an.id, i, serie);
5569 else
5570 omexml.setPolygonID("Shape:" + i + ":" + serie, i, serie);
5571 omexml.setPolygonPoints(an.PointsToString(b), i, serie);
5572 omexml.setPolygonTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5573 omexml.setPolygonTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5574 omexml.setPolygonTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5575 if (an.Text != "")
5576 omexml.setPolygonText(an.Text, i, serie);
5577 else
5578 omexml.setPolygonText(i.ToString(), i, serie);
5579 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5580 omexml.setPolygonFontSize(fl, i, serie);
5581 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5582 omexml.setPolygonStrokeColor(col, i, serie);
5583 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5584 omexml.setPolygonStrokeWidth(sw, i, serie);
5585 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5586 omexml.setPolygonFillColor(colf, i, serie);
5587 }
5588 else
5589 if (an.type == ROI.Type.Rectangle)
5590 {
5591 if (an.id != "")
5592 omexml.setRectangleID(an.id, i, serie);
5593 else
5594 omexml.setRectangleID("Shape:" + i + ":" + serie, i, serie);
5595 omexml.setRectangleWidth(java.lang.Double.valueOf(b.ToImageSizeX(an.W)), i, serie);
5596 omexml.setRectangleHeight(java.lang.Double.valueOf(b.ToImageSizeY(an.H)), i, serie);
5597 omexml.setRectangleX(java.lang.Double.valueOf(b.ToImageSpaceX(an.Rect.X)), i, serie);
5598 omexml.setRectangleY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Rect.Y)), i, serie);
5599 omexml.setRectangleTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5600 omexml.setRectangleTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5601 omexml.setRectangleTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5602 omexml.setRectangleText(i.ToString(), i, serie);
5603 if (an.Text != "")
5604 omexml.setRectangleText(an.Text, i, serie);
5605 else
5606 omexml.setRectangleText(i.ToString(), i, serie);
5607 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5608 omexml.setRectangleFontSize(fl, i, serie);
5609 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5610 omexml.setRectangleStrokeColor(col, i, serie);
5611 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5612 omexml.setRectangleStrokeWidth(sw, i, serie);
5613 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5614 omexml.setRectangleFillColor(colf, i, serie);
5615 }
5616 else
5617 if (an.type == ROI.Type.Line)
5618 {
5619 if (an.id != "")
5620 omexml.setLineID(an.id, i, serie);
5621 else
5622 omexml.setLineID("Shape:" + i + ":" + serie, i, serie);
5623 omexml.setLineX1(java.lang.Double.valueOf(b.ToImageSpaceX(an.GetPoint(0).X)), i, serie);
5624 omexml.setLineY1(java.lang.Double.valueOf(b.ToImageSpaceY(an.GetPoint(0).Y)), i, serie);
5625 omexml.setLineX2(java.lang.Double.valueOf(b.ToImageSpaceX(an.GetPoint(1).X)), i, serie);
5626 omexml.setLineY2(java.lang.Double.valueOf(b.ToImageSpaceY(an.GetPoint(1).Y)), i, serie);
5627 omexml.setLineTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5628 omexml.setLineTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5629 omexml.setLineTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5630 if (an.Text != "")
5631 omexml.setLineText(an.Text, i, serie);
5632 else
5633 omexml.setLineText(i.ToString(), i, serie);
5634 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5635 omexml.setLineFontSize(fl, i, serie);
5636 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5637 omexml.setLineStrokeColor(col, i, serie);
5638 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5639 omexml.setLineStrokeWidth(sw, i, serie);
5640 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5641 omexml.setLineFillColor(colf, i, serie);
5642 }
5643 else
5644 if (an.type == ROI.Type.Ellipse)
5645 {
5646
5647 if (an.id != "")
5648 omexml.setEllipseID(an.id, i, serie);
5649 else
5650 omexml.setEllipseID("Shape:" + i + ":" + serie, i, serie);
5651 //We need to change System.Drawing.Rectangle to ellipse radius;
5652 double w = (double)an.W / 2;
5653 double h = (double)an.H / 2;
5654 omexml.setEllipseRadiusX(java.lang.Double.valueOf(b.ToImageSizeX(w)), i, serie);
5655 omexml.setEllipseRadiusY(java.lang.Double.valueOf(b.ToImageSizeY(h)), i, serie);
5656
5657 double x = an.Point.X + w;
5658 double y = an.Point.Y + h;
5659 omexml.setEllipseX(java.lang.Double.valueOf(b.ToImageSpaceX(x)), i, serie);
5660 omexml.setEllipseY(java.lang.Double.valueOf(b.ToImageSpaceX(y)), i, serie);
5661 omexml.setEllipseTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5662 omexml.setEllipseTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5663 omexml.setEllipseTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5664 if (an.Text != "")
5665 omexml.setEllipseText(an.Text, i, serie);
5666 else
5667 omexml.setEllipseText(i.ToString(), i, serie);
5668 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5669 omexml.setEllipseFontSize(fl, i, serie);
5670 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5671 omexml.setEllipseStrokeColor(col, i, serie);
5672 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5673 omexml.setEllipseStrokeWidth(sw, i, serie);
5674 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5675 omexml.setEllipseFillColor(colf, i, serie);
5676 }
5677 else
5678 if (an.type == ROI.Type.Label)
5679 {
5680 if (an.id != "")
5681 omexml.setLabelID(an.id, i, serie);
5682 else
5683 omexml.setLabelID("Shape:" + i + ":" + serie, i, serie);
5684 omexml.setLabelX(java.lang.Double.valueOf(b.ToImageSpaceX(an.Rect.X)), i, serie);
5685 omexml.setLabelY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Rect.Y)), i, serie);
5686 omexml.setLabelTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5687 omexml.setLabelTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5688 omexml.setLabelTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5689 omexml.setLabelText(i.ToString(), i, serie);
5690 if (an.Text != "")
5691 omexml.setLabelText(an.Text, i, serie);
5692 else
5693 omexml.setLabelText(i.ToString(), i, serie);
5694 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5695 omexml.setLabelFontSize(fl, i, serie);
5696 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5697 omexml.setLabelStrokeColor(col, i, serie);
5698 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5699 omexml.setLabelStrokeWidth(sw, i, serie);
5700 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5701 omexml.setLabelFillColor(colf, i, serie);
5702 }
5703 else
5704 if (an.type == ROI.Type.Mask || an.roiMask != null)
5705 {
5706 if (an.id != "")
5707 omexml.setMaskID(an.id, i, serie);
5708 else
5709 omexml.setMaskID("Shape:" + i + ":" + serie, i, serie);
5710 omexml.setMaskX(java.lang.Double.valueOf(b.ToImageSpaceX(an.Rect.X)), i, serie);
5711 omexml.setMaskY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Rect.Y)), i, serie);
5712 omexml.setMaskTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5713 omexml.setMaskTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5714 omexml.setMaskTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5715 omexml.setMaskWidth(new java.lang.Double(an.W), i, serie);
5716 omexml.setMaskHeight(new java.lang.Double(an.H), i, serie);
5717 if (an.Text != "")
5718 omexml.setMaskText(an.Text, i, serie);
5719 else
5720 omexml.setMaskText(i.ToString(), i, serie);
5721 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5722 omexml.setMaskFontSize(fl, i, serie);
5723 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5724 omexml.setMaskStrokeColor(col, i, serie);
5725 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5726 omexml.setMaskStrokeWidth(sw, i, serie);
5727 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5728 omexml.setMaskFillColor(colf, i, serie);
5729 byte[] bts = an.roiMask.GetBytes();
5730 omexml.setMaskBinData(bts, i, serie);
5731 omexml.setMaskBinDataBigEndian(new java.lang.Boolean(!BitConverter.IsLittleEndian), i, serie);
5732 omexml.setMaskBinDataLength(new NonNegativeLong(new java.lang.Long(bts.Length)), i, serie);
5733 omexml.setMaskBinDataCompression(ome.xml.model.enums.Compression.ZLIB, i, serie);
5734 }
5735
5736 i++;
5737 }
5738
5739 if (b.Buffers[0].Plane != null && planes)
5740 for (int bu = 0; bu < b.Buffers.Count; bu++)
5741 {
5742 //Correct order of parameters.
5743 if (b.Buffers[bu].Plane.Delta != 0)
5744 {
5745 ome.units.quantity.Time t = new ome.units.quantity.Time(java.lang.Double.valueOf(b.Buffers[bu].Plane.Delta), ome.units.UNITS.MILLISECOND);
5746 omexml.setPlaneDeltaT(t, serie, bu);
5747 }
5748 if (b.Buffers[bu].Plane.Exposure != 0)
5749 {
5750 ome.units.quantity.Time et = new ome.units.quantity.Time(java.lang.Double.valueOf(b.Buffers[bu].Plane.Exposure), ome.units.UNITS.MILLISECOND);
5751 omexml.setPlaneExposureTime(et, serie, bu);
5752 }
5753 ome.units.quantity.Length lx = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.X), ome.units.UNITS.MICROMETER);
5754 ome.units.quantity.Length ly = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.Y), ome.units.UNITS.MICROMETER);
5755 ome.units.quantity.Length lz = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.Z), ome.units.UNITS.MICROMETER);
5756 omexml.setPlanePositionX(lx, serie, bu);
5757 omexml.setPlanePositionY(ly, serie, bu);
5758 omexml.setPlanePositionZ(lz, serie, bu);
5759 omexml.setPlaneTheC(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.C)), serie, bu);
5760 omexml.setPlaneTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.Z)), serie, bu);
5761 omexml.setPlaneTheT(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.T)), serie, bu);
5762
5763 omexml.setTiffDataPlaneCount(new NonNegativeInteger(java.lang.Integer.valueOf(1)), serie, bu);
5764 omexml.setTiffDataIFD(new NonNegativeInteger(java.lang.Integer.valueOf(bu)), serie, bu);
5765 omexml.setTiffDataFirstC(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.C)), serie, bu);
5766 omexml.setTiffDataFirstZ(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.Z)), serie, bu);
5767 omexml.setTiffDataFirstT(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.T)), serie, bu);
5768
5769 }
5770
5771 }
5772 writer.setMetadataRetrieve(omexml);
5773 f = f.Replace("\\", "/");
5774 writer.setId(f);
5775 status = "Saving OME Image Planes.";
5776 for (int i = 0; i < files.Length; i++)
5777 {
5778 BioImage b = files[i];
5779 writer.setSeries(i);
5780 for (int bu = 0; bu < b.Buffers.Count; bu++)
5781 {
5782 progressValue = (float)bu / (float)b.Buffers.Count;
5783 byte[] bts = b.Buffers[bu].GetSaveBytes(BitConverter.IsLittleEndian);
5784 writer.saveBytes(bu, bts);
5785 }
5786 }
5787 bool stop = false;
5788 do
5789 {
5790 try
5791 {
5792 writer.close();
5793 stop = true;
5794 }
5795 catch (Exception e)
5796 {
5797 //Scripting.LogLine(e.Message);
5798 }
5799
5800 } while (!stop);
5801 }

◆ SavePyramidalAsync()

static async Task BioGTK.BioImage.SavePyramidalAsync ( BioImage[]  imgs,
string  file,
Enums::ForeignTiffCompression  com,
int  compLevel 
)
inlinestatic

The function SavePyramidalAsync saves an array of BioImage objects as a pyramidal TIFF file asynchronously.

Parameters
imgsimgs is an array of BioImage objects.
fileThe "file" parameter is a string that represents the file path where the pyramidal image will be saved.
comThe parameter "com" is of type Enums.ForeignTiffCompression, which is an enumeration representing different compression options for the TIFF file.
compLevelThe compLevel parameter is an integer that represents the compression level for the TIFF file. It is used to specify the level of compression to be applied to the image data when saving the pyramidal image. The higher the compression level, the smaller the file size but potentially lower image quality.
7542 {
7543 bms = imgs;
7544 savefile = file;
7545 comp = com;
7546 compLev = compLevel;
7547 await Task.Run(SavePyramidalThread);
7548 }

◆ SaveSeries()

static void BioGTK.BioImage.SaveSeries ( string[]  IDs,
string  file 
)
inlinestatic

It takes a list of image IDs, and saves them as a single multi-page TIFF file.

Parameters
Anarray of IDs of the images to save
Thepath to the file to save to.
4736 {
4737 string desc = "";
4738 int stride = 0;
4739 ImageJDesc j = new ImageJDesc();
4740 BioImage bi = Images.GetImage(IDs[0]);
4741 j.FromImage(bi);
4742 desc = j.GetString();
4743 for (int fi = 0; fi < IDs.Length; fi++)
4744 {
4745 string id = IDs[fi];
4746 BioImage b = Images.GetImage(id);
4747 string fn = Path.GetFileNameWithoutExtension(id);
4748 string dir = Path.GetDirectoryName(file);
4749 stride = b.Buffers[0].Stride;
4750
4751 //Save ROIs to CSV file.
4752 if (b.Annotations.Count > 0)
4753 {
4754 string f = dir + "//" + fn + ".csv";
4755 ExportROIsCSV(f, b.Annotations);
4756 }
4757
4758 //Embed ROI's to image description.
4759 for (int i = 0; i < b.Annotations.Count; i++)
4760 {
4761 desc += "-ROI:" + b.series + ":" + ROIToString(b.Annotations[i]) + NewLine;
4762 }
4763 foreach (Channel c in b.Channels)
4764 {
4765 string cj = JsonConvert.SerializeObject(c.info, Formatting.None);
4766 desc += "-Channel:" + fi + ":" + cj + NewLine;
4767 }
4768 string json = JsonConvert.SerializeObject(b.imageInfo, Formatting.None);
4769 desc += "-ImageInfo:" + fi + ":" + json + NewLine;
4770 }
4771
4772 Tiff image = Tiff.Open(file, "w");
4773 for (int fi = 0; fi < IDs.Length; fi++)
4774 {
4775 int im = 0;
4776 string id = IDs[fi];
4777 Progress pr = Progress.Create(file, "Saving TIFF", "Writing");
4778 pr.Show();
4779 BioImage b = Images.GetImage(id);
4780 int sizec = 1;
4781 if (!b.isRGB)
4782 {
4783 sizec = b.SizeC;
4784 }
4785 byte[] buffer;
4786 for (int c = 0; c < sizec; c++)
4787 {
4788 for (int z = 0; z < b.SizeZ; z++)
4789 {
4790 for (int t = 0; t < b.SizeT; t++)
4791 {
4792 image.SetDirectory((short)(im + (b.Buffers.Count * fi)));
4793 image.SetField(TiffTag.IMAGEWIDTH, b.SizeX);
4794 image.SetField(TiffTag.IMAGEDESCRIPTION, desc);
4795 image.SetField(TiffTag.IMAGELENGTH, b.SizeY);
4796 image.SetField(TiffTag.BITSPERSAMPLE, b.bitsPerPixel);
4797 image.SetField(TiffTag.SAMPLESPERPIXEL, b.RGBChannelCount);
4798 image.SetField(TiffTag.ROWSPERSTRIP, b.SizeY);
4799 image.SetField(TiffTag.ORIENTATION, BitMiracle.LibTiff.Classic.Orientation.TOPLEFT);
4800 image.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
4801 image.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
4802 image.SetField(TiffTag.ROWSPERSTRIP, image.DefaultStripSize(0));
4803 if (b.PhysicalSizeX != -1 && b.PhysicalSizeY != -1)
4804 {
4805 image.SetField(TiffTag.XRESOLUTION, (b.PhysicalSizeX * b.SizeX) / ((b.PhysicalSizeX * b.SizeX) * b.PhysicalSizeX));
4806 image.SetField(TiffTag.YRESOLUTION, (b.PhysicalSizeY * b.SizeY) / ((b.PhysicalSizeY * b.SizeY) * b.PhysicalSizeY));
4807 image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.NONE);
4808 }
4809 else
4810 {
4811 image.SetField(TiffTag.XRESOLUTION, 100.0);
4812 image.SetField(TiffTag.YRESOLUTION, 100.0);
4813 image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
4814 }
4815 // specify that it's a page within the multipage file
4816 image.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
4817 // specify the page number
4818 buffer = b.Buffers[im].GetSaveBytes(true);
4819 image.SetField(TiffTag.PAGENUMBER, im + (b.Buffers.Count * fi), b.Buffers.Count * IDs.Length);
4820 for (int i = 0, offset = 0; i < b.SizeY; i++)
4821 {
4822 image.WriteScanline(buffer, offset, i, 0);
4823 offset += stride;
4824 }
4825 image.WriteDirectory();
4826 pr.ProgressValue = (float)im / (float)b.ImageCount;
4827 im++;
4828 }
4829 }
4830 }
4831 pr.Hide();
4832 }
4833 image.Dispose();
4834
4835 }

◆ SaveSeriesAsync()

static async Task BioGTK.BioImage.SaveSeriesAsync ( BioImage[]  imgs,
string  file,
bool  ome 
)
inlinestatic

The function SaveSeriesAsync saves a series of BioImage objects to a file asynchronously.

Parameters
imgsimgs is an array of BioImage objects.
fileThe "file" parameter is a string that represents the file path where the series of BioImages will be saved.
omeThe "ome" parameter is a boolean flag that indicates whether the images should be saved in OME-TIFF format or not. If "ome" is set to true, the images will be saved in OME-TIFF format. If "ome" is set to false, the images will be
7511 {
7512 sts.Clear();
7513 foreach (BioImage item in imgs)
7514 {
7515 sts.Add(item.ID);
7516 }
7517 savefile = file;
7518 some = ome;
7519 await Task.Run(SaveSeriesThread);
7520 }

◆ SetValue() [1/3]

void BioGTK.BioImage.SetValue ( int  x,
int  y,
int  ind,
ushort  value 
)
inline

It sets the value of a pixel in a buffer

Parameters
xThe x coordinate of the pixel to set.
yThe y coordinate of the pixel to set.
indThe index of the buffer to set the value in.
valueThe value to set the pixel to.
4217 {
4218 Buffers[ind].SetValue(x, y, value);
4219 }

◆ SetValue() [2/3]

void BioGTK.BioImage.SetValue ( int  x,
int  y,
ZCT  coord,
ushort  value 
)
inline

This function sets the value of a pixel at a given x,y coordinate in a given image plane

Parameters
xx coordinate of the pixel
yThe y coordinate of the pixel to set.
ZCTa struct that contains the Z, C, and T coordinates of the pixel
valuethe value to set
4227 {
4228 SetValue(x, y, Coords[coord.Z, coord.C, coord.T], value);
4229 }
void SetValue(ZCTXY coord, ushort value)
Definition Bio.cs:4205

◆ SetValue() [3/3]

void BioGTK.BioImage.SetValue ( ZCTXY  coord,
ushort  value 
)
inline

It takes a coordinate and a value, and sets the value at that coordinate

Parameters
ZCTXYa struct that contains the Z, C, T, X, and Y coordinates of the pixel
valuethe value to be set
4206 {
4207 int i = Coords[coord.Z, coord.C, coord.T];
4208 Buffers[i].SetValue(coord.X, coord.Y, value);
4209 }

◆ SetValueRGB()

void BioGTK.BioImage.SetValueRGB ( ZCTXY  coord,
int  RGBindex,
ushort  value 
)
inline

It takes a coordinate, an RGB index, and a value, and sets the value of the pixel at that coordinate to the value

Parameters
ZCTXYa struct that contains the Z, C, T, X, and Y coordinates of the pixel
RGBindex0 = Red, 1 = Green, 2 = Blue
valuethe value to be set
4237 {
4238 int ind = Coords[coord.Z, coord.C, coord.T];
4239 Buffers[ind].SetValueRGB(coord.X, coord.Y, RGBindex, value);
4240 }

◆ SplitChannels() [1/3]

BioImage[] BioGTK.BioImage.SplitChannels ( )
inline

It takes a single image and splits it into three images, one for each channel

Returns
A list of BioImages
3897 {
3898 BioImage[] bms;
3899 if (isRGB)
3900 {
3901 bms = new BioImage[3];
3902 BioImage ri = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-1" + Path.GetExtension(ID));
3903 BioImage gi = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-2" + Path.GetExtension(ID));
3904 BioImage bi = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-3" + Path.GetExtension(ID));
3905 ri.sizeC = 1;
3906 gi.sizeC = 1;
3907 bi.sizeC = 1;
3908 ri.sizeZ = SizeZ;
3909 gi.sizeZ = SizeZ;
3910 bi.sizeZ = SizeZ;
3911 ri.sizeT = SizeT;
3912 gi.sizeT = SizeT;
3913 bi.sizeT = SizeT;
3914
3915 ri.Coords = new int[SizeZ, 1, SizeT];
3916 gi.Coords = new int[SizeZ, 1, SizeT];
3917 bi.Coords = new int[SizeZ, 1, SizeT];
3918 int ind = 0;
3919 for (int i = 0; i < ImageCount; i++)
3920 {
3921 if (Buffers[i].PixelFormat == PixelFormat.Format48bppRgb)
3922 {
3923 //For 48bit images we need to use our own function as AForge won't give us a proper image.
3924 Bitmap[] bfs = Bitmap.RGB48To16(ID, SizeX, SizeY, Buffers[i].Stride, Buffers[i].Bytes, Buffers[i].Coordinate, ind, Buffers[i].Plane);
3925 ind += 3;
3926 ri.Buffers.Add(bfs[0]);
3927 gi.Buffers.Add(bfs[1]);
3928 bi.Buffers.Add(bfs[2]);
3929 Statistics.CalcStatistics(bfs[0]);
3930 Statistics.CalcStatistics(bfs[1]);
3931 Statistics.CalcStatistics(bfs[2]);
3932 ri.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3933 gi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3934 bi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3935 }
3936 else
3937 {
3938
3939 Bitmap rImage = extractR.Apply(Buffers[i]);
3940 Bitmap rbf = new Bitmap(ri.ID, rImage, Buffers[i].Coordinate, ind++);
3941 Statistics.CalcStatistics(rbf);
3942 ri.Buffers.Add(rbf);
3943 ri.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3944
3945 Bitmap gImage = extractG.Apply(Buffers[i]);
3946 Bitmap gbf = new Bitmap(gi.ID, gImage, Buffers[i].Coordinate, ind++);
3947 Statistics.CalcStatistics(gbf);
3948 gi.Buffers.Add(gbf);
3949 gi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3950
3951 Bitmap bImage = extractB.Apply(Buffers[i]);
3952 //Clipboard.SetImage(bImage);
3953 Bitmap bbf = new Bitmap(bi.ID, bImage, Buffers[i].Coordinate, ind++);
3954 Statistics.CalcStatistics(bbf);
3955 bi.Buffers.Add(bbf);
3956 bi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3957
3958 }
3959 }
3960 //We wait for threshold image statistics calculation
3961 do
3962 {
3963 Thread.Sleep(100);
3964 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3965 ri.Resolutions.Add(new BioGTK.Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3966 gi.Resolutions.Add(new BioGTK.Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3967 bi.Resolutions.Add(new BioGTK.Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3968 ri.Channels.Add(Channels[0].Copy());
3969 gi.Channels.Add(Channels[0].Copy());
3970 bi.Channels.Add(Channels[0].Copy());
3971 AutoThreshold(ri, false);
3972 AutoThreshold(gi, false);
3973 AutoThreshold(bi, false);
3974 Images.AddImage(ri, true);
3975 Images.AddImage(gi, true);
3976 Images.AddImage(bi, true);
3977 Statistics.ClearCalcBuffer();
3978 bms[0] = ri;
3979 bms[1] = gi;
3980 bms[2] = bi;
3981 }
3982 else
3983 {
3984 bms = new BioImage[SizeC];
3985 for (int c = 0; c < SizeC; c++)
3986 {
3987 BioImage b = BioImage.Substack(this, 0, 0, SizeZ, c, c + 1, 0, SizeT);
3988 bms[c] = b;
3989 }
3990 }
3991
3992 Statistics.ClearCalcBuffer();
3993 Recorder.AddLine("BioGTK.BioImage.SplitChannels(" + '"' + Filename + '"' + ");");
3994 return bms;
3995 }
string Filename
Definition Bio.cs:2144
int SizeT
Definition Bio.cs:2647
int ImageCount
Definition Bio.cs:2355

◆ SplitChannels() [2/3]

static BioImage[] BioGTK.BioImage.SplitChannels ( BioImage  bb)
inlinestatic

‍SplitChannels splits a BioImage into its constituent channels

Parameters
BioImageThe image to split
Returns
An array of BioImages
4002 {
4003 return bb.SplitChannels();
4004 }

◆ SplitChannels() [3/3]

static BioImage[] BioGTK.BioImage.SplitChannels ( string  name)
inlinestatic

This function takes an image and splits it into its individual channels

Parameters
nameThe name of the image to split.
Returns
An array of BioImage objects.
4011 {
4012 return SplitChannels(Images.GetImage(name));
4013 }
BioImage[] SplitChannels()
Definition Bio.cs:3896

◆ StackThreshold()

void BioGTK.BioImage.StackThreshold ( bool  bit16)
inline

This function sets the minimum and maximum values of the image to the minimum and maximum values of the stack

Parameters
bit16true = 16 bit, false = 8 bit
7126 {
7127 if (bit16)
7128 {
7129 for (int ch = 0; ch < Channels.Count; ch++)
7130 {
7131 for (int i = 0; i < Channels[ch].range.Length; i++)
7132 {
7133 Channels[ch].range[i].Min = (int)Channels[ch].stats[i].StackMin;
7134 Channels[ch].range[i].Max = (int)Channels[ch].stats[i].StackMax;
7135 }
7136 Channels[ch].BitsPerPixel = 16;
7137 }
7138 bitsPerPixel = 16;
7139 }
7140 else
7141 {
7142 for (int ch = 0; ch < Channels.Count; ch++)
7143 {
7144 for (int i = 0; i < Channels[ch].range.Length; i++)
7145 {
7146 Channels[ch].range[i].Min = (int)Channels[ch].stats[i].StackMin;
7147 Channels[ch].range[i].Max = (int)Channels[ch].stats[i].StackMax;
7148 }
7149 Channels[ch].BitsPerPixel = 8;
7150 }
7151 bitsPerPixel = 8;
7152 }
7153 }

◆ StringToROI()

static ROI BioGTK.BioImage.StringToROI ( string  sts)
inlinestatic

It takes a string and returns an ROI object

Parameters
ststhe string that contains the ROI data
Returns
A ROI object.
8043 {
8044 //Works with either comma or tab separated values.
8045 if (sts.StartsWith("<?xml") || sts.StartsWith("{"))
8046 return null;
8047 ROI an = new ROI();
8048 string val = "";
8049 bool inSep = false;
8050 int col = 0;
8051 double x = 0;
8052 double y = 0;
8053 double w = 0;
8054 double h = 0;
8055 string line = sts;
8056 bool points = false;
8057 char sep = '"';
8058 for (int i = 0; i < line.Length; i++)
8059 {
8060 char c = line[i];
8061 if (c == sep)
8062 {
8063 if (!inSep)
8064 {
8065 inSep = true;
8066 }
8067 else
8068 inSep = false;
8069 continue;
8070 }
8071
8072 if ((c == ',' || c == '\t') && (!inSep || points))
8073 {
8074 //ROIID,ROINAME,TYPE,ID,SHAPEINDEX,TEXT,C,Z,T,X,Y,W,H,POINTS,STROKECOLOR,STROKECOLORW,FILLCOLOR,FONTSIZE
8075 if (col == 0)
8076 {
8077 //ROIID
8078 an.roiID = val;
8079 }
8080 else
8081 if (col == 1)
8082 {
8083 //ROINAME
8084 an.roiName = val;
8085 }
8086 else
8087 if (col == 2)
8088 {
8089 //TYPE
8090 an.type = (ROI.Type)Enum.Parse(typeof(ROI.Type), val);
8091 if (an.type == ROI.Type.Freeform || an.type == ROI.Type.Polygon)
8092 an.closed = true;
8093 }
8094 else
8095 if (col == 3)
8096 {
8097 //ID
8098 an.id = val;
8099 }
8100 else
8101 if (col == 4)
8102 {
8103 //SHAPEINDEX/
8104 an.shapeIndex = int.Parse(val);
8105 }
8106 else
8107 if (col == 5)
8108 {
8109 //TEXT/
8110 an.Text = val;
8111 }
8112 else
8113 if (col == 6)
8114 {
8115 an.serie = int.Parse(val);
8116 }
8117 else
8118 if (col == 7)
8119 {
8120 an.coord.Z = int.Parse(val);
8121 }
8122 else
8123 if (col == 8)
8124 {
8125 an.coord.C = int.Parse(val);
8126 }
8127 else
8128 if (col == 9)
8129 {
8130 an.coord.T = int.Parse(val);
8131 }
8132 else
8133 if (col == 10)
8134 {
8135 x = double.Parse(val, CultureInfo.InvariantCulture);
8136 }
8137 else
8138 if (col == 11)
8139 {
8140 y = double.Parse(val, CultureInfo.InvariantCulture);
8141 }
8142 else
8143 if (col == 12)
8144 {
8145 w = double.Parse(val, CultureInfo.InvariantCulture);
8146 }
8147 else
8148 if (col == 13)
8149 {
8150 h = double.Parse(val, CultureInfo.InvariantCulture);
8151 }
8152 else
8153 if (col == 14)
8154 {
8155 //POINTS
8156 an.AddPoints(an.stringToPoints(val));
8157 points = false;
8158 an.Rect = new RectangleD(x, y, w, h);
8159 }
8160 else
8161 if (col == 15)
8162 {
8163 //STROKECOLOR
8164 string[] st = val.Split(',');
8165 an.strokeColor = Color.FromArgb(int.Parse(st[0]), int.Parse(st[1]), int.Parse(st[2]), int.Parse(st[3]));
8166 }
8167 else
8168 if (col == 16)
8169 {
8170 //STROKECOLORW
8171 an.strokeWidth = double.Parse(val, CultureInfo.InvariantCulture);
8172 }
8173 else
8174 if (col == 17)
8175 {
8176 //FILLCOLOR
8177 string[] st = val.Split(',');
8178 an.fillColor = Color.FromArgb(int.Parse(st[0]), int.Parse(st[1]), int.Parse(st[2]), int.Parse(st[3]));
8179 }
8180 else
8181 if (col == 18)
8182 {
8183 //FONTSIZE
8184 double s = double.Parse(val, CultureInfo.InvariantCulture);
8185 an.fontSize = (float)s;
8186 an.family = "Times New Roman";
8187 }
8188 col++;
8189 val = "";
8190 }
8191 else
8192 val += c;
8193 }
8194
8195 return an;
8196 }

◆ Substack()

static BioImage BioGTK.BioImage.Substack ( BioImage  orig,
int  ser,
int  zs,
int  ze,
int  cs,
int  ce,
int  ts,
int  te 
)
inlinestatic

It takes a BioImage object, and returns a new BioImage object that is a subset of the original

Parameters
BioImagethe image to be processed
serseries number
zsstarting z-plane
zeend of z-stack
cschannel start
cechannel end
tstime start
tetime end
Returns
A new BioImage object.
3658 {
3659 BioImage b = CopyInfo(orig, false, false);
3660 b.ID = Images.GetImageName(orig.ID);
3661 int i = 0;
3662 b.Coords = new int[ze - zs, ce - cs, te - ts];
3663 b.sizeZ = ze - zs;
3664 b.sizeC = ce - cs;
3665 b.sizeT = te - ts;
3666 for (int ti = 0; ti < b.SizeT; ti++)
3667 {
3668 for (int zi = 0; zi < b.SizeZ; zi++)
3669 {
3670 for (int ci = 0; ci < b.SizeC; ci++)
3671 {
3672 int ind = orig.Coords[zs + zi, cs + ci, ts + ti];
3673 Bitmap bf = new Bitmap(Images.GetImageName(orig.id), orig.SizeX, orig.SizeY, orig.Buffers[0].PixelFormat, orig.Buffers[ind].Bytes, new ZCT(zi, ci, ti), i);
3674 Statistics.CalcStatistics(bf);
3675 b.Buffers.Add(bf);
3676 b.Coords[zi, ci, ti] = i;
3677 i++;
3678 }
3679 }
3680 }
3681 for (int ci = cs; ci < ce; ci++)
3682 {
3683 b.Channels.Add(orig.Channels[ci]);
3684 }
3685 //We wait for threshold image statistics calculation
3686 do
3687 {
3688 Thread.Sleep(100);
3689 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
3690 Statistics.ClearCalcBuffer();
3691 b.Resolutions.Add(new BioGTK.Resolution(b.Buffers[0].SizeX, b.Buffers[0].SizeY, b.Buffers[0].PixelFormat, b.PhysicalSizeX, b.PhysicalSizeY, b.PhysicalSizeZ, b.StageSizeX, b.StageSizeY, b.StageSizeZ));
3692 AutoThreshold(b, false);
3693 if (b.bitsPerPixel > 8)
3694 b.StackThreshold(true);
3695 else
3696 b.StackThreshold(false);
3697 Images.AddImage(b, true);
3698 Recorder.AddLine("BioGTK.BioImage.Substack(" + '"' + orig.Filename + '"' + "," + ser + "," + zs + "," + ze + "," + cs + "," + ce + "," + ts + "," + te + ");");
3699 return b;
3700 }

◆ To16Bit()

void BioGTK.BioImage.To16Bit ( )
inline

Converts the image to 16 bit.

2850 {
2851 if (Buffers[0].RGBChannelsCount == 4)
2852 To24Bit();
2853 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
2854 return;
2855 bitsPerPixel = 16;
2856 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
2857 {
2858 List<Bitmap> bfs = new List<Bitmap>();
2859 int index = 0;
2860 for (int i = 0; i < Buffers.Count; i++)
2861 {
2862 Array.Reverse(Buffers[i].Bytes);
2863 Bitmap[] bs = Bitmap.RGB48To16(ID, SizeX, SizeY, Buffers[i].Stride, Buffers[i].Bytes, Buffers[i].Coordinate, index, Buffers[i].Plane);
2864 bfs.AddRange(bs);
2865 index += 3;
2866 }
2867 Buffers = bfs;
2869 if (Channels[0].SamplesPerPixel == 3)
2870 {
2871 Channel c = Channels[0].Copy();
2872 c.SamplesPerPixel = 1;
2873 c.range = new IntRange[1];
2874 Channels.Clear();
2875 Channels.Add(c);
2876 Channels.Add(c.Copy());
2877 Channels.Add(c.Copy());
2878 Channels[1].Index = 1;
2879 Channels[2].Index = 2;
2880 }
2881 }
2882 else if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
2883 {
2884 for (int i = 0; i < Buffers.Count; i++)
2885 {
2886 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
2887 Statistics.CalcStatistics(Buffers[i]);
2888 }
2889 for (int c = 0; c < Channels.Count; c++)
2890 {
2891 for (int i = 0; i < Channels[c].range.Length; i++)
2892 {
2893 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
2894 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
2895 }
2896 Channels[c].BitsPerPixel = 16;
2897 }
2898 bitsPerPixel = 16;
2899 }
2900 else if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb)
2901 {
2902 List<Bitmap> bfs = new List<Bitmap>();
2903 int index = 0;
2904 for (int i = 0; i < Buffers.Count; i++)
2905 {
2906 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2907 Bitmap br = new Bitmap(ID, bs[2].Image, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2908 Bitmap bg = new Bitmap(ID, bs[1].Image, new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2909 Bitmap bb = new Bitmap(ID, bs[0].Image, new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2910 for (int b = 0; b < 3; b++)
2911 {
2912 bs[b].Dispose();
2913 bs[b] = null;
2914 }
2915 bs = null;
2916 GC.Collect();
2917 br.To16Bit();
2918 bg.To16Bit();
2919 bb.To16Bit();
2920 Statistics.CalcStatistics(br);
2921 Statistics.CalcStatistics(bg);
2922 Statistics.CalcStatistics(bb);
2923 bfs.Add(br);
2924 bfs.Add(bg);
2925 bfs.Add(bb);
2926 index += 3;
2927 }
2928 Buffers = bfs;
2930 for (int c = 0; c < Channels.Count; c++)
2931 {
2932 for (int i = 0; i < Channels[c].range.Length; i++)
2933 {
2934 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
2935 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
2936 }
2937 Channels[c].BitsPerPixel = 16;
2938 }
2939 }
2940 //We wait for threshold image statistics calculation
2941 do
2942 {
2943 Thread.Sleep(100);
2944 } while (Buffers[Buffers.Count - 1].Stats == null);
2945 Statistics.ClearCalcBuffer();
2946 AutoThreshold(this, false);
2947 StackThreshold(true);
2948 App.viewer.UpdateGUI();
2949 App.viewer.UpdateImages();
2950 App.viewer.UpdateView();
2951 Recorder.AddLine("BioGTK.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To16Bit();");
2952 }
void StackThreshold(bool bit16)
Definition Bio.cs:7125
void To24Bit()
Converts the image to 24 bit.
Definition Bio.cs:2954
void UpdateCoords()
It takes a list of images and assigns them to a 3D array of coordinates.
Definition Bio.cs:3271

◆ To24Bit()

void BioGTK.BioImage.To24Bit ( )
inline

Converts the image to 24 bit.

2955 {
2956 if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb)
2957 return;
2958 bitsPerPixel = 8;
2959 if (Buffers[0].PixelFormat == PixelFormat.Format32bppArgb || Buffers[0].PixelFormat == PixelFormat.Format32bppRgb)
2960 {
2961 for (int i = 0; i < Buffers.Count; i++)
2962 {
2963 Buffers[i] = Bitmap.To24Bit(Buffers[i]);
2964 Buffers[i].SwitchRedBlue();
2965 }
2966 if (Channels.Count == 4)
2967 {
2968 Channels.RemoveAt(0);
2969 }
2970 else
2971 {
2972 Channels[0].SamplesPerPixel = 3;
2973 }
2974 }
2975 else
2976 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
2977 {
2978 //We run 8bit so we get 24 bit rgb.
2979 for (int i = 0; i < Buffers.Count; i++)
2980 {
2981 Buffers[i].Image = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2982 Buffers[i].SwitchRedBlue();
2983 }
2984 }
2985 else
2986 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale || Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
2987 {
2988 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
2989 {
2990 for (int i = 0; i < Buffers.Count; i++)
2991 {
2992 Buffers[i].Image = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2993 }
2994 for (int c = 0; c < Channels.Count; c++)
2995 {
2996 for (int i = 0; i < Channels[c].range.Length; i++)
2997 {
2998 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)ushort.MaxValue) * byte.MaxValue);
2999 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)ushort.MaxValue) * byte.MaxValue);
3000 }
3001 Channels[c].BitsPerPixel = 8;
3002 }
3003 }
3004 List<Bitmap> bfs = new List<Bitmap>();
3005 if (Buffers.Count % 3 != 0 && Buffers.Count % 2 != 0)
3006 for (int i = 0; i < Buffers.Count; i++)
3007 {
3008 Bitmap bs = new Bitmap(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane);
3009 Bitmap bbs = Bitmap.RGB8To24(bs);
3010 bs.Dispose();
3011 bs = null;
3012 bfs.Add(bbs);
3013 }
3014 else
3015 for (int i = 0; i < Buffers.Count; i += Channels.Count)
3016 {
3017 Bitmap[] bs = new Bitmap[3];
3018 bs[2] = new Bitmap(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane);
3019 bs[1] = new Bitmap(ID, SizeX, SizeY, Buffers[i + 1].PixelFormat, Buffers[i + 1].Bytes, new ZCT(Buffers[i + 1].Coordinate.Z, 0, Buffers[i + 1].Coordinate.T), i + 1, Buffers[i + 1].Plane);
3020 if (Channels.Count > 2)
3021 bs[0] = new Bitmap(ID, SizeX, SizeY, Buffers[i + 2].PixelFormat, Buffers[i + 2].Bytes, new ZCT(Buffers[i + 2].Coordinate.Z, 0, Buffers[i + 2].Coordinate.T), i + 2, Buffers[i + 2].Plane);
3022 Bitmap bbs = Bitmap.RGB8To24(bs);
3023 for (int b = 0; b < 3; b++)
3024 {
3025 if (bs[b] != null)
3026 bs[b].Dispose();
3027 bs[b] = null;
3028 }
3029 bfs.Add(bbs);
3030 }
3031 Buffers = bfs;
3033 }
3034 Recorder.AddLine("BioGTK.Images.GetImage(" + '"' + ID + '"' + ")" + ".To24Bit();");
3035 AutoThreshold(this, true);
3036 StackThreshold(false);
3037 App.viewer.UpdateGUI();
3038 App.viewer.UpdateImages();
3039 App.viewer.UpdateView();
3040 }

◆ To32Bit()

void BioGTK.BioImage.To32Bit ( )
inline

Converts the image to 32 bit.

3043 {
3044 if (Buffers[0].PixelFormat == PixelFormat.Format32bppArgb)
3045 return;
3046 if (Buffers[0].PixelFormat != PixelFormat.Format24bppRgb)
3047 {
3048 To24Bit();
3049 }
3050 for (int i = 0; i < Buffers.Count; i++)
3051 {
3052 UnmanagedImage b = Bitmap.To32Bit(Buffers[i]);
3053 Buffers[i].Image = b;
3054 }
3055 AutoThreshold(this, true);
3056 App.viewer.UpdateGUI();
3057 App.viewer.UpdateImages();
3058 App.viewer.UpdateView();
3059 Recorder.AddLine("BioGTK.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To32Bit();");
3060 }

◆ To48Bit()

void BioGTK.BioImage.To48Bit ( )
inline

It converts a 16 bit image to a 48 bit image

Returns
A list of Bitmaps.
3065 {
3066 if (Buffers[0].RGBChannelsCount == 4)
3067 To24Bit();
3068 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
3069 return;
3070 if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed || Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
3071 {
3072 if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
3073 {
3074 for (int i = 0; i < Buffers.Count; i++)
3075 {
3076 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
3077 }
3078 }
3079 List<Bitmap> bfs = new List<Bitmap>();
3080 if (Buffers.Count % 3 != 0 && Buffers.Count % 2 != 0)
3081 for (int i = 0; i < Buffers.Count; i++)
3082 {
3083 Bitmap bs = new Bitmap(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane);
3084 Bitmap bbs = Bitmap.RGB16To48(bs);
3085 Statistics.CalcStatistics(bbs);
3086 bs.Dispose();
3087 bs = null;
3088 bfs.Add(bbs);
3089 }
3090 else
3091 for (int i = 0; i < Buffers.Count; i += Channels.Count)
3092 {
3093 Bitmap[] bs = new Bitmap[3];
3094 bs[0] = new Bitmap(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane);
3095 bs[1] = new Bitmap(ID, SizeX, SizeY, Buffers[i + 1].PixelFormat, Buffers[i + 1].Bytes, new ZCT(Buffers[i + 1].Coordinate.Z, 0, Buffers[i + 1].Coordinate.T), i + 1, Buffers[i + 1].Plane);
3096 if (Channels.Count > 2)
3097 bs[2] = new Bitmap(ID, SizeX, SizeY, Buffers[i+2].PixelFormat, Buffers[i+2].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i+2].Coordinate.T), i+2, Buffers[i].Plane);
3098 Bitmap bbs = Bitmap.RGB16To48(bs);
3099 for (int b = 0; b < 3; b++)
3100 {
3101 if (bs[b] != null)
3102 bs[b].Dispose();
3103 bs[b] = null;
3104 }
3105 Statistics.CalcStatistics(bbs);
3106 bfs.Add(bbs);
3107 }
3108 GC.Collect();
3109 Buffers = bfs;
3111 Channel c = Channels[0].Copy();
3112 c.SamplesPerPixel = 3;
3113 rgbChannels[0] = 0;
3114 rgbChannels[1] = 0;
3115 rgbChannels[2] = 0;
3116 Channels.Clear();
3117 Channels.Add(c);
3118 }
3119 else
3120 if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb || Buffers[0].PixelFormat == PixelFormat.Format32bppArgb)
3121 {
3122 for (int i = 0; i < Buffers.Count; i++)
3123 {
3124 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
3125 Buffers[i].SwitchRedBlue();
3126 Statistics.CalcStatistics(Buffers[i]);
3127 }
3128 for (int c = 0; c < Channels.Count; c++)
3129 {
3130 for (int i = 0; i < Channels[c].range.Length; i++)
3131 {
3132 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
3133 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
3134 }
3135 Channels[c].BitsPerPixel = 16;
3136 }
3137 }
3138 else
3139 {
3140 int index = 0;
3141 List<Bitmap> buffers = new List<Bitmap>();
3142 for (int i = 0; i < Buffers.Count; i += 3)
3143 {
3144 Bitmap[] bf = new Bitmap[3];
3145 bf[0] = Buffers[i];
3146 bf[1] = Buffers[i + 1];
3147 bf[2] = Buffers[i + 2];
3148 Bitmap inf = Bitmap.RGB16To48(bf);
3149 buffers.Add(inf);
3150 Statistics.CalcStatistics(inf);
3151 for (int b = 0; b < 3; b++)
3152 {
3153 bf[b].Dispose();
3154 }
3155 index++;
3156 }
3157 Buffers = buffers;
3159 }
3160 //We wait for threshold image statistics calculation
3161 do
3162 {
3163 Thread.Sleep(50);
3164 } while (Buffers[Buffers.Count - 1].Stats == null);
3165 Statistics.ClearCalcBuffer();
3166 bitsPerPixel = 16;
3167 AutoThreshold(this, false);
3168 StackThreshold(true);
3169 App.viewer.UpdateGUI();
3170 App.viewer.UpdateImages();
3171 App.viewer.UpdateView();
3172 Recorder.AddLine("BioGTK.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To48Bit();");
3173 }

◆ To8Bit()

void BioGTK.BioImage.To8Bit ( )
inline

Converts a 16-bit image to an 8-bit image.

2754 {
2755 if (Buffers[0].RGBChannelsCount == 4)
2756 To24Bit();
2757 PixelFormat px = Buffers[0].PixelFormat;
2758 if (px == PixelFormat.Format8bppIndexed)
2759 return;
2760 if (px == PixelFormat.Format48bppRgb)
2761 {
2762 To24Bit();
2763 List<AForge.Bitmap> bfs = new List<AForge.Bitmap>();
2764 int index = 0;
2765 for (int i = 0; i < Buffers.Count; i++)
2766 {
2767 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2768 Bitmap br = new Bitmap(ID, bs[2], new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2769 Bitmap bg = new Bitmap(ID, bs[1], new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2770 Bitmap bb = new Bitmap(ID, bs[0], new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2771 for (int b = 0; b < 3; b++)
2772 {
2773 bs[b].Dispose();
2774 }
2775 bs = null;
2776 GC.Collect();
2777 Statistics.CalcStatistics(br);
2778 Statistics.CalcStatistics(bg);
2779 Statistics.CalcStatistics(bb);
2780 bfs.Add(br);
2781 bfs.Add(bg);
2782 bfs.Add(bb);
2783 index += 3;
2784 }
2785 Buffers = bfs;
2787 }
2788 else if (px == PixelFormat.Format24bppRgb)
2789 {
2790 List<Bitmap> bfs = new List<Bitmap>();
2791 int index = 0;
2792 for (int i = 0; i < Buffers.Count; i++)
2793 {
2794 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2795 Bitmap br = new Bitmap(ID, bs[2], new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2796 Bitmap bg = new Bitmap(ID, bs[1], new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2797 Bitmap bb = new Bitmap(ID, bs[0], new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2798 for (int b = 0; b < 3; b++)
2799 {
2800 bs[b].Dispose();
2801 bs[b] = null;
2802 }
2803 bs = null;
2804 GC.Collect();
2805 Statistics.CalcStatistics(br);
2806 Statistics.CalcStatistics(bg);
2807 Statistics.CalcStatistics(bb);
2808 bfs.Add(br);
2809 bfs.Add(bg);
2810 bfs.Add(bb);
2811 index += 3;
2812 }
2813 Buffers = bfs;
2815 }
2816 else
2817 {
2818 for (int i = 0; i < Buffers.Count; i++)
2819 {
2820 Bitmap b = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2821 Buffers[i] = b;
2822 Statistics.CalcStatistics(Buffers[i]);
2823 }
2824 for (int c = 0; c < Channels.Count; c++)
2825 {
2826 Channels[c].BitsPerPixel = 8;
2827 for (int i = 0; i < Channels[c].range.Length; i++)
2828 {
2829 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)ushort.MaxValue) * byte.MaxValue);
2830 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)ushort.MaxValue) * byte.MaxValue);
2831 }
2832 }
2833
2834 }
2835 //We wait for threshold image statistics calculation
2836 do
2837 {
2838 Thread.Sleep(100);
2839 } while (Buffers[Buffers.Count - 1].Stats == null);
2840 Statistics.ClearCalcBuffer();
2841 AutoThreshold(this, false);
2842 bitsPerPixel = 8;
2843 App.viewer.UpdateGUI();
2844 App.viewer.UpdateImages();
2845 App.viewer.UpdateView();
2846 Recorder.AddLine("BioGTK.Table.GetImage(" + '"' + ID + '"' + ")" + "." + "To8Bit();");
2847 }

◆ ToImageSizeX()

double BioGTK.BioImage.ToImageSizeX ( double  d)
inline

Convert a physical size to an image size

Parameters
dthe distance in microns
Returns
The value of d divided by the physicalSizeX.
3410 {
3411 return d / PhysicalSizeX;
3412 }

◆ ToImageSizeY()

double BioGTK.BioImage.ToImageSizeY ( double  d)
inline

Convert a physical size in Y direction to an image size in Y direction

Parameters
dthe distance in microns
Returns
The return value is the value of the parameter d divided by the value of the physicalSizeY field.
3420 {
3421 return d / PhysicalSizeY;
3422 }

◆ ToImageSpace() [1/4]

PointD[] BioGTK.BioImage.ToImageSpace ( List< PointD >  p)
inline

Convert a list of points from stage space to image space

Parameters
pList of points in stage space
Returns
A PointD array.
3463 {
3464 PointD[] ps = new PointD[p.Count];
3465 for (int i = 0; i < p.Count; i++)
3466 {
3467 PointD pp = new PointD();
3468 pp.X = ((p[i].X - StageSizeX) / PhysicalSizeX);
3469 pp.Y = ((p[i].Y - StageSizeY) / PhysicalSizeY);
3470 ps[i] = pp;
3471 }
3472 return ps;
3473 }

◆ ToImageSpace() [2/4]

PointD BioGTK.BioImage.ToImageSpace ( PointD  p)
inline

Convert a point in the stage coordinate system to a point in the image coordinate system

Parameters
PointD
Returns
A PointF object.
3451 {
3452 PointD pp = new PointD();
3453 pp.X = (float)((p.X - StageSizeX) / PhysicalSizeX);
3454 pp.Y = (float)((p.Y - StageSizeY) / PhysicalSizeY);
3455 return pp;
3456 }

◆ ToImageSpace() [3/4]

PointF[] BioGTK.BioImage.ToImageSpace ( PointF[]  p)
inline

‍The function takes a list of points in the stage coordinate system and returns a list of

points in the image coordinate system

Parameters
pthe points to be converted
Returns
A PointF[]
3481 {
3482 PointF[] ps = new PointF[p.Length];
3483 for (int i = 0; i < p.Length; i++)
3484 {
3485 PointF pp = new PointF();
3486 pp.X = (float)((p[i].X - StageSizeX) / PhysicalSizeX);
3487 pp.Y = (float)((p[i].Y - StageSizeY) / PhysicalSizeY);
3488 ps[i] = pp;
3489 }
3490 return ps;
3491 }
AForge.PointF PointF
Definition ImageView.cs:11

◆ ToImageSpace() [4/4]

RectangleF BioGTK.BioImage.ToImageSpace ( RectangleD  p)
inline

‍Convert a rectangle in physical space to a rectangle in image space

Parameters
RectangleD
Returns
A RectangleF object.
3498 {
3499 RectangleF r = new RectangleF();
3500 Point pp = new Point();
3501 r.X = (int)((p.X - StageSizeX) / PhysicalSizeX);
3502 r.Y = (int)((p.Y - StageSizeY) / PhysicalSizeY);
3503 r.Width = (int)(p.W / PhysicalSizeX);
3504 r.Height = (int)(p.H / PhysicalSizeY);
3505 return r;
3506 }
AForge.Point Point
Definition ImageView.cs:10

◆ ToImageSpaceX()

double BioGTK.BioImage.ToImageSpaceX ( double  x)
inline

‍Convert a stage coordinate to an image coordinate

Parameters
xthe x coordinate of the point in the image
Returns
The return value is a double.
3429 {
3430 if (isPyramidal)
3431 return x;
3432 return (float)((x - StageSizeX) / PhysicalSizeX);
3433 }
bool isPyramidal
Definition Bio.cs:2712

◆ ToImageSpaceY()

double BioGTK.BioImage.ToImageSpaceY ( double  y)
inline

‍Convert a Y coordinate from stage space to image space

Parameters
ythe y coordinate of the point in the image
Returns
The return value is the y-coordinate of the image.
3440 {
3441 if (isPyramidal)
3442 return y;
3443 return (float)((y - StageSizeY) / PhysicalSizeY);
3444 }

◆ ToStageSpace() [1/7]

PointD BioGTK.BioImage.ToStageSpace ( PointD  p)
inline

‍This function converts a point in the image space to a point in the stage space

Parameters
PointDA class that contains an X and Y coordinate.
Returns
A PointD object.
3513 {
3514 PointD pp = new PointD();
3515 if (isPyramidal)
3516 {
3517 pp.X = ((p.X * Resolutions[Level].PhysicalSizeX) + Volume.Location.X);
3518 pp.Y = ((p.Y * Resolutions[Level].PhysicalSizeY) + Volume.Location.Y);
3519 return pp;
3520 }
3521 else
3522 {
3523 pp.X = ((p.X * PhysicalSizeX) + Volume.Location.X);
3524 pp.Y = ((p.Y * PhysicalSizeY) + Volume.Location.Y);
3525 return pp;
3526 }
3527 }

◆ ToStageSpace() [2/7]

static PointD BioGTK.BioImage.ToStageSpace ( PointD  p,
double  physicalSizeX,
double  physicalSizeY,
double  volumeX,
double  volumeY 
)
inlinestatic

‍The function takes a point in the volume space and converts it to a point in the stage

space

Parameters
PointDA custom class that holds an X and Y coordinate.
physicalSizeXThe width of the stage in mm
physicalSizeYThe height of the stage in mm
volumeXThe X coordinate of the top left corner of the volume in stage space.
volumeYThe Y position of the top left corner of the volume in stage space.
Returns
A PointD object.
3552 {
3553 PointD pp = new PointD();
3554 pp.X = ((p.X * physicalSizeX) + volumeX);
3555 pp.Y = ((p.Y * physicalSizeY) + volumeY);
3556 return pp;
3557 }

◆ ToStageSpace() [3/7]

PointD BioGTK.BioImage.ToStageSpace ( PointD  p,
int  resolution 
)
inline

Convert a point in the image space to a point in the stage space

Parameters
PointDA point in the image space
resolutionthe resolution of the image (0, 1, 2, 3, 4)
Returns
A PointD object.
3535 {
3536 PointD pp = new PointD();
3537 pp.X = ((p.X * Resolutions[resolution].PhysicalSizeX) + Volume.Location.X);
3538 pp.Y = ((p.Y * Resolutions[resolution].PhysicalSizeY) + Volume.Location.Y);
3539 return pp;
3540 }

◆ ToStageSpace() [4/7]

PointD[] BioGTK.BioImage.ToStageSpace ( PointD[]  p)
inline

‍This function takes a list of points in the coordinate system of the image and returns a

list of points in the coordinate system of the stage

Parameters
pThe array of points to convert
Returns
A PointD[] array.
3599 {
3600 PointD[] ps = new PointD[p.Length];
3601 for (int i = 0; i < p.Length; i++)
3602 {
3603 PointD pp = new PointD();
3604 pp.X = ((p[i].X * PhysicalSizeX) + Volume.Location.X);
3605 pp.Y = ((p[i].Y * PhysicalSizeY) + Volume.Location.Y);
3606 ps[i] = pp;
3607 }
3608 return ps;
3609 }

◆ ToStageSpace() [5/7]

static PointD[] BioGTK.BioImage.ToStageSpace ( PointD[]  p,
double  physicalSizeX,
double  physicalSizeY,
double  volumeX,
double  volumeY 
)
inlinestatic

It takes a list of points, and converts them from a coordinate system where the origin is in the center of the image, to a coordinate system where the origin is in the top left corner of the image

Parameters
pthe array of points to convert
physicalSizeXThe width of the image in microns
physicalSizeYThe height of the image in microns
volumeXThe X position of the volume in stage space.
volumeYThe Y position of the top left corner of the volume in stage space.
Returns
A PointD array.
3622 {
3623 PointD[] ps = new PointD[p.Length];
3624 for (int i = 0; i < p.Length; i++)
3625 {
3626 PointD pp = new PointD();
3627 pp.X = ((p[i].X * physicalSizeX) + volumeX);
3628 pp.Y = ((p[i].Y * physicalSizeY) + volumeY);
3629 ps[i] = pp;
3630 }
3631 return ps;
3632 }

◆ ToStageSpace() [6/7]

RectangleD BioGTK.BioImage.ToStageSpace ( RectangleD  p)
inline

‍Convert a rectangle from the coordinate space of the image to the coordinate space of the

stage

Parameters
RectangleDA rectangle with double precision coordinates.
Returns
A RectangleD object.
3565 {
3566 RectangleD r = new RectangleD();
3567 r.X = ((p.X * PhysicalSizeX) + Volume.Location.X);
3568 r.Y = ((p.Y * PhysicalSizeY) + Volume.Location.Y);
3569 r.W = (p.W * PhysicalSizeX);
3570 r.H = (p.H * PhysicalSizeY);
3571 return r;
3572 }

◆ ToStageSpace() [7/7]

static RectangleD BioGTK.BioImage.ToStageSpace ( RectangleD  p,
double  physicalSizeX,
double  physicalSizeY,
double  volumeX,
double  volumeY 
)
inlinestatic

‍This function takes a rectangle in the coordinate space of the image and converts it to

the coordinate space of the stage

Parameters
RectangleDA rectangle with double precision.
physicalSizeXThe width of the physical screen in pixels
physicalSizeYThe height of the stage in pixels
volumeXThe X position of the volume in stage space.
volumeYThe Y position of the top of the volume in stage space.
Returns
A RectangleD object.
3584 {
3585 RectangleD r = new RectangleD();
3586 r.X = ((p.X * physicalSizeX) + volumeX);
3587 r.Y = ((p.Y * physicalSizeY) + volumeY);
3588 r.W = (p.W * physicalSizeX);
3589 r.H = (p.H * physicalSizeY);
3590 return r;
3591 }

◆ ToString()

override string BioGTK.BioImage.ToString ( )
inline

This function returns the filename of the object, and the location of the object in the 3D space

Returns
The filename, and the location of the volume.
8449 {
8450 return Filename.ToString() + ", (" + Volume.Location.X + ", " + Volume.Location.Y + ", " + Volume.Location.Z + ")";
8451 }

◆ Update() [1/2]

void BioGTK.BioImage.Update ( )
inline

‍Update() is a function that calls the Update() function of the parent class

7441 {
7442 Update(this);
7443 }
void Update()
‍Update() is a function that calls the Update() function of the parent class
Definition Bio.cs:7440

◆ Update() [2/2]

static void BioGTK.BioImage.Update ( BioImage  b)
inlinestatic

The function takes a BioImage object, opens the file, and returns a updated BioImage object

Parameters
BioImageThis is the class that contains the image data.
7397 {
7398 b = OpenFile(b.file);
7399 }

◆ UpdateBuffersPyramidal()

async void BioGTK.BioImage.UpdateBuffersPyramidal ( )
inline

Updates the Buffers based on current pyramidal origin and resolution.

7404 {
7405 for (int i = 0; i < Buffers.Count; i++)
7406 {
7407 Buffers[i].Dispose();
7408 }
7409 Buffers.Clear();
7410 for (int i = 0; i < imagesPerSeries; i++)
7411 {
7412 if (openSlideImage != null)
7413 {
7414 byte[] bts = openslideBase.GetSlice(new OpenSlideGTK.SliceInfo(PyramidalOrigin.X, PyramidalOrigin.Y, PyramidalSize.Width, PyramidalSize.Height, resolution));
7415 Buffers.Add(new Bitmap((int)Math.Round(OpenSlideBase.destExtent.Width), (int)Math.Round(OpenSlideBase.destExtent.Height), PixelFormat.Format24bppRgb, bts, new ZCT(), ""));
7416 }
7417 else
7418 {
7419 start:
7420 byte[] bts = await slideBase.GetSlice(new Bio.SliceInfo(PyramidalOrigin.X, PyramidalOrigin.Y, PyramidalSize.Width, PyramidalSize.Height, resolution,App.viewer.GetCoordinate()));
7421 if(bts == null)
7422 {
7423 if(PyramidalOrigin.X == 0 && PyramidalOrigin.Y == 0)
7424 {
7425 Resolution = 1;
7426 }
7427 pyramidalOrigin = new PointD(0, 0);
7428 goto start;
7429 }
7430 Buffers.Add(new Bitmap((int)Math.Round(SlideBase.destExtent.Width), (int)Math.Round(SlideBase.destExtent.Height), PixelFormat.Format24bppRgb, bts, new ZCT(), ""));
7431 }
7432 }
7433 BioImage.AutoThreshold(this, true);
7434 if (bitsPerPixel > 8)
7435 StackThreshold(true);
7436 else
7437 StackThreshold(false);
7438 }
Slice info.
Definition ISlideSource.cs:425
Definition SlideBase.cs:15
static Extent destExtent
Definition ISlideSource.cs:176
async Task< byte[]> GetSlice(SliceInfo sliceInfo)
Get slice.
Definition ISlideSource.cs:181
int imagesPerSeries
Definition Bio.cs:2163
PointD PyramidalOrigin
Definition Bio.cs:2395
Size PyramidalSize
Definition Bio.cs:2392
OpenSlideImage openSlideImage
Definition Bio.cs:6962
Definition ISlideSource.cs:14

◆ UpdateCoords() [1/3]

void BioGTK.BioImage.UpdateCoords ( )
inline

It takes a list of images and assigns them to a 3D array of coordinates.

3272 {
3273 int z = 0;
3274 int c = 0;
3275 int t = 0;
3276 Coords = new int[SizeZ, SizeC, SizeT];
3277 for (int im = 0; im < Buffers.Count; im++)
3278 {
3279 ZCT co = new ZCT(z, c, t);
3280 Coords[co.Z, co.C, co.T] = im;
3281 Buffers[im].Coordinate = co;
3282 if (c < SizeC - 1)
3283 c++;
3284 else
3285 {
3286 c = 0;
3287 if (z < SizeZ - 1)
3288 z++;
3289 else
3290 {
3291 z = 0;
3292 if (t < SizeT - 1)
3293 t++;
3294 else
3295 t = 0;
3296 }
3297 }
3298 }
3299 }

◆ UpdateCoords() [2/3]

void BioGTK.BioImage.UpdateCoords ( int  sz,
int  sc,
int  st 
)
inline

It takes the number of Z, C, and T planes in the image and then assigns each image buffer a coordinate in the ZCT space

Parameters
szsize of the Z dimension
scnumber of channels
stnumber of time points
3307 {
3308 int z = 0;
3309 int c = 0;
3310 int t = 0;
3311 sizeZ = sz;
3312 sizeC = sc;
3313 sizeT = st;
3314 Coords = new int[sz, sc, st];
3315 for (int im = 0; im < Buffers.Count; im++)
3316 {
3317 ZCT co = new ZCT(z, c, t);
3318 Coords[co.Z, co.C, co.T] = im;
3319 Buffers[im].Coordinate = co;
3320 if (c < SizeC - 1)
3321 c++;
3322 else
3323 {
3324 c = 0;
3325 if (z < SizeZ - 1)
3326 z++;
3327 else
3328 {
3329 z = 0;
3330 if (t < SizeT - 1)
3331 t++;
3332 else
3333 t = 0;
3334 }
3335 }
3336 }
3337 }

◆ UpdateCoords() [3/3]

void BioGTK.BioImage.UpdateCoords ( int  sz,
int  sc,
int  st,
string  order 
)
inline

It takes a list of images and assigns them to a 3D array of coordinates

Parameters
szsize of the Z dimension
scnumber of channels
stnumber of time points
orderXYCZT or XYZCT
3345 {
3346 int z = 0;
3347 int c = 0;
3348 int t = 0;
3349 sizeZ = sz;
3350 sizeC = sc;
3351 sizeT = st;
3352 Coords = new int[sz, sc, st];
3353 if (order == "XYCZT")
3354 {
3355 for (int im = 0; im < Buffers.Count; im++)
3356 {
3357 ZCT co = new ZCT(z, c, t);
3358 Coords[co.Z, co.C, co.T] = im;
3359 Buffers[im].Coordinate = co;
3360 if (c < SizeC - 1)
3361 c++;
3362 else
3363 {
3364 c = 0;
3365 if (z < SizeZ - 1)
3366 z++;
3367 else
3368 {
3369 z = 0;
3370 if (t < SizeT - 1)
3371 t++;
3372 else
3373 t = 0;
3374 }
3375 }
3376 }
3377 }
3378 else if (order == "XYZCT")
3379 {
3380 for (int im = 0; im < Buffers.Count; im++)
3381 {
3382 ZCT co = new ZCT(z, c, t);
3383 Coords[co.Z, co.C, co.T] = im;
3384 Buffers[im].Coordinate = co;
3385 if (z < SizeZ - 1)
3386 z++;
3387 else
3388 {
3389 z = 0;
3390 if (c < SizeC - 1)
3391 c++;
3392 else
3393 {
3394 c = 0;
3395 if (t < SizeT - 1)
3396 t++;
3397 else
3398 t = 0;
3399 }
3400 }
3401 }
3402 }
3403 }

◆ VipsSupport()

static bool BioGTK.BioImage.VipsSupport ( string  file)
inlinestatic

The function checks if a given file is supported by the Vips library and returns true if it is, false otherwise.

Parameters
fileThe "file" parameter is a string that represents the file path of the TIFF image that you want to load using the NetVips library.
Returns
The method is returning a boolean value. If the try block is executed successfully, it will return true. If an exception is caught, it will return false.
7571 {
7572 //Currently GTKSharp and LibVips causes an error so on windows no netvips support.
7573 if (OperatingSystem.IsWindows())
7574 return false;
7575 try
7576 {
7577 netim = NetVips.Image.Tiffload(file);
7578 Settings.AddSettings("VipsSupport", "true");
7579 }
7580 catch (Exception e)
7581 {
7582 Console.WriteLine(e.ToString());
7583 return false;
7584 }
7585 netim.Close();
7586 netim.Dispose();
7587 return true;
7588 }

Member Data Documentation

◆ Annotations

List<ROI> BioGTK.BioImage.Annotations = new List<ROI>()

◆ bitsPerPixel

int BioGTK.BioImage.bitsPerPixel

◆ Buffers

List<AForge.Bitmap> BioGTK.BioImage.Buffers = new List<AForge.Bitmap>()

◆ Channels

List<Channel> BioGTK.BioImage.Channels = new List<Channel>()

◆ columns

const string BioGTK.BioImage.columns = "ROIID,ROINAME,TYPE,ID,SHAPEINDEX,TEXT,S,C,Z,T,X,Y,W,H,POINTS,STROKECOLOR,STROKECOLORW,FILLCOLOR,FONTSIZE\n"
static

◆ Coords

int [,,] BioGTK.BioImage.Coords

◆ file

string BioGTK.BioImage.file

◆ filename

string BioGTK.BioImage.filename = ""

◆ filter16

LevelsLinear16bpp BioGTK.BioImage.filter16 = new LevelsLinear16bpp()
static

◆ filter8

LevelsLinear BioGTK.BioImage.filter8 = new LevelsLinear()
static

◆ frameInterval

double BioGTK.BioImage.frameInterval = 0

◆ imagesPerSeries

int BioGTK.BioImage.imagesPerSeries = 0

◆ imRead

ImageReader BioGTK.BioImage.imRead

◆ isGroup

bool BioGTK.BioImage.isGroup = false

◆ littleEndian

bool BioGTK.BioImage.littleEndian = false

◆ Loading

bool BioGTK.BioImage.Loading = false

◆ loadTimeMS

long BioGTK.BioImage.loadTimeMS = 0

◆ loadTimeTicks

long BioGTK.BioImage.loadTimeTicks = 0

◆ NewLine

const char BioGTK.BioImage.NewLine = '\n'
static

◆ openSlideImage

OpenSlideImage BioGTK.BioImage.openSlideImage

◆ Planes

bool BioGTK.BioImage.Planes = false
static

◆ Plate

WellPlate BioGTK.BioImage.Plate = null

◆ progFile

string BioGTK.BioImage.progFile
static

◆ Resolutions

List<Resolution> BioGTK.BioImage.Resolutions = new List<Resolution>()

◆ rgbChannels

int [] BioGTK.BioImage.rgbChannels = new int[3]

◆ script

string BioGTK.BioImage.script = ""

◆ selected

bool BioGTK.BioImage.selected = false

◆ seriesCount

int BioGTK.BioImage.seriesCount = 1

◆ status

string BioGTK.BioImage.status
static

◆ swatch

Stopwatch BioGTK.BioImage.swatch = new Stopwatch()
static

◆ tifRead

Tiff BioGTK.BioImage.tifRead

◆ vipPages

List<NetVips.Image> BioGTK.BioImage.vipPages = new List<NetVips.Image>()

◆ Volume

VolumeD BioGTK.BioImage.Volume

◆ watch

Stopwatch BioGTK.BioImage.watch = new Stopwatch()

Property Documentation

◆ AnnotationsB

List<ROI> BioGTK.BioImage.AnnotationsB
get
2467 {
2468 get
2469 {
2470 return GetAnnotations(Coordinate.Z, BChannel.Index, Coordinate.T);
2471 }
2472 }
List< ROI > GetAnnotations(ZCT coord)
Definition Bio.cs:4545

◆ AnnotationsG

List<ROI> BioGTK.BioImage.AnnotationsG
get
2459 {
2460 get
2461 {
2462 return GetAnnotations(Coordinate.Z, GChannel.Index, Coordinate.T);
2463 }
2464 }

◆ AnnotationsR

List<ROI> BioGTK.BioImage.AnnotationsR
get
2451 {
2452 get
2453 {
2454 return GetAnnotations(Coordinate.Z, RChannel.Index, Coordinate.T);
2455 }
2456 }

◆ AnnotationsRGB

List<ROI> BioGTK.BioImage.AnnotationsRGB
get
2474 {
2475 get
2476 {
2477 if (SelectedImage == null)
2478 return null;
2479 List<ROI> ans = new List<ROI>();
2480 if (App.viewer.Mode == ViewMode.RGBImage)
2481 {
2482 if (App.viewer.showRROIs)
2483 ans.AddRange(AnnotationsR);
2484 if (App.viewer.showGROIs)
2485 ans.AddRange(AnnotationsG);
2486 if (App.viewer.showBROIs)
2487 ans.AddRange(AnnotationsB);
2488 }
2489 else
2490 {
2491 ans.AddRange(GetAnnotations(Coordinate));
2492 }
2493 return ans;
2494 }
2495 }
List< ROI > AnnotationsG
Definition Bio.cs:2459
List< ROI > AnnotationsR
Definition Bio.cs:2451
List< ROI > AnnotationsB
Definition Bio.cs:2467

◆ BChannel

Channel BioGTK.BioImage.BChannel
get
2440 {
2441 get
2442 {
2443 if (Channels[0].range.Length == 1)
2444 return Channels[rgbChannels[2]];
2445 else
2446 return Channels[0];
2447 }
2448 }

◆ BRange

IntRange BioGTK.BioImage.BRange
get
2667 {
2668 get
2669 {
2670 return BChannel.RangeB;
2671 }
2672 }

◆ Coordinate

ZCT BioGTK.BioImage.Coordinate
getset
2082 {
2083 get
2084 {
2085 return coordinate;
2086 }
2087 set
2088 {
2089 coordinate = value;
2090 }
2091 }

◆ Filename

string BioGTK.BioImage.Filename
getset
2144 {
2145 get
2146 {
2147 return filename;
2148 }
2149 set
2150 {
2151 filename = value;
2152 }
2153 }

◆ GChannel

Channel BioGTK.BioImage.GChannel
get
2430 {
2431 get
2432 {
2433 if (Channels[0].range.Length == 1)
2434 return Channels[rgbChannels[1]];
2435 else
2436 return Channels[0];
2437 }
2438 }

◆ GRange

IntRange BioGTK.BioImage.GRange
get
2660 {
2661 get
2662 {
2663 return GChannel.RangeG;
2664 }
2665 }

◆ ID

string BioGTK.BioImage.ID
getset
2350 {
2351 get { return id; }
2352 set { id = value; }
2353 }

◆ ImageCount

int BioGTK.BioImage.ImageCount
get
2355 {
2356 get
2357 {
2358 return Buffers.Count;
2359 }
2360 }

◆ Initialized

bool BioGTK.BioImage.Initialized
staticget
2746 {
2747 get
2748 {
2749 return initialized;
2750 }
2751 }

◆ isPyramidal

bool BioGTK.BioImage.isPyramidal
get
2712 {
2713 get
2714 {
2715 if (Type == ImageType.pyramidal)
2716 return true;
2717 else
2718 return false;
2719 }
2720 }
ImageType Type
Definition Bio.cs:2099

◆ isRGB

bool BioGTK.BioImage.isRGB
get
2682 {
2683 get
2684 {
2685 if (RGBChannelCount == 3 || RGBChannelCount == 4)
2686 return true;
2687 else
2688 return false;
2689 }
2690 }

◆ isSeries

bool BioGTK.BioImage.isSeries
get
2702 {
2703 get
2704 {
2705 if (seriesCount > 1)
2706 return true;
2707 else
2708 return false;
2709 }
2710 }

◆ isTime

bool BioGTK.BioImage.isTime
get
2692 {
2693 get
2694 {
2695 if (SizeT > 1)
2696 return true;
2697 else
2698 return false;
2699 }
2700 }

◆ LabelResolution

int? BioGTK.BioImage.LabelResolution
getset
3175{ get;set; }

◆ Level

int BioGTK.BioImage.Level
getset
2106 {
2107 get
2108 {
2109 if (openslideBase != null)
2110 return OpenSlideGTK.TileUtil.GetLevel(openslideBase.Schema.Resolutions, Resolution);
2111 else
2112 if (slideBase != null)
2114 return level;
2115 }
2116 set
2117 {
2118 if(Type == ImageType.well)
2119 {
2120 level = value;
2121 reader.setId(file);
2122 reader.setSeries(value);
2123 // read the image data bytes
2124 int pages = reader.getImageCount();
2125 bool inter = reader.isInterleaved();
2126 PixelFormat pf = Buffers[0].PixelFormat;
2127 int w = Buffers[0].SizeX; int h = Buffers[0].SizeY;
2128 Buffers.Clear();
2129 for (int p = 0; p < pages; p++)
2130 {
2131 Bitmap bf;
2132 byte[] bytes = reader.openBytes(p);
2133 bf = new Bitmap(file, w, h, pf, bytes, new ZCT(), p, null, littleEndian, inter);
2134 Buffers.Add(bf);
2135 }
2136 }
2137 }
2138 }
int LevelFromResolution(double Resolution)
Returns the level of a given resolution.
Definition Bio.cs:2330

◆ MacroResolution

int? BioGTK.BioImage.MacroResolution
getset
3174{ get;set; }

◆ OpenSlideBase

OpenSlideBase BioGTK.BioImage.OpenSlideBase
get
2416{ get { return openslideBase; } }

◆ PhysicalSizeX

double BioGTK.BioImage.PhysicalSizeX
get
2362 {
2363 get { return Resolutions[Level].PhysicalSizeX; }
2364 }

◆ PhysicalSizeY

double BioGTK.BioImage.PhysicalSizeY
get
2366 {
2367 get { return Resolutions[Level].PhysicalSizeY; }
2368 }

◆ PhysicalSizeZ

double BioGTK.BioImage.PhysicalSizeZ
get
2370 {
2371 get { return Resolutions[Level].PhysicalSizeZ; }
2372 }

◆ progressValue

double BioGTK.BioImage.progressValue
staticgetset
2723 {
2724 get
2725 {
2726 if (App.progress != null)
2727 return App.progress.ProgressValue;
2728 else
2729 return 0;
2730 }
2731 set
2732 {
2733 if (App.progress != null)
2734 {
2735 // update ui on main UI thread
2736 Application.Invoke(delegate
2737 {
2738 App.progress.ProgressValue = value;
2739 });
2740 }
2741 }
2742 }

◆ PyramidalOrigin

PointD BioGTK.BioImage.PyramidalOrigin
getset
2395 {
2396 get { return pyramidalOrigin; }
2397 set
2398 {
2399 pyramidalOrigin = value;
2400 }
2401 }

◆ PyramidalSize

Size BioGTK.BioImage.PyramidalSize
getset
2392{ get { return s; } set { s = value; } }

◆ RChannel

Channel BioGTK.BioImage.RChannel
get
2420 {
2421 get
2422 {
2423 if (Channels[0].range.Length == 1)
2424 return Channels[rgbChannels[0]];
2425 else
2426 return Channels[0];
2427 }
2428 }

◆ Resolution

double BioGTK.BioImage.Resolution
getset
2186 {
2187 get { return resolution; }
2188 set
2189 {
2190 if (value < 0)
2191 return;
2192 resolution = value;
2193 }
2194 }

◆ RGBChannelCount

int BioGTK.BioImage.RGBChannelCount
get
2156 {
2157 get
2158 {
2159 return Buffers[0].RGBChannelsCount;
2160 }
2161 }

◆ RRange

IntRange BioGTK.BioImage.RRange
get
2653 {
2654 get
2655 {
2656 return RChannel.RangeR;
2657 }
2658 }

◆ SelectedBuffer

Bitmap BioGTK.BioImage.SelectedBuffer
get
2674 {
2675 get
2676 {
2678 }
2679 }

◆ series

int BioGTK.BioImage.series
getset
2403 {
2404 get
2405 {
2406 return imageInfo.Series;
2407 }
2408 set
2409 {
2410 imageInfo.Series = value;
2411 }
2412 }
int Series
Definition Bio.cs:1979

◆ SizeC

int BioGTK.BioImage.SizeC
get
2643 {
2644 get { return sizeC; }
2645 }

◆ SizeT

int BioGTK.BioImage.SizeT
get
2647 {
2648 get { return sizeT; }
2649 }

◆ SizeX

int BioGTK.BioImage.SizeX
get
2621 {
2622 get
2623 {
2624 if (Buffers.Count > 0)
2625 return Buffers[0].SizeX;
2626 else return 0;
2627 }
2628 }

◆ SizeY

int BioGTK.BioImage.SizeY
get
2630 {
2631 get
2632 {
2633 if (Buffers.Count > 0)
2634 return Buffers[0].SizeY;
2635 else return 0;
2636 }
2637 }

◆ SizeZ

int BioGTK.BioImage.SizeZ
get
2639 {
2640 get { return sizeZ; }
2641 }

◆ SlideBase

SlideBase BioGTK.BioImage.SlideBase
get
2418{ get { return slideBase; } }

◆ StageSizeX

double BioGTK.BioImage.StageSizeX
getset
2374 {
2375 get
2376 {
2377 return Resolutions[Level].StageSizeX;
2378 }
2379 set { imageInfo.StageSizeX = value; }
2380 }

◆ StageSizeY

double BioGTK.BioImage.StageSizeY
getset
2382 {
2383 get { return Resolutions[Level].StageSizeY; }
2384 set { imageInfo.StageSizeY = value; }
2385 }

◆ StageSizeZ

double BioGTK.BioImage.StageSizeZ
getset
2387 {
2388 get { return Resolutions[Level].StageSizeZ; }
2389 set { imageInfo.StageSizeZ = value; }
2390 }

◆ Statistics

Statistics BioGTK.BioImage.Statistics
getset
2172 {
2173 get
2174 {
2175 return statistics;
2176 }
2177 set
2178 {
2179 statistics = value;
2180 }
2181 }

◆ Tag

object BioGTK.BioImage.Tag
getset
2651{ get;set; }

◆ Type

ImageType BioGTK.BioImage.Type
getset
2099{ get; set; }

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