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

Classes

class  ImageJDesc
 
class  WellPlate
 

Public Types

enum  ImageType
 

Public Member Functions

BioImage Copy (bool rois)
 
BioImage Copy ()
 
void SetLabelMacroResolutions ()
 
double GetLevelDownsample (int level)
 Get the downsampling factor of a given level. More...
 
int LevelFromResolution (double Resolution)
 Returns the level of a given resolution. More...
 
double GetUnitPerPixel (int level)
 Get Unit Per Pixel for pyramidal images. More...
 
void UpdateBuffersPyramidal ()
 Updates the Buffers based on current pyramidal origin and resolution. More...
 
void To8Bit ()
 Converts a 16-bit image to an 8-bit image. More...
 
void To16Bit ()
 Converts the image to 16 bit. More...
 
void To24Bit ()
 Converts the image to 24 bit. More...
 
void To32Bit ()
 Converts the image to 32 bit. More...
 
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. More...
 
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)
 
void Update ()
 

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

More...
 
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 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 SaveOMESeries (BioImage[] bms, string f, bool planes)
 
static void SaveOMESeries (string[] files, string f, bool planes)
 
static int GetBands (PixelFormat format)
 
static void SaveOMEPyramidal (BioImage[] bms, string file, Enums.ForeignTiffCompression compression, int compressionLevel)
 
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 More...
 
static Bitmap GetTile (BioImage b, ZCT coord, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
 
static Bitmap GetTile (BioImage b, int i, 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)
 
static async Task OpenAsync (string[] files, bool OME, bool tab, bool images)
 
static async Task SaveAsync (string file, string id, int serie, bool ome)
 The SaveAsync function saves data to a file asynchronously. More...
 
static async Task SaveSeriesAsync (BioImage[] imgs, string file, bool ome)
 The function SaveSeriesAsync saves a series of BioImage objects to a file asynchronously. More...
 
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. More...
 
static void Open (string file)
 
static void Open (string[] files)
 
static BioImage ImagesToStack (string[] files, bool tab)
 
static void Update (BioImage b)
 
static void Save (string file, string ID)
 
static bool OMESupport ()
 
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. More...
 
static void AutoThresholdThread (BioImage b)
 
static int FindFocus (BioImage im, int Channel, int Time)
 
static long CalculateFocusQuality (Bitmap 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

int[,,] Coords
 
WellPlate Plate = null
 
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
 
OpenSlideImage openSlideImage
 
OpenSlideBase openSlideBase
 
SlideBase slideBase
 
SlideImage slideImage
 
Stopwatch watch = new Stopwatch()
 
string file
 
bool Loading = false
 
ImageReader imRead
 
Tiff tifRead
 

Static Public Attributes

static float progressValue = 0
 
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()
 
static bool OmeSupport = false
 
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]
 
double Resolution [get, set]
 
string Filename [get, set]
 
int RGBChannelCount [get]
 
Statistics Statistics [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]
 
int series [get, set]
 
Channel RChannel [get]
 
Channel GChannel [get]
 
Channel BChannel [get]
 
int SizeX [get]
 
int SizeY [get]
 
int SizeZ [get]
 
int SizeC [get]
 
int SizeT [get]
 
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 bool Initialized [get]
 
int? MacroResolution [get, set]
 
int? LabelResolution [get, set]
 
AForge.Size PyramidalSize [get, set]
 
PointD PyramidalOrigin [get, set]
 
int Level [get, set]
 

Detailed Description

Definition at line 1898 of file Bio.cs.

Member Enumeration Documentation

◆ ImageType

enum BioImager.BioImage.ImageType

Definition at line 1982 of file Bio.cs.

1983 {
1984 pyramidal,
1985 stack,
1986 well
1987 }

Constructor & Destructor Documentation

◆ BioImage()

BioImager.BioImage.BioImage ( string  file)

Definition at line 3506 of file Bio.cs.

3507 {
3508 id = file;
3509 this.file = file;
3510 filename = Images.GetImageName(id);
3511 Coordinate = new ZCT();
3512 rgbChannels[0] = 0;
3513 rgbChannels[1] = 0;
3514 rgbChannels[2] = 0;
3515 }

Member Function Documentation

◆ AutoThreshold() [1/2]

static void BioImager.BioImage.AutoThreshold ( )
static

◆ AutoThreshold() [2/2]

static void BioImager.BioImage.AutoThreshold ( BioImage  b,
bool  updateImageStats 
)
static

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.

Definition at line 7969 of file Bio.cs.

7970 {
7971 bstats = b;
7972 Statistics statistics = null;
7973 if (b.bitsPerPixel > 8)
7974 statistics = new Statistics(true);
7975 else
7976 statistics = new Statistics(false);
7977 for (int i = 0; i < b.Buffers.Count; i++)
7978 {
7979 if (b.Buffers[i].Stats == null || updateImageStats)
7980 b.Buffers[i].Stats = Statistics.FromBytes(b.Buffers[i]);
7981 if (b.Buffers[i].RGBChannelsCount == 1)
7982 statistics.AddStatistics(b.Buffers[i].Stats[0]);
7983 else
7984 {
7985 for (int r = 0; r < b.Buffers[i].RGBChannelsCount; r++)
7986 {
7987 statistics.AddStatistics(b.Buffers[i].Stats[r]);
7988 }
7989 }
7990 }
7991 for (int c = 0; c < b.Channels.Count; c++)
7992 {
7993 Statistics[] sts = new Statistics[b.Buffers[0].RGBChannelsCount];
7994 for (int i = 0; i < b.Buffers[0].RGBChannelsCount; i++)
7995 {
7996 if (b.bitsPerPixel > 8)
7997 {
7998 sts[i] = new Statistics(true);
7999 }
8000 else
8001 sts[i] = new Statistics(false);
8002 }
8003 for (int z = 0; z < b.SizeZ; z++)
8004 {
8005 for (int t = 0; t < b.SizeT; t++)
8006 {
8007 int ind;
8008 if (b.Channels.Count > b.SizeC)
8009 {
8010 ind = b.Coords[z, 0, t];
8011 }
8012 else
8013 ind = b.Coords[z, c, t];
8014 if (b.Buffers[ind].RGBChannelsCount == 1)
8015 sts[0].AddStatistics(b.Buffers[ind].Stats[0]);
8016 else
8017 {
8018 sts[0].AddStatistics(b.Buffers[ind].Stats[0]);
8019 sts[1].AddStatistics(b.Buffers[ind].Stats[1]);
8020 sts[2].AddStatistics(b.Buffers[ind].Stats[2]);
8021 if (b.Buffers[ind].RGBChannelsCount == 4)
8022 sts[3].AddStatistics(b.Buffers[ind].Stats[3]);
8023 }
8024 }
8025 }
8026 if (b.RGBChannelCount == 1)
8027 sts[0].MeanHistogram();
8028 else
8029 {
8030 sts[0].MeanHistogram();
8031 sts[1].MeanHistogram();
8032 sts[2].MeanHistogram();
8033 if (b.Buffers[0].RGBChannelsCount == 4)
8034 sts[3].MeanHistogram();
8035 }
8036 b.Channels[c].stats = sts;
8037 }
8038 statistics.MeanHistogram();
8039 b.statistics = statistics;
8040
8041 }

Referenced by BioImager.BioImage.UpdateBuffersPyramidal().

◆ AutoThresholdThread()

static void BioImager.BioImage.AutoThresholdThread ( BioImage  b)
static

It creates a new thread that calls the AutoThreshold function

Parameters
BioImageThis is a class that holds the image data and some other information.

Definition at line 8050 of file Bio.cs.

8051 {
8052 bstats = b;
8053 Thread th = new Thread(AutoThreshold);
8054 th.Start();
8055 }

References BioImager.BioImage.AutoThreshold().

◆ Bake() [1/2]

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

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.

Definition at line 3097 of file Bio.cs.

3098 {
3099 Bake(new IntRange(rmin, rmax), new IntRange(gmin, gmax), new IntRange(bmin, bmax));
3100 }
void Bake(int rmin, int rmax, int gmin, int gmax, int bmin, int bmax)
Definition: Bio.cs:3097

References BioImager.BioImage.Bake().

Referenced by BioImager.BioImage.Bake().

◆ Bake() [2/2]

void BioImager.BioImage.Bake ( IntRange  rf,
IntRange  gf,
IntRange  bf 
)

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

Parameters
IntRange
IntRange
IntRange

Definition at line 3107 of file Bio.cs.

3108 {
3109 BioImage bm = new BioImage(Images.GetImageName(ID));
3110 bm = CopyInfo(this, true, true);
3111 for (int i = 0; i < Buffers.Count; i++)
3112 {
3113 ZCT co = Buffers[i].Coordinate;
3114 UnmanagedImage b = GetFiltered(i, rf, gf, bf);
3115 Bitmap inf = new Bitmap(bm.ID, b, co, i);
3116 Statistics.CalcStatistics(inf);
3117 bm.Coords[co.Z, co.C, co.T] = i;
3118 bm.Buffers.Add(inf);
3119 }
3120 foreach (Channel item in bm.Channels)
3121 {
3122 for (int i = 0; i < item.range.Length; i++)
3123 {
3124 item.range[i].Min = 0;
3125 if (bm.bitsPerPixel > 8)
3126 item.range[i].Max = ushort.MaxValue;
3127 else
3128 item.range[i].Max = 255;
3129 }
3130 }
3131 //We wait for threshold image statistics calculation
3132 do
3133 {
3134 Thread.Sleep(50);
3135 } while (Buffers[Buffers.Count - 1].Stats == null);
3136 AutoThreshold(bm, false);
3137 Statistics.ClearCalcBuffer();
3138 Images.AddImage(bm, true);
3139 App.tabsView.AddTab(bm);
3140 Recorder.AddLine("ImageView.SelectedImage.Bake(" + rf.Min + "," + rf.Max + "," + gf.Min + "," + gf.Max + "," + bf.Min + "," + bf.Max + ");");
3141 }
Bitmap GetFiltered(ZCT coord, IntRange r, IntRange g, IntRange b)
Definition: Bio.cs:4150
static BioImage CopyInfo(BioImage b, bool copyAnnotations, bool copyChannels)
Definition: Bio.cs:2130

References BioImager.TabsView.AddTab(), BioImager.BioImage.AutoThreshold(), BioImager.BioImage.CopyInfo(), and BioImager.BioImage.GetFiltered().

◆ CalculateFocusQuality()

static long BioImager.BioImage.CalculateFocusQuality ( Bitmap  b)
static

The function calculates the focus quality of a given bitmap image.

Parameters
BitmapA class representing a bitmap image, which contains information about the image's size, pixel data, and color channels.
Returns
The method is returning a long value which represents the calculated focus quality of the input Bitmap image.

Definition at line 8094 of file Bio.cs.

8095 {
8096 if (b.RGBChannelsCount == 1)
8097 {
8098 long sum = 0;
8099 long sumOfSquaresR = 0;
8100 for (int y = 0; y < b.SizeY; y++)
8101 for (int x = 0; x < b.SizeX; x++)
8102 {
8103 ColorS pixel = b.GetPixel(x, y);
8104 sum += pixel.R;
8105 sumOfSquaresR += pixel.R * pixel.R;
8106 }
8107 return sumOfSquaresR * b.SizeX * b.SizeY - sum * sum;
8108 }
8109 else
8110 {
8111 long sum = 0;
8112 long sumOfSquares = 0;
8113 for (int y = 0; y < b.SizeY; y++)
8114 for (int x = 0; x < b.SizeX; x++)
8115 {
8116 ColorS pixel = b.GetPixel(x, y);
8117 int p = (pixel.R + pixel.G + pixel.B) / 3;
8118 sum += p;
8119 sumOfSquares += p * p;
8120 }
8121 return sumOfSquares * b.SizeX * b.SizeY - sum * sum;
8122 }
8123 }

Referenced by BioImager.BioImage.FindFocus().

◆ Copy() [1/4]

BioImage BioImager.BioImage.Copy ( )

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

Returns
A copy of the BioImage object.

Definition at line 2119 of file Bio.cs.

2120 {
2121 return BioImage.Copy(this, true);
2122 }

References BioImager.BioImage.Copy().

Referenced by BioImager.BioImage.Copy(), and BioImager.BioImage.SplitChannels().

◆ Copy() [2/4]

static BioImage BioImager.BioImage.Copy ( BioImage  b)
static

Copy a BioImage object.

Parameters
BioImageThe image to copy
Returns
A copy of the BioImage object.

Definition at line 2103 of file Bio.cs.

2104 {
2105 return Copy(b, true);
2106 }
BioImage Copy()
Definition: Bio.cs:2119

References BioImager.BioImage.Copy().

◆ Copy() [3/4]

static BioImage BioImager.BioImage.Copy ( BioImage  b,
bool  rois 
)
static

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.

Definition at line 2063 of file Bio.cs.

2064 {
2065 BioImage bi = new BioImage(b.ID);
2066 if (rois)
2067 foreach (ROI an in b.Annotations)
2068 {
2069 bi.Annotations.Add(an);
2070 }
2071 foreach (Bitmap bf in b.Buffers)
2072 {
2073 bi.Buffers.Add(bf.Copy());
2074 }
2075 foreach (Channel c in b.Channels)
2076 {
2077 bi.Channels.Add(c);
2078 }
2079 bi.Volume = b.Volume;
2080 bi.Coords = b.Coords;
2081 bi.sizeZ = b.sizeZ;
2082 bi.sizeC = b.sizeC;
2083 bi.sizeT = b.sizeT;
2084 bi.series = b.series;
2085 bi.seriesCount = b.seriesCount;
2086 bi.frameInterval = b.frameInterval;
2087 bi.littleEndian = b.littleEndian;
2088 bi.isGroup = b.isGroup;
2089 bi.imageInfo = b.imageInfo;
2090 bi.bitsPerPixel = b.bitsPerPixel;
2091 bi.file = b.file;
2092 bi.filename = b.filename;
2093 bi.Resolutions = new List<Resolution>();
2094 bi.Resolutions.AddRange(b.Resolutions);
2095 bi.statistics = b.statistics;
2096 return bi;
2097 }

Referenced by BioImager.BioImage.Copy().

◆ Copy() [4/4]

BioImage BioImager.BioImage.Copy ( bool  rois)

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.

Definition at line 2112 of file Bio.cs.

2113 {
2114 return BioImage.Copy(this, rois);
2115 }

References BioImager.BioImage.Copy().

◆ CopyInfo()

static BioImage BioImager.BioImage.CopyInfo ( BioImage  b,
bool  copyAnnotations,
bool  copyChannels 
)
static

CopyInfo() copies the information from one BioImage to another

Parameters
BioImagethe image to copy
copyAnnotationstrue
copyChannelstrue
Returns
A new BioImage object.

Definition at line 2130 of file Bio.cs.

2131 {
2132 BioImage bi = new BioImage(b.ID);
2133 if (copyAnnotations)
2134 foreach (ROI an in b.Annotations)
2135 {
2136 bi.Annotations.Add(an);
2137 }
2138 if (copyChannels)
2139 foreach (Channel c in b.Channels)
2140 {
2141 bi.Channels.Add(c.Copy());
2142 }
2143
2144 bi.Coords = b.Coords;
2145 bi.Volume = b.Volume;
2146 bi.sizeZ = b.sizeZ;
2147 bi.sizeC = b.sizeC;
2148 bi.sizeT = b.sizeT;
2149 bi.series = b.series;
2150 bi.seriesCount = b.seriesCount;
2151 bi.frameInterval = b.frameInterval;
2152 bi.littleEndian = b.littleEndian;
2153 bi.isGroup = b.isGroup;
2154 bi.imageInfo = b.imageInfo;
2155 bi.bitsPerPixel = b.bitsPerPixel;
2156 bi.Resolutions = b.Resolutions;
2157 bi.Coordinate = b.Coordinate;
2158 bi.file = b.file;
2159 bi.Filename = b.Filename;
2160 bi.ID = Images.GetImageName(b.file);
2161 bi.statistics = b.statistics;
2162 return bi;
2163 }

Referenced by BioImager.BioImage.Bake(), BioImager.BioImage.ImagesToStack(), BioImager.BioImage.MergeT(), BioImager.BioImage.MergeZ(), and BioImager.BioImage.Substack().

◆ Dispose()

void BioImager.BioImage.Dispose ( )

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

Definition at line 8126 of file Bio.cs.

8127 {
8128 for (int i = 0; i < Buffers.Count; i++)
8129 {
8130 Buffers[i].Dispose();
8131 }
8132 for (int i = 0; i < Annotations.Count; i++)
8133 {
8134 if (Annotations[i].roiMask!=null)
8135 Annotations[i].roiMask.Dispose();
8136 }
8137 }

◆ ExportROIFolder()

static void BioImager.BioImage.ExportROIFolder ( string  path,
string  filename 
)
static

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

Definition at line 7927 of file Bio.cs.

7928 {
7929 if (!OMESupport())
7930 return;
7931 string[] fs = Directory.GetFiles(path);
7932 int i = 0;
7933 foreach (string f in fs)
7934 {
7935 List<ROI> annotations = OpenOMEROIs(f, 0);
7936 string ff = Path.GetFileNameWithoutExtension(f);
7937 ExportROIsCSV(path + "//" + ff + "-" + i.ToString() + ".csv", annotations);
7938 i++;
7939 }
7940 }
static void ExportROIsCSV(string filename, List< ROI > Annotations)
Definition: Bio.cs:7896
static List< ROI > OpenOMEROIs(string file, int series)
Definition: Bio.cs:7347
static bool OMESupport()
Definition: Bio.cs:7268

References BioImager.BioImage.ExportROIsCSV(), BioImager.BioImage.OMESupport(), and BioImager.BioImage.OpenOMEROIs().

◆ ExportROIsCSV()

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

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

Definition at line 7896 of file Bio.cs.

7897 {
7898 string con = columns;
7899 con += ROIsToString(Annotations);
7900 File.WriteAllText(filename, con);
7901 }
static string ROIsToString(List< ROI > Annotations)
Definition: Bio.cs:7697

References BioImager.BioImage.ROIsToString().

Referenced by BioImager.BioImage.ExportROIFolder(), and BioImager.BioImage.SaveSeries().

◆ ExtractRegionFromTiledTiff()

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

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.

Definition at line 5812 of file Bio.cs.

5813 {
5814 try
5815 {
5816 NetVips.Image subImage = b.vipPages[res].Crop(x, y, width, height);
5817 if (b.vipPages[res].Format == Enums.BandFormat.Uchar)
5818 {
5819 Bitmap bm;
5820 byte[] imageData = subImage.WriteToMemory();
5821 if (b.Resolutions[res].RGBChannelsCount == 3)
5822 bm = new Bitmap(b.file,width, height, PixelFormat.Format24bppRgb, imageData, new ZCT(), 0, null, b.littleEndian);
5823 else
5824 bm = new Bitmap(b.file, width, height, PixelFormat.Format8bppIndexed, imageData, new ZCT(), 0, null, b.littleEndian);
5825 return bm;
5826
5827 }
5828 else if (b.vipPages[res].Format == Enums.BandFormat.Ushort)
5829 {
5830 Bitmap bm;
5831 byte[] imageData = subImage.WriteToMemory();
5832 if (b.Resolutions[res].RGBChannelsCount == 3)
5833 bm = new Bitmap(b.file, width, height, PixelFormat.Format48bppRgb, imageData, new ZCT(), 0, null, b.littleEndian);
5834 else
5835 bm = new Bitmap(b.file, width, height, PixelFormat.Format16bppGrayScale, imageData, new ZCT(), 0, null, b.littleEndian);
5836 return bm;
5837 }
5838 }
5839 catch (Exception ex)
5840 {
5841 Console.WriteLine($"Error: {ex.Message}");
5842 return null;
5843 }
5844 return null;
5845 }

Referenced by BioImager.BioImage.GetTile().

◆ FilesToStack()

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

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.

Definition at line 5716 of file Bio.cs.

5717 {
5718 BioImage b = new BioImage(files[0]);
5719 for (int i = 0; i < files.Length; i++)
5720 {
5721 BioImage bb = OpenFile(files[i], false);
5722 b.Buffers.AddRange(bb.Buffers);
5723 }
5724 b.UpdateCoords(sizeZ, sizeC, sizeT);
5725 Images.AddImage(b, true);
5726 return b;
5727 }
static BioImage OpenFile(string file)
Definition: Bio.cs:4644

References BioImager.BioImage.OpenFile(), and BioImager.BioImage.UpdateCoords().

◆ FindFocus()

static int BioImager.BioImage.FindFocus ( BioImage  im,
int  Channel,
int  Time 
)
static

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.

Definition at line 8067 of file Bio.cs.

8068 {
8069 long mf = 0;
8070 int fr = 0;
8071 List<double> dt = new List<double>();
8072 ZCT c = new ZCT(0, 0, 0);
8073 for (int i = 0; i < im.SizeZ; i++)
8074 {
8075 long f = CalculateFocusQuality(im.Buffers[im.Coords[i, Channel, Time]]);
8076 dt.Add(f);
8077 if (f > mf)
8078 {
8079 mf = f;
8080 fr = im.Coords[i, Channel, Time];
8081 }
8082 }
8083 //Plot pl = Plot.Create(dt.ToArray(), "Focus");
8084 //pl.Show();
8085 return fr;
8086 }
static long CalculateFocusQuality(Bitmap b)
Definition: Bio.cs:8094

References BioImager.BioImage.CalculateFocusQuality().

◆ FolderToStack()

static BioImage BioImager.BioImage.FolderToStack ( string  path,
bool  tab 
)
static

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.

Definition at line 5733 of file Bio.cs.

5734 {
5735 string[] files = Directory.GetFiles(path);
5736 BioImage b = new BioImage(files[0]);
5737 int z = 0;
5738 int c = 0;
5739 int t = 0;
5740 BioImage bb = null;
5741 for (int i = 0; i < files.Length; i++)
5742 {
5743 string[] st = files[i].Split('_');
5744 if (st.Length > 3)
5745 {
5746 z = int.Parse(st[1].Replace("Z", ""));
5747 c = int.Parse(st[2].Replace("C", ""));
5748 t = int.Parse(st[3].Replace("T", ""));
5749 }
5750 bb = OpenFile(files[i], tab);
5751 b.Buffers.AddRange(bb.Buffers);
5752 }
5753 if (z == 0)
5754 {
5755 /*TO DO
5756 ImagesToStack im = new ImagesToStack();
5757 if (im.ShowDialog() != DialogResult.OK)
5758 return null;
5759 b.UpdateCoords(im.SizeZ, im.SizeC, im.SizeT);
5760 */
5761 }
5762 else
5763 b.UpdateCoords(z + 1, c + 1, t + 1);
5764 Images.AddImage(b, tab);
5765 Recorder.AddLine("BioImage.FolderToStack(\"" + path + "\");");
5766 return b;
5767 }

References BioImager.BioImage.OpenFile(), and BioImager.BioImage.UpdateCoords().

◆ GetAnnotations() [1/2]

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

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.

Definition at line 4456 of file Bio.cs.

4457 {
4458 List<ROI> annotations = new List<ROI>();
4459 foreach (ROI an in Annotations)
4460 {
4461 if (an.coord.Z == Z && an.coord.Z == Z && an.coord.C == C && an.coord.T == T)
4462 annotations.Add(an);
4463 }
4464 return annotations;
4465 }

◆ GetAnnotations() [2/2]

List< ROI > BioImager.BioImage.GetAnnotations ( ZCT  coord)

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.

Definition at line 4436 of file Bio.cs.

4437 {
4438 List<ROI> annotations = new List<ROI>();
4439 foreach (ROI an in Annotations)
4440 {
4441 if (an == null)
4442 continue;
4443 if (an.coord == coord)
4444 annotations.Add(an);
4445 }
4446 return annotations;
4447 }

Referenced by BioImager.BioImage.MergeChannels().

◆ GetBands()

static int BioImager.BioImage.GetBands ( PixelFormat  format)
static

Definition at line 5525 of file Bio.cs.

5526 {
5527 switch (format)
5528 {
5529 case AForge.PixelFormat.Format8bppIndexed: return 1;
5530 case AForge.PixelFormat.Format16bppGrayScale: return 1;
5531 case AForge.PixelFormat.Format24bppRgb: return 3;
5532 case AForge.PixelFormat.Format32bppArgb:
5533 case AForge.PixelFormat.Format32bppPArgb:
5534 case AForge.PixelFormat.Format32bppRgb:
5535 return 4;
5536 case AForge.PixelFormat.Format48bppRgb:
5537 return 3;
5538 default:
5539 throw new NotSupportedException($"Unsupported pixel format: {format}");
5540 }
5541 }

◆ GetBitmap() [1/2]

Bitmap BioImager.BioImage.GetBitmap ( int  z,
int  c,
int  t 
)

"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.

Definition at line 3914 of file Bio.cs.

3915 {
3916 return Buffers[Coords[z, c, t]];
3917 }

◆ GetBitmap() [2/2]

Bitmap BioImager.BioImage.GetBitmap ( ZCT  coord)

‍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.

Definition at line 4138 of file Bio.cs.

4139 {
4140 return (Bitmap)GetImageByCoord(coord.Z, coord.C, coord.T);
4141 }
Bitmap GetImageByCoord(int z, int c, int t)
Definition: Bio.cs:3901

References BioImager.BioImage.GetImageByCoord().

◆ GetBitmapRGB()

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

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.

Definition at line 4270 of file Bio.cs.

4271 {
4272 if (px == PixelFormat.Format32bppArgb)
4273 {
4274 //opening a 8 bit per pixel jpg image
4275 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4276 //creating the bitmapdata and lock bits
4277 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4278 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4279 //iterating through all the pixels in y direction
4280 for (int y = 0; y < h; y++)
4281 {
4282 //getting the pixels of current row
4283 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4284 int rowRGB = y * w * 4;
4285 //iterating through all the pixels in x direction
4286 for (int x = 0; x < w; x++)
4287 {
4288 int indexRGB = x * 4;
4289 int indexRGBA = x * 4;
4290 row[indexRGBA + 3] = bts[rowRGB + indexRGB + 3];//byte A
4291 row[indexRGBA + 2] = bts[rowRGB + indexRGB + 2];//byte R
4292 row[indexRGBA + 1] = bts[rowRGB + indexRGB + 1];//byte G
4293 row[indexRGBA] = bts[rowRGB + indexRGB];//byte B
4294 }
4295 }
4296 //unlocking bits and disposing image
4297 bmp.UnlockBits(bmd);
4298 return bmp;
4299 }
4300 else if (px == PixelFormat.Format24bppRgb)
4301 {
4302 //opening a 8 bit per pixel jpg image
4303 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4304 //creating the bitmapdata and lock bits
4305 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4306 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4307 //iterating through all the pixels in y direction
4308 for (int y = 0; y < h; y++)
4309 {
4310 //getting the pixels of current row
4311 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4312 int rowRGB = y * w * 3;
4313 //iterating through all the pixels in x direction
4314 for (int x = 0; x < w; x++)
4315 {
4316 int indexRGB = x * 3;
4317 int indexRGBA = x * 4;
4318 row[indexRGBA + 3] = byte.MaxValue;//byte A
4319 row[indexRGBA + 2] = bts[rowRGB + indexRGB + 2];//byte R
4320 row[indexRGBA + 1] = bts[rowRGB + indexRGB + 1];//byte G
4321 row[indexRGBA] = bts[rowRGB + indexRGB];//byte B
4322 }
4323 }
4324 //unlocking bits and disposing image
4325 bmp.UnlockBits(bmd);
4326 return bmp;
4327 }
4328 else
4329 if (px == PixelFormat.Format48bppRgb)
4330 {
4331 //opening a 8 bit per pixel jpg image
4332 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4333 //creating the bitmapdata and lock bits
4334 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4335 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4336 unsafe
4337 {
4338 //iterating through all the pixels in y direction
4339 for (int y = 0; y < h; y++)
4340 {
4341 //getting the pixels of current row
4342 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4343 int rowRGB = y * w * 6;
4344 //iterating through all the pixels in x direction
4345 for (int x = 0; x < w; x++)
4346 {
4347 int indexRGB = x * 6;
4348 int indexRGBA = x * 4;
4349 int b = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB) / 255);
4350 int g = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB + 2) / 255);
4351 int r = (int)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB + 4) / 255);
4352 row[indexRGBA + 3] = 255;//byte A
4353 row[indexRGBA + 2] = (byte)(b);//byte R
4354 row[indexRGBA + 1] = (byte)(g);//byte G
4355 row[indexRGBA] = (byte)(r);//byte B
4356 }
4357 }
4358 }
4359 bmp.UnlockBits(bmd);
4360 return bmp;
4361 }
4362 else
4363 if (px == PixelFormat.Format8bppIndexed)
4364 {
4365 //opening a 8 bit per pixel jpg image
4366 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4367 //creating the bitmapdata and lock bits
4368 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4369 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4370 unsafe
4371 {
4372 //iterating through all the pixels in y direction
4373 for (int y = 0; y < h; y++)
4374 {
4375 //getting the pixels of current row
4376 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4377 int rowRGB = y * w;
4378 //iterating through all the pixels in x direction
4379 for (int x = 0; x < w; x++)
4380 {
4381 int indexRGB = x;
4382 int indexRGBA = x * 4;
4383 byte b = bts[rowRGB + indexRGB];
4384 row[indexRGBA + 3] = 255;//byte A
4385 row[indexRGBA + 2] = (byte)(b);//byte R
4386 row[indexRGBA + 1] = (byte)(b);//byte G
4387 row[indexRGBA] = (byte)(b);//byte B
4388 }
4389 }
4390 }
4391 bmp.UnlockBits(bmd);
4392 return bmp;
4393 }
4394 else
4395 if (px == PixelFormat.Format16bppGrayScale)
4396 {
4397 //opening a 8 bit per pixel jpg image
4398 Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
4399 //creating the bitmapdata and lock bits
4400 AForge.Rectangle rec = new AForge.Rectangle(0, 0, w, h);
4401 BitmapData bmd = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
4402 unsafe
4403 {
4404 //iterating through all the pixels in y direction
4405 for (int y = 0; y < h; y++)
4406 {
4407 //getting the pixels of current row
4408 byte* row = (byte*)bmd.Scan0 + (y * bmd.Stride);
4409 int rowRGB = y * w * 2;
4410 //iterating through all the pixels in x direction
4411 for (int x = 0; x < w; x++)
4412 {
4413 int indexRGB = x * 2;
4414 int indexRGBA = x * 4;
4415 ushort b = (ushort)((float)BitConverter.ToUInt16(bts, rowRGB + indexRGB) / 255);
4416 row[indexRGBA + 3] = 255;//byte A
4417 row[indexRGBA + 2] = (byte)(b);//byte R
4418 row[indexRGBA + 1] = (byte)(b);//byte G
4419 row[indexRGBA] = (byte)(b);//byte B
4420 }
4421 }
4422 }
4423 bmp.UnlockBits(bmd);
4424 return bmp;
4425 }
4426
4427 throw new NotSupportedException("Pixelformat " + px + " is not supported.");
4428 }

◆ GetBitMaxValue()

static int BioImager.BioImage.GetBitMaxValue ( int  bt)
static

It returns the maximum value of a bit.

Parameters
btbit depth
Returns
The maximum value of a bit.

Definition at line 6908 of file Bio.cs.

6909 {
6910 if (bt == 8)
6911 return 255;
6912 if (bt == 9)
6913 return 512;
6914 else if (bt == 10)
6915 return 1023;
6916 else if (bt == 11)
6917 return 2047;
6918 else if (bt == 12)
6919 return 4095;
6920 else if (bt == 13)
6921 return 8191;
6922 else if (bt == 14)
6923 return 16383;
6924 else if (bt == 15)
6925 return 32767;
6926 else
6927 return 65535;
6928 }

◆ GetBitsPerPixel()

static int BioImager.BioImage.GetBitsPerPixel ( int  bt)
static

‍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.

Definition at line 6882 of file Bio.cs.

6883 {
6884 if (bt <= 255)
6885 return 8;
6886 if (bt <= 512)
6887 return 9;
6888 else if (bt <= 1023)
6889 return 10;
6890 else if (bt <= 2047)
6891 return 11;
6892 else if (bt <= 4095)
6893 return 12;
6894 else if (bt <= 8191)
6895 return 13;
6896 else if (bt <= 16383)
6897 return 14;
6898 else if (bt <= 32767)
6899 return 15;
6900 else
6901 return 16;
6902 }

◆ GetChannelImage()

UnmanagedImage BioImager.BioImage.GetChannelImage ( int  ind,
short  s 
)

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

Parameters
indthe index of the buffer
s0, 1, 2

Definition at line 4185 of file Bio.cs.

4186 {
4187 Bitmap bf = Buffers[ind];
4188 if (bf.isRGB)
4189 {
4190 if (s == 0)
4191 return extractR.Apply(Buffers[ind].Image);
4192 else
4193 if (s == 1)
4194 return extractG.Apply(Buffers[ind].Image);
4195 else
4196 return extractB.Apply(Buffers[ind].Image);
4197 }
4198 else
4199 throw new InvalidOperationException();
4200 }

◆ GetEmission()

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

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.

Definition at line 4210 of file Bio.cs.

4211 {
4212 if (RGBChannelCount == 1)
4213 {
4214 Bitmap[] bs = new Bitmap[Channels.Count];
4215 for (int c = 0; c < Channels.Count; c++)
4216 {
4217 int index = Coords[coord.Z, c, coord.T];
4218 bs[c] = Buffers[index];
4219 }
4220 Bitmap bm = (Bitmap)Bitmap.GetEmissionBitmap(bs, Channels.ToArray());
4221 return bm;
4222 }
4223 else
4224 {
4225 int index = Coords[coord.Z, coord.C, coord.T];
4226 return Buffers[index];
4227 }
4228 }

Referenced by BioImager.ImageView.UpdateImages().

◆ GetFiltered() [1/2]

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

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.

Definition at line 4163 of file Bio.cs.

4164 {
4165 if (Buffers[ind].BitsPerPixel > 8)
4166 {
4167 BioImage.filter16.InRed = r;
4168 BioImage.filter16.InGreen = g;
4169 BioImage.filter16.InBlue = b;
4170 return BioImage.filter16.Apply(Buffers[ind]);
4171 }
4172 else
4173 {
4174 // set ranges
4175 BioImage.filter8.InRed = r;
4176 BioImage.filter8.InGreen = g;
4177 BioImage.filter8.InBlue = b;
4178 return BioImage.filter8.Apply(Buffers[ind]);
4179 }
4180 }

◆ GetFiltered() [2/2]

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

‍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.

Definition at line 4150 of file Bio.cs.

4151 {
4152 int index = Coords[coord.Z, coord.C, coord.T];
4153 return GetFiltered(index, r, g, b);
4154 }

References BioImager.BioImage.GetFiltered().

Referenced by BioImager.BioImage.Bake(), BioImager.BioImage.GetFiltered(), and BioImager.ImageView.UpdateImages().

◆ GetImageByCoord()

Bitmap BioImager.BioImage.GetImageByCoord ( int  z,
int  c,
int  t 
)

‍Get the image at the specified coordinates

Parameters
zthe z-stack index
cchannel
ttime
Returns
A Bitmap object.

Definition at line 3901 of file Bio.cs.

3902 {
3903 return Buffers[Coords[z, c, t]];
3904 }

Referenced by BioImager.BioImage.GetBitmap().

◆ GetIndex()

int BioImager.BioImage.GetIndex ( int  ix,
int  iy 
)

‍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.

The stridex and stridey are the same for a square image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The stridex and stridey are different for a rectangular image.

The

Parameters
ixx coordinate of the pixel
iyThe y coordinate of the pixel
Returns
The index of the pixel in the array.

Definition at line 3948 of file Bio.cs.

3949 {
3950 if (ix > SizeX || iy > SizeY || ix < 0 || iy < 0)
3951 return 0;
3952 int stridex = SizeX;
3953 int x = ix;
3954 int y = iy;
3955 if (bitsPerPixel > 8)
3956 {
3957 return (y * stridex + x) * 2;
3958 }
3959 else
3960 {
3961 return (y * stridex + x);
3962 }
3963 }

◆ GetIndexRGB()

int BioImager.BioImage.GetIndexRGB ( int  ix,
int  iy,
int  index 
)

‍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.

Definition at line 3971 of file Bio.cs.

3972 {
3973 int stridex = SizeX;
3974 //For 16bit (2*8bit) images we multiply buffer index by 2
3975 int x = ix;
3976 int y = iy;
3977 if (bitsPerPixel > 8)
3978 {
3979 return (y * stridex + x) * 2 * index;
3980 }
3981 else
3982 {
3983 return (y * stridex + x) * index;
3984 }
3985 }

◆ GetLevelDownsample()

double BioImager.BioImage.GetLevelDownsample ( int  level)

Get the downsampling factor of a given level.

Parameters
levelThe desired level.

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

Exceptions
OpenSlideException

Definition at line 2578 of file Bio.cs.

2579 {
2580 int originalWidth = Resolutions[0].SizeX; // Width of the original level
2581 int nextLevelWidth = Resolutions[level].SizeX; // Width of the next level (downsampled)
2582 return (double)originalWidth / (double)nextLevelWidth;
2583 }

Referenced by BioImager.BioImage.GetUnitPerPixel(), and BioImager.BioImage.LevelFromResolution().

◆ GetPixelFormat() [1/2]

static PixelFormat BioImager.BioImage.GetPixelFormat ( int  rgbChannelCount,
int  bitsPerPixel 
)
static

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.

Definition at line 6938 of file Bio.cs.

6939 {
6940 if (bitsPerPixel == 8)
6941 {
6942 if (rgbChannelCount == 1)
6943 return PixelFormat.Format8bppIndexed;
6944 else if (rgbChannelCount == 3)
6945 return PixelFormat.Format24bppRgb;
6946 else if (rgbChannelCount == 4)
6947 return PixelFormat.Format32bppArgb;
6948 }
6949 else
6950 {
6951 if (rgbChannelCount == 1)
6952 return PixelFormat.Format16bppGrayScale;
6953 if (rgbChannelCount == 3)
6954 return PixelFormat.Format48bppRgb;
6955 }
6956 throw new NotSupportedException("Not supported pixel format.");
6957 }

Referenced by BioImager.BioImage.OpenOME().

◆ GetPixelFormat() [2/2]

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

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.

Definition at line 6968 of file Bio.cs.

6969 {
6970 if (rgbChannelCount == 1)
6971 {
6972 if (px == ome.xml.model.enums.PixelType.INT8 || px == ome.xml.model.enums.PixelType.UINT8)
6973 return PixelFormat.Format8bppIndexed;
6974 else if (px == ome.xml.model.enums.PixelType.INT16 || px == ome.xml.model.enums.PixelType.UINT16)
6975 return PixelFormat.Format16bppGrayScale;
6976 }
6977 else
6978 {
6979 if (px == ome.xml.model.enums.PixelType.INT8 || px == ome.xml.model.enums.PixelType.UINT8)
6980 return PixelFormat.Format24bppRgb;
6981 else if (px == ome.xml.model.enums.PixelType.INT16 || px == ome.xml.model.enums.PixelType.UINT16)
6982 return PixelFormat.Format48bppRgb;
6983 }
6984 throw new NotSupportedException("Not supported pixel format.");
6985 }

◆ GetRGBBitmap()

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

‍Get the RGB bitmap for the specified ZCT coordinate

Parameters
ZCTZ, C, T coordinates
IntRange
IntRange
IntRange
Returns
A Bitmap object.

Definition at line 4237 of file Bio.cs.

4238 {
4239 int index = Coords[coord.Z, coord.C, coord.T];
4240 if (Buffers[0].RGBChannelsCount == 1)
4241 {
4242 if (Channels.Count >= 3)
4243 {
4244 Bitmap[] bs = new Bitmap[3];
4245 bs[2] = Buffers[index + RChannel.Index];
4246 bs[1] = Buffers[index + GChannel.Index];
4247 bs[0] = Buffers[index + BChannel.Index];
4248 return Bitmap.GetRGBBitmap(bs, rf, gf, bf);
4249 }
4250 else
4251 {
4252 Bitmap[] bs = new Bitmap[3];
4253 bs[2] = Buffers[index + RChannel.Index];
4254 bs[1] = Buffers[index + RChannel.Index + 1];
4255 bs[0] = Buffers[index + RChannel.Index + 2];
4256 return Bitmap.GetRGBBitmap(bs, rf, gf, bf);
4257 }
4258 }
4259 else
4260 return Buffers[index];
4261 }

Referenced by BioImager.ImageView.UpdateImages().

◆ GetTile() [1/2]

static Bitmap BioImager.BioImage.GetTile ( BioImage  b,
int  i,
int  serie,
int  tilex,
int  tiley,
int  tileSizeX,
int  tileSizeY 
)
static

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.
ithe Z, C, T image index
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.

Definition at line 6764 of file Bio.cs.

6765 {
6766 if ((b.file.EndsWith("ome.tif") && vips) || (b.file.EndsWith(".tif") && vips))
6767 {
6768 //We can get a tile faster with libvips rather than bioformats.
6769 return ExtractRegionFromTiledTiff(b, tilex, tiley, tileSizeX, tileSizeY, serie);
6770 }
6771 //We check if we can open this with OpenSlide as this is faster than Bioformats with IKVM.
6772 if (b.openSlideImage != null)
6773 {
6774 return new Bitmap(tileSizeX, tileSizeY, AForge.PixelFormat.Format32bppArgb, b.openSlideImage.ReadRegion(serie, tilex, tiley, tileSizeX, tileSizeY), new ZCT(), "");
6775 }
6776
6777 string curfile = reader.getCurrentFile();
6778 if (curfile == null)
6779 {
6780 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
6781 reader.close();
6782 reader.setMetadataStore(b.meta);
6783 Console.WriteLine(b.file);
6784 reader.setId(b.file);
6785 }
6786 else
6787 {
6788 string fi = b.file.Replace("\\", "/");
6789 string cf = curfile.Replace("\\", "/");
6790 if (cf != fi)
6791 {
6792 reader.close();
6793 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
6794 reader.setMetadataStore(b.meta);
6795 reader.setId(b.file);
6796 }
6797 }
6798 if (reader.getSeries() != serie)
6799 reader.setSeries(serie);
6800 int SizeX = reader.getSizeX();
6801 int SizeY = reader.getSizeY();
6802 bool flat = reader.hasFlattenedResolutions();
6803 bool littleEndian = reader.isLittleEndian();
6804 PixelFormat PixelFormat = b.Resolutions[serie].PixelFormat;
6805 if (tilex < 0)
6806 tilex = 0;
6807 if (tiley < 0)
6808 tiley = 0;
6809 if (tilex >= SizeX)
6810 tilex = SizeX;
6811 if (tiley >= SizeY)
6812 tiley = SizeY;
6813 int sx = tileSizeX;
6814 if (tilex + tileSizeX > SizeX)
6815 sx -= (tilex + tileSizeX) - (SizeX);
6816 int sy = tileSizeY;
6817 if (tiley + tileSizeY > SizeY)
6818 sy -= (tiley + tileSizeY) - (SizeY);
6819 //For some reason calling openBytes with 1x1px area causes an exception.
6820 if (sx <= 1)
6821 return null;
6822 if (sy <= 1)
6823 return null;
6824 try
6825 {
6826 byte[] bytesr = reader.openBytes(i, tilex, tiley, sx, sy);
6827 bool interleaved = reader.isInterleaved();
6828 if (bm != null)
6829 bm.Dispose();
6830 bm = new Bitmap(b.file, sx, sy, PixelFormat, bytesr, new ZCT(), i, null, littleEndian, interleaved);
6831 return bm;
6832 }
6833 catch (Exception e)
6834 {
6835 Console.WriteLine(e.Message);
6836 return null;
6837 }
6838 }
static Bitmap ExtractRegionFromTiledTiff(BioImage b, int x, int y, int width, int height, int res)
Definition: Bio.cs:5812

References BioImager.BioImage.ExtractRegionFromTiledTiff().

◆ GetTile() [2/2]

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

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.

Definition at line 6678 of file Bio.cs.

6679 {
6680 if ((b.file.EndsWith("ome.tif") && vips) || (b.file.EndsWith(".tif") && vips))
6681 {
6682 //We can get a tile faster with libvips rather than bioformats.
6683 return ExtractRegionFromTiledTiff(b, tilex, tiley, tileSizeX, tileSizeY, serie);
6684 }
6685 //We check if we can open this with OpenSlide as this is faster than Bioformats with IKVM.
6686 if (b.openSlideImage != null)
6687 {
6688 return new Bitmap(tileSizeX, tileSizeY, AForge.PixelFormat.Format32bppArgb, b.openSlideImage.ReadRegion(serie, tilex, tiley, tileSizeX, tileSizeY), coord, "");
6689 }
6690
6691 string curfile = reader.getCurrentFile();
6692 if (curfile == null)
6693 {
6694 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
6695 reader.close();
6696 reader.setMetadataStore(b.meta);
6697 Console.WriteLine(b.file);
6698 reader.setId(b.file);
6699 }
6700 else
6701 {
6702 string fi = b.file.Replace("\\", "/");
6703 string cf = curfile.Replace("\\", "/");
6704 if (cf != fi)
6705 {
6706 reader.close();
6707 b.meta = (IMetadata)((OMEXMLService)factory.getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
6708 reader.setMetadataStore(b.meta);
6709 reader.setId(b.file);
6710 }
6711 }
6712 if (reader.getSeries() != serie)
6713 reader.setSeries(serie);
6714 int SizeX = reader.getSizeX();
6715 int SizeY = reader.getSizeY();
6716 bool flat = reader.hasFlattenedResolutions();
6717 int p = b.Coords[coord.Z, coord.C, coord.T];
6718 bool littleEndian = reader.isLittleEndian();
6719 PixelFormat PixelFormat = b.Resolutions[serie].PixelFormat;
6720 if (tilex < 0)
6721 tilex = 0;
6722 if (tiley < 0)
6723 tiley = 0;
6724 if (tilex >= SizeX)
6725 tilex = SizeX;
6726 if (tiley >= SizeY)
6727 tiley = SizeY;
6728 int sx = tileSizeX;
6729 if (tilex + tileSizeX > SizeX)
6730 sx -= (tilex + tileSizeX) - (SizeX);
6731 int sy = tileSizeY;
6732 if (tiley + tileSizeY > SizeY)
6733 sy -= (tiley + tileSizeY) - (SizeY);
6734 //For some reason calling openBytes with 1x1px area causes an exception.
6735 if (sx <= 1)
6736 return null;
6737 if (sy <= 1)
6738 return null;
6739 try
6740 {
6741 byte[] bytesr = reader.openBytes(b.Coords[coord.Z, coord.C, coord.T], tilex, tiley, sx, sy);
6742 bool interleaved = reader.isInterleaved();
6743 bm = new Bitmap(b.file, sx, sy, PixelFormat, bytesr, coord, p, null, littleEndian, interleaved);
6744 return bm;
6745 }
6746 catch (Exception e)
6747 {
6748 Console.WriteLine(e.Message);
6749 return null;
6750 }
6751 }

References BioImager.BioImage.ExtractRegionFromTiledTiff().

Referenced by BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenOME(), BioImager.SlideImage.ReadRegion(), and BioImager.SlideImage.TryReadRegion().

◆ GetUnitPerPixel()

double BioImager.BioImage.GetUnitPerPixel ( int  level)

Get Unit Per Pixel for pyramidal images.

Parameters
level
Returns

Definition at line 2617 of file Bio.cs.

2618 {
2619 return Resolutions[0].PhysicalSizeX * GetLevelDownsample(level);
2620 }
double GetLevelDownsample(int level)
Get the downsampling factor of a given level.
Definition: Bio.cs:2578

References BioImager.BioImage.GetLevelDownsample().

Referenced by BioImager.ImageView.GoToImage().

◆ GetValue() [1/3]

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

‍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.

Definition at line 4056 of file Bio.cs.

4057 {
4058 return GetValue(new ZCTXY(z, c, t, x, y));
4059 }
ushort GetValue(ZCTXY coord)
Definition: Bio.cs:3992

References BioImager.BioImage.GetValue().

◆ GetValue() [2/3]

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

‍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.

Definition at line 4043 of file Bio.cs.

4044 {
4045 return GetValueRGB(new ZCTXY(coord.Z, coord.C, coord.T, x, y), 0);
4046 }
ushort GetValueRGB(ZCTXY coord, int index)
Definition: Bio.cs:4017

References BioImager.BioImage.GetValueRGB().

◆ GetValue() [3/3]

ushort BioImager.BioImage.GetValue ( ZCTXY  coord)

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.

Definition at line 3992 of file Bio.cs.

3993 {
3994 if (coord.X < 0 || coord.Y < 0 || coord.X > SizeX || coord.Y > SizeY)
3995 {
3996 return 0;
3997 }
3998 if (isRGB)
3999 {
4000 if (coord.C == 0)
4001 return GetValueRGB(coord, 0);
4002 else if (coord.C == 1)
4003 return GetValueRGB(coord, 1);
4004 else if (coord.C == 2)
4005 return GetValueRGB(coord, 2);
4006 }
4007 else
4008 return GetValueRGB(coord, 0);
4009 return 0;
4010 }

References BioImager.BioImage.GetValueRGB().

Referenced by BioImager.BioImage.GetValue(), and BioImager.BioImage.GetValueRGB().

◆ GetValueRGB() [1/3]

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

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.

Definition at line 4089 of file Bio.cs.

4090 {
4091 return GetValueRGB(new ZCT(z, c, t), x, y, RGBindex);
4092 }

References BioImager.BioImage.GetValueRGB().

◆ GetValueRGB() [2/3]

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

‍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.

Definition at line 4068 of file Bio.cs.

4069 {
4070 ZCTXY c = new ZCTXY(coord.Z, coord.C, coord.T, x, y);
4071 if (isRGB)
4072 {
4073 return GetValueRGB(c, RGBindex);
4074 }
4075 else
4076 return GetValue(coord, x, y);
4077 }

References BioImager.BioImage.GetValue(), and BioImager.BioImage.GetValueRGB().

◆ GetValueRGB() [3/3]

ushort BioImager.BioImage.GetValueRGB ( ZCTXY  coord,
int  index 
)

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.

Definition at line 4017 of file Bio.cs.

4018 {
4019 int ind = 0;
4020 if (coord.C >= SizeC)
4021 {
4022 coord.C = 0;
4023 }
4024 ind = Coords[coord.Z, coord.C, coord.T];
4025 ColorS c = Buffers[ind].GetPixel(coord.X, coord.Y);
4026 if (index == 0)
4027 return c.R;
4028 else
4029 if (index == 1)
4030 return c.G;
4031 else
4032 if (index == 2)
4033 return c.B;
4034 throw new IndexOutOfRangeException();
4035 }

Referenced by BioImager.BioImage.GetValue(), and BioImager.BioImage.GetValueRGB().

◆ ImagesToStack()

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

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.

Definition at line 7199 of file Bio.cs.

7200 {
7201 BioImage[] bs = new BioImage[files.Length];
7202 int z = 0;
7203 int c = 0;
7204 int t = 0;
7205 for (int i = 0; i < files.Length; i++)
7206 {
7207 string str = Path.GetFileNameWithoutExtension(files[i]);
7208 str = str.Replace(".ome", "");
7209 string[] st = str.Split('_');
7210 if (st.Length > 3)
7211 {
7212 z = int.Parse(st[1].Replace("Z", ""));
7213 c = int.Parse(st[2].Replace("C", ""));
7214 t = int.Parse(st[3].Replace("T", ""));
7215 }
7216 if (i == 0)
7217 bs[0] = OpenOME(files[i], tab);
7218 else
7219 {
7220 bs[i] = OpenFile(files[i], 0, tab, false);
7221 }
7222 }
7223 BioImage b = BioImage.CopyInfo(bs[0], true, true);
7224 for (int i = 0; i < files.Length; i++)
7225 {
7226 for (int bc = 0; bc < bs[i].Buffers.Count; bc++)
7227 {
7228 b.Buffers.Add(bs[i].Buffers[bc]);
7229 }
7230 }
7231 b.UpdateCoords(z + 1, c + 1, t + 1);
7232 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));
7233 return b;
7234 }
static BioImage OpenOME(string file, bool tab)
Definition: Bio.cs:5684

References BioImager.BioImage.CopyInfo(), BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenOME(), and BioImager.BioImage.UpdateCoords().

◆ ImportROIsCSV()

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

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.

Definition at line 7907 of file Bio.cs.

7908 {
7909 List<ROI> list = new List<ROI>();
7910 if (!File.Exists(filename))
7911 return list;
7912 string[] sts = File.ReadAllLines(filename);
7913 //We start reading from line 1.
7914 for (int i = 1; i < sts.Length; i++)
7915 {
7916 list.Add(StringToROI(sts[i]));
7917 }
7918 return list;
7919 }
static ROI StringToROI(string sts)
Definition: Bio.cs:7737

References BioImager.BioImage.StringToROI().

Referenced by BioImager.BioImage.OpenFile().

◆ Initialize()

static void BioImager.BioImage.Initialize ( )
static

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

Definition at line 4470 of file Bio.cs.

4471 {
4472 if (!OMESupport())
4473 return;
4474 //We initialize OME on a seperate thread so the user doesn't have to wait for initialization to
4475 //view images.
4476 System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(InitOME));
4477 t.Start();
4478 }

References BioImager.BioImage.OMESupport().

Referenced by BioImager.App.Initialize().

◆ isOME()

static bool BioImager.BioImage.isOME ( string  file)
static

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.

Definition at line 5105 of file Bio.cs.

5106 {
5107 if (file.EndsWith("ome.tif") || file.EndsWith("ome.tiff"))
5108 {
5109 return true;
5110 }
5111 if (file.EndsWith(".tif") || file.EndsWith(".TIF") || file.EndsWith("tiff") || file.EndsWith("TIFF"))
5112 {
5113 Tiff image = Tiff.Open(file, "r");
5114 string desc = "";
5115 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
5116 desc = f[0].ToString();
5117 image.Close();
5118 if (desc.Contains("OME-XML"))
5119 return true;
5120 else
5121 return false;
5122 }
5123 if (!(file.EndsWith("png") || file.EndsWith("PNG") || file.EndsWith("jpg") || file.EndsWith("JPG") ||
5124 file.EndsWith("jpeg") || file.EndsWith("JPEG") || file.EndsWith("bmp") || file.EndsWith("BMP")))
5125 {
5126 return true;
5127 }
5128 else return false;
5129 }

Referenced by BioImager.BioImage.isOMESeries(), and BioImager.BioImage.OpenFile().

◆ isOMESeries()

static bool BioImager.BioImage.isOMESeries ( string  file)
static

‍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.

Definition at line 5135 of file Bio.cs.

5136 {
5137 if (!isOME(file))
5138 return false;
5139 ImageReader reader = new ImageReader();
5140 var meta = (IMetadata)((OMEXMLService)new ServiceFactory().getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
5141 reader.setMetadataStore((MetadataStore)meta);
5142 file = file.Replace("\\", "/");
5143 reader.setId(file);
5144 bool ser = false;
5145 if (reader.getSeriesCount() > 1)
5146 ser = true;
5147 reader.close();
5148 reader = null;
5149 return ser;
5150 }
static bool isOME(string file)
Definition: Bio.cs:5105

References BioImager.BioImage.isOME().

◆ isTiffSeries()

static bool BioImager.BioImage.isTiffSeries ( string  file)
static

‍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.

Definition at line 5070 of file Bio.cs.

5071 {
5072 Tiff image = Tiff.Open(file, "r");
5073 string desc = "";
5074 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
5075 image.Close();
5076 string[] sts = desc.Split('\n');
5077 int index = 0;
5078 for (int i = 0; i < sts.Length; i++)
5079 {
5080 if (sts[i].StartsWith("-ImageInfo"))
5081 {
5082 string val = sts[i].Substring(11);
5083 val = val.Substring(0, val.IndexOf(':'));
5084 int serie = int.Parse(val);
5085 if (sts[i].Length > 10)
5086 {
5087 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
5088 ImageInfo info = JsonConvert.DeserializeObject<ImageInfo>(cht);
5089 if (info.Series > 1)
5090 return true;
5091 else
5092 return false;
5093 }
5094 }
5095 }
5096 return false;
5097 }

◆ LevelFromResolution()

int BioImager.BioImage.LevelFromResolution ( double  Resolution)

Returns the level of a given resolution.

Parameters
Resolution
Returns

Definition at line 2589 of file Bio.cs.

2590 {
2591 int l = 0;
2592 double[] ds = new double[Resolutions.Count];
2593 for (int i = 0; i < Resolutions.Count; i++)
2594 {
2595 ds[i] = Resolutions[0].PhysicalSizeX * GetLevelDownsample(i);
2596 }
2597 for (int i = 0; i < ds.Length; i++)
2598 {
2599 if (ds[i] > Resolution)
2600 {
2601 l = i;
2602 break;
2603 }
2604 }
2605 if(MacroResolution.HasValue)
2606 {
2607 return MacroResolution.Value - 1;
2608 }
2609 else
2610 return l;
2611 }

References BioImager.BioImage.GetLevelDownsample().

Referenced by BioImager.SlideSourceBase.GetSlice().

◆ MergeChannels() [1/2]

static BioImage BioImager.BioImage.MergeChannels ( BioImage  b2,
BioImage  b 
)
static

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.

Definition at line 3579 of file Bio.cs.

3580 {
3581 BioImage res = new BioImage(b2.ID);
3582 res.ID = Images.GetImageName(b2.ID);
3583 res.series = b2.series;
3584 res.sizeZ = b2.SizeZ;
3585 int cOrig = b2.SizeC;
3586 res.sizeC = b2.SizeC + b.SizeC;
3587 res.sizeT = b2.SizeT;
3588 res.bitsPerPixel = b2.bitsPerPixel;
3589 res.imageInfo = b2.imageInfo;
3590 res.littleEndian = b2.littleEndian;
3591 res.seriesCount = b2.seriesCount;
3592 res.imagesPerSeries = res.ImageCount / res.seriesCount;
3593 res.Coords = new int[res.SizeZ, res.SizeC, res.SizeT];
3594
3595 int i = 0;
3596 int cc = 0;
3597 for (int ti = 0; ti < res.SizeT; ti++)
3598 {
3599 for (int zi = 0; zi < res.SizeZ; zi++)
3600 {
3601 for (int ci = 0; ci < res.SizeC; ci++)
3602 {
3603 ZCT co = new ZCT(zi, ci, ti);
3604 if (ci < cOrig)
3605 {
3606 //If this channel is part of the image b1 we add planes from it.
3607 Bitmap copy = new Bitmap(b2.id, b2.SizeX, b2.SizeY, b2.Buffers[0].PixelFormat, b2.Buffers[i].Bytes, co, i);
3608 if (b2.littleEndian)
3609 copy.RotateFlip(AForge.RotateFlipType.Rotate180FlipNone);
3610 res.Coords[zi, ci, ti] = i;
3611 res.Buffers.Add(b2.Buffers[i]);
3612 res.Buffers.Add(copy);
3613 //Lets copy the ROI's from the original image.
3614 List<ROI> anns = b2.GetAnnotations(zi, ci, ti);
3615 if (anns.Count > 0)
3616 res.Annotations.AddRange(anns);
3617 }
3618 else
3619 {
3620 //This plane is not part of b1 so we add the planes from b2 channels.
3621 Bitmap copy = new Bitmap(b.id, b.SizeX, b.SizeY, b.Buffers[0].PixelFormat, b.Buffers[i].Bytes, co, i);
3622 if (b2.littleEndian)
3623 copy.RotateFlip(AForge.RotateFlipType.Rotate180FlipNone);
3624 res.Coords[zi, ci, ti] = i;
3625 res.Buffers.Add(b.Buffers[i]);
3626 res.Buffers.Add(copy);
3627
3628 //Lets copy the ROI's from the original image.
3629 List<ROI> anns = b.GetAnnotations(zi, cc, ti);
3630 if (anns.Count > 0)
3631 res.Annotations.AddRange(anns);
3632 }
3633 i++;
3634 }
3635 }
3636 }
3637 for (int ci = 0; ci < res.SizeC; ci++)
3638 {
3639 if (ci < cOrig)
3640 {
3641 res.Channels.Add(b2.Channels[ci].Copy());
3642 }
3643 else
3644 {
3645 res.Channels.Add(b.Channels[cc].Copy());
3646 res.Channels[cOrig + cc].Index = ci;
3647 cc++;
3648 }
3649 }
3650 Images.AddImage(res, true);
3651 //We wait for threshold image statistics calculation
3652 do
3653 {
3654 Thread.Sleep(100);
3655 } while (res.Buffers[res.Buffers.Count - 1].Stats == null);
3656 AutoThreshold(res, false);
3657 if (res.bitsPerPixel > 8)
3658 res.StackThreshold(true);
3659 else
3660 res.StackThreshold(false);
3661 Recorder.AddLine("Bio.BioImage.MergeChannels(" + '"' + b.ID + '"' + "," + '"' + b2.ID + '"' + ");");
3662 return res;
3663 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.GetAnnotations(), and BioImager.BioImage.StackThreshold().

Referenced by BioImager.BioImage.MergeChannels().

◆ MergeChannels() [2/2]

static BioImage BioImager.BioImage.MergeChannels ( string  bname,
string  b2name 
)
static

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.

Definition at line 3670 of file Bio.cs.

3671 {
3672 BioImage b = Images.GetImage(bname);
3673 BioImage b2 = Images.GetImage(b2name);
3674 return MergeChannels(b, b2);
3675 }
static BioImage MergeChannels(BioImage b2, BioImage b)
Definition: Bio.cs:3579

References BioImager.BioImage.MergeChannels().

◆ MergeT()

static BioImage BioImager.BioImage.MergeT ( BioImage  b)
static

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.

Definition at line 3726 of file Bio.cs.

3727 {
3728 BioImage bi = BioImage.CopyInfo(b, true, true);
3729 int ind = 0;
3730 for (int c = 0; c < b.SizeC; c++)
3731 {
3732 for (int z = 0; z < b.sizeZ; z++)
3733 {
3734 Merge m = new Merge(b.Buffers[b.Coords[z, c, 0]]);
3735 Bitmap bm = new Bitmap(b.SizeX, b.SizeY, b.Buffers[0].PixelFormat);
3736 for (int i = 1; i < b.sizeT; i++)
3737 {
3738 m.OverlayImage = bm;
3739 bm = m.Apply(b.Buffers[b.Coords[z, c, i]]);
3740 }
3741 Bitmap bf = new Bitmap(b.file, bm, new ZCT(z, c, 0), ind);
3742 bi.Buffers.Add(bf);
3743 Statistics.CalcStatistics(bf);
3744 ind++;
3745 }
3746 }
3747 Images.AddImage(bi, true);
3748 bi.UpdateCoords(1, b.SizeC, b.SizeT);
3749 bi.Coordinate = new ZCT(0, 0, 0);
3750 //We wait for threshold image statistics calculation
3751 do
3752 {
3753 Thread.Sleep(100);
3754 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3755 Statistics.ClearCalcBuffer();
3756 bi.Resolutions.Add(new 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));
3757 AutoThreshold(bi, false);
3758 if (bi.bitsPerPixel > 8)
3759 bi.StackThreshold(true);
3760 else
3761 bi.StackThreshold(false);
3762 Recorder.AddLine("Bio.BioImage.MergeT(" + '"' + b.ID + '"' + ");");
3763 return bi;
3764 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.CopyInfo(), BioImager.BioImage.StackThreshold(), and BioImager.BioImage.UpdateCoords().

◆ MergeZ()

static BioImage BioImager.BioImage.MergeZ ( BioImage  b)
static

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.

Definition at line 3681 of file Bio.cs.

3682 {
3683 BioImage bi = BioImage.CopyInfo(b, true, true);
3684 int ind = 0;
3685 for (int c = 0; c < b.SizeC; c++)
3686 {
3687 for (int t = 0; t < b.sizeT; t++)
3688 {
3689 Merge m = new Merge(b.Buffers[b.Coords[0, c, t]]);
3690 Bitmap bm = new Bitmap(b.SizeX, b.SizeY, b.Buffers[0].PixelFormat);
3691 for (int i = 1; i < b.sizeZ; i++)
3692 {
3693 m.OverlayImage = bm;
3694 bm = m.Apply(b.Buffers[b.Coords[i, c, t]]);
3695 }
3696 Bitmap bf = new Bitmap(b.file, bm, new ZCT(0, c, t), ind);
3697 bi.Buffers.Add(bf);
3698 Statistics.CalcStatistics(bf);
3699 ind++;
3700 }
3701 }
3702 Images.AddImage(bi, true);
3703 bi.UpdateCoords(1, b.SizeC, b.SizeT);
3704 bi.Coordinate = new ZCT(0, 0, 0);
3705 //We wait for threshold image statistics calculation
3706 do
3707 {
3708 Thread.Sleep(100);
3709 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3710 Statistics.ClearCalcBuffer();
3711 bi.Resolutions.Add(new 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));
3712
3713 AutoThreshold(bi, false);
3714 if (bi.bitsPerPixel > 8)
3715 bi.StackThreshold(true);
3716 else
3717 bi.StackThreshold(false);
3718 Recorder.AddLine("Bio.BioImage.MergeZ(" + '"' + b.ID + '"' + ");");
3719 return bi;
3720 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.CopyInfo(), BioImager.BioImage.StackThreshold(), and BioImager.BioImage.UpdateCoords().

◆ OMESupport()

static bool BioImager.BioImage.OMESupport ( )
static

The function checks if the operating system is macOS and displays a message if OME images are not supported, otherwise it sets OmeSupport to true.

Returns
The method is returning a boolean value. If the operating system is MacOS and the supportDialog flag is false, it will display a message dialog and return false. Otherwise, it will set the OmeSupport flag to true and return true.

Definition at line 7268 of file Bio.cs.

7269 {
7270 bool isMacOS = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
7271 if (RuntimeInformation.OSArchitecture == Architecture.Arm64 && isMacOS)
7272 {
7273 if (!supportDialog)
7274 {
7275 MessageDialog md = new MessageDialog(
7276 null,
7277 DialogFlags.DestroyWithParent,
7278 MessageType.Info,
7279 ButtonsType.Ok, "BioGTK currently doens't support OME images on Arm64 MacOS due to dependency IKVM 8.6.4 not yet supporting Mac Arm64." +
7280 "On MacOS ImageJ Tiff files, LibVips supported whole-slide images, and BioGTK Tiff files are supported.");
7281 md.Run();
7282 }
7283 supportDialog = true;
7284 return false;
7285 }
7286 else
7287 {
7288 OmeSupport = true;
7289 return true;
7290 }
7291 }

Referenced by BioImager.BioImage.ExportROIFolder(), BioImager.BioImage.Initialize(), BioImager.BioImage.OpenOME(), BioImager.BioImage.OpenOMEROIs(), BioImager.BioImage.SaveOME(), and BioImager.BioImage.SaveOMESeries().

◆ Open() [1/2]

static void BioImager.BioImage.Open ( string  file)
static

It opens a file

Parameters
fileThe file to open.

Definition at line 7180 of file Bio.cs.

7181 {
7182 OpenFile(file);
7183 }

References BioImager.BioImage.OpenFile().

Referenced by BioImager.BioImage.Open(), and BioImager.BioImage.OpenSeries().

◆ Open() [2/2]

static void BioImager.BioImage.Open ( string[]  files)
static

It opens a file

Parameters
filesThe files to open.

Definition at line 7187 of file Bio.cs.

7188 {
7189 foreach (string file in files)
7190 {
7191 Open(file);
7192 }
7193 }
static void Open(string file)
Definition: Bio.cs:7180

References BioImager.BioImage.Open().

◆ OpenAsync() [1/2]

static async Task BioImager.BioImage.OpenAsync ( string  file,
bool  OME,
bool  newtab,
bool  images 
)
static

It opens a file in a new thread.

Parameters
fileThe file to open

Definition at line 7046 of file Bio.cs.

7047 {
7048 openfile = file;
7049 omes = OME;
7050 tab = newtab;
7051 add = images;
7052 await Task.Run(OpenThread);
7053 }

Referenced by BioImager.BioImage.OpenAsync().

◆ OpenAsync() [2/2]

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

It opens a file asynchronously

Parameters
filesThe file(s) to open.

Definition at line 7057 of file Bio.cs.

7058 {
7059 foreach (string file in files)
7060 {
7061 await OpenAsync(file, OME, tab, images);
7062 }
7063 }
static async Task OpenAsync(string file, bool OME, bool newtab, bool images)
Definition: Bio.cs:7046

References BioImager.BioImage.OpenAsync().

◆ OpenFile() [1/4]

static BioImage BioImager.BioImage.OpenFile ( string  file)
static

This function opens a file and returns a BioImage object

Parameters
fileThe path to the file to open.
Returns
A BioImage object.

Definition at line 4644 of file Bio.cs.

4645 {
4646 return OpenFile(file, 0, false, true);
4647 }

References BioImager.BioImage.OpenFile().

Referenced by BioImager.BioImage.FilesToStack(), BioImager.BioImage.FolderToStack(), BioImager.BioImage.ImagesToStack(), BioImager.BioImage.Open(), BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenSeries(), BioImager.ImageJ.RunOnImage(), and BioImager.BioImage.Update().

◆ OpenFile() [2/4]

static BioImage BioImager.BioImage.OpenFile ( string  file,
bool  tab 
)
static

Definition at line 4648 of file Bio.cs.

4649 {
4650 return OpenFile(file, 0, tab, true);
4651 }

◆ OpenFile() [3/4]

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

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.

Definition at line 4658 of file Bio.cs.

4659 {
4660 return OpenFile(file, series, tab, addToImages, false, 0, 0, 0, 0);
4661 }

References BioImager.BioImage.OpenFile().

◆ OpenFile() [4/4]

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

The OpenFile function in C# 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.

Definition at line 4784 of file Bio.cs.

4785 {
4786 string fs = file.Replace("\\", "/");
4787 vips = VipsSupport(file);
4788 Console.WriteLine("Opening BioImage: " + file);
4789 bool ome = isOME(file);
4790 if (ome) return OpenOME(file, series, tab, addToImages, tile, tileX, tileY, tileSizeX, tileSizeY);
4791 bool tiled = IsTiffTiled(file);
4792 Console.WriteLine("IsTiled=" + tiled.ToString());
4793 tile = tiled;
4794
4795 Stopwatch st = new Stopwatch();
4796 st.Start();
4797 status = "Opening Image";
4798 progFile = file;
4799 progressValue = 0;
4800 BioImage b = new BioImage(file);
4801 if (tiled && file.EndsWith(".tif") && !file.EndsWith(".ome.tif"))
4802 {
4803 //To open this we need libvips
4804 vips = VipsSupport(b.file);
4805 }
4806 if(tiled)
4807 {
4808 b.type = ImageType.pyramidal;
4809 }
4810 b.series = series;
4811 b.file = file;
4812 string fn = Path.GetFileNameWithoutExtension(file);
4813 string dir = Path.GetDirectoryName(file);
4814 if (File.Exists(fn + ".csv"))
4815 {
4816 string f = dir + "//" + fn + ".csv";
4817 b.Annotations = BioImage.ImportROIsCSV(f);
4818 }
4819 if (file.EndsWith("tif") || file.EndsWith("tiff") || file.EndsWith("TIF") || file.EndsWith("TIFF"))
4820 {
4821 Tiff image = Tiff.Open(file, "r");
4822 b.tifRead = image;
4823 int SizeX = image.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
4824 int SizeY = image.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
4825 b.bitsPerPixel = image.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
4826 b.littleEndian = !image.IsBigEndian();
4827 int RGBChannelCount = image.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
4828 string desc = "";
4829
4830 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
4831 desc = f[0].ToString();
4832 ImageJDesc imDesc = null;
4833 b.sizeC = 1;
4834 b.sizeT = 1;
4835 b.sizeZ = 1;
4836 if (f != null && !tile)
4837 {
4838 imDesc = new ImageJDesc();
4839 desc = f[0].ToString();
4840 if (desc.StartsWith("ImageJ"))
4841 {
4842 imDesc.SetString(desc);
4843 if (imDesc.channels != 0)
4844 b.sizeC = imDesc.channels;
4845 else
4846 b.sizeC = 1;
4847 if (imDesc.slices != 0)
4848 b.sizeZ = imDesc.slices;
4849 else
4850 b.sizeZ = 1;
4851 if (imDesc.frames != 0)
4852 b.sizeT = imDesc.frames;
4853 else
4854 b.sizeT = 1;
4855 if (imDesc.finterval != 0)
4856 b.frameInterval = imDesc.finterval;
4857 else
4858 b.frameInterval = 1;
4859 if (imDesc.spacing != 0)
4860 b.imageInfo.PhysicalSizeZ = imDesc.spacing;
4861 else
4862 b.imageInfo.PhysicalSizeZ = 1;
4863 }
4864 }
4865 int stride = 0;
4866 PixelFormat PixelFormat;
4867 if (RGBChannelCount == 1)
4868 {
4869 if (b.bitsPerPixel > 8)
4870 {
4871 PixelFormat = PixelFormat.Format16bppGrayScale;
4872 stride = SizeX * 2;
4873 }
4874 else
4875 {
4876 PixelFormat = PixelFormat.Format8bppIndexed;
4877 stride = SizeX;
4878 }
4879 }
4880 else
4881 if (RGBChannelCount == 3)
4882 {
4883 b.sizeC = 1;
4884 if (b.bitsPerPixel > 8)
4885 {
4886 PixelFormat = PixelFormat.Format48bppRgb;
4887 stride = SizeX * 2 * 3;
4888 }
4889 else
4890 {
4891 PixelFormat = PixelFormat.Format24bppRgb;
4892 stride = SizeX * 3;
4893 }
4894 }
4895 else
4896 {
4897 PixelFormat = PixelFormat.Format32bppArgb;
4898 stride = SizeX * 4;
4899 }
4900
4901 string[] sts = desc.Split('\n');
4902 int index = 0;
4903 for (int i = 0; i < sts.Length; i++)
4904 {
4905 if (sts[i].StartsWith("-Channel"))
4906 {
4907 string val = sts[i].Substring(9);
4908 val = val.Substring(0, val.IndexOf(':'));
4909 int serie = int.Parse(val);
4910 if (serie == series && sts[i].Length > 7)
4911 {
4912 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
4913 Channel.ChannelInfo info = JsonConvert.DeserializeObject<Channel.ChannelInfo>(cht);
4914 Channel ch = new Channel(index, b.bitsPerPixel, info.SamplesPerPixel);
4915 ch.info = info;
4916 b.Channels.Add(ch);
4917 if (index == 0)
4918 {
4919 b.rgbChannels[0] = 0;
4920 }
4921 else
4922 if (index == 1)
4923 {
4924 b.rgbChannels[1] = 1;
4925 }
4926 else
4927 if (index == 2)
4928 {
4929 b.rgbChannels[2] = 2;
4930 }
4931 index++;
4932 }
4933 }
4934 else
4935 if (sts[i].StartsWith("-ROI"))
4936 {
4937 string val = sts[i].Substring(5);
4938 val = val.Substring(0, val.IndexOf(':'));
4939 int serie = int.Parse(val);
4940 if (serie == series && sts[i].Length > 7)
4941 {
4942 string s = sts[i].Substring(sts[i].IndexOf("ROI:") + 4, sts[i].Length - (sts[i].IndexOf("ROI:") + 4));
4943 string ro = s.Substring(s.IndexOf(":") + 1, s.Length - (s.IndexOf(':') + 1));
4944 ROI roi = StringToROI(ro);
4945 b.Annotations.Add(roi);
4946 }
4947 }
4948 else
4949 if (sts[i].StartsWith("-ImageInfo"))
4950 {
4951 string val = sts[i].Substring(11);
4952 val = val.Substring(0, val.IndexOf(':'));
4953 int serie = int.Parse(val);
4954 if (serie == series && sts[i].Length > 10)
4955 {
4956 string cht = sts[i].Substring(sts[i].IndexOf('{'), sts[i].Length - sts[i].IndexOf('{'));
4957 b.imageInfo = JsonConvert.DeserializeObject<ImageInfo>(cht);
4958 }
4959 }
4960 }
4961 b.Coords = new int[b.SizeZ, b.SizeC, b.SizeT];
4962 if (tiled && tileSizeX == 0 && tileSizeY == 0)
4963 {
4964 tileSizeX = 1920;
4965 tileSizeY = 1080;
4966 }
4967
4968 //If this is a tiff file not made by Bio we init channels based on RGBChannels.
4969 if (b.Channels.Count == 0)
4970 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
4971
4972 //Lets check to see the channels are correctly defined in this file
4973 for (int ch = 0; ch < b.Channels.Count; ch++)
4974 {
4975 if (b.Channels[ch].SamplesPerPixel != RGBChannelCount)
4976 {
4977 b.Channels[ch].SamplesPerPixel = RGBChannelCount;
4978 }
4979 }
4980
4981 b.Buffers = new List<Bitmap>();
4982 int pages = image.NumberOfDirectories() / b.seriesCount;
4983 int str = image.ScanlineSize();
4984 bool inter = true;
4985 if (stride != str)
4986 inter = false;
4987 InitDirectoryResolution(b, image, imDesc);
4988 if (tiled)
4989 {
4990 Console.WriteLine("Opening tiles.");
4991 if (vips)
4992 OpenVips(b, b.Resolutions.Count);
4993 for (int t = 0; t < b.SizeT; t++)
4994 {
4995 for (int c = 0; c < b.SizeC; c++)
4996 {
4997 for (int z = 0; z < b.SizeZ; z++)
4998 {
4999 Bitmap bmp = GetTile(b, new ZCT(z, c, t), series, tileX, tileY, tileSizeX, tileSizeY);
5000 b.Buffers.Add(bmp);
5001 Statistics.CalcStatistics(bmp);
5002 }
5003 }
5004 }
5005 Console.WriteLine("Calculating statisitics.");
5006 }
5007 else
5008 {
5009 for (int p = series * pages; p < (series + 1) * pages; p++)
5010 {
5011 image.SetDirectory((short)p);
5012
5013 byte[] bytes = new byte[stride * SizeY];
5014 for (int im = 0, offset = 0; im < SizeY; im++)
5015 {
5016 image.ReadScanline(bytes, offset, im, 0);
5017 offset += stride;
5018 }
5019 Bitmap inf = new Bitmap(file, SizeX, SizeY, b.Resolutions[series].PixelFormat, bytes, new ZCT(0, 0, 0), p, null, b.littleEndian, inter);
5020 b.Buffers.Add(inf);
5021 Statistics.CalcStatistics(inf);
5022 progressValue = (float)p / (float)(series + 1) * pages;
5023 }
5024 }
5025 image.Close();
5026 b.UpdateCoords();
5027 }
5028 if (b.StageSizeX == -1)
5029 {
5030 b.imageInfo.Series = 0;
5031 b.StageSizeX = 0;
5032 b.StageSizeY = 0;
5033 b.StageSizeZ = 0;
5034 }
5035 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));
5036
5037 //If file is ome and we have OME support then check for annotation in metadata.
5038 if (ome && OmeSupport)
5039 {
5040 b.Annotations.AddRange(OpenOMEROIs(file, series));
5041 }
5042
5043 //We wait for histogram image statistics calculation
5044 do
5045 {
5046 Thread.Sleep(50);
5047 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
5048 Statistics.ClearCalcBuffer();
5049 AutoThreshold(b, false);
5050 if (b.bitsPerPixel > 8)
5051 b.StackThreshold(true);
5052 else
5053 b.StackThreshold(false);
5054 Recorder.AddLine("Bio.BioImage.Open(" + '"' + file + '"' + ");");
5055 if (addToImages)
5056 Images.AddImage(b, tab);
5057 //pr.Close();
5058 //pr.Dispose();
5059 st.Stop();
5060 b.loadTimeMS = st.ElapsedMilliseconds;
5061 Console.WriteLine("BioImage loaded " + b.ToString());
5062 return b;
5063 }
static void OpenVips(BioImage b, int pagecount)
Definition: Bio.cs:5778
static bool VipsSupport(string file)
Definition: Bio.cs:7301
static Bitmap GetTile(BioImage b, ZCT coord, int serie, int tilex, int tiley, int tileSizeX, int tileSizeY)
Definition: Bio.cs:6678

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.GetTile(), BioImager.BioImage.ImportROIsCSV(), BioImager.BioImage.isOME(), BioImager.BioImage.OpenOME(), BioImager.BioImage.OpenOMEROIs(), BioImager.BioImage.OpenVips(), BioImager.BioImage.ImageJDesc.SetString(), BioImager.BioImage.StackThreshold(), BioImager.BioImage.StringToROI(), BioImager.BioImage.ToString(), BioImager.BioImage.UpdateCoords(), and BioImager.BioImage.VipsSupport().

◆ OpenOME() [1/3]

static BioImage BioImager.BioImage.OpenOME ( string  file,
bool  tab 
)
static

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.

Definition at line 5684 of file Bio.cs.

5685 {
5686 if (!OMESupport())
5687 return null;
5688 return OpenOMESeries(file, tab, true)[0];
5689 }
static BioImage[] OpenOMESeries(string file, bool tab, bool addToImages)
Definition: Bio.cs:6993

References BioImager.BioImage.OMESupport(), and BioImager.BioImage.OpenOMESeries().

Referenced by BioImager.BioImage.ImagesToStack(), BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenOME(), BioImager.BioImage.OpenOMESeries(), and BioImager.BioImage.SaveOMESeries().

◆ OpenOME() [2/3]

static BioImage BioImager.BioImage.OpenOME ( string  file,
int  serie 
)
static

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.

Definition at line 5698 of file Bio.cs.

5699 {
5700 if (!OMESupport())
5701 return null;
5702 Recorder.AddLine("Bio.BioImage.OpenOME(\"" + file + "\"," + serie + ");");
5703 return OpenOME(file, serie, true, false, false, 0, 0, 0, 0);
5704 }

References BioImager.BioImage.OMESupport(), and BioImager.BioImage.OpenOME().

◆ OpenOME() [3/3]

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

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.

Definition at line 5872 of file Bio.cs.

5873 {
5874 //We wait incase OME has not initialized.
5875 do
5876 {
5877 Thread.Sleep(10);
5878 } while (!initialized);
5879 Console.WriteLine("OpenOME " + file);
5880 reader = new ImageReader();
5881 Progress pr = new Progress(file, "Opening OME");
5882 pr.Show();
5883 if (tileSizeX == 0)
5884 tileSizeX = 1920;
5885 if (tileSizeY == 0)
5886 tileSizeY = 1080;
5887 progressValue = 0;
5888 progFile = file;
5889 BioImage b = new BioImage(file);
5890 b.Type = ImageType.stack;
5891 b.Loading = true;
5892 if (b.meta == null)
5893 b.meta = service.createOMEXMLMetadata();
5894 string f = file.Replace("\\", "/");
5895 string cf = reader.getCurrentFile();
5896 if (cf != null)
5897 cf = cf.Replace("\\", "/");
5898 if (cf != f)
5899 {
5900 reader.close();
5901 reader.setMetadataStore(b.meta);
5902 try
5903 {
5904 reader.setId(f);
5905 }
5906 catch (Exception e)
5907 {
5908 Console.WriteLine(e.Message);
5909 return null;
5910 }
5911
5912 pr.Status = "Reading Metadata";
5913 }
5914
5915 //status = "Reading OME Metadata.";
5916 reader.setSeries(serie);
5917 int RGBChannelCount = reader.getRGBChannelCount();
5918 //OME reader.getBitsPerPixel(); sometimes returns incorrect bits per pixel, like when opening ImageJ images.
5919 //So we check the pixel type from xml metadata and if it fails we use the readers value.
5920 PixelFormat PixelFormat;
5921 try
5922 {
5923 PixelFormat = GetPixelFormat(RGBChannelCount, b.meta.getPixelsType(serie));
5924 }
5925 catch (Exception)
5926 {
5927 PixelFormat = GetPixelFormat(RGBChannelCount, reader.getBitsPerPixel());
5928 }
5929
5930 b.id = file;
5931 b.file = file;
5932 int SizeX, SizeY;
5933 SizeX = reader.getSizeX();
5934 SizeY = reader.getSizeY();
5935 int SizeZ = reader.getSizeZ();
5936 b.sizeC = reader.getSizeC();
5937 b.sizeZ = reader.getSizeZ();
5938 b.sizeT = reader.getSizeT();
5939 b.littleEndian = reader.isLittleEndian();
5940 b.seriesCount = reader.getSeriesCount();
5941 b.imagesPerSeries = reader.getImageCount();
5942 b.bitsPerPixel = reader.getBitsPerPixel();
5943 b.series = serie;
5944 string order = reader.getDimensionOrder();
5945
5946 //Lets get the channels and initialize them
5947 int i = 0;
5948 pr.Status = "Reading Channels";
5949 int sumSamples = 0;
5950 while (true)
5951 {
5952 Channel ch = new Channel(i, b.bitsPerPixel, 1);
5953 bool def = false;
5954 try
5955 {
5956 if (b.meta.getChannelSamplesPerPixel(serie, i) != null)
5957 {
5958 int s = b.meta.getChannelSamplesPerPixel(serie, i).getNumberValue().intValue();
5959 ch.SamplesPerPixel = s;
5960 sumSamples += s;
5961 def = true;
5962 }
5963 if (b.meta.getChannelName(serie, i) != null)
5964 ch.Name = b.meta.getChannelName(serie, i);
5965 if (b.meta.getChannelAcquisitionMode(serie, i) != null)
5966 ch.AcquisitionMode = b.meta.getChannelAcquisitionMode(serie, i).ToString();
5967 if (b.meta.getChannelID(serie, i) != null)
5968 ch.info.ID = b.meta.getChannelID(serie, i);
5969 if (b.meta.getChannelFluor(serie, i) != null)
5970 ch.Fluor = b.meta.getChannelFluor(serie, i);
5971 if (b.meta.getChannelColor(serie, i) != null)
5972 {
5973 ome.xml.model.primitives.Color cc = b.meta.getChannelColor(serie, i);
5974 ch.Color = Color.FromArgb(cc.getRed(), cc.getGreen(), cc.getBlue());
5975 }
5976 if (b.meta.getChannelIlluminationType(serie, i) != null)
5977 ch.IlluminationType = b.meta.getChannelIlluminationType(serie, i).ToString();
5978 if (b.meta.getChannelContrastMethod(serie, i) != null)
5979 ch.ContrastMethod = b.meta.getChannelContrastMethod(serie, i).ToString();
5980 if (b.meta.getChannelEmissionWavelength(serie, i) != null)
5981 ch.Emission = b.meta.getChannelEmissionWavelength(serie, i).value().intValue();
5982 if (b.meta.getChannelExcitationWavelength(serie, i) != null)
5983 ch.Excitation = b.meta.getChannelExcitationWavelength(serie, i).value().intValue();
5984 if (b.meta.getLightEmittingDiodePower(serie, i) != null)
5985 ch.LightSourceIntensity = b.meta.getLightEmittingDiodePower(serie, i).value().doubleValue();
5986 if (b.meta.getLightEmittingDiodeID(serie, i) != null)
5987 ch.DiodeName = b.meta.getLightEmittingDiodeID(serie, i);
5988 if (b.meta.getChannelLightSourceSettingsAttenuation(serie, i) != null)
5989 ch.LightSourceAttenuation = b.meta.getChannelLightSourceSettingsAttenuation(serie, i).toString();
5990
5991 }
5992 catch (Exception e)
5993 {
5994 Console.WriteLine(e.Message);
5995 }
5996 //If this channel is not defined we have loaded all the channels in the file.
5997 if (!def)
5998 break;
5999 else
6000 b.Channels.Add(ch);
6001 if (i == 0)
6002 {
6003 b.rgbChannels[0] = 0;
6004 }
6005 else
6006 if (i == 1)
6007 {
6008 b.rgbChannels[1] = 1;
6009 }
6010 else
6011 if (i == 2)
6012 {
6013 b.rgbChannels[2] = 2;
6014 }
6015 i++;
6016 }
6017 //If the file doens't have channels we initialize them.
6018 if (b.Channels.Count == 0)
6019 {
6020 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
6021 }
6022
6023 //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.
6024 if (RGBChannelCount >= 3)
6025 {
6026 b.sizeC = sumSamples / b.Channels[0].SamplesPerPixel;
6027 }
6028 b.Coords = new int[b.SizeZ, b.SizeC, b.SizeT];
6029
6030 int resc = reader.getResolutionCount();
6031
6032 try
6033 {
6034 int wells = b.meta.getWellCount(0);
6035 if (wells > 0)
6036 {
6037 b.Type = ImageType.well;
6038 b.Plate = new WellPlate(b);
6039 tile = false;
6040 }
6041 }
6042 catch (Exception)
6043 {
6044
6045 }
6046 List<Resolution> rss = new List<Resolution>();
6047 for (int s = 0; s < b.seriesCount; s++)
6048 {
6049 reader.setSeries(s);
6050 for (int r = 0; r < reader.getResolutionCount(); r++)
6051 {
6052 Resolution res = new Resolution();
6053 try
6054 {
6055 int rgbc = reader.getRGBChannelCount();
6056 int bps = reader.getBitsPerPixel();
6057 PixelFormat px;
6058 try
6059 {
6060 px = GetPixelFormat(rgbc, b.meta.getPixelsType(r));
6061 }
6062 catch (Exception)
6063 {
6064 px = GetPixelFormat(rgbc, bps);
6065 }
6066 res.PixelFormat = px;
6067 res.SizeX = reader.getSizeX();
6068 res.SizeY = reader.getSizeY();
6069 if (b.meta.getPixelsPhysicalSizeX(r) != null)
6070 {
6071 res.PhysicalSizeX = b.meta.getPixelsPhysicalSizeX(r).value().doubleValue();
6072 }
6073 else
6074 res.PhysicalSizeX = (96 / 2.54) / 1000;
6075 if (b.meta.getPixelsPhysicalSizeY(r) != null)
6076 {
6077 res.PhysicalSizeY = b.meta.getPixelsPhysicalSizeY(r).value().doubleValue();
6078 }
6079 else
6080 res.PhysicalSizeY = (96 / 2.54) / 1000;
6081
6082 if (b.meta.getStageLabelX(r) != null)
6083 res.StageSizeX = b.meta.getStageLabelX(r).value().doubleValue();
6084 if (b.meta.getStageLabelY(r) != null)
6085 res.StageSizeY = b.meta.getStageLabelY(r).value().doubleValue();
6086 if (b.meta.getStageLabelZ(r) != null)
6087 res.StageSizeZ = b.meta.getStageLabelZ(r).value().doubleValue();
6088 else
6089 res.StageSizeZ = 1;
6090 if (b.meta.getPixelsPhysicalSizeZ(r) != null)
6091 {
6092 res.PhysicalSizeZ = b.meta.getPixelsPhysicalSizeZ(r).value().doubleValue();
6093 }
6094 else
6095 {
6096 res.PhysicalSizeZ = 1;
6097 }
6098 }
6099 catch (Exception e)
6100 {
6101 Console.WriteLine("No Stage Coordinates. PhysicalSize:(" + res.PhysicalSizeX + "," + res.PhysicalSizeY + "," + res.PhysicalSizeZ + ")");
6102 }
6103 rss.Add(res);
6104 }
6105 }
6106 reader.setSeries(serie);
6107
6108 int pyramidCount = 0;
6109 int pyramidResolutions = 0;
6110 List<Tuple<int, int>> prs = new List<Tuple<int, int>>();
6111 //We need to determine if this image is pyramidal or not.
6112 //We do this by seeing if the resolutions are downsampled or not.
6113 if (rss.Count > 1 && b.Type != ImageType.well)
6114 {
6115 if (rss[0].SizeX > rss[1].SizeX)
6116 {
6117 b.Type = ImageType.pyramidal;
6118 tile = true;
6119 //We need to determine number of pyramids in this image and which belong to the series we are opening.
6120 int? sr = null;
6121 for (int r = 0; r < rss.Count - 1; r++)
6122 {
6123 if (rss[r].SizeX > rss[r + 1].SizeX && rss[r].PixelFormat == rss[r + 1].PixelFormat)
6124 {
6125 if (sr == null)
6126 {
6127 sr = r;
6128 prs.Add(new Tuple<int, int>(r, 0));
6129 }
6130 }
6131 else
6132 {
6133 if (rss[prs[prs.Count - 1].Item1].PixelFormat == rss[r].PixelFormat)
6134 prs[prs.Count - 1] = new Tuple<int, int>(prs[prs.Count - 1].Item1, r);
6135 sr = null;
6136 }
6137 }
6138 pyramidCount = prs.Count;
6139 for (int p = 0; p < prs.Count; p++)
6140 {
6141 pyramidResolutions += (prs[p].Item2 - prs[p].Item1) + 1;
6142 }
6143
6144 if (prs[serie].Item2 == 0)
6145 {
6146 prs[serie] = new Tuple<int, int>(prs[serie].Item1, rss.Count);
6147 }
6148 for (int r = prs[serie].Item1; r < prs[serie].Item2; r++)
6149 {
6150 b.Resolutions.Add(rss[r]);
6151 }
6152 }
6153 else
6154 {
6155 b.Resolutions.AddRange(rss);
6156 }
6157 }
6158 else
6159 b.Resolutions.AddRange(rss);
6160
6161 //If we have 2 resolutions that we're not added they are the label & macro resolutions so we add them to the image.
6162 if (rss.Count - pyramidResolutions == 2)
6163 {
6164 b.Resolutions.Add(rss[rss.Count - 2]);
6165 b.Resolutions.Add(rss[rss.Count - 1]);
6166 }
6167
6168 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.PhysicalSizeX * SizeX, b.PhysicalSizeY * SizeY, b.PhysicalSizeZ * SizeZ));
6169 pr.Status = "Reading ROIs";
6170 int rc = b.meta.getROICount();
6171 for (int im = 0; im < rc; im++)
6172 {
6173 string roiID = b.meta.getROIID(im);
6174 string roiName = b.meta.getROIName(im);
6175 ZCT co = new ZCT(0, 0, 0);
6176 int scount = 1;
6177 try
6178 {
6179 scount = b.meta.getShapeCount(im);
6180 }
6181 catch (Exception e)
6182 {
6183 Console.WriteLine(e.Message.ToString());
6184 }
6185 for (int sc = 0; sc < scount; sc++)
6186 {
6187 string type = b.meta.getShapeType(im, sc);
6188 ROI an = new ROI();
6189 an.roiID = roiID;
6190 an.roiName = roiName;
6191 an.shapeIndex = sc;
6192 if (type == "Point")
6193 {
6194 an.type = ROI.Type.Point;
6195 an.id = b.meta.getPointID(im, sc);
6196 double dx = b.meta.getPointX(im, sc).doubleValue();
6197 double dy = b.meta.getPointY(im, sc).doubleValue();
6198 an.AddPoint(b.ToStageSpace(new PointD(dx, dy)));
6199 an.coord = new ZCT();
6200 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPointTheZ(im, sc);
6201 if (nz != null)
6202 an.coord.Z = nz.getNumberValue().intValue();
6203 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPointTheC(im, sc);
6204 if (nc != null)
6205 an.coord.C = nc.getNumberValue().intValue();
6206 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPointTheT(im, sc);
6207 if (nt != null)
6208 an.coord.T = nt.getNumberValue().intValue();
6209 an.Text = b.meta.getPointText(im, sc);
6210 ome.units.quantity.Length fl = b.meta.getPointFontSize(im, sc);
6211 if (fl != null)
6212 an.fontSize = fl.value().intValue();
6213 ome.xml.model.enums.FontFamily ff = b.meta.getPointFontFamily(im, sc);
6214 if (ff != null)
6215 an.family = ff.name();
6216 ome.xml.model.primitives.Color col = b.meta.getPointStrokeColor(im, sc);
6217 if (col != null)
6218 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6219 ome.units.quantity.Length fw = b.meta.getPointStrokeWidth(im, sc);
6220 if (fw != null)
6221 an.strokeWidth = (float)fw.value().floatValue();
6222 ome.xml.model.primitives.Color colf = b.meta.getPointStrokeColor(im, sc);
6223 if (colf != null)
6224 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6225 }
6226 else
6227 if (type == "Line")
6228 {
6229 an.type = ROI.Type.Line;
6230 an.id = b.meta.getLineID(im, sc);
6231 double px1 = b.meta.getLineX1(im, sc).doubleValue();
6232 double py1 = b.meta.getLineY1(im, sc).doubleValue();
6233 double px2 = b.meta.getLineX2(im, sc).doubleValue();
6234 double py2 = b.meta.getLineY2(im, sc).doubleValue();
6235 an.AddPoint(b.ToStageSpace(new PointD(px1, py1)));
6236 an.AddPoint(b.ToStageSpace(new PointD(px2, py2)));
6237 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLineTheZ(im, sc);
6238 if (nz != null)
6239 co.Z = nz.getNumberValue().intValue();
6240 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLineTheC(im, sc);
6241 if (nc != null)
6242 co.C = nc.getNumberValue().intValue();
6243 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLineTheT(im, sc);
6244 if (nt != null)
6245 co.T = nt.getNumberValue().intValue();
6246 an.coord = co;
6247 an.Text = b.meta.getLineText(im, sc);
6248 ome.units.quantity.Length fl = b.meta.getLineFontSize(im, sc);
6249 if (fl != null)
6250 an.fontSize = fl.value().intValue();
6251 ome.xml.model.enums.FontFamily ff = b.meta.getLineFontFamily(im, sc);
6252 if (ff != null)
6253 an.family = ff.name();
6254 ome.xml.model.primitives.Color col = b.meta.getLineStrokeColor(im, sc);
6255 if (col != null)
6256 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6257 ome.units.quantity.Length fw = b.meta.getLineStrokeWidth(im, sc);
6258 if (fw != null)
6259 an.strokeWidth = (float)fw.value().floatValue();
6260 ome.xml.model.primitives.Color colf = b.meta.getLineFillColor(im, sc);
6261 if (colf != null)
6262 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6263 }
6264 else
6265 if (type == "Rectangle")
6266 {
6267 an.type = ROI.Type.Rectangle;
6268 an.id = b.meta.getRectangleID(im, sc);
6269 double px = b.meta.getRectangleX(im, sc).doubleValue();
6270 double py = b.meta.getRectangleY(im, sc).doubleValue();
6271 double pw = b.meta.getRectangleWidth(im, sc).doubleValue();
6272 double ph = b.meta.getRectangleHeight(im, sc).doubleValue();
6273 an.Rect = b.ToStageSpace(new RectangleD(px, py, pw, ph));
6274 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getRectangleTheZ(im, sc);
6275 if (nz != null)
6276 co.Z = nz.getNumberValue().intValue();
6277 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getRectangleTheC(im, sc);
6278 if (nc != null)
6279 co.C = nc.getNumberValue().intValue();
6280 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getRectangleTheT(im, sc);
6281 if (nt != null)
6282 co.T = nt.getNumberValue().intValue();
6283 an.coord = co;
6284
6285 an.Text = b.meta.getRectangleText(im, sc);
6286 ome.units.quantity.Length fl = b.meta.getRectangleFontSize(im, sc);
6287 if (fl != null)
6288 an.fontSize = fl.value().intValue();
6289 ome.xml.model.enums.FontFamily ff = b.meta.getRectangleFontFamily(im, sc);
6290 if (ff != null)
6291 an.family = ff.name();
6292 ome.xml.model.primitives.Color col = b.meta.getRectangleStrokeColor(im, sc);
6293 if (col != null)
6294 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6295 ome.units.quantity.Length fw = b.meta.getRectangleStrokeWidth(im, sc);
6296 if (fw != null)
6297 an.strokeWidth = (float)fw.value().floatValue();
6298 ome.xml.model.primitives.Color colf = b.meta.getRectangleFillColor(im, sc);
6299 if (colf != null)
6300 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6301 ome.xml.model.enums.FillRule fr = b.meta.getRectangleFillRule(im, sc);
6302 }
6303 else
6304 if (type == "Ellipse")
6305 {
6306 an.type = ROI.Type.Ellipse;
6307 an.id = b.meta.getEllipseID(im, sc);
6308 double px = b.meta.getEllipseX(im, sc).doubleValue();
6309 double py = b.meta.getEllipseY(im, sc).doubleValue();
6310 double ew = b.meta.getEllipseRadiusX(im, sc).doubleValue();
6311 double eh = b.meta.getEllipseRadiusY(im, sc).doubleValue();
6312 //We convert the ellipse radius to Rectangle
6313 double w = ew * 2;
6314 double h = eh * 2;
6315 double x = px - ew;
6316 double y = py - eh;
6317 an.Rect = b.ToStageSpace(new RectangleD(x, y, w, h));
6318 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getEllipseTheZ(im, sc);
6319 if (nz != null)
6320 co.Z = nz.getNumberValue().intValue();
6321 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getEllipseTheC(im, sc);
6322 if (nc != null)
6323 co.C = nc.getNumberValue().intValue();
6324 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getEllipseTheT(im, sc);
6325 if (nt != null)
6326 co.T = nt.getNumberValue().intValue();
6327 an.coord = co;
6328 an.Text = b.meta.getEllipseText(im, sc);
6329 ome.units.quantity.Length fl = b.meta.getEllipseFontSize(im, sc);
6330 if (fl != null)
6331 an.fontSize = fl.value().intValue();
6332 ome.xml.model.enums.FontFamily ff = b.meta.getEllipseFontFamily(im, sc);
6333 if (ff != null)
6334 an.family = ff.name();
6335 ome.xml.model.primitives.Color col = b.meta.getEllipseStrokeColor(im, sc);
6336 if (col != null)
6337 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6338 ome.units.quantity.Length fw = b.meta.getEllipseStrokeWidth(im, sc);
6339 if (fw != null)
6340 an.strokeWidth = (float)fw.value().floatValue();
6341 ome.xml.model.primitives.Color colf = b.meta.getEllipseFillColor(im, sc);
6342 if (colf != null)
6343 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6344 }
6345 else
6346 if (type == "Polygon")
6347 {
6348 an.type = ROI.Type.Polygon;
6349 an.id = b.meta.getPolygonID(im, sc);
6350 an.closed = true;
6351 string pxs = b.meta.getPolygonPoints(im, sc);
6352 PointD[] pts = an.stringToPoints(pxs);
6353 pts = b.ToStageSpace(pts);
6354 if (pts.Length > 100)
6355 {
6356 an.type = ROI.Type.Freeform;
6357 }
6358 an.AddPoints(pts);
6359 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolygonTheZ(im, sc);
6360 if (nz != null)
6361 co.Z = nz.getNumberValue().intValue();
6362 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolygonTheC(im, sc);
6363 if (nc != null)
6364 co.C = nc.getNumberValue().intValue();
6365 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolygonTheT(im, sc);
6366 if (nt != null)
6367 co.T = nt.getNumberValue().intValue();
6368 an.coord = co;
6369 an.Text = b.meta.getPolygonText(im, sc);
6370 ome.units.quantity.Length fl = b.meta.getPolygonFontSize(im, sc);
6371 if (fl != null)
6372 an.fontSize = fl.value().intValue();
6373 ome.xml.model.enums.FontFamily ff = b.meta.getPolygonFontFamily(im, sc);
6374 if (ff != null)
6375 an.family = ff.name();
6376 ome.xml.model.primitives.Color col = b.meta.getPolygonStrokeColor(im, sc);
6377 if (col != null)
6378 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6379 ome.units.quantity.Length fw = b.meta.getPolygonStrokeWidth(im, sc);
6380 if (fw != null)
6381 an.strokeWidth = (float)fw.value().floatValue();
6382 ome.xml.model.primitives.Color colf = b.meta.getPolygonFillColor(im, sc);
6383 if (colf != null)
6384 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6385 }
6386 else
6387 if (type == "Polyline")
6388 {
6389 an.type = ROI.Type.Polyline;
6390 an.id = b.meta.getPolylineID(im, sc);
6391 string pxs = b.meta.getPolylinePoints(im, sc);
6392 PointD[] pts = an.stringToPoints(pxs);
6393 for (int pi = 0; pi < pts.Length; pi++)
6394 {
6395 pts[pi] = b.ToStageSpace(pts[pi]);
6396 }
6397 an.AddPoints(an.stringToPoints(pxs));
6398 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolylineTheZ(im, sc);
6399 if (nz != null)
6400 co.Z = nz.getNumberValue().intValue();
6401 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolylineTheC(im, sc);
6402 if (nc != null)
6403 co.C = nc.getNumberValue().intValue();
6404 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolylineTheT(im, sc);
6405 if (nt != null)
6406 co.T = nt.getNumberValue().intValue();
6407 an.coord = co;
6408 an.Text = b.meta.getPolylineText(im, sc);
6409 ome.units.quantity.Length fl = b.meta.getPolylineFontSize(im, sc);
6410 if (fl != null)
6411 an.fontSize = fl.value().intValue();
6412 ome.xml.model.enums.FontFamily ff = b.meta.getPolylineFontFamily(im, sc);
6413 if (ff != null)
6414 an.family = ff.name();
6415 ome.xml.model.primitives.Color col = b.meta.getPolylineStrokeColor(im, sc);
6416 if (col != null)
6417 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6418 ome.units.quantity.Length fw = b.meta.getPolylineStrokeWidth(im, sc);
6419 if (fw != null)
6420 an.strokeWidth = (float)fw.value().floatValue();
6421 ome.xml.model.primitives.Color colf = b.meta.getPolylineFillColor(im, sc);
6422 if (colf != null)
6423 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6424 }
6425 else
6426 if (type == "Label")
6427 {
6428 an.type = ROI.Type.Label;
6429 an.id = b.meta.getLabelID(im, sc);
6430
6431 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLabelTheZ(im, sc);
6432 if (nz != null)
6433 co.Z = nz.getNumberValue().intValue();
6434 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLabelTheC(im, sc);
6435 if (nc != null)
6436 co.C = nc.getNumberValue().intValue();
6437 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLabelTheT(im, sc);
6438 if (nt != null)
6439 co.T = nt.getNumberValue().intValue();
6440 an.coord = co;
6441
6442 ome.units.quantity.Length fl = b.meta.getLabelFontSize(im, sc);
6443 if (fl != null)
6444 an.fontSize = fl.value().intValue();
6445 ome.xml.model.enums.FontFamily ff = b.meta.getLabelFontFamily(im, sc);
6446 if (ff != null)
6447 an.family = ff.name();
6448 ome.xml.model.primitives.Color col = b.meta.getLabelStrokeColor(im, sc);
6449 if (col != null)
6450 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6451 ome.units.quantity.Length fw = b.meta.getLabelStrokeWidth(im, sc);
6452 if (fw != null)
6453 an.strokeWidth = (float)fw.value().floatValue();
6454 ome.xml.model.primitives.Color colf = b.meta.getLabelFillColor(im, sc);
6455 if (colf != null)
6456 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6457 PointD p = new PointD(b.meta.getLabelX(im, sc).doubleValue(), b.meta.getLabelY(im, sc).doubleValue());
6458 an.AddPoint(b.ToStageSpace(p));
6459 an.Text = b.meta.getLabelText(im, sc);
6460 }
6461 else
6462 if (type == "Mask")
6463 {
6464 byte[] bts = b.meta.getMaskBinData(im, sc);
6465 bool end = b.meta.getMaskBinDataBigEndian(im, sc).booleanValue();
6466 an = ROI.CreateMask(co, bts, b.Resolutions[0].SizeX, b.Resolutions[0].SizeY, new PointD(b.StageSizeX, b.StageSizeY), b.PhysicalSizeX, b.PhysicalSizeY);
6467 an.Text = b.meta.getMaskText(im, sc);
6468 an.id = b.meta.getMaskID(im, sc);
6469 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getMaskTheZ(im, sc);
6470 if (nz != null)
6471 co.Z = nz.getNumberValue().intValue();
6472 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getMaskTheC(im, sc);
6473 if (nc != null)
6474 co.C = nc.getNumberValue().intValue();
6475 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getMaskTheT(im, sc);
6476 if (nt != null)
6477 co.T = nt.getNumberValue().intValue();
6478 an.coord = co;
6479
6480 ome.units.quantity.Length fl = b.meta.getMaskFontSize(im, sc);
6481 if (fl != null)
6482 an.fontSize = fl.value().intValue();
6483 ome.xml.model.enums.FontFamily ff = b.meta.getMaskFontFamily(im, sc);
6484 if (ff != null)
6485 an.family = ff.name();
6486 ome.xml.model.primitives.Color col = b.meta.getMaskStrokeColor(im, sc);
6487 if (col != null)
6488 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6489 ome.units.quantity.Length fw = b.meta.getMaskStrokeWidth(im, sc);
6490 if (fw != null)
6491 an.strokeWidth = (float)fw.value().floatValue();
6492 ome.xml.model.primitives.Color colf = b.meta.getMaskFillColor(im, sc);
6493 if (colf != null)
6494 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6495 }
6496 b.Annotations.Add(an);
6497 }
6498 }
6499
6500 List<string> serFiles = new List<string>();
6501 serFiles.AddRange(reader.getSeriesUsedFiles());
6502
6503 b.Buffers = new List<Bitmap>();
6504 if (b.Type == ImageType.pyramidal)
6505 try
6506 {
6507 string st = OpenSlideImage.DetectVendor(file);
6508 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
6509 {
6510 b.openSlideImage = OpenSlideImage.Open(file);
6511 b.openSlideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file);
6512 }
6513 else
6514 {
6515 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6516 b.slideImage = b.slideBase.SlideImage;
6517 }
6518 }
6519 catch (Exception e)
6520 {
6521 Console.WriteLine(e.Message.ToString());
6522 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6523 b.slideImage = b.slideBase.SlideImage;
6524 }
6525
6526 // read the image data bytes
6527 int pages = reader.getImageCount();
6528 bool inter = reader.isInterleaved();
6529 int z = 0;
6530 int c = 0;
6531 int t = 0;
6532 pr.Status = "Reading Image Data";
6533 if (!tile)
6534 {
6535 try
6536 {
6537 for (int p = 0; p < pages; p++)
6538 {
6539 Bitmap bf;
6540 pr.ProgressValue = (float)p / (float)pages;
6541 byte[] bytes = reader.openBytes(p);
6542 bf = new Bitmap(file, SizeX, SizeY, PixelFormat, bytes, new ZCT(z, c, t), p, null, b.littleEndian, inter);
6543 b.Buffers.Add(bf);
6544 }
6545 }
6546 catch (Exception)
6547 {
6548 //If we failed to read an entire plane it is likely too large so we open as pyramidal.
6549 b.Type = ImageType.pyramidal;
6550 try
6551 {
6552 string st = OpenSlideImage.DetectVendor(file);
6553 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
6554 {
6555 b.openSlideImage = OpenSlideImage.Open(file);
6556 b.openSlideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file);
6557 }
6558 else
6559 {
6560 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6561 b.slideImage = b.slideBase.SlideImage;
6562 }
6563 }
6564 catch (Exception e)
6565 {
6566 Console.WriteLine(e.Message.ToString());
6567 b.slideBase = new SlideBase(b, SlideImage.Open(b));
6568 b.slideImage = b.slideBase.SlideImage;
6569 }
6570 b.imRead = reader;
6571 for (int p = 0; p < pages; p++)
6572 {
6573 b.Buffers.Add(GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6574 Statistics.CalcStatistics(b.Buffers.Last());
6575 }
6576 }
6577
6578 }
6579 else
6580 {
6581 b.imRead = reader;
6582 for (int p = 0; p < pages; p++)
6583 {
6584 b.Buffers.Add(GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6585 Statistics.CalcStatistics(b.Buffers.Last());
6586 }
6587 }
6588 int pls;
6589 try
6590 {
6591 pls = b.meta.getPlaneCount(serie);
6592 }
6593 catch (Exception)
6594 {
6595 pls = 0;
6596 }
6597 pr.Status = "Reading Plane Data";
6598 if (pls == b.Buffers.Count)
6599 for (int bi = 0; bi < b.Buffers.Count; bi++)
6600 {
6601 Plane pl = new Plane();
6602 pl.Coordinate = new ZCT();
6603 double px = 0; double py = 0; double pz = 0;
6604 if (b.meta.getPlanePositionX(serie, bi) != null)
6605 px = b.meta.getPlanePositionX(serie, bi).value().doubleValue();
6606 if (b.meta.getPlanePositionY(serie, bi) != null)
6607 py = b.meta.getPlanePositionY(serie, bi).value().doubleValue();
6608 if (b.meta.getPlanePositionZ(serie, bi) != null)
6609 pz = b.meta.getPlanePositionZ(serie, bi).value().doubleValue();
6610 pl.Location = new AForge.Point3D(px, py, pz);
6611 int cc = 0; int zc = 0; int tc = 0;
6612 if (b.meta.getPlaneTheC(serie, bi) != null)
6613 cc = b.meta.getPlaneTheC(serie, bi).getNumberValue().intValue();
6614 if (b.meta.getPlaneTheZ(serie, bi) != null)
6615 zc = b.meta.getPlaneTheZ(serie, bi).getNumberValue().intValue();
6616 if (b.meta.getPlaneTheT(serie, bi) != null)
6617 tc = b.meta.getPlaneTheT(serie, bi).getNumberValue().intValue();
6618 pl.Coordinate = new ZCT(zc, cc, tc);
6619 if (b.meta.getPlaneDeltaT(serie, bi) != null)
6620 pl.Delta = b.meta.getPlaneDeltaT(serie, bi).value().doubleValue();
6621 if (b.meta.getPlaneExposureTime(serie, bi) != null)
6622 pl.Exposure = b.meta.getPlaneExposureTime(serie, bi).value().doubleValue();
6623 b.Buffers[bi].Plane = pl;
6624 }
6625
6626 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, order);
6627 //We wait for histogram image statistics calculation
6628 do
6629 {
6630 Thread.Sleep(50);
6631 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
6632 b.SetLabelMacroResolutions();
6633 Statistics.ClearCalcBuffer();
6634 AutoThreshold(b, true);
6635 if (b.bitsPerPixel > 8)
6636 b.StackThreshold(true);
6637 else
6638 b.StackThreshold(false);
6639 if (!tile)
6640 {
6641 //We use a try block to close the reader as sometimes this will cause an error.
6642 bool stop = false;
6643 do
6644 {
6645 try
6646 {
6647 reader.close();
6648 stop = true;
6649 }
6650 catch (Exception e)
6651 {
6652 Console.WriteLine(e.Message);
6653 }
6654 } while (!stop);
6655 }
6656 if (addToImages)
6657 Images.AddImage(b, tab);
6658 b.Loading = false;
6659 pr.Hide();
6660 Console.WriteLine("Opening complete " + file);
6661 return b;
6662 }
static PixelFormat GetPixelFormat(int rgbChannelCount, int bitsPerPixel)
Definition: Bio.cs:6938

References BioImager.ROI.AddPoint(), BioImager.ROI.AddPoints(), BioImager.BioImage.AutoThreshold(), BioImager.BioImage.GetPixelFormat(), BioImager.BioImage.GetTile(), BioImager.SlideImage.Open(), BioImager.BioImage.StackThreshold(), BioImager.ROI.stringToPoints(), BioImager.BioImage.ToStageSpace(), and BioImager.BioImage.UpdateCoords().

◆ OpenOMEROIs()

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

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.

Definition at line 7347 of file Bio.cs.

7348 {
7349 if (!OMESupport())
7350 return null;
7351 List<ROI> Annotations = new List<ROI>();
7352 // create OME-XML metadata store
7353 ServiceFactory factory = new ServiceFactory();
7354 OMEXMLService service = (OMEXMLService)factory.getInstance(typeof(OMEXMLService));
7355 loci.formats.ome.OMEXMLMetadata meta = service.createOMEXMLMetadata();
7356 // create format reader
7357 ImageReader imageReader = new ImageReader();
7358 imageReader.setMetadataStore(meta);
7359 // initialize file
7360 file = file.Replace("\\", "/");
7361 imageReader.setId(file);
7362 int imageCount = imageReader.getImageCount();
7363 int seriesCount = imageReader.getSeriesCount();
7364 double physicalSizeX = 0;
7365 double physicalSizeY = 0;
7366 double physicalSizeZ = 0;
7367 double stageSizeX = 0;
7368 double stageSizeY = 0;
7369 double stageSizeZ = 0;
7370 int SizeX = imageReader.getSizeX();
7371 int SizeY = imageReader.getSizeY();
7372 int SizeZ = imageReader.getSizeY();
7373 try
7374 {
7375 bool hasPhysical = false;
7376 if (meta.getPixelsPhysicalSizeX(series) != null)
7377 {
7378 physicalSizeX = meta.getPixelsPhysicalSizeX(series).value().doubleValue();
7379 hasPhysical = true;
7380 }
7381 if (meta.getPixelsPhysicalSizeY(series) != null)
7382 {
7383 physicalSizeY = meta.getPixelsPhysicalSizeY(series).value().doubleValue();
7384 }
7385 if (meta.getPixelsPhysicalSizeZ(series) != null)
7386 {
7387 physicalSizeZ = meta.getPixelsPhysicalSizeZ(series).value().doubleValue();
7388 }
7389 else
7390 {
7391 physicalSizeZ = 1;
7392 }
7393 if (meta.getStageLabelX(series) != null)
7394 stageSizeX = meta.getStageLabelX(series).value().doubleValue();
7395 if (meta.getStageLabelY(series) != null)
7396 stageSizeY = meta.getStageLabelY(series).value().doubleValue();
7397 if (meta.getStageLabelZ(series) != null)
7398 stageSizeZ = meta.getStageLabelZ(series).value().doubleValue();
7399 else
7400 stageSizeZ = 1;
7401 }
7402 catch (Exception e)
7403 {
7404 stageSizeX = 0;
7405 stageSizeY = 0;
7406 stageSizeZ = 1;
7407 }
7408 VolumeD volume = new VolumeD(new Point3D(stageSizeX, stageSizeY, stageSizeZ), new Point3D(physicalSizeX * SizeX, physicalSizeY * SizeY, physicalSizeZ * SizeZ));
7409 int rc = meta.getROICount();
7410 for (int im = 0; im < rc; im++)
7411 {
7412 string roiID = meta.getROIID(im);
7413 string roiName = meta.getROIName(im);
7414 ZCT co = new ZCT(0, 0, 0);
7415 int scount = 1;
7416 try
7417 {
7418 scount = meta.getShapeCount(im);
7419 }
7420 catch (Exception e)
7421 {
7422 Console.WriteLine(e.Message.ToString());
7423 }
7424 for (int sc = 0; sc < scount; sc++)
7425 {
7426 string type = meta.getShapeType(im, sc);
7427 ROI an = new ROI();
7428 an.roiID = roiID;
7429 an.roiName = roiName;
7430 an.shapeIndex = sc;
7431 if (type == "Point")
7432 {
7433 an.type = ROI.Type.Point;
7434 an.id = meta.getPointID(im, sc);
7435 double dx = meta.getPointX(im, sc).doubleValue();
7436 double dy = meta.getPointY(im, sc).doubleValue();
7437 an.AddPoint(ToStageSpace(new PointD(dx, dy), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7438 an.coord = new ZCT();
7439 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPointTheZ(im, sc);
7440 if (nz != null)
7441 an.coord.Z = nz.getNumberValue().intValue();
7442 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPointTheC(im, sc);
7443 if (nc != null)
7444 an.coord.C = nc.getNumberValue().intValue();
7445 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPointTheT(im, sc);
7446 if (nt != null)
7447 an.coord.T = nt.getNumberValue().intValue();
7448 an.Text = meta.getPointText(im, sc);
7449 ome.units.quantity.Length fl = meta.getPointFontSize(im, sc);
7450 if (fl != null)
7451 an.fontSize = fl.value().intValue();
7452 an.family = meta.getPointFontFamily(im, sc).name();
7453 ome.xml.model.primitives.Color col = meta.getPointStrokeColor(im, sc);
7454 if (col != null)
7455 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7456 ome.units.quantity.Length fw = meta.getPointStrokeWidth(im, sc);
7457 if (fw != null)
7458 an.strokeWidth = (float)fw.value().floatValue();
7459 ome.xml.model.primitives.Color colf = meta.getPointStrokeColor(im, sc);
7460 if (colf != null)
7461 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7462 }
7463 else
7464 if (type == "Line")
7465 {
7466 an.type = ROI.Type.Line;
7467 an.id = meta.getLineID(im, sc);
7468 double px1 = meta.getLineX1(im, sc).doubleValue();
7469 double py1 = meta.getLineY1(im, sc).doubleValue();
7470 double px2 = meta.getLineX2(im, sc).doubleValue();
7471 double py2 = meta.getLineY2(im, sc).doubleValue();
7472 an.AddPoint(ToStageSpace(new PointD(px1, py1), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7473 an.AddPoint(ToStageSpace(new PointD(px2, py2), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7474 ome.xml.model.primitives.NonNegativeInteger nz = meta.getLineTheZ(im, sc);
7475 if (nz != null)
7476 co.Z = nz.getNumberValue().intValue();
7477 ome.xml.model.primitives.NonNegativeInteger nc = meta.getLineTheC(im, sc);
7478 if (nc != null)
7479 co.C = nc.getNumberValue().intValue();
7480 ome.xml.model.primitives.NonNegativeInteger nt = meta.getLineTheT(im, sc);
7481 if (nt != null)
7482 co.T = nt.getNumberValue().intValue();
7483 an.coord = co;
7484 an.Text = meta.getLineText(im, sc);
7485 ome.units.quantity.Length fl = meta.getLineFontSize(im, sc);
7486 if (fl != null)
7487 an.fontSize = fl.value().intValue();
7488 an.family = meta.getPointFontFamily(im, sc).name();
7489 ome.xml.model.primitives.Color col = meta.getLineStrokeColor(im, sc);
7490 if (col != null)
7491 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7492 ome.units.quantity.Length fw = meta.getLineStrokeWidth(im, sc);
7493 if (fw != null)
7494 an.strokeWidth = (float)fw.value().floatValue();
7495 ome.xml.model.primitives.Color colf = meta.getLineFillColor(im, sc);
7496 if (colf != null)
7497 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7498 }
7499 else
7500 if (type == "Rectangle")
7501 {
7502 an.type = ROI.Type.Rectangle;
7503 an.id = meta.getRectangleID(im, sc);
7504 double px = meta.getRectangleX(im, sc).doubleValue();
7505 double py = meta.getRectangleY(im, sc).doubleValue();
7506 double pw = meta.getRectangleWidth(im, sc).doubleValue();
7507 double ph = meta.getRectangleHeight(im, sc).doubleValue();
7508 an.Rect = ToStageSpace(new RectangleD(px, py, pw, ph), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7509 ome.xml.model.primitives.NonNegativeInteger nz = meta.getRectangleTheZ(im, sc);
7510 if (nz != null)
7511 co.Z = nz.getNumberValue().intValue();
7512 ome.xml.model.primitives.NonNegativeInteger nc = meta.getRectangleTheC(im, sc);
7513 if (nc != null)
7514 co.C = nc.getNumberValue().intValue();
7515 ome.xml.model.primitives.NonNegativeInteger nt = meta.getRectangleTheT(im, sc);
7516 if (nt != null)
7517 co.T = nt.getNumberValue().intValue();
7518 an.coord = co;
7519
7520 an.Text = meta.getRectangleText(im, sc);
7521 ome.units.quantity.Length fl = meta.getRectangleFontSize(im, sc);
7522 if (fl != null)
7523 an.fontSize = fl.value().intValue();
7524 an.family = meta.getPointFontFamily(im, sc).name();
7525 ome.xml.model.primitives.Color col = meta.getRectangleStrokeColor(im, sc);
7526 if (col != null)
7527 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7528 ome.units.quantity.Length fw = meta.getRectangleStrokeWidth(im, sc);
7529 if (fw != null)
7530 an.strokeWidth = (float)fw.value().floatValue();
7531 ome.xml.model.primitives.Color colf = meta.getRectangleFillColor(im, sc);
7532 if (colf != null)
7533 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7534 ome.xml.model.enums.FillRule fr = meta.getRectangleFillRule(im, sc);
7535 }
7536 else
7537 if (type == "Ellipse")
7538 {
7539 an.type = ROI.Type.Ellipse;
7540 an.id = meta.getEllipseID(im, sc);
7541 double px = meta.getEllipseX(im, sc).doubleValue();
7542 double py = meta.getEllipseY(im, sc).doubleValue();
7543 double ew = meta.getEllipseRadiusX(im, sc).doubleValue();
7544 double eh = meta.getEllipseRadiusY(im, sc).doubleValue();
7545 //We convert the ellipse radius to Rectangle
7546 double w = ew * 2;
7547 double h = eh * 2;
7548 double x = px - ew;
7549 double y = py - eh;
7550 an.Rect = ToStageSpace(new RectangleD(px, py, w, h), physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7551 ome.xml.model.primitives.NonNegativeInteger nz = meta.getEllipseTheZ(im, sc);
7552 if (nz != null)
7553 co.Z = nz.getNumberValue().intValue();
7554 ome.xml.model.primitives.NonNegativeInteger nc = meta.getEllipseTheC(im, sc);
7555 if (nc != null)
7556 co.C = nc.getNumberValue().intValue();
7557 ome.xml.model.primitives.NonNegativeInteger nt = meta.getEllipseTheT(im, sc);
7558 if (nt != null)
7559 co.T = nt.getNumberValue().intValue();
7560 an.coord = co;
7561 an.Text = meta.getEllipseText(im, sc);
7562 ome.units.quantity.Length fl = meta.getEllipseFontSize(im, sc);
7563 if (fl != null)
7564 an.fontSize = fl.value().intValue();
7565 an.family = meta.getPointFontFamily(im, sc).name();
7566 ome.xml.model.primitives.Color col = meta.getEllipseStrokeColor(im, sc);
7567 if (col != null)
7568 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7569 ome.units.quantity.Length fw = meta.getEllipseStrokeWidth(im, sc);
7570 if (fw != null)
7571 an.strokeWidth = (float)fw.value().floatValue();
7572 ome.xml.model.primitives.Color colf = meta.getEllipseFillColor(im, sc);
7573 if (colf != null)
7574 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7575 }
7576 else
7577 if (type == "Polygon")
7578 {
7579 an.type = ROI.Type.Polygon;
7580 an.id = meta.getPolygonID(im, sc);
7581 an.closed = true;
7582 string pxs = meta.getPolygonPoints(im, sc);
7583 PointD[] pts = an.stringToPoints(pxs);
7584 pts = ToStageSpace(pts, physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7585 if (pts.Length > 100)
7586 {
7587 an.type = ROI.Type.Freeform;
7588 }
7589 an.AddPoints(pts);
7590 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPolygonTheZ(im, sc);
7591 if (nz != null)
7592 co.Z = nz.getNumberValue().intValue();
7593 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPolygonTheC(im, sc);
7594 if (nc != null)
7595 co.C = nc.getNumberValue().intValue();
7596 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPolygonTheT(im, sc);
7597 if (nt != null)
7598 co.T = nt.getNumberValue().intValue();
7599 an.coord = co;
7600 an.Text = meta.getPolygonText(im, sc);
7601 ome.units.quantity.Length fl = meta.getPolygonFontSize(im, sc);
7602 if (fl != null)
7603 an.fontSize = fl.value().intValue();
7604 an.family = meta.getPointFontFamily(im, sc).name();
7605 ome.xml.model.primitives.Color col = meta.getPolygonStrokeColor(im, sc);
7606 if (col != null)
7607 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7608 ome.units.quantity.Length fw = meta.getPolygonStrokeWidth(im, sc);
7609 if (fw != null)
7610 an.strokeWidth = (float)fw.value().floatValue();
7611 ome.xml.model.primitives.Color colf = meta.getPolygonFillColor(im, sc);
7612 if (colf != null)
7613 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7614 }
7615 else
7616 if (type == "Polyline")
7617 {
7618 an.type = ROI.Type.Polyline;
7619 an.id = meta.getPolylineID(im, sc);
7620 string pxs = meta.getPolylinePoints(im, sc);
7621 PointD[] pts = an.stringToPoints(pxs);
7622 for (int pi = 0; pi < pts.Length; pi++)
7623 {
7624 pts[pi] = ToStageSpace(pts[pi], physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y);
7625 }
7626 an.AddPoints(an.stringToPoints(pxs));
7627 ome.xml.model.primitives.NonNegativeInteger nz = meta.getPolylineTheZ(im, sc);
7628 if (nz != null)
7629 co.Z = nz.getNumberValue().intValue();
7630 ome.xml.model.primitives.NonNegativeInteger nc = meta.getPolylineTheC(im, sc);
7631 if (nc != null)
7632 co.C = nc.getNumberValue().intValue();
7633 ome.xml.model.primitives.NonNegativeInteger nt = meta.getPolylineTheT(im, sc);
7634 if (nt != null)
7635 co.T = nt.getNumberValue().intValue();
7636 an.coord = co;
7637 an.Text = meta.getPolylineText(im, sc);
7638 ome.units.quantity.Length fl = meta.getPolylineFontSize(im, sc);
7639 if (fl != null)
7640 an.fontSize = fl.value().intValue();
7641 an.family = meta.getPointFontFamily(im, sc).name();
7642 ome.xml.model.primitives.Color col = meta.getPolylineStrokeColor(im, sc);
7643 if (col != null)
7644 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7645 ome.units.quantity.Length fw = meta.getPolylineStrokeWidth(im, sc);
7646 if (fw != null)
7647 an.strokeWidth = (float)fw.value().floatValue();
7648 ome.xml.model.primitives.Color colf = meta.getPolylineFillColor(im, sc);
7649 if (colf != null)
7650 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7651 }
7652 else
7653 if (type == "Label")
7654 {
7655 an.type = ROI.Type.Label;
7656 an.id = meta.getLabelID(im, sc);
7657
7658 ome.xml.model.primitives.NonNegativeInteger nz = meta.getLabelTheZ(im, sc);
7659 if (nz != null)
7660 co.Z = nz.getNumberValue().intValue();
7661 ome.xml.model.primitives.NonNegativeInteger nc = meta.getLabelTheC(im, sc);
7662 if (nc != null)
7663 co.C = nc.getNumberValue().intValue();
7664 ome.xml.model.primitives.NonNegativeInteger nt = meta.getLabelTheT(im, sc);
7665 if (nt != null)
7666 co.T = nt.getNumberValue().intValue();
7667 an.coord = co;
7668
7669 ome.units.quantity.Length fl = meta.getLabelFontSize(im, sc);
7670 if (fl != null)
7671 an.fontSize = fl.value().intValue();
7672 an.family = meta.getPointFontFamily(im, sc).name();
7673 ome.xml.model.primitives.Color col = meta.getLabelStrokeColor(im, sc);
7674 if (col != null)
7675 an.strokeColor = System.Drawing.Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7676 ome.units.quantity.Length fw = meta.getLabelStrokeWidth(im, sc);
7677 if (fw != null)
7678 an.strokeWidth = (float)fw.value().floatValue();
7679 ome.xml.model.primitives.Color colf = meta.getLabelFillColor(im, sc);
7680 if (colf != null)
7681 an.fillColor = System.Drawing.Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7682 PointD p = new PointD(meta.getLabelX(im, sc).doubleValue(), meta.getLabelY(im, sc).doubleValue());
7683 an.AddPoint(ToStageSpace(p, physicalSizeX, physicalSizeY, volume.Location.X, volume.Location.Y));
7684 an.Text = meta.getLabelText(im, sc);
7685 }
7686 }
7687 }
7688
7689 imageReader.close();
7690 return Annotations;
7691 }
PointD ToStageSpace(PointD p)
Definition: Bio.cs:3384

References BioImager.ROI.AddPoint(), BioImager.ROI.AddPoints(), BioImager.BioImage.OMESupport(), BioImager.ROI.stringToPoints(), and BioImager.BioImage.ToStageSpace().

Referenced by BioImager.BioImage.ExportROIFolder(), and BioImager.BioImage.OpenFile().

◆ OpenOMESeries()

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

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.

Definition at line 6993 of file Bio.cs.

6994 {
6995 //We wait incase OME has not initialized yet.
6996 if (!initialized)
6997 do
6998 {
6999 Thread.Sleep(100);
7000 //Application.DoEvents();
7001 } while (!Initialized);
7002 var meta = (IMetadata)((OMEXMLService)new ServiceFactory().getInstance(typeof(OMEXMLService))).createOMEXMLMetadata();
7003 reader.setMetadataStore((MetadataStore)meta);
7004 file = file.Replace("\\", "/");
7005 try
7006 {
7007 if (reader.getCurrentFile() != file)
7008 {
7009 status = "Opening OME Image.";
7010 file = file.Replace("\\", "/");
7011 reader.setId(file);
7012 }
7013 }
7014 catch (Exception e)
7015 {
7016 Scripting.LogLine(e.Message);
7017 return null;
7018 }
7019
7020 bool tile = false;
7021 if (reader.getOptimalTileWidth() != reader.getSizeX())
7022 tile = true;
7023 int count = reader.getSeriesCount();
7024 BioImage[] bs = null;
7025 if (tile)
7026 {
7027 bs = new BioImage[1];
7028 bs[0] = OpenOME(file, 0, tab, addToImages, true, 0, 0, 1920, 1080);
7029 Images.AddImage(bs[0], tab);
7030 return bs;
7031 }
7032 else
7033 bs = new BioImage[count];
7034 reader.close();
7035 for (int i = 0; i < count; i++)
7036 {
7037 bs[i] = OpenOME(file, i, tab, addToImages, false, 0, 0, 0, 0);
7038 if (bs[i] == null)
7039 return null;
7040 }
7041 return bs;
7042 }

References BioImager.BioImage.OpenOME().

Referenced by BioImager.BioImage.OpenOME().

◆ OpenSeries()

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

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.

Definition at line 4612 of file Bio.cs.

4613 {
4614 Tiff image = Tiff.Open(file, "r");
4615 int pages = image.NumberOfDirectories();
4616 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
4617 int sp = image.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
4618 ImageJDesc imDesc = new ImageJDesc();
4619 int count = 1;
4620 if (f != null)
4621 {
4622 string desc = f[0].ToString();
4623 if (desc.StartsWith("ImageJ"))
4624 {
4625 imDesc.SetString(desc);
4626 if (imDesc.channels != 0)
4627 count = imDesc.channels;
4628 }
4629 }
4630 int scount = (pages * sp) / count;
4631 BioImage[] bs = new BioImage[pages];
4632 image.Close();
4633 for (int i = 0; i < pages; i++)
4634 {
4635 bs[i] = OpenFile(file, i, tab, true);
4636 }
4637 return bs;
4638 }

References BioImager.BioImage.Open(), BioImager.BioImage.OpenFile(), and BioImager.BioImage.ImageJDesc.SetString().

◆ OpenVips()

static void BioImager.BioImage.OpenVips ( BioImage  b,
int  pagecount 
)
static

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.

Definition at line 5778 of file Bio.cs.

5779 {
5780 try
5781 {
5782 for (int i = 0; i < pagecount; i++)
5783 {
5784 b.vipPages.Add(NetVips.Image.Tiffload(b.file, i));
5785 }
5786 }
5787 catch (Exception e)
5788 {
5789 Console.WriteLine(e.Message);
5790 }
5791
5792 }

Referenced by BioImager.BioImage.OpenFile().

◆ OpenXML()

static string BioImager.BioImage.OpenXML ( string  file)
static

‍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.

Definition at line 7332 of file Bio.cs.

7333 {
7334 if (!file.EndsWith(".tif"))
7335 return null;
7336 Tiff image = Tiff.Open(file, "r");
7337 FieldValue[] f = image.GetField(TiffTag.IMAGEDESCRIPTION);
7338 return f[0].ToString();
7339 }

◆ operator*()

static BioImage BioImager.BioImage.operator* ( BioImage  a,
ColorS  b 
)
static

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

Definition at line 8211 of file Bio.cs.

8212 {
8213 for (int i = 0; i < a.Buffers.Count; i++)
8214 {
8215 a.Buffers[i] = a.Buffers[i] * b;
8216 }
8217 return a;
8218 }

◆ operator+() [1/2]

static BioImage BioImager.BioImage.operator+ ( BioImage  a,
ColorS  b 
)
static

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

Definition at line 8226 of file Bio.cs.

8227 {
8228 for (int i = 0; i < a.Buffers.Count; i++)
8229 {
8230 a.Buffers[i] = a.Buffers[i] + b;
8231 }
8232 return a;
8233 }

◆ operator+() [2/2]

static BioImage BioImager.BioImage.operator+ ( BioImage  a,
float  b 
)
static

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.

Definition at line 8168 of file Bio.cs.

8169 {
8170 for (int i = 0; i < a.Buffers.Count; i++)
8171 {
8172 a.Buffers[i] = a.Buffers[i] + b;
8173 }
8174 return a;
8175 }

◆ operator-() [1/2]

static BioImage BioImager.BioImage.operator- ( BioImage  a,
ColorS  b 
)
static

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.

Definition at line 8240 of file Bio.cs.

8241 {
8242 for (int i = 0; i < a.Buffers.Count; i++)
8243 {
8244 a.Buffers[i] = a.Buffers[i] - b;
8245 }
8246 return a;
8247 }

◆ operator-() [2/2]

static BioImage BioImager.BioImage.operator- ( BioImage  a,
float  b 
)
static

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.

Definition at line 8182 of file Bio.cs.

8183 {
8184 for (int i = 0; i < a.Buffers.Count; i++)
8185 {
8186 a.Buffers[i] = a.Buffers[i] - b;
8187 }
8188 return a;
8189 }

◆ operator/() [1/2]

static BioImage BioImager.BioImage.operator/ ( BioImage  a,
ColorS  b 
)
static

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.

Definition at line 8197 of file Bio.cs.

8198 {
8199 for (int i = 0; i < a.Buffers.Count; i++)
8200 {
8201 a.Buffers[i] = a.Buffers[i] / b;
8202 }
8203 return a;
8204 }

◆ operator/() [2/2]

static BioImage BioImager.BioImage.operator/ ( BioImage  a,
float  b 
)
static

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.

Definition at line 8153 of file Bio.cs.

8154 {
8155 for (int i = 0; i < a.Buffers.Count; i++)
8156 {
8157 a.Buffers[i] = a.Buffers[i] / b;
8158 }
8159 return a;
8160 }

◆ ROIsToString()

static string BioImager.BioImage.ROIsToString ( List< ROI Annotations)
static

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

Definition at line 7697 of file Bio.cs.

7698 {
7699 string s = "";
7700 for (int i = 0; i < Annotations.Count; i++)
7701 {
7702 s += ROIToString(Annotations[i]);
7703 }
7704 return s;
7705 }
static string ROIToString(ROI an)
Definition: Bio.cs:7712

References BioImager.BioImage.ROIToString().

Referenced by BioImager.BioImage.ExportROIsCSV().

◆ ROIToString()

static string BioImager.BioImage.ROIToString ( ROI  an)
static

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

Definition at line 7712 of file Bio.cs.

7713 {
7714 PointD[] points = an.GetPoints();
7715 string pts = "";
7716 for (int j = 0; j < points.Length; j++)
7717 {
7718 if (j == points.Length - 1)
7719 pts += points[j].X.ToString(CultureInfo.InvariantCulture) + "," + points[j].Y.ToString(CultureInfo.InvariantCulture);
7720 else
7721 pts += points[j].X.ToString(CultureInfo.InvariantCulture) + "," + points[j].Y.ToString(CultureInfo.InvariantCulture) + " ";
7722 }
7723 char sep = (char)34;
7724 string sColor = sep.ToString() + an.strokeColor.A.ToString() + ',' + an.strokeColor.R.ToString() + ',' + an.strokeColor.G.ToString() + ',' + an.strokeColor.B.ToString() + sep.ToString();
7725 string bColor = sep.ToString() + an.fillColor.A.ToString() + ',' + an.fillColor.R.ToString() + ',' + an.fillColor.G.ToString() + ',' + an.fillColor.B.ToString() + sep.ToString();
7726
7727 string line = an.roiID + ',' + an.roiName + ',' + an.type.ToString() + ',' + an.id + ',' + an.shapeIndex.ToString() + ',' +
7728 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) + ',' +
7729 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;
7730 return line;
7731 }

References BioImager.ROI.GetPoints().

Referenced by BioImager.ImageView.CopySelection(), BioImager.BioImage.ROIsToString(), and BioImager.BioImage.SaveSeries().

◆ RotateFlip()

void BioImager.BioImage.RotateFlip ( AForge.RotateFlipType  rot)

Rotates the image by specified degrees or flips it.

Parameters
rotThe type of rotation to perform.

Definition at line 3081 of file Bio.cs.

3082 {
3083 for (int i = 0; i < Buffers.Count; i++)
3084 {
3085 Buffers[i].RotateFlip(rot);
3086 }
3087 Volume = new VolumeD(new Point3D(StageSizeX, StageSizeY, StageSizeZ), new Point3D(PhysicalSizeX * SizeX, PhysicalSizeY * SizeY, PhysicalSizeZ * SizeZ));
3088 }

◆ Save()

static void BioImager.BioImage.Save ( string  file,
string  ID 
)
static

It takes a file and an ID and saves the file to the ID

Parameters
fileThe file to save the data to.
IDThe ID of the user

Definition at line 7251 of file Bio.cs.

7252 {
7253 SaveFile(file, ID);
7254 }
static void SaveFile(string file, string ID)
Definition: Bio.cs:4493

References BioImager.BioImage.SaveFile().

◆ SaveAsync()

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

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.

Definition at line 7093 of file Bio.cs.

7094 {
7095 savefile = file;
7096 saveid = id;
7097 some = ome;
7098 await Task.Run(SaveThread);
7099 }

◆ SaveFile()

static void BioImager.BioImage.SaveFile ( string  file,
string  ID 
)
static

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.

Definition at line 4493 of file Bio.cs.

4494 {
4495 string[] sts = new string[1];
4496 sts[0] = ID;
4497 SaveSeries(sts, file);
4498 }
static void SaveSeries(string[] IDs, string file)
Definition: Bio.cs:4503

References BioImager.BioImage.SaveSeries().

Referenced by BioImager.BioImage.Save().

◆ SaveOME()

static void BioImager.BioImage.SaveOME ( string  file,
string  ID 
)
static

This function takes a string array of image IDs, a file name, and a number of planes. It then saves the images to the file name

Parameters
filethe file name to save the image to
IDThe ID of the image you want to save

Definition at line 5156 of file Bio.cs.

5157 {
5158 if (!OMESupport())
5159 return;
5160 string[] sts = new string[1];
5161 sts[0] = ID;
5162 SaveOMESeries(sts, file, BioImage.Planes);
5163 }
static void SaveOMESeries(BioImage[] bms, string f, bool planes)
Definition: Bio.cs:5169

References BioImager.BioImage.OMESupport(), and BioImager.BioImage.SaveOMESeries().

◆ SaveOMEPyramidal()

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

Definition at line 5542 of file Bio.cs.

5543 {
5544 if (File.Exists(file))
5545 File.Delete(file);
5546 //We need to go through the images and find the ones belonging to each resolution.
5547 //As well we need to determine the dimensions of the tiles.
5548 Dictionary<double, List<BioImage>> bis = new Dictionary<double, List<BioImage>>();
5549 Dictionary<double, Point3D> min = new Dictionary<double, Point3D>();
5550 Dictionary<double, Point3D> max = new Dictionary<double, Point3D>();
5551 for (int i = 0; i < bms.Length; i++)
5552 {
5553 for (int r = 0; r < bms[i].Resolutions.Count; r++)
5554 {
5555 Resolution res = bms[i].Resolutions[r];
5556 if (bis.ContainsKey(res.PhysicalSizeX))
5557 {
5558 bis[res.PhysicalSizeX].Add(bms[i]);
5559 if (bms[i].StageSizeX < min[res.PhysicalSizeX].X || bms[i].StageSizeY < min[res.PhysicalSizeX].Y)
5560 {
5561 min[res.PhysicalSizeX] = bms[i].Volume.Location;
5562 }
5563 if (bms[i].StageSizeX > max[res.PhysicalSizeX].X || bms[i].StageSizeY > max[res.PhysicalSizeX].Y)
5564 {
5565 max[res.PhysicalSizeX] = bms[i].Volume.Location;
5566 }
5567 }
5568 else
5569 {
5570 bis.Add(res.PhysicalSizeX, new List<BioImage>());
5571 min.Add(res.PhysicalSizeX, new Point3D(double.MaxValue, double.MaxValue, double.MaxValue));
5572 max.Add(res.PhysicalSizeX, new Point3D(double.MinValue, double.MinValue, double.MinValue));
5573 if (bms[i].StageSizeX < min[res.PhysicalSizeX].X || bms[i].StageSizeY < min[res.PhysicalSizeX].Y)
5574 {
5575 min[res.PhysicalSizeX] = bms[i].Volume.Location;
5576 }
5577 if (bms[i].StageSizeX > max[res.PhysicalSizeX].X || bms[i].StageSizeY > max[res.PhysicalSizeX].Y)
5578 {
5579 max[res.PhysicalSizeX] = bms[i].Volume.Location;
5580 }
5581 bis[res.PhysicalSizeX].Add(bms[i]);
5582 }
5583 }
5584 }
5585 int s = 0;
5586 //We determine the sizes of each resolution.
5587 Dictionary<double, AForge.Size> ss = new Dictionary<double, AForge.Size>();
5588 int minx = int.MaxValue;
5589 int miny = int.MaxValue;
5590 double last = 0;
5591 foreach (double px in bis.Keys)
5592 {
5593 int xs = (1 + (int)Math.Ceiling((max[px].X - min[px].X) / bis[px][0].Resolutions[0].VolumeWidth)) * bis[px][0].SizeX;
5594 int ys = (1 + (int)Math.Ceiling((max[px].Y - min[px].Y) / bis[px][0].Resolutions[0].VolumeHeight)) * bis[px][0].SizeY;
5595 if (minx > xs)
5596 minx = xs;
5597 if (miny > ys)
5598 miny = ys;
5599 ss.Add(px, new AForge.Size(xs, ys));
5600 last = px;
5601 }
5602 s = 0;
5603 string met = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
5604 "<OME xmlns=\"http://www.openmicroscopy.org/Schemas/OME/2016-06\" " +
5605 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
5606 "xsi:schemaLocation=\"http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd\">";
5607 NetVips.Image img = null;
5608 int ib = 0;
5609
5610 foreach (double px in bis.Keys)
5611 {
5612 int c = bis[px][s].SizeC;
5613 if (bis[px][s].Buffers[0].isRGB)
5614 c = 3;
5615 string endian = (bis[px][s].Buffers[0].LittleEndian).ToString().ToLower();
5616 met +=
5617 "<Image ID=\"Image:" + ib + "\">" +
5618 "<Pixels BigEndian=\"" + endian + "\" DimensionOrder= \"XYCZT\" ID= \"Pixels:0\" Interleaved=\"true\" " +
5619 "PhysicalSizeX=\"" + bis[px][s].PhysicalSizeX + "\" PhysicalSizeXUnit=\"µm\" PhysicalSizeY=\"" + bis[px][s].PhysicalSizeY + "\" PhysicalSizeYUnit=\"µm\" SignificantBits=\"" + bis[px][s].bitsPerPixel + "\" " +
5620 "SizeC = \"" + c + "\" SizeT = \"" + bis[px][s].SizeT + "\" SizeX =\"" + ss[px].Width +
5621 "\" SizeY= \"" + ss[px].Height + "\" SizeZ=\"" + bis[px][s].SizeZ;
5622 if (bis[px][s].bitsPerPixel > 8) met += "\" Type= \"uint16\">";
5623 else met += "\" Type= \"uint8\">";
5624 int i = 0;
5625 foreach (Channel ch in bis[px][s].Channels)
5626 {
5627 met += "<Channel ID=\"Channel:" + ib + ":" + i + "\" SamplesPerPixel=\"1\"></Channel>";
5628 i++;
5629 }
5630 met += "</Pixels></Image>";
5631 ib++;
5632 }
5633 met += "</OME>";
5634 foreach (double px in bis.Keys)
5635 {
5636 PixelFormat pf = bis[px][0].Buffers[0].PixelFormat;
5637 Bitmap level = new Bitmap(ss[px].Width, ss[px].Height, pf);
5638 int bands = GetBands(pf);
5639 if(bis[px][0].bitsPerPixel > 8)
5640 img = NetVips.Image.NewFromMemory(level.Data, (ulong)level.Length, level.Width, level.Height, bands, Enums.BandFormat.Ushort);
5641 else
5642 img = NetVips.Image.NewFromMemory(level.Data, (ulong)level.Length, level.Width, level.Height, bands, Enums.BandFormat.Uchar);
5643 int i = 0;
5644 foreach (BioImage b in bis[px])
5645 {
5646 AForge.Size si = ss[px];
5647 double xs = (-(min[px].X - bis[px][i].Volume.Location.X) / bis[px][i].Resolutions[0].VolumeWidth) * bis[px][i].SizeX;
5648 double ys = (-(min[px].Y - bis[px][i].Volume.Location.Y) / bis[px][i].Resolutions[0].VolumeHeight) * bis[px][i].SizeY;
5649 NetVips.Image tile;
5650 if(b.bitsPerPixel > 8)
5651 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);
5652 else
5653 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);
5654 img = img.Insert(tile, (int)xs, (int)ys);
5655 i++;
5656 };
5657 using var mutated = img.Mutate(mutable =>
5658 {
5659 // Set the ImageDescription tag
5660 mutable.Set(GValue.GStrType, "image-description", met);
5661 mutable.Set(GValue.GIntType, "page-height", ss[last].Height);
5662 });
5663 if (bis[px][0].bitsPerPixel > 8)
5664 mutated.Tiffsave(file, compression, 1, Enums.ForeignTiffPredictor.None, true, ss[px].Width, ss[px].Height, true, false, 16,
5665 Enums.ForeignTiffResunit.Cm, 1000 * bis[px][0].PhysicalSizeX, 1000 * bis[px][0].PhysicalSizeY, true, null, Enums.RegionShrink.Nearest,
5666 compressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, ss[px].Height);
5667 else
5668 mutated.Tiffsave(file, compression, 1, Enums.ForeignTiffPredictor.None, true, ss[px].Width, ss[px].Height, true, false, 8,
5669 Enums.ForeignTiffResunit.Cm, 1000 * bis[px][0].PhysicalSizeX, 1000 * bis[px][0].PhysicalSizeY, true, null, Enums.RegionShrink.Nearest,
5670 compressionLevel, true, Enums.ForeignDzDepth.One, true, false, null, null, ss[px].Height);
5671 s++;
5672 }
5673
5674 }
override string ToString()
Definition: Bio.cs:8142

◆ SaveOMESeries() [1/2]

static void BioImager.BioImage.SaveOMESeries ( BioImage[]  bms,
string  f,
bool  planes 
)
static

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.

Definition at line 5169 of file Bio.cs.

5170 {
5171 if (!OMESupport())
5172 return;
5173 if (File.Exists(f))
5174 File.Delete(f);
5175 loci.formats.meta.IMetadata omexml = service.createOMEXMLMetadata();
5176 status = "Saving OME Image Metadata.";
5177 for (int fi = 0; fi < bms.Length; fi++)
5178 {
5179 progFile = bms[fi].file;
5180 int serie = fi;
5181 string file = bms[fi].file;
5182
5183 BioImage b = bms[fi];
5184 if (b.isPyramidal)
5185 {
5186 b = OpenOME(b.file, b.level, false, false, true, (int)App.viewer.PyramidalOrigin.X, (int)App.viewer.PyramidalOrigin.Y, App.viewer.Width, App.viewer.Height);
5187 }
5188 // create OME-XML metadata store
5189
5190 omexml.setImageID("Image:" + serie, serie);
5191 omexml.setPixelsID("Pixels:" + serie, serie);
5192 omexml.setPixelsInterleaved(java.lang.Boolean.TRUE, serie);
5193 omexml.setPixelsDimensionOrder(ome.xml.model.enums.DimensionOrder.XYCZT, serie);
5194 if (b.bitsPerPixel > 8)
5195 omexml.setPixelsType(ome.xml.model.enums.PixelType.UINT16, serie);
5196 else
5197 omexml.setPixelsType(ome.xml.model.enums.PixelType.UINT8, serie);
5198 omexml.setPixelsSizeX(new PositiveInteger(java.lang.Integer.valueOf(b.SizeX)), serie);
5199 omexml.setPixelsSizeY(new PositiveInteger(java.lang.Integer.valueOf(b.SizeY)), serie);
5200 omexml.setPixelsSizeZ(new PositiveInteger(java.lang.Integer.valueOf(b.SizeZ)), serie);
5201 int samples = 1;
5202 if (b.isRGB)
5203 samples = 3;
5204 omexml.setPixelsSizeC(new PositiveInteger(java.lang.Integer.valueOf(b.SizeC)), serie);
5205 omexml.setPixelsSizeT(new PositiveInteger(java.lang.Integer.valueOf(b.SizeT)), serie);
5206 if (BitConverter.IsLittleEndian)
5207 omexml.setPixelsBigEndian(java.lang.Boolean.FALSE, serie);
5208 else
5209 omexml.setPixelsBigEndian(java.lang.Boolean.TRUE, serie);
5210 ome.units.quantity.Length p1 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeX), ome.units.UNITS.MICROMETER);
5211 omexml.setPixelsPhysicalSizeX(p1, serie);
5212 ome.units.quantity.Length p2 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeY), ome.units.UNITS.MICROMETER);
5213 omexml.setPixelsPhysicalSizeY(p2, serie);
5214 ome.units.quantity.Length p3 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.PhysicalSizeZ), ome.units.UNITS.MICROMETER);
5215 omexml.setPixelsPhysicalSizeZ(p3, serie);
5216 ome.units.quantity.Length s1 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.X), ome.units.UNITS.MICROMETER);
5217 omexml.setStageLabelX(s1, serie);
5218 ome.units.quantity.Length s2 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.Y), ome.units.UNITS.MICROMETER);
5219 omexml.setStageLabelY(s2, serie);
5220 ome.units.quantity.Length s3 = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Volume.Location.Z), ome.units.UNITS.MICROMETER);
5221 omexml.setStageLabelZ(s3, serie);
5222 omexml.setStageLabelName("StageLabel:" + serie, serie);
5223
5224 for (int channel = 0; channel < b.Channels.Count; channel++)
5225 {
5226 Channel c = b.Channels[channel];
5227 for (int r = 0; r < c.range.Length; r++)
5228 {
5229 omexml.setChannelID("Channel:" + channel + ":" + serie, serie, channel + r);
5230 omexml.setChannelSamplesPerPixel(new PositiveInteger(java.lang.Integer.valueOf(1)), serie, channel + r);
5231 if (c.LightSourceWavelength != 0)
5232 {
5233 omexml.setChannelLightSourceSettingsID("LightSourceSettings:" + channel, serie, channel + r);
5234 ome.units.quantity.Length lw = new ome.units.quantity.Length(java.lang.Double.valueOf(c.LightSourceWavelength), ome.units.UNITS.NANOMETER);
5235 omexml.setChannelLightSourceSettingsWavelength(lw, serie, channel + r);
5236 omexml.setChannelLightSourceSettingsAttenuation(PercentFraction.valueOf(c.LightSourceAttenuation), serie, channel + r);
5237 }
5238 omexml.setChannelName(c.Name, serie, channel + r);
5239 if (c.Color != null)
5240 {
5241 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);
5242 omexml.setChannelColor(col, serie, channel + r);
5243 }
5244 if (c.Emission != 0)
5245 {
5246 ome.units.quantity.Length em = new ome.units.quantity.Length(java.lang.Double.valueOf(c.Emission), ome.units.UNITS.NANOMETER);
5247 omexml.setChannelEmissionWavelength(em, serie, channel + r);
5248 ome.units.quantity.Length ex = new ome.units.quantity.Length(java.lang.Double.valueOf(c.Excitation), ome.units.UNITS.NANOMETER);
5249 omexml.setChannelExcitationWavelength(ex, serie, channel + r);
5250 }
5251 /*
5252 if (c.ContrastMethod != null)
5253 {
5254 ome.xml.model.enums.ContrastMethod cm = (ome.xml.model.enums.ContrastMethod)Enum.Parse(typeof(ome.xml.model.enums.ContrastMethod), c.ContrastMethod);
5255 omexml.setChannelContrastMethod(cm, serie, channel + r);
5256 }
5257 if (c.IlluminationType != null)
5258 {
5259 ome.xml.model.enums.IlluminationType il = (ome.xml.model.enums.IlluminationType)Enum.Parse(typeof(ome.xml.model.enums.IlluminationType), c.IlluminationType.ToUpper());
5260 omexml.setChannelIlluminationType(il, serie, channel + r);
5261 }
5262 if (c.AcquisitionMode != null)
5263 {
5264 ome.xml.model.enums.AcquisitionMode am = (ome.xml.model.enums.AcquisitionMode)Enum.Parse(typeof(ome.xml.model.enums.AcquisitionMode), c.AcquisitionMode.ToUpper());
5265 omexml.setChannelAcquisitionMode(am, serie, channel + r);
5266 }
5267 */
5268 omexml.setChannelFluor(c.Fluor, serie, channel + r);
5269 if (c.LightSourceIntensity != 0)
5270 {
5271 ome.units.quantity.Power pw = new ome.units.quantity.Power(java.lang.Double.valueOf(c.LightSourceIntensity), ome.units.UNITS.VOLT);
5272 omexml.setLightEmittingDiodePower(pw, serie, channel + r);
5273 omexml.setLightEmittingDiodeID(c.DiodeName, serie, channel + r);
5274 }
5275 }
5276 }
5277
5278 int i = 0;
5279 foreach (ROI an in b.Annotations)
5280 {
5281 if (an.roiID == "")
5282 omexml.setROIID("ROI:" + i.ToString() + ":" + serie, i);
5283 else
5284 omexml.setROIID(an.roiID, i);
5285 omexml.setROIName(an.roiName, i);
5286 if (an.type == ROI.Type.Point)
5287 {
5288 if (an.id != "")
5289 omexml.setPointID(an.id, i, serie);
5290 else
5291 omexml.setPointID("Shape:" + i + ":" + serie, i, serie);
5292 omexml.setPointX(java.lang.Double.valueOf(b.ToImageSpaceX(an.X)), i, serie);
5293 omexml.setPointY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Y)), i, serie);
5294 omexml.setPointTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5295 omexml.setPointTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5296 omexml.setPointTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5297 if (an.Text != "")
5298 omexml.setPointText(an.Text, i, serie);
5299 else
5300 omexml.setPointText(i.ToString(), i, serie);
5301 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5302 omexml.setPointFontSize(fl, i, serie);
5303 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5304 omexml.setPointStrokeColor(col, i, serie);
5305 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5306 omexml.setPointStrokeWidth(sw, i, serie);
5307 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5308 omexml.setPointFillColor(colf, i, serie);
5309 }
5310 else
5311 if (an.type == ROI.Type.Polygon || an.type == ROI.Type.Freeform)
5312 {
5313 if (an.id != "")
5314 omexml.setPolygonID(an.id, i, serie);
5315 else
5316 omexml.setPolygonID("Shape:" + i + ":" + serie, i, serie);
5317 omexml.setPolygonPoints(an.PointsToString(b), i, serie);
5318 omexml.setPolygonTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5319 omexml.setPolygonTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5320 omexml.setPolygonTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5321 if (an.Text != "")
5322 omexml.setPolygonText(an.Text, i, serie);
5323 else
5324 omexml.setPolygonText(i.ToString(), i, serie);
5325 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5326 omexml.setPolygonFontSize(fl, i, serie);
5327 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5328 omexml.setPolygonStrokeColor(col, i, serie);
5329 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5330 omexml.setPolygonStrokeWidth(sw, i, serie);
5331 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5332 omexml.setPolygonFillColor(colf, i, serie);
5333 }
5334 else
5335 if (an.type == ROI.Type.Rectangle)
5336 {
5337 if (an.id != "")
5338 omexml.setRectangleID(an.id, i, serie);
5339 else
5340 omexml.setRectangleID("Shape:" + i + ":" + serie, i, serie);
5341 omexml.setRectangleWidth(java.lang.Double.valueOf(b.ToImageSizeX(an.W)), i, serie);
5342 omexml.setRectangleHeight(java.lang.Double.valueOf(b.ToImageSizeY(an.H)), i, serie);
5343 omexml.setRectangleX(java.lang.Double.valueOf(b.ToImageSpaceX(an.Rect.X)), i, serie);
5344 omexml.setRectangleY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Rect.Y)), i, serie);
5345 omexml.setRectangleTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5346 omexml.setRectangleTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5347 omexml.setRectangleTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5348 omexml.setRectangleText(i.ToString(), i, serie);
5349 if (an.Text != "")
5350 omexml.setRectangleText(an.Text, i, serie);
5351 else
5352 omexml.setRectangleText(i.ToString(), i, serie);
5353 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5354 omexml.setRectangleFontSize(fl, i, serie);
5355 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5356 omexml.setRectangleStrokeColor(col, i, serie);
5357 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5358 omexml.setRectangleStrokeWidth(sw, i, serie);
5359 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5360 omexml.setRectangleFillColor(colf, i, serie);
5361 }
5362 else
5363 if (an.type == ROI.Type.Line)
5364 {
5365 if (an.id != "")
5366 omexml.setLineID(an.id, i, serie);
5367 else
5368 omexml.setLineID("Shape:" + i + ":" + serie, i, serie);
5369 omexml.setLineX1(java.lang.Double.valueOf(b.ToImageSpaceX(an.GetPoint(0).X)), i, serie);
5370 omexml.setLineY1(java.lang.Double.valueOf(b.ToImageSpaceY(an.GetPoint(0).Y)), i, serie);
5371 omexml.setLineX2(java.lang.Double.valueOf(b.ToImageSpaceX(an.GetPoint(1).X)), i, serie);
5372 omexml.setLineY2(java.lang.Double.valueOf(b.ToImageSpaceY(an.GetPoint(1).Y)), i, serie);
5373 omexml.setLineTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5374 omexml.setLineTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5375 omexml.setLineTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5376 if (an.Text != "")
5377 omexml.setLineText(an.Text, i, serie);
5378 else
5379 omexml.setLineText(i.ToString(), i, serie);
5380 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5381 omexml.setLineFontSize(fl, i, serie);
5382 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5383 omexml.setLineStrokeColor(col, i, serie);
5384 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5385 omexml.setLineStrokeWidth(sw, i, serie);
5386 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5387 omexml.setLineFillColor(colf, i, serie);
5388 }
5389 else
5390 if (an.type == ROI.Type.Ellipse)
5391 {
5392
5393 if (an.id != "")
5394 omexml.setEllipseID(an.id, i, serie);
5395 else
5396 omexml.setEllipseID("Shape:" + i + ":" + serie, i, serie);
5397 //We need to change Rectangle to ellipse radius;
5398 double w = (double)an.W / 2;
5399 double h = (double)an.H / 2;
5400 omexml.setEllipseRadiusX(java.lang.Double.valueOf(b.ToImageSizeX(w)), i, serie);
5401 omexml.setEllipseRadiusY(java.lang.Double.valueOf(b.ToImageSizeY(h)), i, serie);
5402
5403 double x = an.Point.X + w;
5404 double y = an.Point.Y + h;
5405 omexml.setEllipseX(java.lang.Double.valueOf(b.ToImageSpaceX(x)), i, serie);
5406 omexml.setEllipseY(java.lang.Double.valueOf(b.ToImageSpaceX(y)), i, serie);
5407 omexml.setEllipseTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5408 omexml.setEllipseTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5409 omexml.setEllipseTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5410 if (an.Text != "")
5411 omexml.setEllipseText(an.Text, i, serie);
5412 else
5413 omexml.setEllipseText(i.ToString(), i, serie);
5414 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5415 omexml.setEllipseFontSize(fl, i, serie);
5416 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5417 omexml.setEllipseStrokeColor(col, i, serie);
5418 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5419 omexml.setEllipseStrokeWidth(sw, i, serie);
5420 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5421 omexml.setEllipseFillColor(colf, i, serie);
5422 }
5423 else
5424 if (an.type == ROI.Type.Label)
5425 {
5426 if (an.id != "")
5427 omexml.setLabelID(an.id, i, serie);
5428 else
5429 omexml.setLabelID("Shape:" + i + ":" + serie, i, serie);
5430 omexml.setLabelX(java.lang.Double.valueOf(b.ToImageSpaceX(an.Rect.X)), i, serie);
5431 omexml.setLabelY(java.lang.Double.valueOf(b.ToImageSpaceY(an.Rect.Y)), i, serie);
5432 omexml.setLabelTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.Z)), i, serie);
5433 omexml.setLabelTheC(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.C)), i, serie);
5434 omexml.setLabelTheT(new NonNegativeInteger(java.lang.Integer.valueOf(an.coord.T)), i, serie);
5435 omexml.setLabelText(i.ToString(), i, serie);
5436 if (an.Text != "")
5437 omexml.setLabelText(an.Text, i, serie);
5438 else
5439 omexml.setLabelText(i.ToString(), i, serie);
5440 ome.units.quantity.Length fl = new ome.units.quantity.Length(java.lang.Double.valueOf(an.fontSize), ome.units.UNITS.PIXEL);
5441 omexml.setLabelFontSize(fl, i, serie);
5442 ome.xml.model.primitives.Color col = new ome.xml.model.primitives.Color(an.strokeColor.R, an.strokeColor.G, an.strokeColor.B, an.strokeColor.A);
5443 omexml.setLabelStrokeColor(col, i, serie);
5444 ome.units.quantity.Length sw = new ome.units.quantity.Length(java.lang.Double.valueOf(an.strokeWidth), ome.units.UNITS.PIXEL);
5445 omexml.setLabelStrokeWidth(sw, i, serie);
5446 ome.xml.model.primitives.Color colf = new ome.xml.model.primitives.Color(an.fillColor.R, an.fillColor.G, an.fillColor.B, an.fillColor.A);
5447 omexml.setLabelFillColor(colf, i, serie);
5448 }
5449 i++;
5450 }
5451
5452 if (b.Buffers[0].Plane != null && planes)
5453 for (int bu = 0; bu < b.Buffers.Count; bu++)
5454 {
5455 //Correct order of parameters.
5456 if (b.Buffers[bu].Plane.Delta != 0)
5457 {
5458 ome.units.quantity.Time t = new ome.units.quantity.Time(java.lang.Double.valueOf(b.Buffers[bu].Plane.Delta), ome.units.UNITS.MILLISECOND);
5459 omexml.setPlaneDeltaT(t, serie, bu);
5460 }
5461 if (b.Buffers[bu].Plane.Exposure != 0)
5462 {
5463 ome.units.quantity.Time et = new ome.units.quantity.Time(java.lang.Double.valueOf(b.Buffers[bu].Plane.Exposure), ome.units.UNITS.MILLISECOND);
5464 omexml.setPlaneExposureTime(et, serie, bu);
5465 }
5466 ome.units.quantity.Length lx = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.X), ome.units.UNITS.MICROMETER);
5467 ome.units.quantity.Length ly = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.Y), ome.units.UNITS.MICROMETER);
5468 ome.units.quantity.Length lz = new ome.units.quantity.Length(java.lang.Double.valueOf(b.Buffers[bu].Plane.Location.Z), ome.units.UNITS.MICROMETER);
5469 omexml.setPlanePositionX(lx, serie, bu);
5470 omexml.setPlanePositionY(ly, serie, bu);
5471 omexml.setPlanePositionZ(lz, serie, bu);
5472 omexml.setPlaneTheC(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.C)), serie, bu);
5473 omexml.setPlaneTheZ(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.Z)), serie, bu);
5474 omexml.setPlaneTheT(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.T)), serie, bu);
5475
5476 omexml.setTiffDataPlaneCount(new NonNegativeInteger(java.lang.Integer.valueOf(1)), serie, bu);
5477 omexml.setTiffDataIFD(new NonNegativeInteger(java.lang.Integer.valueOf(bu)), serie, bu);
5478 omexml.setTiffDataFirstC(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.C)), serie, bu);
5479 omexml.setTiffDataFirstZ(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.Z)), serie, bu);
5480 omexml.setTiffDataFirstT(new NonNegativeInteger(java.lang.Integer.valueOf(b.Buffers[bu].Plane.Coordinate.T)), serie, bu);
5481
5482 }
5483
5484 }
5485 writer.setMetadataRetrieve(omexml);
5486 f = f.Replace("\\", "/");
5487 writer.setId(f);
5488 status = "Saving OME Image Planes.";
5489 for (int i = 0; i < bms.Length; i++)
5490 {
5491 string file = bms[i].file;
5492 BioImage b = bms[i];
5493 writer.setSeries(i);
5494 for (int bu = 0; bu < b.Buffers.Count; bu++)
5495 {
5496 progressValue = (float)bu / (float)b.Buffers.Count;
5497 byte[] bts = b.Buffers[bu].GetSaveBytes(BitConverter.IsLittleEndian);
5498 writer.saveBytes(bu, bts);
5499 }
5500 }
5501 bool stop = false;
5502 do
5503 {
5504 try
5505 {
5506 writer.close();
5507 stop = true;
5508 }
5509 catch (Exception e)
5510 {
5511 //Scripting.LogLine(e.Message);
5512 }
5513
5514 } while (!stop);
5515 }

References BioImager.ROI.GetPoint(), BioImager.BioImage.OMESupport(), BioImager.BioImage.OpenOME(), BioImager.ROI.PointsToString(), and BioImager.ImageView.PyramidalOrigin.

Referenced by BioImager.BioImage.SaveOME().

◆ SaveOMESeries() [2/2]

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

Definition at line 5516 of file Bio.cs.

5517 {
5518 BioImage[] bm = new BioImage[files.Length];
5519 for (int i = 0; i < files.Length; i++)
5520 {
5521 bm[i] = Images.GetImage(files[i]);
5522 }
5523 SaveOMESeries(bm,f,planes);
5524 }

◆ SavePyramidalAsync()

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

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.

Definition at line 7157 of file Bio.cs.

7158 {
7159 bms = imgs;
7160 savefile = file;
7161 comp = com;
7162 compLev = compLevel;
7163 await Task.Run(SavePyramidalThread);
7164 }

◆ SaveSeries()

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

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.

Definition at line 4503 of file Bio.cs.

4504 {
4505 string desc = "";
4506 int stride = 0;
4507 ImageJDesc j = new ImageJDesc();
4508 BioImage bi = Images.GetImage(IDs[0]);
4509 j.FromImage(bi);
4510 desc = j.GetString();
4511 for (int fi = 0; fi < IDs.Length; fi++)
4512 {
4513 string id = IDs[fi];
4514 BioImage b = Images.GetImage(id);
4515 string fn = Path.GetFileNameWithoutExtension(id);
4516 string dir = Path.GetDirectoryName(file);
4517 stride = b.Buffers[0].Stride;
4518
4519 //Save ROIs to CSV file.
4520 if (b.Annotations.Count > 0)
4521 {
4522 string f = dir + "//" + fn + ".csv";
4523 ExportROIsCSV(f, b.Annotations);
4524 }
4525
4526 //Embed ROI's to image description.
4527 for (int i = 0; i < b.Annotations.Count; i++)
4528 {
4529 desc += "-ROI:" + b.series + ":" + ROIToString(b.Annotations[i]) + NewLine;
4530 }
4531 foreach (Channel c in b.Channels)
4532 {
4533 string cj = JsonConvert.SerializeObject(c.info, Formatting.None);
4534 desc += "-Channel:" + fi + ":" + cj + NewLine;
4535 }
4536 string json = JsonConvert.SerializeObject(b.imageInfo, Formatting.None);
4537 desc += "-ImageInfo:" + fi + ":" + json + NewLine;
4538 }
4539
4540 Tiff image = Tiff.Open(file, "w");
4541 for (int fi = 0; fi < IDs.Length; fi++)
4542 {
4543 int im = 0;
4544 string id = IDs[fi];
4545 //Progress pr = new //Progress(file, "Saving");
4546 //pr.Show();
4547 //Application.DoEvents();
4548 BioImage b = Images.GetImage(id);
4549 int sizec = 1;
4550 if (!b.isRGB)
4551 {
4552 sizec = b.SizeC;
4553 }
4554 byte[] buffer;
4555 for (int c = 0; c < sizec; c++)
4556 {
4557 for (int z = 0; z < b.SizeZ; z++)
4558 {
4559 for (int t = 0; t < b.SizeT; t++)
4560 {
4561 image.SetDirectory((short)(im + (b.Buffers.Count * fi)));
4562 image.SetField(TiffTag.IMAGEWIDTH, b.SizeX);
4563 image.SetField(TiffTag.IMAGEDESCRIPTION, desc);
4564 image.SetField(TiffTag.IMAGELENGTH, b.SizeY);
4565 image.SetField(TiffTag.BITSPERSAMPLE, b.bitsPerPixel);
4566 image.SetField(TiffTag.SAMPLESPERPIXEL, b.RGBChannelCount);
4567 image.SetField(TiffTag.ROWSPERSTRIP, b.SizeY);
4568 image.SetField(TiffTag.ORIENTATION, BitMiracle.LibTiff.Classic.Orientation.TOPLEFT);
4569 image.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
4570 image.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
4571 image.SetField(TiffTag.ROWSPERSTRIP, image.DefaultStripSize(0));
4572 if (b.PhysicalSizeX != -1 && b.PhysicalSizeY != -1)
4573 {
4574 image.SetField(TiffTag.XRESOLUTION, (b.PhysicalSizeX * b.SizeX) / ((b.PhysicalSizeX * b.SizeX) * b.PhysicalSizeX));
4575 image.SetField(TiffTag.YRESOLUTION, (b.PhysicalSizeY * b.SizeY) / ((b.PhysicalSizeY * b.SizeY) * b.PhysicalSizeY));
4576 image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.NONE);
4577 }
4578 else
4579 {
4580 image.SetField(TiffTag.XRESOLUTION, 100.0);
4581 image.SetField(TiffTag.YRESOLUTION, 100.0);
4582 image.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
4583 }
4584 // specify that it's a page within the multipage file
4585 image.SetField(TiffTag.SUBFILETYPE, FileType.PAGE);
4586 // specify the page number
4587 buffer = b.Buffers[im].GetSaveBytes(true);
4588 image.SetField(TiffTag.PAGENUMBER, im + (b.Buffers.Count * fi), b.Buffers.Count * IDs.Length);
4589 for (int i = 0, offset = 0; i < b.SizeY; i++)
4590 {
4591 image.WriteScanline(buffer, offset, i, 0);
4592 offset += stride;
4593 }
4594 image.WriteDirectory();
4595 //pr.Update//ProgressF((float)im / (float)b.ImageCount);
4596 //Application.DoEvents();
4597 im++;
4598 }
4599 }
4600 }
4601 //pr.Close();
4602 }
4603 image.Dispose();
4604
4605 }

References BioImager.BioImage.ExportROIsCSV(), BioImager.BioImage.ImageJDesc.FromImage(), BioImager.BioImage.ImageJDesc.GetString(), and BioImager.BioImage.ROIToString().

Referenced by BioImager.BioImage.SaveFile().

◆ SaveSeriesAsync()

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

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

Definition at line 7126 of file Bio.cs.

7127 {
7128 sts.Clear();
7129 foreach (BioImage item in imgs)
7130 {
7131 sts.Add(item.ID);
7132 }
7133 savefile = file;
7134 some = ome;
7135 await Task.Run(SaveSeriesThread);
7136 }

◆ SetLabelMacroResolutions()

void BioImager.BioImage.SetLabelMacroResolutions ( )

Definition at line 2489 of file Bio.cs.

2490 {
2491 int i = 0;
2492 AForge.Size s = new AForge.Size(int.MaxValue, int.MaxValue);
2493 bool noMacro = true;
2494 PixelFormat pf = Resolutions[0].PixelFormat;
2495 foreach (Resolution res in Resolutions)
2496 {
2497 if (res.SizeX < s.Width && res.SizeY < s.Height)
2498 {
2499 //If the pixel format changes it means this is the macro resolution.
2500 if (pf != res.PixelFormat)
2501 {
2502 noMacro = false;
2503 break;
2504 }
2505 pf = res.PixelFormat;
2506 s = new AForge.Size(res.SizeX, res.SizeY);
2507 }
2508 else
2509 {
2510 //If this level is bigger than the previous this is the macro resolution.
2511 noMacro = false;
2512 break;
2513 }
2514 i++;
2515 }
2516 if (!noMacro)
2517 {
2518 MacroResolution = i;
2519 LabelResolution = i + 1;
2520 }
2521
2522 }

◆ SetValue() [1/3]

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

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.

Definition at line 4108 of file Bio.cs.

4109 {
4110 Buffers[ind].SetValue(x, y, value);
4111 }

◆ SetValue() [2/3]

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

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

Definition at line 4118 of file Bio.cs.

4119 {
4120 SetValue(x, y, Coords[coord.Z, coord.C, coord.T], value);
4121 }
void SetValue(ZCTXY coord, ushort value)
Definition: Bio.cs:4097

References BioImager.BioImage.SetValue().

◆ SetValue() [3/3]

void BioImager.BioImage.SetValue ( ZCTXY  coord,
ushort  value 
)

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

Definition at line 4097 of file Bio.cs.

4098 {
4099 int i = Coords[coord.Z, coord.C, coord.T];
4100 Buffers[i].SetValue(coord.X, coord.Y, value);
4101 }

Referenced by BioImager.BioImage.SetValue().

◆ SetValueRGB()

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

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

Definition at line 4128 of file Bio.cs.

4129 {
4130 int ind = Coords[coord.Z, coord.C, coord.T];
4131 Buffers[ind].SetValueRGB(coord.X, coord.Y, RGBindex, value);
4132 }

◆ SplitChannels() [1/3]

BioImage[] BioImager.BioImage.SplitChannels ( )

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

Returns
A list of BioImages

Definition at line 3768 of file Bio.cs.

3769 {
3770 BioImage[] bms;
3771 if (isRGB)
3772 {
3773 bms = new BioImage[3];
3774 BioImage ri = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-1" + Path.GetExtension(ID));
3775 BioImage gi = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-2" + Path.GetExtension(ID));
3776 BioImage bi = new BioImage(Path.GetFileNameWithoutExtension(ID) + "-3" + Path.GetExtension(ID));
3777 ri.sizeC = 1;
3778 gi.sizeC = 1;
3779 bi.sizeC = 1;
3780 ri.sizeZ = SizeZ;
3781 gi.sizeZ = SizeZ;
3782 bi.sizeZ = SizeZ;
3783 ri.sizeT = SizeT;
3784 gi.sizeT = SizeT;
3785 bi.sizeT = SizeT;
3786
3787 ri.Coords = new int[SizeZ, 1, SizeT];
3788 gi.Coords = new int[SizeZ, 1, SizeT];
3789 bi.Coords = new int[SizeZ, 1, SizeT];
3790 int ind = 0;
3791 for (int i = 0; i < ImageCount; i++)
3792 {
3793 if (Buffers[i].PixelFormat == PixelFormat.Format48bppRgb)
3794 {
3795 //For 48bit images we need to use our own function as AForge won't give us a proper image.
3796 Bitmap[] bfs = Bitmap.RGB48To16(ID, SizeX, SizeY, Buffers[i].Stride, Buffers[i].Bytes, Buffers[i].Coordinate, ind, Buffers[i].Plane);
3797 ind += 3;
3798 ri.Buffers.Add(bfs[0]);
3799 gi.Buffers.Add(bfs[1]);
3800 bi.Buffers.Add(bfs[2]);
3801 Statistics.CalcStatistics(bfs[0]);
3802 Statistics.CalcStatistics(bfs[1]);
3803 Statistics.CalcStatistics(bfs[2]);
3804 ri.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3805 gi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3806 bi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3807 }
3808 else
3809 {
3810
3811 Bitmap rImage = extractR.Apply(Buffers[i]);
3812 Bitmap rbf = new Bitmap(ri.ID, rImage, Buffers[i].Coordinate, ind++);
3813 Statistics.CalcStatistics(rbf);
3814 ri.Buffers.Add(rbf);
3815 ri.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3816
3817 Bitmap gImage = extractG.Apply(Buffers[i]);
3818 Bitmap gbf = new Bitmap(gi.ID, gImage, Buffers[i].Coordinate, ind++);
3819 Statistics.CalcStatistics(gbf);
3820 gi.Buffers.Add(gbf);
3821 gi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3822
3823 Bitmap bImage = extractB.Apply(Buffers[i]);
3824 //Clipboard.SetImage(bImage);
3825 Bitmap bbf = new Bitmap(bi.ID, bImage, Buffers[i].Coordinate, ind++);
3826 Statistics.CalcStatistics(bbf);
3827 bi.Buffers.Add(bbf);
3828 bi.Coords[Buffers[i].Coordinate.Z, Buffers[i].Coordinate.C, Buffers[i].Coordinate.T] = i;
3829
3830 }
3831 }
3832 //We wait for threshold image statistics calculation
3833 do
3834 {
3835 Thread.Sleep(100);
3836 } while (bi.Buffers[bi.Buffers.Count - 1].Stats == null);
3837 ri.Resolutions.Add(new Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3838 gi.Resolutions.Add(new Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3839 bi.Resolutions.Add(new Resolution(Buffers[0].SizeX, Buffers[0].SizeY, Buffers[0].PixelFormat, PhysicalSizeX, PhysicalSizeY, PhysicalSizeZ, StageSizeX, StageSizeY, StageSizeZ));
3840 ri.Channels.Add(Channels[0].Copy());
3841 gi.Channels.Add(Channels[0].Copy());
3842 bi.Channels.Add(Channels[0].Copy());
3843 AutoThreshold(ri, false);
3844 AutoThreshold(gi, false);
3845 AutoThreshold(bi, false);
3846 Images.AddImage(ri, true);
3847 Images.AddImage(gi, true);
3848 Images.AddImage(bi, true);
3849 Statistics.ClearCalcBuffer();
3850 bms[0] = ri;
3851 bms[1] = gi;
3852 bms[2] = bi;
3853 }
3854 else
3855 {
3856 bms = new BioImage[SizeC];
3857 for (int c = 0; c < SizeC; c++)
3858 {
3859 BioImage b = BioImage.Substack(this, 0, 0, SizeZ, c, c + 1, 0, SizeT);
3860 bms[c] = b;
3861 }
3862 }
3863
3864 Statistics.ClearCalcBuffer();
3865 Recorder.AddLine("Bio.BioImage.SplitChannels(" + '"' + Filename + '"' + ");");
3866 return bms;
3867 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.Copy(), and BioImager.BioImage.Substack().

Referenced by BioImager.BioImage.SplitChannels().

◆ SplitChannels() [2/3]

static BioImage[] BioImager.BioImage.SplitChannels ( BioImage  bb)
static

‍SplitChannels splits a BioImage into its constituent channels

Parameters
BioImageThe image to split
Returns
An array of BioImages

Definition at line 3873 of file Bio.cs.

3874 {
3875 return bb.SplitChannels();
3876 }

References BioImager.BioImage.SplitChannels().

◆ SplitChannels() [3/3]

static BioImage[] BioImager.BioImage.SplitChannels ( string  name)
static

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.

Definition at line 3882 of file Bio.cs.

3883 {
3884 return SplitChannels(Images.GetImage(name));
3885 }
BioImage[] SplitChannels()
Definition: Bio.cs:3768

References BioImager.BioImage.SplitChannels().

◆ StackThreshold()

void BioImager.BioImage.StackThreshold ( bool  bit16)

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

Definition at line 6843 of file Bio.cs.

6844 {
6845 if (bit16)
6846 {
6847 for (int ch = 0; ch < Channels.Count; ch++)
6848 {
6849 for (int i = 0; i < Channels[ch].range.Length; i++)
6850 {
6851 Channels[ch].range[i].Min = (int)Channels[ch].stats[i].StackMin;
6852 Channels[ch].range[i].Max = (int)Channels[ch].stats[i].StackMax;
6853 }
6854 Channels[ch].BitsPerPixel = 16;
6855 }
6856 bitsPerPixel = 16;
6857 }
6858 else
6859 {
6860 for (int ch = 0; ch < Channels.Count; ch++)
6861 {
6862 for (int i = 0; i < Channels[ch].range.Length; i++)
6863 {
6864 Channels[ch].range[i].Min = (int)Channels[ch].stats[i].StackMin;
6865 Channels[ch].range[i].Max = (int)Channels[ch].stats[i].StackMax;
6866 }
6867 Channels[ch].BitsPerPixel = 8;
6868 }
6869 bitsPerPixel = 8;
6870 }
6871 }

Referenced by BioImager.BioImage.MergeChannels(), BioImager.BioImage.MergeT(), BioImager.BioImage.MergeZ(), BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenOME(), BioImager.BioImage.Substack(), BioImager.BioImage.To16Bit(), BioImager.BioImage.To24Bit(), BioImager.BioImage.To48Bit(), and BioImager.BioImage.UpdateBuffersPyramidal().

◆ StringToROI()

static ROI BioImager.BioImage.StringToROI ( string  sts)
static

It takes a string and returns an ROI object

Parameters
ststhe string that contains the ROI data
Returns
A ROI object.

Definition at line 7737 of file Bio.cs.

7738 {
7739 //Works with either comma or tab separated values.
7740 if (sts.StartsWith("<?xml") || sts.StartsWith("{"))
7741 return null;
7742 ROI an = new ROI();
7743 string val = "";
7744 bool inSep = false;
7745 int col = 0;
7746 double x = 0;
7747 double y = 0;
7748 double w = 0;
7749 double h = 0;
7750 string line = sts;
7751 bool points = false;
7752 char sep = '"';
7753 for (int i = 0; i < line.Length; i++)
7754 {
7755 char c = line[i];
7756 if (c == sep)
7757 {
7758 if (!inSep)
7759 {
7760 inSep = true;
7761 }
7762 else
7763 inSep = false;
7764 continue;
7765 }
7766
7767 if ((c == ',' || c == '\t') && (!inSep || points))
7768 {
7769 //ROIID,ROINAME,TYPE,ID,SHAPEINDEX,TEXT,C,Z,T,X,Y,W,H,POINTS,STROKECOLOR,STROKECOLORW,FILLCOLOR,FONTSIZE
7770 if (col == 0)
7771 {
7772 //ROIID
7773 an.roiID = val;
7774 }
7775 else
7776 if (col == 1)
7777 {
7778 //ROINAME
7779 an.roiName = val;
7780 }
7781 else
7782 if (col == 2)
7783 {
7784 //TYPE
7785 an.type = (ROI.Type)Enum.Parse(typeof(ROI.Type), val);
7786 if (an.type == ROI.Type.Freeform || an.type == ROI.Type.Polygon)
7787 an.closed = true;
7788 }
7789 else
7790 if (col == 3)
7791 {
7792 //ID
7793 an.id = val;
7794 }
7795 else
7796 if (col == 4)
7797 {
7798 //SHAPEINDEX/
7799 an.shapeIndex = int.Parse(val);
7800 }
7801 else
7802 if (col == 5)
7803 {
7804 //TEXT/
7805 an.Text = val;
7806 }
7807 else
7808 if (col == 6)
7809 {
7810 an.serie = int.Parse(val);
7811 }
7812 else
7813 if (col == 7)
7814 {
7815 an.coord.Z = int.Parse(val);
7816 }
7817 else
7818 if (col == 8)
7819 {
7820 an.coord.C = int.Parse(val);
7821 }
7822 else
7823 if (col == 9)
7824 {
7825 an.coord.T = int.Parse(val);
7826 }
7827 else
7828 if (col == 10)
7829 {
7830 x = double.Parse(val, CultureInfo.InvariantCulture);
7831 }
7832 else
7833 if (col == 11)
7834 {
7835 y = double.Parse(val, CultureInfo.InvariantCulture);
7836 }
7837 else
7838 if (col == 12)
7839 {
7840 w = double.Parse(val, CultureInfo.InvariantCulture);
7841 }
7842 else
7843 if (col == 13)
7844 {
7845 h = double.Parse(val, CultureInfo.InvariantCulture);
7846 }
7847 else
7848 if (col == 14)
7849 {
7850 //POINTS
7851 an.AddPoints(an.stringToPoints(val));
7852 points = false;
7853 an.Rect = new RectangleD(x, y, w, h);
7854 }
7855 else
7856 if (col == 15)
7857 {
7858 //STROKECOLOR
7859 string[] st = val.Split(',');
7860 an.strokeColor = System.Drawing.Color.FromArgb(int.Parse(st[0]), int.Parse(st[1]), int.Parse(st[2]), int.Parse(st[3]));
7861 }
7862 else
7863 if (col == 16)
7864 {
7865 //STROKECOLORW
7866 an.strokeWidth = double.Parse(val, CultureInfo.InvariantCulture);
7867 }
7868 else
7869 if (col == 17)
7870 {
7871 //FILLCOLOR
7872 string[] st = val.Split(',');
7873 an.fillColor = System.Drawing.Color.FromArgb(int.Parse(st[0]), int.Parse(st[1]), int.Parse(st[2]), int.Parse(st[3]));
7874 }
7875 else
7876 if (col == 18)
7877 {
7878 //FONTSIZE
7879 double s = double.Parse(val, CultureInfo.InvariantCulture);
7880 an.fontSize = (float)s;
7881 an.family = "Times New Roman";
7882 }
7883 col++;
7884 val = "";
7885 }
7886 else
7887 val += c;
7888 }
7889
7890 return an;
7891 }

References BioImager.ROI.AddPoints(), and BioImager.ROI.stringToPoints().

Referenced by BioImager.App.AddROI(), BioImager.BioImage.ImportROIsCSV(), BioImager.BioImage.OpenFile(), and BioImager.ImageView.PasteSelection().

◆ Substack()

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

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.

Definition at line 3529 of file Bio.cs.

3530 {
3531 BioImage b = CopyInfo(orig, false, false);
3532 b.ID = Images.GetImageName(orig.ID);
3533 int i = 0;
3534 b.Coords = new int[ze - zs, ce - cs, te - ts];
3535 b.sizeZ = ze - zs;
3536 b.sizeC = ce - cs;
3537 b.sizeT = te - ts;
3538 for (int ti = 0; ti < b.SizeT; ti++)
3539 {
3540 for (int zi = 0; zi < b.SizeZ; zi++)
3541 {
3542 for (int ci = 0; ci < b.SizeC; ci++)
3543 {
3544 int ind = orig.Coords[zs + zi, cs + ci, ts + ti];
3545 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);
3546 Statistics.CalcStatistics(bf);
3547 b.Buffers.Add(bf);
3548 b.Coords[zi, ci, ti] = i;
3549 i++;
3550 }
3551 }
3552 }
3553 for (int ci = cs; ci < ce; ci++)
3554 {
3555 b.Channels.Add(orig.Channels[ci]);
3556 }
3557 //We wait for threshold image statistics calculation
3558 do
3559 {
3560 Thread.Sleep(100);
3561 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
3562 Statistics.ClearCalcBuffer();
3563 b.Resolutions.Add(new 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));
3564 AutoThreshold(b, false);
3565 if (b.bitsPerPixel > 8)
3566 b.StackThreshold(true);
3567 else
3568 b.StackThreshold(false);
3569 Images.AddImage(b, true);
3570 Recorder.AddLine("Bio.BioImage.Substack(" + '"' + orig.Filename + '"' + "," + ser + "," + zs + "," + ze + "," + cs + "," + ce + "," + ts + "," + te + ");");
3571 return b;
3572 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.CopyInfo(), and BioImager.BioImage.StackThreshold().

Referenced by BioImager.BioImage.SplitChannels().

◆ To16Bit()

void BioImager.BioImage.To16Bit ( )

Converts the image to 16 bit.

Definition at line 2760 of file Bio.cs.

2761 {
2762 if (Buffers[0].RGBChannelsCount == 4)
2763 To24Bit();
2764 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
2765 return;
2766 bitsPerPixel = 16;
2767 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
2768 {
2769 List<Bitmap> bfs = new List<Bitmap>();
2770 int index = 0;
2771 for (int i = 0; i < Buffers.Count; i++)
2772 {
2773 Array.Reverse(Buffers[i].Bytes);
2774 Bitmap[] bs = Bitmap.RGB48To16(ID, SizeX, SizeY, Buffers[i].Stride, Buffers[i].Bytes, Buffers[i].Coordinate, index, Buffers[i].Plane);
2775 bfs.AddRange(bs);
2776 index += 3;
2777 }
2778 Buffers = bfs;
2779 UpdateCoords(SizeZ, SizeC * 3, SizeT);
2780 if (Channels[0].SamplesPerPixel == 3)
2781 {
2782 Channel c = Channels[0].Copy();
2783 c.SamplesPerPixel = 1;
2784 c.range = new IntRange[1];
2785 Channels.Clear();
2786 Channels.Add(c);
2787 Channels.Add(c.Copy());
2788 Channels.Add(c.Copy());
2789 Channels[1].Index = 1;
2790 Channels[2].Index = 2;
2791 }
2792 }
2793 else if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
2794 {
2795 for (int i = 0; i < Buffers.Count; i++)
2796 {
2797 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
2798 Statistics.CalcStatistics(Buffers[i]);
2799 }
2800 for (int c = 0; c < Channels.Count; c++)
2801 {
2802 for (int i = 0; i < Channels[c].range.Length; i++)
2803 {
2804 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
2805 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
2806 }
2807 Channels[c].BitsPerPixel = 16;
2808 }
2809 }
2810 else if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb)
2811 {
2812 List<Bitmap> bfs = new List<Bitmap>();
2813 int index = 0;
2814 for (int i = 0; i < Buffers.Count; i++)
2815 {
2816 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2817 Bitmap br = new Bitmap(ID, bs[2].Image, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2818 Bitmap bg = new Bitmap(ID, bs[1].Image, new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2819 Bitmap bb = new Bitmap(ID, bs[0].Image, new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2820 for (int b = 0; b < 3; b++)
2821 {
2822 bs[b].Dispose();
2823 bs[b] = null;
2824 }
2825 bs = null;
2826 GC.Collect();
2827 br.To16Bit();
2828 bg.To16Bit();
2829 bb.To16Bit();
2830 Statistics.CalcStatistics(br);
2831 Statistics.CalcStatistics(bg);
2832 Statistics.CalcStatistics(bb);
2833 bfs.Add(br);
2834 bfs.Add(bg);
2835 bfs.Add(bb);
2836 index += 3;
2837 }
2838 Buffers = bfs;
2839 UpdateCoords(SizeZ, 3, SizeT);
2840 for (int c = 0; c < Channels.Count; c++)
2841 {
2842 for (int i = 0; i < Channels[c].range.Length; i++)
2843 {
2844 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
2845 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
2846 }
2847 Channels[c].BitsPerPixel = 16;
2848 }
2849 }
2850 //We wait for threshold image statistics calculation
2851 do
2852 {
2853 Thread.Sleep(100);
2854 } while (Buffers[Buffers.Count - 1].Stats == null);
2855 Statistics.ClearCalcBuffer();
2856 AutoThreshold(this, false);
2857 StackThreshold(true);
2858 App.viewer.UpdateImages();
2859 App.viewer.UpdateView();
2860 Recorder.AddLine("Bio.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To16Bit();");
2861 }
void To24Bit()
Converts the image to 24 bit.
Definition: Bio.cs:2863
void StackThreshold(bool bit16)
Definition: Bio.cs:6843
void UpdateCoords()
It takes a list of images and assigns them to a 3D array of coordinates.
Definition: Bio.cs:3143

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.StackThreshold(), BioImager.BioImage.To24Bit(), BioImager.BioImage.UpdateCoords(), BioImager.ImageView.UpdateImages(), and BioImager.ImageView.UpdateView().

◆ To24Bit()

void BioImager.BioImage.To24Bit ( )

Converts the image to 24 bit.

Definition at line 2863 of file Bio.cs.

2864 {
2865 if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb)
2866 return;
2867 bitsPerPixel = 8;
2868 if (Buffers[0].PixelFormat == PixelFormat.Format32bppArgb || Buffers[0].PixelFormat == PixelFormat.Format32bppRgb)
2869 {
2870 for (int i = 0; i < Buffers.Count; i++)
2871 {
2872 Buffers[i] = Bitmap.To24Bit(Buffers[i]);
2873 Buffers[i].SwitchRedBlue();
2874 }
2875 if (Channels.Count == 4)
2876 {
2877 Channels.RemoveAt(0);
2878 }
2879 else
2880 {
2881 Channels[0].SamplesPerPixel = 3;
2882 }
2883 }
2884 else
2885 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
2886 {
2887 //We run 8bit so we get 24 bit rgb.
2888 for (int i = 0; i < Buffers.Count; i++)
2889 {
2890 Buffers[i].Image = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2891 }
2892 }
2893 else
2894 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale || Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
2895 {
2896 if (Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
2897 {
2898 for (int i = 0; i < Buffers.Count; i++)
2899 {
2900 Buffers[i].Image = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2901 }
2902 for (int c = 0; c < Channels.Count; c++)
2903 {
2904 for (int i = 0; i < Channels[c].range.Length; i++)
2905 {
2906 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)ushort.MaxValue) * byte.MaxValue);
2907 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)ushort.MaxValue) * byte.MaxValue);
2908 }
2909 Channels[c].BitsPerPixel = 8;
2910 }
2911 }
2912 List<Bitmap> bfs = new List<Bitmap>();
2913 if (Buffers.Count % 3 != 0 && Buffers.Count % 2 != 0)
2914 for (int i = 0; i < Buffers.Count; i++)
2915 {
2916 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);
2917 Bitmap bbs = Bitmap.RGB16To48(bs);
2918 bs.Dispose();
2919 bs = null;
2920 bfs.Add(bbs);
2921 }
2922 else
2923 for (int i = 0; i < Buffers.Count; i += Channels.Count)
2924 {
2925 Bitmap[] bs = new Bitmap[3];
2926 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);
2927 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);
2928 if (Channels.Count > 2)
2929 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);
2930 Bitmap bbs = Bitmap.RGB8To24(bs);
2931 for (int b = 0; b < 3; b++)
2932 {
2933 if (bs[b] != null)
2934 bs[b].Dispose();
2935 bs[b] = null;
2936 }
2937 bfs.Add(bbs);
2938 }
2939 Buffers = bfs;
2940 UpdateCoords(SizeZ, 1, SizeT);
2941 }
2942 Recorder.AddLine("Bio.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To24Bit();");
2943 AutoThreshold(this, true);
2944 StackThreshold(false);
2945 App.viewer.UpdateImages();
2946 App.viewer.UpdateView();
2947 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.StackThreshold(), BioImager.BioImage.UpdateCoords(), BioImager.ImageView.UpdateImages(), and BioImager.ImageView.UpdateView().

Referenced by BioImager.BioImage.To16Bit(), BioImager.BioImage.To32Bit(), BioImager.BioImage.To48Bit(), and BioImager.BioImage.To8Bit().

◆ To32Bit()

void BioImager.BioImage.To32Bit ( )

Converts the image to 32 bit.

Definition at line 2949 of file Bio.cs.

2950 {
2951 if (Buffers[0].PixelFormat == PixelFormat.Format32bppArgb)
2952 return;
2953 if (Buffers[0].PixelFormat != PixelFormat.Format24bppRgb)
2954 {
2955 To24Bit();
2956 }
2957 for (int i = 0; i < Buffers.Count; i++)
2958 {
2959 UnmanagedImage b = Bitmap.To32Bit(Buffers[i]);
2960 Buffers[i].Image = b;
2961 }
2962 AutoThreshold(this, true);
2963 App.viewer.UpdateImages();
2964 App.viewer.UpdateView();
2965 Recorder.AddLine("Bio.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To32Bit();");
2966 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.To24Bit(), BioImager.BioImage.To32Bit(), BioImager.ImageView.UpdateImages(), and BioImager.ImageView.UpdateView().

Referenced by BioImager.BioImage.To32Bit().

◆ To48Bit()

void BioImager.BioImage.To48Bit ( )

It converts a 16 bit image to a 48 bit image

Returns
A list of Bitmaps.

Definition at line 2970 of file Bio.cs.

2971 {
2972 if (Buffers[0].RGBChannelsCount == 4)
2973 To24Bit();
2974 if (Buffers[0].PixelFormat == PixelFormat.Format48bppRgb)
2975 return;
2976 if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed || Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
2977 {
2978 if (Buffers[0].PixelFormat == PixelFormat.Format8bppIndexed)
2979 {
2980 for (int i = 0; i < Buffers.Count; i++)
2981 {
2982 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
2983 }
2984 }
2985 List<Bitmap> bfs = new List<Bitmap>();
2986 if (Buffers.Count % 3 != 0 && Buffers.Count % 2 != 0)
2987 for (int i = 0; i < Buffers.Count; i++)
2988 {
2989 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);
2990 Bitmap bbs = Bitmap.RGB16To48(bs);
2991 Statistics.CalcStatistics(bbs);
2992 bs.Dispose();
2993 bs = null;
2994 bfs.Add(bbs);
2995 }
2996 else
2997 for (int i = 0; i < Buffers.Count; i += Channels.Count)
2998 {
2999 Bitmap[] bs = new Bitmap[3];
3000 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);
3001 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);
3002 if (Channels.Count > 2)
3003 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);
3004 Bitmap bbs = Bitmap.RGB16To48(bs);
3005 for (int b = 0; b < 3; b++)
3006 {
3007 if (bs[b] != null)
3008 bs[b].Dispose();
3009 bs[b] = null;
3010 }
3011 Statistics.CalcStatistics(bbs);
3012 bfs.Add(bbs);
3013 }
3014 GC.Collect();
3015 Buffers = bfs;
3016 UpdateCoords(SizeZ, 1, SizeT);
3017 Channel c = Channels[0].Copy();
3018 c.SamplesPerPixel = 3;
3019 rgbChannels[0] = 0;
3020 rgbChannels[1] = 0;
3021 rgbChannels[2] = 0;
3022 Channels.Clear();
3023 Channels.Add(c);
3024 }
3025 else
3026 if (Buffers[0].PixelFormat == PixelFormat.Format24bppRgb)
3027 {
3028 for (int i = 0; i < Buffers.Count; i++)
3029 {
3030 Buffers[i].Image = AForge.Imaging.Image.Convert8bppTo16bpp(Buffers[i]);
3031 Statistics.CalcStatistics(Buffers[i]);
3032 }
3033 for (int c = 0; c < Channels.Count; c++)
3034 {
3035 for (int i = 0; i < Channels[c].range.Length; i++)
3036 {
3037 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)byte.MaxValue) * ushort.MaxValue);
3038 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)byte.MaxValue) * ushort.MaxValue);
3039 }
3040 Channels[c].BitsPerPixel = 16;
3041 }
3042 }
3043 else
3044 {
3045 int index = 0;
3046 List<Bitmap> buffers = new List<Bitmap>();
3047 for (int i = 0; i < Buffers.Count; i += 3)
3048 {
3049 Bitmap[] bf = new Bitmap[3];
3050 bf[0] = Buffers[i];
3051 bf[1] = Buffers[i + 1];
3052 bf[2] = Buffers[i + 2];
3053 Bitmap inf = Bitmap.RGB16To48(bf);
3054 buffers.Add(inf);
3055 Statistics.CalcStatistics(inf);
3056 for (int b = 0; b < 3; b++)
3057 {
3058 bf[b].Dispose();
3059 }
3060 index++;
3061 }
3062 Buffers = buffers;
3063 UpdateCoords(SizeZ, 1, SizeT);
3064 }
3065 //We wait for threshold image statistics calculation
3066 do
3067 {
3068 Thread.Sleep(50);
3069 } while (Buffers[Buffers.Count - 1].Stats == null);
3070 Statistics.ClearCalcBuffer();
3071 bitsPerPixel = 16;
3072 AutoThreshold(this, false);
3073 StackThreshold(true);
3074 App.viewer.UpdateImages();
3075 App.viewer.UpdateView();
3076 Recorder.AddLine("Bio.Images.GetImage(" + '"' + ID + '"' + ")" + "." + "To48Bit();");
3077 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.StackThreshold(), BioImager.BioImage.To24Bit(), BioImager.BioImage.UpdateCoords(), BioImager.ImageView.UpdateImages(), and BioImager.ImageView.UpdateView().

◆ To8Bit()

void BioImager.BioImage.To8Bit ( )

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

Definition at line 2665 of file Bio.cs.

2666 {
2667 if (Buffers[0].RGBChannelsCount == 4)
2668 To24Bit();
2669 PixelFormat px = Buffers[0].PixelFormat;
2670 if (px == PixelFormat.Format8bppIndexed)
2671 return;
2672 if (px == PixelFormat.Format48bppRgb)
2673 {
2674 To24Bit();
2675 List<AForge.Bitmap> bfs = new List<AForge.Bitmap>();
2676 int index = 0;
2677 for (int i = 0; i < Buffers.Count; i++)
2678 {
2679 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2680 Bitmap br = new Bitmap(ID, bs[2], new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2681 Bitmap bg = new Bitmap(ID, bs[1], new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2682 Bitmap bb = new Bitmap(ID, bs[0], new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2683 for (int b = 0; b < 3; b++)
2684 {
2685 bs[b].Dispose();
2686 }
2687 bs = null;
2688 GC.Collect();
2689 Statistics.CalcStatistics(br);
2690 Statistics.CalcStatistics(bg);
2691 Statistics.CalcStatistics(bb);
2692 bfs.Add(br);
2693 bfs.Add(bg);
2694 bfs.Add(bb);
2695 index += 3;
2696 }
2697 Buffers = bfs;
2698 UpdateCoords(SizeZ, 3, SizeT);
2699 }
2700 else if (px == PixelFormat.Format24bppRgb)
2701 {
2702 List<Bitmap> bfs = new List<Bitmap>();
2703 int index = 0;
2704 for (int i = 0; i < Buffers.Count; i++)
2705 {
2706 Bitmap[] bs = Bitmap.RGB24To8(Buffers[i]);
2707 Bitmap br = new Bitmap(ID, bs[2], new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), index, Buffers[i].Plane);
2708 Bitmap bg = new Bitmap(ID, bs[1], new ZCT(Buffers[i].Coordinate.Z, 1, Buffers[i].Coordinate.T), index + 1, Buffers[i].Plane);
2709 Bitmap bb = new Bitmap(ID, bs[0], new ZCT(Buffers[i].Coordinate.Z, 2, Buffers[i].Coordinate.T), index + 2, Buffers[i].Plane);
2710 for (int b = 0; b < 3; b++)
2711 {
2712 bs[b].Dispose();
2713 bs[b] = null;
2714 }
2715 bs = null;
2716 GC.Collect();
2717 Statistics.CalcStatistics(br);
2718 Statistics.CalcStatistics(bg);
2719 Statistics.CalcStatistics(bb);
2720 bfs.Add(br);
2721 bfs.Add(bg);
2722 bfs.Add(bb);
2723 index += 3;
2724 }
2725 Buffers = bfs;
2726 UpdateCoords(SizeZ, 3, SizeT);
2727 }
2728 else
2729 {
2730 for (int i = 0; i < Buffers.Count; i++)
2731 {
2732 Bitmap b = AForge.Imaging.Image.Convert16bppTo8bpp(Buffers[i]);
2733 Buffers[i] = b;
2734 Statistics.CalcStatistics(Buffers[i]);
2735 }
2736 for (int c = 0; c < Channels.Count; c++)
2737 {
2738 Channels[c].BitsPerPixel = 8;
2739 for (int i = 0; i < Channels[c].range.Length; i++)
2740 {
2741 Channels[c].range[i].Min = (int)(((float)Channels[c].range[i].Min / (float)ushort.MaxValue) * byte.MaxValue);
2742 Channels[c].range[i].Max = (int)(((float)Channels[c].range[i].Max / (float)ushort.MaxValue) * byte.MaxValue);
2743 }
2744 }
2745
2746 }
2747 //We wait for threshold image statistics calculation
2748 do
2749 {
2750 Thread.Sleep(100);
2751 } while (Buffers[Buffers.Count - 1].Stats == null);
2752 Statistics.ClearCalcBuffer();
2753 AutoThreshold(this, false);
2754 bitsPerPixel = 8;
2755 App.viewer.UpdateImages();
2756 App.viewer.UpdateView();
2757 Recorder.AddLine("Bio.Table.GetImage(" + '"' + ID + '"' + ")" + "." + "To8Bit();");
2758 }

References BioImager.BioImage.AutoThreshold(), BioImager.BioImage.To24Bit(), BioImager.BioImage.UpdateCoords(), BioImager.ImageView.UpdateImages(), and BioImager.ImageView.UpdateView().

◆ ToImageSizeX()

double BioImager.BioImage.ToImageSizeX ( double  d)

Convert a physical size to an image size

Parameters
dthe distance in microns
Returns
The value of d divided by the physicalSizeX.

Definition at line 3281 of file Bio.cs.

3282 {
3283 return d / PhysicalSizeX;
3284 }

◆ ToImageSizeY()

double BioImager.BioImage.ToImageSizeY ( double  d)

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.

Definition at line 3291 of file Bio.cs.

3292 {
3293 return d / PhysicalSizeY;
3294 }

◆ ToImageSpace() [1/4]

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

Convert a list of points from stage space to image space

Parameters
pList of points in stage space
Returns
A PointD array.

Definition at line 3334 of file Bio.cs.

3335 {
3336 PointD[] ps = new PointD[p.Count];
3337 for (int i = 0; i < p.Count; i++)
3338 {
3339 PointD pp = new PointD();
3340 pp.X = ((p[i].X - StageSizeX) / PhysicalSizeX);
3341 pp.Y = ((p[i].Y - StageSizeY) / PhysicalSizeY);
3342 ps[i] = pp;
3343 }
3344 return ps;
3345 }

◆ ToImageSpace() [2/4]

PointD BioImager.BioImage.ToImageSpace ( PointD  p)

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

Parameters
PointD
Returns
A PointF object.

Definition at line 3322 of file Bio.cs.

3323 {
3324 PointD pp = new PointD();
3325 pp.X = (float)((p.X - StageSizeX) / PhysicalSizeX);
3326 pp.Y = (float)((p.Y - StageSizeY) / PhysicalSizeY);
3327 return pp;
3328 }

Referenced by BioImager.ROI.PointsToString(), BioImager.Tools.ToolDown(), and BioImager.Tools.ToolUp().

◆ ToImageSpace() [3/4]

PointF[] BioImager.BioImage.ToImageSpace ( PointF[]  p)

‍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[]

Definition at line 3352 of file Bio.cs.

3353 {
3354 PointF[] ps = new PointF[p.Length];
3355 for (int i = 0; i < p.Length; i++)
3356 {
3357 PointF pp = new PointF();
3358 pp.X = (float)((p[i].X - StageSizeX) / PhysicalSizeX);
3359 pp.Y = (float)((p[i].Y - StageSizeY) / PhysicalSizeY);
3360 ps[i] = pp;
3361 }
3362 return ps;
3363 }

◆ ToImageSpace() [4/4]

RectangleF BioImager.BioImage.ToImageSpace ( RectangleD  p)

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

Parameters
RectangleD
Returns
A RectangleF object.

Definition at line 3369 of file Bio.cs.

3370 {
3371 RectangleF r = new RectangleF();
3372 Point pp = new Point();
3373 r.X = (int)((p.X - StageSizeX) / PhysicalSizeX);
3374 r.Y = (int)((p.Y - StageSizeY) / PhysicalSizeY);
3375 r.Width = (int)(p.W / PhysicalSizeX);
3376 r.Height = (int)(p.H / PhysicalSizeY);
3377 return r;
3378 }

◆ ToImageSpaceX()

double BioImager.BioImage.ToImageSpaceX ( double  x)

‍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.

Definition at line 3300 of file Bio.cs.

3301 {
3302 if (isPyramidal)
3303 return x;
3304 return (float)((x - StageSizeX) / PhysicalSizeX);
3305 }

◆ ToImageSpaceY()

double BioImager.BioImage.ToImageSpaceY ( double  y)

‍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.

Definition at line 3311 of file Bio.cs.

3312 {
3313 if (isPyramidal)
3314 return y;
3315 return (float)((y - StageSizeY) / PhysicalSizeY);
3316 }

◆ ToStageSpace() [1/7]

PointD BioImager.BioImage.ToStageSpace ( PointD  p)

‍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.

Definition at line 3384 of file Bio.cs.

3385 {
3386 PointD pp = new PointD();
3387 if (isPyramidal)
3388 {
3389 pp.X = ((p.X * Resolutions[Level].PhysicalSizeX) + Volume.Location.X);
3390 pp.Y = ((p.Y * Resolutions[Level].PhysicalSizeY) + Volume.Location.Y);
3391 return pp;
3392 }
3393 else
3394 {
3395 pp.X = ((p.X * PhysicalSizeX) + Volume.Location.X);
3396 pp.Y = ((p.Y * PhysicalSizeY) + Volume.Location.Y);
3397 return pp;
3398 }
3399 }

Referenced by BioImager.ImageJ.RoiDecoder.getRoi(), BioImager.BioImage.OpenOME(), and BioImager.BioImage.OpenOMEROIs().

◆ ToStageSpace() [2/7]

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

‍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.

Definition at line 3423 of file Bio.cs.

3424 {
3425 PointD pp = new PointD();
3426 pp.X = ((p.X * physicalSizeX) + volumeX);
3427 pp.Y = ((p.Y * physicalSizeY) + volumeY);
3428 return pp;
3429 }

◆ ToStageSpace() [3/7]

PointD BioImager.BioImage.ToStageSpace ( PointD  p,
int  resolution 
)

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.

Definition at line 3406 of file Bio.cs.

3407 {
3408 PointD pp = new PointD();
3409 pp.X = ((p.X * Resolutions[resolution].PhysicalSizeX) + Volume.Location.X);
3410 pp.Y = ((p.Y * Resolutions[resolution].PhysicalSizeY) + Volume.Location.Y);
3411 return pp;
3412 }

◆ ToStageSpace() [4/7]

PointD[] BioImager.BioImage.ToStageSpace ( PointD[]  p)

‍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.

Definition at line 3470 of file Bio.cs.

3471 {
3472 PointD[] ps = new PointD[p.Length];
3473 for (int i = 0; i < p.Length; i++)
3474 {
3475 PointD pp = new PointD();
3476 pp.X = ((p[i].X * PhysicalSizeX) + Volume.Location.X);
3477 pp.Y = ((p[i].Y * PhysicalSizeY) + Volume.Location.Y);
3478 ps[i] = pp;
3479 }
3480 return ps;
3481 }

◆ ToStageSpace() [5/7]

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

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.

Definition at line 3493 of file Bio.cs.

3494 {
3495 PointD[] ps = new PointD[p.Length];
3496 for (int i = 0; i < p.Length; i++)
3497 {
3498 PointD pp = new PointD();
3499 pp.X = ((p[i].X * physicalSizeX) + volumeX);
3500 pp.Y = ((p[i].Y * physicalSizeY) + volumeY);
3501 ps[i] = pp;
3502 }
3503 return ps;
3504 }

◆ ToStageSpace() [6/7]

RectangleD BioImager.BioImage.ToStageSpace ( RectangleD  p)

‍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.

Definition at line 3436 of file Bio.cs.

3437 {
3438 RectangleD r = new RectangleD();
3439 r.X = ((p.X * PhysicalSizeX) + Volume.Location.X);
3440 r.Y = ((p.Y * PhysicalSizeY) + Volume.Location.Y);
3441 r.W = (p.W * PhysicalSizeX);
3442 r.H = (p.H * PhysicalSizeY);
3443 return r;
3444 }

◆ ToStageSpace() [7/7]

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

‍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.

Definition at line 3455 of file Bio.cs.

3456 {
3457 RectangleD r = new RectangleD();
3458 r.X = ((p.X * physicalSizeX) + volumeX);
3459 r.Y = ((p.Y * physicalSizeY) + volumeY);
3460 r.W = (p.W * physicalSizeX);
3461 r.H = (p.H * physicalSizeY);
3462 return r;
3463 }

◆ ToString()

override string BioImager.BioImage.ToString ( )

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.

Definition at line 8142 of file Bio.cs.

8143 {
8144 return Filename.ToString() + ", (" + Volume.Location.X + ", " + Volume.Location.Y + ", " + Volume.Location.Z + ")";
8145 }

Referenced by BioImager.BioImage.OpenFile().

◆ Update() [1/2]

void BioImager.BioImage.Update ( )

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

Definition at line 7243 of file Bio.cs.

7244 {
7245 Update(this);
7246 }
void Update()
‍Update() is a function that calls the Update() function of the parent class
Definition: Bio.cs:7243

References BioImager.BioImage.Update().

Referenced by BioImager.BioImage.Update().

◆ Update() [2/2]

static void BioImager.BioImage.Update ( BioImage  b)
static

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.

Definition at line 7238 of file Bio.cs.

7239 {
7240 b = OpenFile(b.file);
7241 }

References BioImager.BioImage.OpenFile().

◆ UpdateBuffersPyramidal()

void BioImager.BioImage.UpdateBuffersPyramidal ( )

Updates the Buffers based on current pyramidal origin and resolution.

Definition at line 2624 of file Bio.cs.

2625 {
2626 if (!isPyramidal)
2627 return;
2628 for (int i = 0; i < Buffers.Count; i++)
2629 {
2630 Buffers[i].Dispose();
2631 }
2632 Buffers.Clear();
2633 for (int i = 0; i < imagesPerSeries; i++)
2634 {
2635 if (openSlideImage != null)
2636 {
2637 byte[] bts = openSlideBase.GetSlice(new OpenSlideGTK.SliceInfo(PyramidalOrigin.X, PyramidalOrigin.Y, PyramidalSize.Width, PyramidalSize.Height, resolution));
2638 Bitmap bf = new Bitmap((int)Math.Round(OpenSlideBase.destExtent.Width), (int)Math.Round(OpenSlideBase.destExtent.Height), PixelFormat.Format24bppRgb, bts, new ZCT(), "");
2639 Buffers.Add(bf);
2640 }
2641 else
2642 {
2643 start:
2644 byte[] bts = slideBase.GetSlice(new SliceInfo(PyramidalOrigin.X, PyramidalOrigin.Y, PyramidalSize.Width, PyramidalSize.Height, resolution, App.viewer.GetCoordinate())).Result;
2645 if (bts == null)
2646 {
2647 if (PyramidalOrigin.X == 0 && PyramidalOrigin.Y == 0)
2648 {
2649 resolution = 1;
2650 }
2651 pyramidalOrigin = new PointD(0, 0);
2652 goto start;
2653 }
2654 Buffers.Add(new Bitmap((int)Math.Round(SlideBase.destExtent.Width), (int)Math.Round(SlideBase.destExtent.Height), PixelFormat.Format24bppRgb, bts, new ZCT(), ""));
2655 }
2656 }
2657 BioImage.AutoThreshold(this, true);
2658 if (bitsPerPixel > 8)
2659 StackThreshold(true);
2660 else
2661 StackThreshold(false);
2662 }
async Task< byte[]> GetSlice(SliceInfo sliceInfo)
Get slice.

References BioImager.BioImage.AutoThreshold(), BioImager.ImageView.GetCoordinate(), and BioImager.BioImage.StackThreshold().

Referenced by BioImager.ImageView.UpdateImages().

◆ UpdateCoords() [1/3]

void BioImager.BioImage.UpdateCoords ( )

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

Definition at line 3143 of file Bio.cs.

3144 {
3145 int z = 0;
3146 int c = 0;
3147 int t = 0;
3148 Coords = new int[SizeZ, SizeC, SizeT];
3149 for (int im = 0; im < Buffers.Count; im++)
3150 {
3151 ZCT co = new ZCT(z, c, t);
3152 Coords[co.Z, co.C, co.T] = im;
3153 Buffers[im].Coordinate = co;
3154 if (c < SizeC - 1)
3155 c++;
3156 else
3157 {
3158 c = 0;
3159 if (z < SizeZ - 1)
3160 z++;
3161 else
3162 {
3163 z = 0;
3164 if (t < SizeT - 1)
3165 t++;
3166 else
3167 t = 0;
3168 }
3169 }
3170 }
3171 }

Referenced by BioImager.BioImage.FilesToStack(), BioImager.BioImage.FolderToStack(), BioImager.BioImage.ImagesToStack(), BioImager.BioImage.MergeT(), BioImager.BioImage.MergeZ(), BioImager.BioImage.OpenFile(), BioImager.BioImage.OpenOME(), BioImager.BioImage.To16Bit(), BioImager.BioImage.To24Bit(), BioImager.BioImage.To48Bit(), and BioImager.BioImage.To8Bit().

◆ UpdateCoords() [2/3]

void BioImager.BioImage.UpdateCoords ( int  sz,
int  sc,
int  st 
)

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

Definition at line 3178 of file Bio.cs.

3179 {
3180 int z = 0;
3181 int c = 0;
3182 int t = 0;
3183 sizeZ = sz;
3184 sizeC = sc;
3185 sizeT = st;
3186 Coords = new int[sz, sc, st];
3187 for (int im = 0; im < Buffers.Count; im++)
3188 {
3189 ZCT co = new ZCT(z, c, t);
3190 Coords[co.Z, co.C, co.T] = im;
3191 Buffers[im].Coordinate = co;
3192 if (c < SizeC - 1)
3193 c++;
3194 else
3195 {
3196 c = 0;
3197 if (z < SizeZ - 1)
3198 z++;
3199 else
3200 {
3201 z = 0;
3202 if (t < SizeT - 1)
3203 t++;
3204 else
3205 t = 0;
3206 }
3207 }
3208 }
3209 }

◆ UpdateCoords() [3/3]

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

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

Definition at line 3216 of file Bio.cs.

3217 {
3218 int z = 0;
3219 int c = 0;
3220 int t = 0;
3221 sizeZ = sz;
3222 sizeC = sc;
3223 sizeT = st;
3224 Coords = new int[sz, sc, st];
3225 if (order == "XYCZT")
3226 {
3227 for (int im = 0; im < Buffers.Count; im++)
3228 {
3229 ZCT co = new ZCT(z, c, t);
3230 Coords[co.Z, co.C, co.T] = im;
3231 Buffers[im].Coordinate = co;
3232 if (c < SizeC - 1)
3233 c++;
3234 else
3235 {
3236 c = 0;
3237 if (z < SizeZ - 1)
3238 z++;
3239 else
3240 {
3241 z = 0;
3242 if (t < SizeT - 1)
3243 t++;
3244 else
3245 t = 0;
3246 }
3247 }
3248 }
3249 }
3250 else if (order == "XYZCT")
3251 {
3252 for (int im = 0; im < Buffers.Count; im++)
3253 {
3254 ZCT co = new ZCT(z, c, t);
3255 Coords[co.Z, co.C, co.T] = im;
3256 Buffers[im].Coordinate = co;
3257 if (z < SizeZ - 1)
3258 z++;
3259 else
3260 {
3261 z = 0;
3262 if (c < SizeC - 1)
3263 c++;
3264 else
3265 {
3266 c = 0;
3267 if (t < SizeT - 1)
3268 t++;
3269 else
3270 t = 0;
3271 }
3272 }
3273 }
3274 }
3275 }

◆ VipsSupport()

static bool BioImager.BioImage.VipsSupport ( string  file)
static

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.

Definition at line 7301 of file Bio.cs.

7302 {
7303 try
7304 {
7305 netim = NetVips.Image.Tiffload(file);
7306 }
7307 catch (Exception e)
7308 {
7309 Console.WriteLine(e.ToString());
7310 return false;
7311 }
7312 netim.Close();
7313 netim.Dispose();
7314 return true;
7315 }

Referenced by BioImager.BioImage.OpenFile().

Member Data Documentation

◆ Annotations

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

Definition at line 2012 of file Bio.cs.

◆ bitsPerPixel

int BioImager.BioImage.bitsPerPixel

Definition at line 2034 of file Bio.cs.

◆ Buffers

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

Definition at line 2001 of file Bio.cs.

◆ Channels

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

Definition at line 1999 of file Bio.cs.

◆ columns

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

Definition at line 7325 of file Bio.cs.

◆ Coords

int [,,] BioImager.BioImage.Coords

Definition at line 1969 of file Bio.cs.

◆ file

string BioImager.BioImage.file

Definition at line 2477 of file Bio.cs.

◆ filename

string BioImager.BioImage.filename = ""

Definition at line 2013 of file Bio.cs.

◆ filter16

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

Definition at line 3889 of file Bio.cs.

◆ filter8

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

Definition at line 3888 of file Bio.cs.

◆ frameInterval

double BioImager.BioImage.frameInterval = 0

Definition at line 2037 of file Bio.cs.

◆ imagesPerSeries

int BioImager.BioImage.imagesPerSeries = 0

Definition at line 2035 of file Bio.cs.

◆ imRead

ImageReader BioImager.BioImage.imRead

Definition at line 6663 of file Bio.cs.

◆ isGroup

bool BioImager.BioImage.isGroup = false

Definition at line 2039 of file Bio.cs.

◆ littleEndian

bool BioImager.BioImage.littleEndian = false

Definition at line 2038 of file Bio.cs.

◆ Loading

bool BioImager.BioImage.Loading = false

Definition at line 4467 of file Bio.cs.

◆ loadTimeMS

long BioImager.BioImage.loadTimeMS = 0

Definition at line 2040 of file Bio.cs.

◆ loadTimeTicks

long BioImager.BioImage.loadTimeTicks = 0

Definition at line 2041 of file Bio.cs.

◆ NewLine

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

Definition at line 7324 of file Bio.cs.

◆ OmeSupport

bool BioImager.BioImage.OmeSupport = false
static

Definition at line 7260 of file Bio.cs.

◆ openSlideBase

OpenSlideBase BioImager.BioImage.openSlideBase

Definition at line 2406 of file Bio.cs.

◆ openSlideImage

OpenSlideImage BioImager.BioImage.openSlideImage

Definition at line 2405 of file Bio.cs.

◆ Planes

bool BioImager.BioImage.Planes = false
static

Definition at line 2409 of file Bio.cs.

◆ Plate

WellPlate BioImager.BioImage.Plate = null

Definition at line 1989 of file Bio.cs.

◆ progFile

string BioImager.BioImage.progFile
static

Definition at line 2479 of file Bio.cs.

◆ progressValue

float BioImager.BioImage.progressValue = 0
static

Definition at line 2057 of file Bio.cs.

◆ Resolutions

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

Definition at line 2000 of file Bio.cs.

◆ rgbChannels

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

Definition at line 2026 of file Bio.cs.

◆ script

string BioImager.BioImage.script = ""

Definition at line 2014 of file Bio.cs.

◆ selected

bool BioImager.BioImage.selected = false

Definition at line 2042 of file Bio.cs.

◆ seriesCount

int BioImager.BioImage.seriesCount = 1

Definition at line 2036 of file Bio.cs.

◆ slideBase

SlideBase BioImager.BioImage.slideBase

Definition at line 2407 of file Bio.cs.

◆ slideImage

SlideImage BioImager.BioImage.slideImage

Definition at line 2408 of file Bio.cs.

◆ status

string BioImager.BioImage.status
static

Definition at line 2478 of file Bio.cs.

◆ swatch

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

Definition at line 4429 of file Bio.cs.

◆ tifRead

Tiff BioImager.BioImage.tifRead

Definition at line 6664 of file Bio.cs.

◆ vipPages

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

Definition at line 2002 of file Bio.cs.

◆ Volume

VolumeD BioImager.BioImage.Volume

Definition at line 2011 of file Bio.cs.

◆ watch

Stopwatch BioImager.BioImage.watch = new Stopwatch()

Definition at line 2438 of file Bio.cs.

Property Documentation

◆ BChannel

Channel BioImager.BioImage.BChannel
get

Definition at line 2240 of file Bio.cs.

2241 {
2242 get
2243 {
2244 if (Channels[0].range.Length == 1)
2245 return Channels[rgbChannels[2]];
2246 else
2247 return Channels[0];
2248 }
2249 }

◆ BRange

IntRange BioImager.BioImage.BRange
get

Definition at line 2424 of file Bio.cs.

2425 {
2426 get
2427 {
2428 return BChannel.RangeB;
2429 }
2430 }

◆ Coordinate

ZCT BioImager.BioImage.Coordinate
getset

Definition at line 1971 of file Bio.cs.

1972 {
1973 get
1974 {
1975 return coordinate;
1976 }
1977 set
1978 {
1979 coordinate = value;
1980 }
1981 }

◆ Filename

string BioImager.BioImage.Filename
getset

Definition at line 2015 of file Bio.cs.

2016 {
2017 get
2018 {
2019 return filename;
2020 }
2021 set
2022 {
2023 filename = value;
2024 }
2025 }

◆ GChannel

Channel BioImager.BioImage.GChannel
get

Definition at line 2230 of file Bio.cs.

2231 {
2232 get
2233 {
2234 if (Channels[0].range.Length == 1)
2235 return Channels[rgbChannels[1]];
2236 else
2237 return Channels[0];
2238 }
2239 }

◆ GRange

IntRange BioImager.BioImage.GRange
get

Definition at line 2417 of file Bio.cs.

2418 {
2419 get
2420 {
2421 return GChannel.RangeG;
2422 }
2423 }

◆ ID

string BioImager.BioImage.ID
getset

Definition at line 2164 of file Bio.cs.

2165 {
2166 get { return id; }
2167 set { id = value; }
2168 }

◆ ImageCount

int BioImager.BioImage.ImageCount
get

Definition at line 2169 of file Bio.cs.

2170 {
2171 get
2172 {
2173 return Buffers.Count;
2174 }
2175 }

◆ Initialized

bool BioImager.BioImage.Initialized
staticget

Definition at line 2480 of file Bio.cs.

2481 {
2482 get
2483 {
2484 return initialized;
2485 }
2486 }

◆ isPyramidal

bool BioImager.BioImage.isPyramidal
get

Definition at line 2469 of file Bio.cs.

2470 {
2471 get
2472 {
2473 if (Type == ImageType.pyramidal) return true;
2474 else return false;
2475 }
2476 }

◆ isRGB

bool BioImager.BioImage.isRGB
get

Definition at line 2439 of file Bio.cs.

2440 {
2441 get
2442 {
2443 if (RGBChannelCount == 3 || RGBChannelCount == 4)
2444 return true;
2445 else
2446 return false;
2447 }
2448 }

◆ isSeries

bool BioImager.BioImage.isSeries
get

Definition at line 2459 of file Bio.cs.

2460 {
2461 get
2462 {
2463 if (seriesCount > 1)
2464 return true;
2465 else
2466 return false;
2467 }
2468 }

◆ isTime

bool BioImager.BioImage.isTime
get

Definition at line 2449 of file Bio.cs.

2450 {
2451 get
2452 {
2453 if (SizeT > 1)
2454 return true;
2455 else
2456 return false;
2457 }
2458 }

◆ LabelResolution

int? BioImager.BioImage.LabelResolution
getset

Definition at line 2488 of file Bio.cs.

2488{ get; set; }

◆ Level

int BioImager.BioImage.Level
getset

Definition at line 2536 of file Bio.cs.

2537 {
2538 get
2539 {
2540 if (openSlideBase != null)
2541 return OpenSlideGTK.TileUtil.GetLevel(openSlideBase.Schema.Resolutions, Resolution);
2542 else
2543 if (slideBase != null)
2544 return LevelFromResolution(Resolution);
2545 return level;
2546 }
2547 set
2548 {
2549 if (Type == ImageType.well)
2550 {
2551 level = value;
2552 reader.setId(file);
2553 reader.setSeries(value);
2554 // read the image data bytes
2555 int pages = reader.getImageCount();
2556 bool inter = reader.isInterleaved();
2557 PixelFormat pf = Buffers[0].PixelFormat;
2558 int w = Buffers[0].SizeX; int h = Buffers[0].SizeY;
2559 Buffers.Clear();
2560 for (int p = 0; p < pages; p++)
2561 {
2562 Bitmap bf;
2563 byte[] bytes = reader.openBytes(p);
2564 bf = new Bitmap(file, w, h, pf, bytes, new ZCT(), p, null, littleEndian, inter);
2565 Buffers.Add(bf);
2566 }
2567 }
2568 }
2569 }
int LevelFromResolution(double Resolution)
Returns the level of a given resolution.
Definition: Bio.cs:2589

◆ MacroResolution

int? BioImager.BioImage.MacroResolution
getset

Definition at line 2487 of file Bio.cs.

2487{ get; set; }

◆ PhysicalSizeX

double BioImager.BioImage.PhysicalSizeX
get

Definition at line 2176 of file Bio.cs.

2177 {
2178 get { return Resolutions[Level].PhysicalSizeX; }
2179 }

◆ PhysicalSizeY

double BioImager.BioImage.PhysicalSizeY
get

Definition at line 2180 of file Bio.cs.

2181 {
2182 get { return Resolutions[Level].PhysicalSizeY; }
2183 }

◆ PhysicalSizeZ

double BioImager.BioImage.PhysicalSizeZ
get

Definition at line 2184 of file Bio.cs.

2185 {
2186 get { return Resolutions[Level].PhysicalSizeZ; }
2187 }

◆ PyramidalOrigin

PointD BioImager.BioImage.PyramidalOrigin
getset

Definition at line 2527 of file Bio.cs.

2528 {
2529 get { return pyramidalOrigin; }
2530 set
2531 {
2532 pyramidalOrigin = value;
2533 }
2534 }

◆ PyramidalSize

AForge.Size BioImager.BioImage.PyramidalSize
getset

Definition at line 2525 of file Bio.cs.

2525{ get { return s; } set { s = value; } }

◆ RChannel

Channel BioImager.BioImage.RChannel
get

Definition at line 2220 of file Bio.cs.

2221 {
2222 get
2223 {
2224 if (Channels[0].range.Length == 1)
2225 return Channels[rgbChannels[0]];
2226 else
2227 return Channels[0];
2228 }
2229 }

◆ Resolution

double BioImager.BioImage.Resolution
getset

Definition at line 2003 of file Bio.cs.

2004 {
2005 get { return resolution; }
2006 set
2007 {
2008 resolution = value;
2009 }
2010 }

◆ RGBChannelCount

int BioImager.BioImage.RGBChannelCount
get

Definition at line 2027 of file Bio.cs.

2028 {
2029 get
2030 {
2031 return Buffers[0].RGBChannelsCount;
2032 }
2033 }

◆ RRange

IntRange BioImager.BioImage.RRange
get

Definition at line 2410 of file Bio.cs.

2411 {
2412 get
2413 {
2414 return RChannel.RangeR;
2415 }
2416 }

◆ SelectedBuffer

Bitmap BioImager.BioImage.SelectedBuffer
get

Definition at line 2431 of file Bio.cs.

2432 {
2433 get
2434 {
2435 return Buffers[Coords[Coordinate.Z, Coordinate.C, Coordinate.T]];
2436 }
2437 }

◆ series

int BioImager.BioImage.series
getset

Definition at line 2207 of file Bio.cs.

2208 {
2209 get
2210 {
2211 return imageInfo.Series;
2212 }
2213 set
2214 {
2215 imageInfo.Series = value;
2216 }
2217 }

◆ SizeC

int BioImager.BioImage.SizeC
get

Definition at line 2397 of file Bio.cs.

2398 {
2399 get { return sizeC; }
2400 }

◆ SizeT

int BioImager.BioImage.SizeT
get

Definition at line 2401 of file Bio.cs.

2402 {
2403 get { return sizeT; }
2404 }

◆ SizeX

int BioImager.BioImage.SizeX
get

Definition at line 2375 of file Bio.cs.

2376 {
2377 get
2378 {
2379 if (Buffers.Count > 0)
2380 return Buffers[0].SizeX;
2381 else return 0;
2382 }
2383 }

◆ SizeY

int BioImager.BioImage.SizeY
get

Definition at line 2384 of file Bio.cs.

2385 {
2386 get
2387 {
2388 if (Buffers.Count > 0)
2389 return Buffers[0].SizeY;
2390 else return 0;
2391 }
2392 }

◆ SizeZ

int BioImager.BioImage.SizeZ
get

Definition at line 2393 of file Bio.cs.

2394 {
2395 get { return sizeZ; }
2396 }

◆ StageSizeX

double BioImager.BioImage.StageSizeX
getset

Definition at line 2188 of file Bio.cs.

2189 {
2190 get
2191 {
2192 return Resolutions[Level].StageSizeX;
2193 }
2194 set { imageInfo.StageSizeX = value; }
2195 }

◆ StageSizeY

double BioImager.BioImage.StageSizeY
getset

Definition at line 2196 of file Bio.cs.

2197 {
2198 get { return Resolutions[Level].StageSizeY; }
2199 set { imageInfo.StageSizeY = value; }
2200 }

◆ StageSizeZ

double BioImager.BioImage.StageSizeZ
getset

Definition at line 2201 of file Bio.cs.

2202 {
2203 get { return Resolutions[Level].StageSizeZ; }
2204 set { imageInfo.StageSizeZ = value; }
2205 }

◆ Statistics

Statistics BioImager.BioImage.Statistics
getset

Definition at line 2043 of file Bio.cs.

2044 {
2045 get
2046 {
2047 return statistics;
2048 }
2049 set
2050 {
2051 statistics = value;
2052 }
2053 }

◆ Type

ImageType BioImager.BioImage.Type
getset

Definition at line 1990 of file Bio.cs.

1991 {
1992 get { return type; }
1993 set
1994 {
1995 type = value;
1996 }
1997 }

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