BioLib  3.9.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 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
735 {
736 int length = r.Length;
737 byte[] result = new byte[length * 4];
738
739 System.Threading.Tasks.Parallel.For(0, length, i =>
740 {
741 int idx = i * 4;
742 result[idx + 3] = b[i];
743 result[idx + 2] = g[i];
744 result[idx + 1] = r[i];
745 result[idx] = 255;
746 });
747
748 return result;
749 }

◆ Connect() [1/2]

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

◆ Connect() [2/2]

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

◆ GetAllFiles()

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

◆ GetDataset() [1/2]

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

◆ GetDataset() [2/2]

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

◆ GetDatasetFiles() [1/2]

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

◆ GetDatasetFiles() [2/2]

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

◆ GetDatasetIds()

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

◆ GetDatasets()

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

◆ GetDatasetsData()

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

◆ GetFolders()

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

◆ GetFullPlane()

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

◆ GetID()

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

◆ GetImage() [1/2]

static BioImage BioLib.OMERO.GetImage ( long id)
static
730 {
731 string n = browsefacil.getImage(sc, id).getName();
732 return GetImage(n,id);
733 }

◆ GetImage() [2/2]

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

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

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

◆ GetNameFromID()

static string BioLib.OMERO.GetNameFromID ( long id)
static
889 {
890 ReConnect();
891 return browsefacil.getImage(sc, id).getName();
892 }

◆ GetOMEROImage()

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

◆ GetPoints()

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

◆ GetROIs()

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

◆ GetStageLabel()

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

◆ GetThumbnails()

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

◆ GetTile()

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

◆ ReConnect()

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

◆ Upload()

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

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