BioLib  3.7.0
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 Bitmap GetFullPlane (BioImage b, ZCT coord, int level, int tileSize=1024)
 
static 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
 

Member Function Documentation

◆ 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
915 {
916 ReConnect();
917 var meta = session.getMetadataService();
918 var uims = browsefacil.getUserImages(sc);
919 List<string> files = new List<string>();
920 var itr = uims.iterator();
921 while (itr.hasNext())
922 {
923 ImageData da = (ImageData)itr.next();
924 files.Add(da.getName());
925 }
926 return files;
927 }

◆ GetDataset() [1/2]

static DatasetData BioLib.OMERO.GetDataset ( string name)
static
955 {
956 ReConnect();
957 var d = browsefacil.getDatasets(sc);
958 var itr = d.iterator();
959 while (itr.hasNext())
960 {
961 DatasetData dd = (DatasetData)itr.next();
962 if (dd.getName() == name)
963 return dd;
964 }
965 return null;
966 }

◆ GetDataset() [2/2]

static DatasetData BioLib.OMERO.GetDataset ( string name,
long id )
static
968 {
969 ReConnect();
970 var d = browsefacil.getDatasets(sc);
971 var itr = d.iterator();
972 while (itr.hasNext())
973 {
974 DatasetData dd = (DatasetData)itr.next();
975 if (dd.getName() == name && id == dd.getId())
976 return dd;
977 }
978 return null;
979 }

◆ GetDatasetFiles() [1/2]

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

◆ GetDatasetFiles() [2/2]

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

◆ GetDatasetIds()

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

◆ GetDatasets()

static List< string > BioLib.OMERO.GetDatasets ( )
static
929 {
930 ReConnect();
931 var d = browsefacil.getDatasets(sc);
932 var itr = d.iterator();
933 List<string> dbs = new List<string>();
934 while (itr.hasNext())
935 {
936 DatasetData dd = (DatasetData)itr.next();
937 dbs.Add(dd.getName());
938 }
939 return dbs;
940 }

◆ GetDatasetsData()

static List< DatasetData > BioLib.OMERO.GetDatasetsData ( )
static
942 {
943 ReConnect();
944 var d = browsefacil.getDatasets(sc);
945 var itr = d.iterator();
946 List<DatasetData> dbs = new List<DatasetData>();
947 while (itr.hasNext())
948 {
949 DatasetData dd = (DatasetData)itr.next();
950 dbs.Add(dd);
951 }
952 return dbs;
953 }

◆ GetFolders()

static List< string > BioLib.OMERO.GetFolders ( )
static
981 {
982 ReConnect();
983 var d = browsefacil.getFolders(sc);
984 var itr = d.iterator();
985 List<string> dbs = new List<string>();
986 while (itr.hasNext())
987 {
988 dbs.Add((string)itr.next());
989 }
990 return dbs;
991 }

◆ 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
747 {
748 string n = browsefacil.getImage(sc, id).getName();
749 return GetImage(n,id);
750 }

◆ GetImage() [2/2]

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

◆ 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
895 {
896 ReConnect();
897 return browsefacil.getImage(sc, id).getName();
898 }

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

◆ GetTile()

static Bitmap BioLib.OMERO.GetTile ( BioImage b,
ZCT coord,
int x,
int y,
int width,
int height,
int level )
static
810 {
811 ReConnect();
812 if (width >= b.SizeX || height >= b.SizeY)
813 return GetFullPlane(b, coord, level);
814 var itr = images.iterator();
815 java.util.List li = new java.util.ArrayList();
816 java.util.ArrayList imgs = new java.util.ArrayList();
817 do
818 {
819 java.util.ArrayList list = new java.util.ArrayList();
820 ImageData o = (ImageData)itr.next();
821 string name = o.getName();
822 if (name != 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 pid = o.getId();
829 b.Filename = name;
830 b.ID = name;
831 long ind = o.getId();
832 long ll = pd.getId();
833 list.add(java.lang.Long.valueOf(ind));
834 Pixels ps = pd.asPixels();
835 int chc = ps.sizeOfChannels();
836 store.setPixelsId(ps.getId().getValue(), true);
837 store.setResolutionLevel(level);
838
839 if (width == pd.getSizeX() || height == pd.getSizeY())
840 {
841
842 }
843 byte[] bts = store.getTile(coord.Z, coord.C, coord.T, x, y, width, height);
844 PixelsType pxt = ps.getPixelsType();
845 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
846 int bits = pxt.getBitSize().getValue();
847 px = GetPixelFormat(bits);
848 return new AForge.Bitmap("", width, height, px, bts, coord, 0, null, false);
849 } while (itr.hasNext());
850 return null;
851 }

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