BioLib  4.1.1
A GUI-less version of Bio .NET library for editing & annotating various microscopy image formats.
Loading...
Searching...
No Matches
BioLib.OMERO Class Reference

Static Public Member Functions

static void Connect (string host, int port, string username, string password)
 
static void Connect ()
 
static long GetID ()
 
static void ReConnect ()
 
static List<(double X, double Y)> GetPoints (Image image, Shape shape, double physX, double physY)
 
static ROI[] GetROIs (double physX, double physY, long imageId)
 
static Image GetOMEROImage (long imageId)
 
static double[] GetImageSize (long imageId)
 Gets the physical pixel sizes (SizeX, SizeY, SizeZ) for a given image. Returns a double array {SizeX, SizeY, SizeZ}, with 0.0 for missing values.
 
static void Upload (BioImage b, long id)
 
static omero.model.? StageLabel GetStageLabel (long imageId)
 
static BioImage GetImage (string filename, long dataset)
 
static BioImage GetImage (long id)
 
static byte[] CombineToBGRA (byte[] r, byte[] g, byte[] b)
 
static Bitmap GetFullPlane (BioImage b, ZCT coord, int level, int tileSize=1024)
 
static async Task< Bitmap > GetTile (BioImage b, ZCT coord, int x, int y, int width, int height, int level)
 
static Dictionary< long, Pixbuf > GetThumbnails (string[] filenames, int width, int height)
 
static string GetNameFromID (long id)
 
static List< string > GetAllFiles ()
 
static List< string > GetDatasets ()
 
static List< DatasetData > GetDatasetsData ()
 
static DatasetData GetDataset (string name)
 
static DatasetData GetDataset (string name, long id)
 
static List< string > GetFolders ()
 
static List< string > GetDatasetFiles (string db)
 
static List< string > GetDatasetFiles (long dbid)
 
static List< long > GetDatasetIds (long dbid)
 

Static Public Attributes

static string host
 
static string username
 
static string password = ""
 
static int port
 
static omero.client client
 
static ServiceFactoryPrx session
 
static Gateway gateway
 
static ExperimenterData experimenter
 
static ExperimenterData experimenterSudo
 
static IMetadataPrx meta
 
static BrowseFacility browsefacil
 
static MetadataFacility metafacil
 
static DataManagerFacility datafacil
 
static RawDataFacility rawdatafacil
 
static EventContext adminContext
 
static IAdminPrx adminPrx
 
static SecurityContext sc
 
static omero.api.RawPixelsStorePrx store
 
static java.util.Collection datasets
 
static java.util.Collection folders
 
static java.util.Collection images
 
static double progress = 0
 
static bool ShowRGB = false
 

Member Function Documentation

◆ CombineToBGRA()

static byte[] BioLib.OMERO.CombineToBGRA ( byte[] r,
byte[] g,
byte[] b )
static
731 {
732 int length = r.Length;
733 byte[] result = new byte[length * 4];
734
735 System.Threading.Tasks.Parallel.For(0, length, i =>
736 {
737 int idx = i * 4;
738 result[idx + 3] = b[i];
739 result[idx + 2] = g[i];
740 result[idx + 1] = r[i];
741 result[idx] = 255;
742 });
743
744 return result;
745 }

◆ Connect() [1/2]

static void BioLib.OMERO.Connect ( )
static
80 {
81 client = new client(host, port);
82 session = client.createSession(username, password);
83 // Initialize OMERO client and gateway
84 gateway = new Gateway(new SimpleLogger());
85 LoginCredentials credentials = new LoginCredentials();
86 credentials.getServer().setHostname(host);
87 credentials.getServer().setPort(port);
88 credentials.getUser().setUsername(username);
89 credentials.getUser().setPassword(password);
90 experimenter = gateway.connect(credentials);
91 Init();
92 }

◆ Connect() [2/2]

static void BioLib.OMERO.Connect ( string host,
int port,
string username,
string password )
static
62 {
63 OMERO.host = host;
64 OMERO.port = port;
65 OMERO.username = username;
66 OMERO.password = password;
67 client = new client(host, port);
68 session = client.createSession(username, password);
69 // Initialize OMERO client and gateway
70 gateway = new Gateway(new SimpleLogger());
71 LoginCredentials credentials = new LoginCredentials();
72 credentials.getServer().setHostname(host);
73 credentials.getServer().setPort(port);
74 credentials.getUser().setUsername(username);
75 credentials.getUser().setPassword(password);
76 experimenter = gateway.connect(credentials);
77 Init();
78 }

◆ GetAllFiles()

static List< string > BioLib.OMERO.GetAllFiles ( )
static
905 {
906 ReConnect();
907 var meta = session.getMetadataService();
908 var uims = browsefacil.getUserImages(sc);
909 List<string> files = new List<string>();
910 var itr = uims.iterator();
911 while (itr.hasNext())
912 {
913 ImageData da = (ImageData)itr.next();
914 files.Add(da.getName());
915 }
916 return files;
917 }

◆ GetDataset() [1/2]

static DatasetData BioLib.OMERO.GetDataset ( string name)
static
945 {
946 ReConnect();
947 var d = browsefacil.getDatasets(sc);
948 var itr = d.iterator();
949 while (itr.hasNext())
950 {
951 DatasetData dd = (DatasetData)itr.next();
952 if (dd.getName() == name)
953 return dd;
954 }
955 return null;
956 }

◆ GetDataset() [2/2]

static DatasetData BioLib.OMERO.GetDataset ( string name,
long id )
static
958 {
959 ReConnect();
960 var d = browsefacil.getDatasets(sc);
961 var itr = d.iterator();
962 while (itr.hasNext())
963 {
964 DatasetData dd = (DatasetData)itr.next();
965 if (dd.getName() == name && id == dd.getId())
966 return dd;
967 }
968 return null;
969 }

◆ GetDatasetFiles() [1/2]

static List< string > BioLib.OMERO.GetDatasetFiles ( long dbid)
static
1008 {
1009 ReConnect();
1010 var d = browsefacil.getDatasets(sc);
1011 var itr = d.iterator();
1012 while (itr.hasNext())
1013 {
1014 DatasetData idr = (DatasetData)itr.next();
1015 if (dbid == idr.getId())
1016 {
1017 java.util.ArrayList ar = new java.util.ArrayList();
1018 ar.add(java.lang.Long.valueOf(idr.getId()));
1019 var imgs = browsefacil.getImagesForDatasets(sc,ar);
1020 var itr2 = imgs.iterator();
1021 List<string> str = new List<string>();
1022 while (itr2.hasNext())
1023 {
1024 ImageData imageData = (ImageData)itr2.next();
1025 str.Add(imageData.getName());
1026 }
1027 return str;
1028 }
1029 }
1030 return null;
1031 }

◆ GetDatasetFiles() [2/2]

static List< string > BioLib.OMERO.GetDatasetFiles ( string db)
static
983 {
984 ReConnect();
985 var d = browsefacil.getDatasets(sc);
986 var itr = d.iterator();
987 while (itr.hasNext())
988 {
989 DatasetData idr = (DatasetData)itr.next();
990 if(idr.getName() == db)
991 {
992 java.util.ArrayList ar = new java.util.ArrayList();
993 ar.add(java.lang.Long.valueOf(idr.getId()));
994 var ims = browsefacil.getImagesForDatasets(sc,ar);
995 var itr2 = ims.iterator();
996 List<string> fs = new List<string>();
997 while (itr2.hasNext())
998 {
999 var im = (ImageData)itr2.next();
1000 fs.Add(im.getName());
1001 }
1002 return fs;
1003 }
1004 }
1005 return null;
1006 }

◆ GetDatasetIds()

static List< long > BioLib.OMERO.GetDatasetIds ( long dbid)
static
1033 {
1034 ReConnect();
1035 var d = browsefacil.getDatasets(sc);
1036 var itr = d.iterator();
1037 while (itr.hasNext())
1038 {
1039 DatasetData idr = (DatasetData)itr.next();
1040 if (dbid == idr.getId())
1041 {
1042 java.util.ArrayList ar = new java.util.ArrayList();
1043 ar.add(java.lang.Long.valueOf(idr.getId()));
1044 var imgs = browsefacil.getImagesForDatasets(sc, ar);
1045 var itr2 = imgs.iterator();
1046 List<long> str = new List<long>();
1047 while (itr2.hasNext())
1048 {
1049 ImageData imageData = (ImageData)itr2.next();
1050 str.Add(imageData.getId());
1051 }
1052 return str;
1053 }
1054 }
1055 return null;
1056 }

◆ GetDatasets()

static List< string > BioLib.OMERO.GetDatasets ( )
static
919 {
920 ReConnect();
921 var d = browsefacil.getDatasets(sc);
922 var itr = d.iterator();
923 List<string> dbs = new List<string>();
924 while (itr.hasNext())
925 {
926 DatasetData dd = (DatasetData)itr.next();
927 dbs.Add(dd.getName());
928 }
929 return dbs;
930 }

◆ GetDatasetsData()

static List< DatasetData > BioLib.OMERO.GetDatasetsData ( )
static
932 {
933 ReConnect();
934 var d = browsefacil.getDatasets(sc);
935 var itr = d.iterator();
936 List<DatasetData> dbs = new List<DatasetData>();
937 while (itr.hasNext())
938 {
939 DatasetData dd = (DatasetData)itr.next();
940 dbs.Add(dd);
941 }
942 return dbs;
943 }

◆ GetFolders()

static List< string > BioLib.OMERO.GetFolders ( )
static
971 {
972 ReConnect();
973 var d = browsefacil.getFolders(sc);
974 var itr = d.iterator();
975 List<string> dbs = new List<string>();
976 while (itr.hasNext())
977 {
978 dbs.Add((string)itr.next());
979 }
980 return dbs;
981 }

◆ GetFullPlane()

static Bitmap BioLib.OMERO.GetFullPlane ( BioImage b,
ZCT coord,
int level,
int tileSize = 1024 )
static
748 {
749 ReConnect();
750
751 var itr = images.iterator();
752 while (itr.hasNext())
753 {
754 ImageData o = (ImageData)itr.next();
755 if (o.getName() != b.Filename)
756 continue;
757
758 PixelsData pd = o.getDefaultPixels();
759 Pixels ps = pd.asPixels();
760 int sizeX = pd.getSizeX();
761 int sizeY = pd.getSizeY();
762 /*
763 // --- Handle resolution level safety ---
764 int maxLevels = b.Resolutions.Count;
765 if (maxLevels > 1 && level < maxLevels)
766 store.setResolutionLevel(level);
767 else
768 store.setResolutionLevel(0);
769 */
770 // --- Pixel format setup ---
771 PixelsType pxt = ps.getPixelsType();
772 int bits = pxt.getBitSize().getValue();
773 AForge.PixelFormat px = GetPixelFormat(bits);
774 int bytesPerPixel = bits / 8;
775 if (bytesPerPixel <= 0) bytesPerPixel = 1;
776
777 // --- Prepare output byte buffer ---
778 byte[] planeBytes = new byte[sizeX * sizeY * bytesPerPixel];
779
780 // --- Fetch and stitch tiles ---
781 for (int ty = 0; ty < sizeY; ty += tileSize)
782 {
783 for (int tx = 0; tx < sizeX; tx += tileSize)
784 {
785 int w = Math.Min(tileSize, sizeX - tx);
786 int h = Math.Min(tileSize, sizeY - ty);
787 byte[] tile = store.getTile(coord.Z, coord.C, coord.T, tx, ty, w, h);
788 // --- Copy tile into full plane ---
789 for (int row = 0; row < h; row++)
790 {
791 int destOffset = ((ty + row) * sizeX + tx) * bytesPerPixel;
792 int srcOffset = row * w * bytesPerPixel;
793 Buffer.BlockCopy(tile, srcOffset, planeBytes, destOffset, w * bytesPerPixel);
794 }
795 }
796 }
797
798 // --- Create and return assembled AForge bitmap ---
799 return new AForge.Bitmap("", sizeX, sizeY, px, planeBytes, coord, 0, null, false);
800 }
801
802 return null;
803 }

◆ GetID()

static long BioLib.OMERO.GetID ( )
static
94 {
95 return rng.Next(0, 99999);
96 }

◆ GetImage() [1/2]

static BioImage BioLib.OMERO.GetImage ( long id)
static
726 {
727 string n = browsefacil.getImage(sc, id).getName();
728 return GetImage(n,id);
729 }

◆ GetImage() [2/2]

static BioImage BioLib.OMERO.GetImage ( string filename,
long dataset )
static
525 {
526 ReConnect();
527 BioImage b = new BioImage(filename);
528 try
529 {
530 java.util.Collection col = new java.util.ArrayList();
531 col.add(java.lang.Long.valueOf(dataset));
532 var uims = browsefacil.getImagesForDatasets(sc, col);
533 var itr = uims.iterator();
534 java.util.List li = new java.util.ArrayList();
535 java.util.ArrayList imgs = new java.util.ArrayList();
536 Images.AddImage(b);
537
538 do
539 {
540 java.util.ArrayList list = new java.util.ArrayList();
541 ImageData o = (ImageData)itr.next();
542 string name = o.getName();
543 string[] sts = name.Split(' ');
544 if (filename != name)
545 continue;
546
547 PixelsData pd = o.getDefaultPixels();
548 int xs = pd.getSizeX();
549 int ys = pd.getSizeY();
550 int zs = pd.getSizeZ();
551 int cs = pd.getSizeC();
552 int ts = pd.getSizeT();
553 long pid = o.getId();
554
555 b.Filename = sts[0];
556 b.ID = name.Replace(" ","_");
557 RawPixelsStorePrx store = gateway.getPixelsStore(sc);
558 long ind = o.getId();
559 long ll = pd.getId();
560 list.add(java.lang.Long.valueOf(ind));
561 try
562 {
563 var acq = metafacil.getChannelData(sc, ind);
564 int s = acq.size();
565 for (int i = 0; i < s; i++)
566 {
567 var ch = (ChannelData)acq.get(i);
568 var ac = metafacil.getImageAcquisitionData(sc, ind);
569 var chan = ch.asChannel();
570 AForge.Color color = new AForge.Color();
571 try
572 {
573 int re = chan.getRed().getValue();
574 int gr = chan.getGreen().getValue();
575 int bl = chan.getBlue().getValue();
576 color = AForge.Color.FromArgb(re,gr,bl);
577 }
578 catch (Exception e)
579 {
580 Console.WriteLine(e.Message);
581 }
582 var px = pd.asPixels().getPixelsType();
583 int bits = px.getBitSize().getValue();
584 AForge.PixelFormat pxx = GetPixelFormat(bits);
585 AForge.Channel cch = null;
586 if (pxx == AForge.PixelFormat.Format8bppIndexed || pxx == AForge.PixelFormat.Format16bppGrayScale)
587 cch = new AForge.Channel(i, bits, 1);
588 else if (pxx == AForge.PixelFormat.Format24bppRgb || pxx == AForge.PixelFormat.Format48bppRgb)
589 cch = new AForge.Channel(i, bits, 3);
590 else if (pxx == AForge.PixelFormat.Format32bppArgb)
591 cch = new AForge.Channel(i, bits, 4);
592 cch.Fluor = ch.getFluor();
593 var em = ch.getEmissionWavelength(omero.model.enums.UnitsLength.NANOMETER);
594 if (em != null)
595 cch.Emission = (int)em.getValue();
596 cch.Color = color;
597 cch.Name = ch.getName();
598 if (cch.Name == null)
599 cch.Name = i.ToString();
600 b.Channels.Add(cch);
601 }
602 }
603 catch (Exception exx)
604 {
605 Console.WriteLine(exx.Message);
606 }
607 var stage = o.asImage().getStageLabel();
608 bool pyramidal = false;
609 int ls = 0;
610 try
611 {
612 ls = store.getResolutionLevels();
613 pyramidal = true;
614 }
615 catch (Exception e)
616 {
617 ls = 1;
618 }
619
620 try
621 {
622 int i = 0;
623 while(true)
624 {
625 if (i >= ls)
626 break;
627 omero.RInt rint = rtypes.rint(i);
628 Image im = o.asImage();
629 im.setSeries(rint);
630 RInt rin = im.getSeries();
631 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
632 Pixels pxs = im.getPixels(0);
633 store.setPixelsId(pxs.getId().getValue(),true);
634
635 var pxto = pxs.getPixelsType();
636 int bitso = pxto.getBitSize().getValue();
637 int wo = pxs.getSizeX().getValue();
638 int ho = pxs.getSizeY().getValue();
639 px = GetPixelFormat(bitso);
640 double pxxo = pxs.getPhysicalSizeX().getValue();
641 double pyyo = pxs.getPhysicalSizeY().getValue();
642 double pzzo = 0;
643 var pzo = pxs.getPhysicalSizeZ();
644 if (pzo != null)
645 pzzo = pzo.getValue();
646 if (stage != null)
647 {
648 var sta = GetStageLabel(im.getId().getValue());
649 Length? sxxo = sta.getPositionX();
650 Length? syyo = sta.getPositionY();
651 Length? szzo = sta.getPositionZ();
652 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo, pyyo, pzzo, sxxo.getValue(), syyo.getValue(), szzo.getValue()));
653 }
654 else
655 {
656 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo, pyyo, pzzo, 0, 0, 0));
657 }
658 i++;
659 }
660 }
661 catch (Exception ex)
662 {
663 int t = 0;
664 }
665
666 for (int z = 0; z < zs; z++)
667 {
668 for (int c = 0; c < cs; c++)
669 {
670 for (int t = 0; t < ts; t++)
671 {
672 if (b.isPyramidal)
673 {
674 Pixels ps = pd.asPixels();
675 int chc = ps.sizeOfChannels();
676 store.setPixelsId(ps.getId().getValue(), true);
677 store.setResolutionLevel(b.Level+1);
678 Bitmap bt = GetTile(b, new AForge.ZCT(z, c, t), 0, 0, 600, 400, b.Level + 1).Result;
679 b.Buffers.Add(new Bitmap("", 600, 400, PixelFormat.Format32bppArgb, bt.Bytes, new AForge.ZCT(z, c, t), 0, null, false));
680 }
681 else
682 {
683 Pixels ps = pd.asPixels();
684 int chc = ps.sizeOfChannels();
685 store.setPixelsId(ps.getId().getValue(), true);
686 byte[] bts = store.getPlane(z, c, t);
687 PixelsType pxt = ps.getPixelsType();
688 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
689 int bits = pxt.getBitSize().getValue();
690 px = GetPixelFormat(bits);
691 b.Buffers.Add(new AForge.Bitmap("", xs, ys, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
692 }
693 }
694 }
695 }
696 if(b.isPyramidal)
697 {
698 b.SlideBase = new SlideBase(b, SlideImage.Open(b));
699 }
700 b.Volume = new VolumeD(new Point3D(b.Resolutions[0].StageSizeX, b.Resolutions[0].StageSizeY, b.Resolutions[0].StageSizeZ),
701 new Point3D(b.SizeX * b.PhysicalSizeX, b.SizeY * b.PhysicalSizeY, zs * b.PhysicalSizeZ));
702 b.Annotations.AddRange(OMERO.GetROIs(b.PhysicalSizeX,b.PhysicalSizeY,pid));
703 b.UpdateCoords(zs, cs, ts);
704 b.series = o.getSeries();
705 b.imagesPerSeries = b.Buffers.Count;
706 b.rgbChannels = new int[b.Channels.Count];
707 b.ID = o.getId().ToString();
708 BioImage.AutoThreshold(b, true);
709 if (b.bitsPerPixel > 8)
710 b.StackThreshold(true);
711 else
712 b.StackThreshold(false);
713 b.Tag = "OMERO";
714 return b;
715 }
716 while (itr.hasNext());
717
718 }
719 catch (Exception e)
720 {
721 Console.WriteLine(e.ToString());
722 }
723 return null;
724 }

◆ GetImageSize()

static double[] BioLib.OMERO.GetImageSize ( long imageId)
static

Gets the physical pixel sizes (SizeX, SizeY, SizeZ) for a given image. Returns a double array {SizeX, SizeY, SizeZ}, with 0.0 for missing values.

406 {
407 var queryService = session.getQueryService();
408
409 // Query the Pixels object associated with the image
410 string hql = "select pix from Pixels as pix where pix.image.id = :id";
411 var param = new ParametersI();
412 param.addId(imageId);
413
414 var result = queryService.findByQuery(hql, param);
415 if (result == null)
416 {
417 Console.WriteLine($"No pixels found for image {imageId}");
418 return new double[] { 0.0, 0.0, 0.0 };
419 }
420
421 var pixels = (Pixels)result;
422
423 // Handle null sizes safely
424 double sizeX = pixels.getSizeY()?.getValue() ?? 0.0;
425 double sizeY = pixels.getSizeY()?.getValue() ?? 0.0;
426 double sizeZ = pixels.getSizeZ()?.getValue() ?? 0.0;
427
428 return new double[] { sizeX, sizeY, sizeZ };
429 }

◆ GetNameFromID()

static string BioLib.OMERO.GetNameFromID ( long id)
static
885 {
886 ReConnect();
887 return browsefacil.getImage(sc, id).getName();
888 }

◆ GetOMEROImage()

static Image BioLib.OMERO.GetOMEROImage ( long imageId)
static
396 {
397 var qs = session.getQueryService();
398 var obj = qs.get("Image", imageId);
399 return obj as Image;
400 }

◆ GetPoints()

static List<(double X, double Y)> BioLib.OMERO.GetPoints ( Image image,
Shape shape,
double physX,
double physY )
static
131 {
132 var qs = session.getQueryService();
133 var polygons = new List<(double X, double Y)>();
134 if (shape is Polygon polygon)
135 {
136 var pointList = new List<(double X, double Y)>();
137 string pointsStr = polygon.getPoints().getValue();
138 if (!string.IsNullOrEmpty(pointsStr))
139 {
140 // Points are like "10.0,20.0 30.0,40.0 50.0,60.0"
141 var pointPairs = pointsStr.Split(' ');
142 foreach (var pair in pointPairs)
143 {
144 var coords = pair.Split(',');
145 if (coords.Length == 2 &&
146 double.TryParse(coords[0], CultureInfo.InvariantCulture, out double x) &&
147 double.TryParse(coords[1], CultureInfo.InvariantCulture, out double y))
148 {
149 pointList.Add((x * physX, y * physY));
150 }
151 }
152 }
153 polygons.AddRange(pointList);
154 }
155 else if (shape is Polyline poly)
156 {
157 var pointList = new List<(double X, double Y)>();
158
159 string pointsStr = poly.getPoints().getValue();
160 if (!string.IsNullOrEmpty(pointsStr))
161 {
162 // Points are like "10.0,20.0 30.0,40.0 50.0,60.0"
163 var pointPairs = pointsStr.Split(' ');
164 foreach (var pair in pointPairs)
165 {
166 var coords = pair.Split(',');
167 if (coords.Length == 2 &&
168 double.TryParse(coords[0], CultureInfo.InvariantCulture, out double x) &&
169 double.TryParse(coords[1], CultureInfo.InvariantCulture, out double y))
170 {
171 pointList.Add((x * physX, y * physY));
172 }
173 }
174 }
175 polygons.AddRange(pointList);
176 }
177 else if (shape is Line li)
178 {
179 var pointList = new List<(double X, double Y)>();
180 pointList.Add((li.getX1().getValue() * physX, li.getY1().getValue() * physY));
181 pointList.Add((li.getX2().getValue() * physX, li.getY2().getValue() * physY));
182 polygons.AddRange(pointList);
183 }
184 return polygons;
185 }

◆ GetROIs()

static ROI[] BioLib.OMERO.GetROIs ( double physX,
double physY,
long imageId )
static
187 {
188 List<ROI> rois = new List<ROI>();
189 // Assume you already have a live session as 'serviceFactory'
190 var queryService = session.getQueryService();
191
192 // Create query parameters
193 var param = new ParametersI();
194 param.addId(imageId);
195
196 // Query for all ROIs related to a particular image
197 string query = "from Shape s where s.roi.image.id = :id";
198 var roiList = queryService.findAllByQuery(query, param);
199 int c = roiList.size();
200 for (int i = 0; i < c; i++)
201 {
202 var shape = (Shape)roiList.get(i);
203 // Using the ServiceFactory to reload a single ROI by ID
204 var roiId = shape.getRoi().getId().getValue();
205 ROI ro = new ROI();
206 if (shape is Rectangle)
207 {
208 Rectangle rec = (Rectangle)shape;
209 int zo = 0, co = 0, to = 0;
210 if (rec.getTheZ() != null)
211 zo = shape.getTheZ().getValue();
212 if (rec.getTheC() != null)
213 co = shape.getTheC().getValue();
214 if (rec.getTheT() != null)
215 to = shape.getTheT().getValue();
216 double x, y, w, h;
217 x = rec.getX().getValue();
218 y = rec.getY().getValue();
219 w = rec.getWidth().getValue();
220 h = rec.getHeight().getValue();
221
222 double[] ss = GetImageSize(imageId);
223 ro = ROI.CreateRectangle(new ZCT(zo, co, to), x * physX, y * physY, w * physX, h * physY);
224 try
225 {
226 ro.Text = rec.getTextValue().getValue();
227 }
228 catch (Exception e)
229 {
230
231 }
232 rois.Add(ro);
233 }
234 else if (shape is Polygon)
235 {
236 Polygon pl = (Polygon)shape;
237 int zo = 0, co = 0, to = 0;
238 if (pl.getTheZ() != null)
239 zo = shape.getTheZ().getValue();
240 if (pl.getTheC() != null)
241 co = shape.getTheC().getValue();
242 if (pl.getTheT() != null)
243 to = shape.getTheT().getValue();
244 var ps = GetPoints(GetOMEROImage(imageId), pl, physX, physY);
245 PointD[] pds = new PointD[ps.Count];
246 for (int p = 0; p < pds.Length; p++)
247 {
248 pds[p] = new PointD(ps[p].X, ps[p].Y);
249 }
250 ro = ROI.CreatePolygon(new ZCT(zo, co, to), pds);
251 try
252 {
253 ro.Text = pl.getTextValue().getValue();
254 }
255 catch (Exception e)
256 {
257
258 }
259 rois.Add(ro);
260 }
261 else if (shape is Polyline)
262 {
263 Polyline pl = (Polyline)shape;
264 int zo = 0, co = 0, to = 0;
265 if (pl.getTheZ() != null)
266 zo = shape.getTheZ().getValue();
267 if (pl.getTheC() != null)
268 co = shape.getTheC().getValue();
269 if (pl.getTheT() != null)
270 to = shape.getTheT().getValue();
271 var ps = GetPoints(GetOMEROImage(imageId), pl, physX, physY);
272 PointD[] pds = new PointD[ps.Count];
273 for (int p = 0; p < pds.Length; p++)
274 {
275 pds[p] = new PointD(ps[p].X, ps[p].Y);
276 }
277 ro = ROI.CreatePolygon(new ZCT(zo, co, to), pds);
278 try
279 {
280 ro.Text = pl.getTextValue().getValue();
281 }
282 catch (Exception e)
283 {
284
285 }
286 ro.type = ROI.Type.Polyline;
287 ro.closed = false;
288 rois.Add(ro);
289 }
290 else if (shape is Line)
291 {
292 Line pl = (Line)shape;
293 int zo = 0, co = 0, to = 0;
294 if (pl.getTheZ() != null)
295 zo = shape.getTheZ().getValue();
296 if (pl.getTheC() != null)
297 co = shape.getTheC().getValue();
298 if (pl.getTheT() != null)
299 to = shape.getTheT().getValue();
300 var ps = GetPoints(GetOMEROImage(imageId), pl, physX, physY);
301 PointD[] pds = new PointD[ps.Count];
302 for (int p = 0; p < pds.Length; p++)
303 {
304 pds[p] = new PointD(ps[p].X, ps[p].Y);
305 }
306 ro = ROI.CreateLine(new ZCT(zo, co, to), new PointD(pds[0].X, pds[0].Y), new PointD(pds[1].X, pds[1].Y));
307 try
308 {
309 ro.Text = pl.getTextValue().getValue();
310 }
311 catch (Exception e)
312 {
313
314 }
315 rois.Add(ro);
316 }
317 else if (shape is Ellipse)
318 {
319 Ellipse pl = (Ellipse)shape;
320 int zo = 0, co = 0, to = 0;
321 if (pl.getTheZ() != null)
322 zo = shape.getTheZ().getValue();
323 if (pl.getTheC() != null)
324 co = shape.getTheC().getValue();
325 if (pl.getTheT() != null)
326 to = shape.getTheT().getValue();
327 double rx = pl.getRadiusX().getValue() * physX;
328 double ry = pl.getRadiusY().getValue() * physY;
329 double x = pl.getX().getValue() * physX;
330 double y = pl.getY().getValue() * physY;
331 ro = ROI.CreateEllipse(new ZCT(zo, co, to), x, y, rx * 2, ry * 2);
332 try
333 {
334 ro.Text = pl.getTextValue().getValue();
335 }
336 catch (Exception e)
337 {
338
339 }
340 rois.Add(ro);
341
342 }
343 else if (shape is Label)
344 {
345 Label pl = (Label)shape;
346 int zo = 0, co = 0, to = 0;
347 if (pl.getTheZ() != null)
348 zo = shape.getTheZ().getValue();
349 if (pl.getTheC() != null)
350 co = shape.getTheC().getValue();
351 if (pl.getTheT() != null)
352 to = shape.getTheT().getValue();
353 double x = pl.getX().getValue() * physX;
354 double y = pl.getY().getValue() * physY;
355 ro = ROI.CreateRectangle(new ZCT(zo, co, to), x, y, physX * 5, physY * 5);
356 ro.type = ROI.Type.Label;
357 try
358 {
359 ro.Text = pl.getTextValue().getValue();
360 }
361 catch (Exception e)
362 {
363
364 }
365 rois.Add(ro);
366 }
367 else if (shape is omero.model.Point)
368 {
369 omero.model.Point po = (omero.model.Point)shape;
370 int zo = 0, co = 0, to = 0;
371 if (po.getTheZ() != null)
372 zo = shape.getTheZ().getValue();
373 if (po.getTheC() != null)
374 co = shape.getTheC().getValue();
375 if (po.getTheT() != null)
376 to = shape.getTheT().getValue();
377 double x, y, w, h;
378 x = po.getX().getValue();
379 y = po.getY().getValue();
380 ro = ROI.CreatePoint(new ZCT(zo, co, to), x * physX, y * physY);
381 try
382 {
383 ro.Text = po.getTextValue().getValue();
384 }
385 catch (Exception e)
386 {
387
388 }
389 rois.Add(ro);
390 }
391 ro.UpdateBoundingBox();
392 }
393 return rois.ToArray();
394 }
static double[] GetImageSize(long imageId)
Gets the physical pixel sizes (SizeX, SizeY, SizeZ) for a given image. Returns a double array {SizeX,...
Definition OMERO.cs:405

◆ GetStageLabel()

static omero.model.? StageLabel BioLib.OMERO.GetStageLabel ( long imageId)
static
514 {
515 var queryService = session.getQueryService();
516 // Load the image
517 var image = (omero.model.Image)queryService.get("omero.model.Image", imageId);
518 if (image == null || image.getStageLabel() == null)
519 return null;
520 var stageLabelId = image.getStageLabel().getId().getValue();
521 var stageLabel = (omero.model.StageLabel)queryService.get("omero.model.StageLabel", stageLabelId);
522 return stageLabel;
523 }

◆ GetThumbnails()

static Dictionary< long, Pixbuf > BioLib.OMERO.GetThumbnails ( string[] filenames,
int width,
int height )
static
843 {
844 ReConnect();
845 Dictionary<long, Pixbuf> dict = new Dictionary<long, Pixbuf>();
846 try
847 {
848 var meta = session.getMetadataService();
849 ExperimenterGroupI sec = (ExperimenterGroupI)session.getSecurityContexts().get(0);
850 RLong id = sec.getId();
851 SecurityContext sc = new SecurityContext(id.getValue());
852 // Get the thumbnail service
853 ThumbnailStorePrx store = gateway.getThumbnailService(sc);
854 // Access BrowseFacility
855 BrowseFacility facility = (BrowseFacility)gateway.getFacility(brFacility);
856 var uims = facility.getUserImages(sc);
857 var itr = uims.iterator();
858 List<Pixbuf> images = new List<Pixbuf>();
859 while (itr.hasNext())
860 {
861 var img = (ImageData)itr.next();
862 string name = img.getName();
863 for (int i = 0; i < filenames.Length; i++)
864 {
865 if(name == filenames[i])
866 {
867 // Set the pixels ID for the image
868 long pixelId = img.getDefaultPixels().getId();
869 store.setPixelsId(pixelId);
870 byte[] thumbnailBytes = store.getThumbnail(omero.rtypes.rint(width), omero.rtypes.rint(height));
871 Pixbuf pf = new Pixbuf(thumbnailBytes);
872 dict.Add(img.getId(), pf);
873 }
874 }
875 }
876 return dict;
877 }
878 catch (Exception e)
879 {
880 Console.WriteLine(e.Message);
881 return null;
882 }
883 }

◆ GetTile()

static async Task< Bitmap > BioLib.OMERO.GetTile ( BioImage b,
ZCT coord,
int x,
int y,
int width,
int height,
int level )
static
805 {
806 ReConnect();
807 try
808 {
809 var itr = images.iterator();
810 java.util.List li = new java.util.ArrayList();
811 java.util.ArrayList imgs = new java.util.ArrayList();
812 do
813 {
814 java.util.ArrayList list = new java.util.ArrayList();
815 ImageData o = (ImageData)itr.next();
816 string name = o.getName();
817 int sp = name.Count(' ');
818 if (sp != 1 || !name.Contains(b.filename))
819 continue;
820 PixelsData pd = o.getDefaultPixels();
821 int zs = pd.getSizeZ();
822 int cs = pd.getSizeC();
823 int ts = pd.getSizeT();
824 long ind = o.getId();
825 list.add(java.lang.Long.valueOf(ind));
826 Pixels ps = pd.asPixels();
827 int chc = ps.sizeOfChannels();
828 store.setPixelsId(ps.getId().getValue(), true);
829 byte[] btb = store.getTile(coord.Z, 2, coord.T, x, y, width, height);
830 byte[] btg = store.getTile(coord.Z, 1, coord.T, x, y, width, height);
831 byte[] btr = store.getTile(coord.Z, 0, coord.T, x, y, width, height);
832 byte[] bt = CombineToBGRA(btb, btg, btr);
833 return new Bitmap("", width, height, PixelFormat.Format32bppArgb, bt, coord, 0, null, false);
834 } while (itr.hasNext());
835 }
836 catch (Exception e)
837 {
838 Console.WriteLine(e.Message);
839 }
840 return null;
841 }

◆ ReConnect()

static void BioLib.OMERO.ReConnect ( )
static
115 {
116 if (!gateway.isConnected())
117 {
118 client = new client(host, port);
119 session = client.createSession(username, password);
120 // Initialize OMERO client and gateway
121 gateway = new Gateway(new SimpleLogger());
122 LoginCredentials credentials = new LoginCredentials();
123 credentials.getServer().setHostname(host);
124 credentials.getServer().setPort(port);
125 credentials.getUser().setUsername(username);
126 credentials.getUser().setPassword(password);
127 experimenter = gateway.connect(credentials);
128 }
129 }

◆ Upload()

static void BioLib.OMERO.Upload ( BioImage b,
long id )
static
431 {
432 //See above how to load an image.
433 int sizeZ = b.SizeZ;
434 int sizeT = b.SizeT;
435 int sizeC = b.SizeC;
436 int sizeX = b.SizeX;
437 int sizeY = b.SizeY;
438
439 //Read the pixels from the source image.
440 RawPixelsStorePrx store = gateway.getPixelsStore(sc);
441 List<byte[]> planes = new List<byte[]>();
442 for (int z = 0; z < sizeZ; z++)
443 {
444 for (int c = 0; c < sizeC; c++)
445 {
446 for (int t = 0; t < sizeT; t++)
447 {
448 planes.Add(b.GetBitmap(z,c,t).GetSaveBytes(BitConverter.IsLittleEndian));
449 }
450 }
451 }
452
453 //Now we are going to create the new image.
454 IPixelsPrx proxy = gateway.getPixelsService(sc);
455
456 //Create new image.
457 String name = b.Filename;
458 PixelsType pixelsType = new PixelsTypeI();
459 if (b.Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
460 pixelsType.setValue(omero.rtypes.rstring("uint16"));
461 else
462 pixelsType.setValue(omero.rtypes.rstring("uint8"));
463 RLong idNew = proxy.createImage(sizeX, sizeY, sizeZ, sizeT, java.util.Arrays.asList(new java.lang.Integer(0)), pixelsType, name, "");
464 IContainerPrx proxyCS = session.getContainerService();
465 java.util.List results = proxyCS.getImages("omero.model.Image", java.util.Arrays.asList(new java.lang.Long(idNew.getValue())), new ParametersI());
466 ImageData newImage = new ImageData((Image)results.get(0));
467 var user = gateway.getLoggedInUser();
468 long userId = user.getId();
469 try
470 {
471 // Set physical sizes
472 var pixels = newImage.getDefaultPixels();
473 pixels.setPixelSizeX(new LengthI(b.PhysicalSizeX, omero.model.enums.UnitsLength.MICROMETER));
474 pixels.setPixelSizeY(new LengthI(b.PhysicalSizeY, omero.model.enums.UnitsLength.MICROMETER));
475 pixels.setPixelSizeZ(new LengthI(b.PhysicalSizeZ, omero.model.enums.UnitsLength.MICROMETER));
476 // Write pixel planes with correct endianness
477 store.setPixelsId(newImage.getDefaultPixels().getId(), false);
478 int index = 0;
479 if (sizeC == 3)
480 sizeC = 1;
481 for (int z = 0; z < sizeZ; z++)
482 {
483 for (int c = 0; c < sizeC; c++)
484 {
485 for (int t = 0; t < sizeT; t++)
486 {
487 byte[] planeBytes = planes[index++];
488 if (b.Buffers[0].PixelFormat == PixelFormat.Format16bppGrayScale)
489 {
490 for (int i = 0; i < planeBytes.Length; i += 2)
491 {
492 byte tmp = planeBytes[i];
493 planeBytes[i] = planeBytes[i + 1];
494 planeBytes[i + 1] = tmp;
495 }
496 }
497 store.setPlane(planeBytes, z, c, t);
498 }
499 }
500 }
501 store.save();
502 // Save ROI data
503 int roiCount = ROI.AddROIsToOMERO(newImage.getId(), userId, b);
504 Console.WriteLine($"Uploaded {roiCount} ROIs.");
505 Recorder.Record($"OMERO.Upload({b}, {id});");
506
507 }
508 finally
509 {
510 store.close();
511 }
512 }

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