BioLib  3.6.2
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 void ReConnect ()
 
static BioImage GetImage (string filename, long dataset)
 
static BioImage GetImage (long id)
 
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 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 IMetadataPrx meta
 
static BrowseFacility browsefacil
 
static MetadataFacility metafacil
 
static SecurityContext sc
 
static Omero::omero.api.RawPixelsStorePrx store
 
static java.util.Collection datasets
 
static java.util.Collection folders
 
static java.util.Collection images
 

Detailed Description

Definition at line 27 of file OMERO.cs.

Member Function Documentation

◆ Connect() [1/2]

static void BioLib.OMERO.Connect ( )
static

Definition at line 64 of file OMERO.cs.

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

◆ Connect() [2/2]

static void BioLib.OMERO.Connect ( string host,
int port,
string username,
string password )
static

Definition at line 46 of file OMERO.cs.

47 {
48 OMERO.host = host;
49 OMERO.port = port;
50 OMERO.username = username;
51 OMERO.password = password;
52 client = new client(host, port);
53 session = client.createSession(username, password);
54 // Initialize OMERO client and gateway
55 gateway = new Gateway(new SimpleLogger());
56 LoginCredentials credentials = new LoginCredentials();
57 credentials.getServer().setHostname(host);
58 credentials.getServer().setPort(port);
59 credentials.getUser().setUsername(username);
60 credentials.getUser().setPassword(password);
61 experimenter = gateway.connect(credentials);
62 Init();
63 }

◆ GetAllFiles()

static List< string > BioLib.OMERO.GetAllFiles ( )
static

Definition at line 450 of file OMERO.cs.

451 {
452 ReConnect();
453 var meta = session.getMetadataService();
454 var uims = browsefacil.getUserImages(sc);
455 List<string> files = new List<string>();
456 var itr = uims.iterator();
457 while (itr.hasNext())
458 {
459 ImageData da = (ImageData)itr.next();
460 files.Add(da.getName());
461 }
462 return files;
463 }

◆ GetDatasetFiles() [1/2]

static List< string > BioLib.OMERO.GetDatasetFiles ( long dbid)
static

Definition at line 527 of file OMERO.cs.

528 {
529 ReConnect();
530 var d = browsefacil.getDatasets(sc);
531 var itr = d.iterator();
532 while (itr.hasNext())
533 {
534 DatasetData idr = (DatasetData)itr.next();
535 if (dbid == idr.getId())
536 {
537 java.util.ArrayList ar = new java.util.ArrayList();
538 ar.add(java.lang.Long.valueOf(idr.getId()));
539 var imgs = browsefacil.getImagesForDatasets(sc,ar);
540 var itr2 = imgs.iterator();
541 List<string> str = new List<string>();
542 while (itr2.hasNext())
543 {
544 ImageData imageData = (ImageData)itr2.next();
545 str.Add(imageData.getName());
546 }
547 return str;
548 }
549 }
550 return null;
551 }

◆ GetDatasetFiles() [2/2]

static List< string > BioLib.OMERO.GetDatasetFiles ( string db)
static

Definition at line 502 of file OMERO.cs.

503 {
504 ReConnect();
505 var d = browsefacil.getDatasets(sc);
506 var itr = d.iterator();
507 while (itr.hasNext())
508 {
509 DatasetData idr = (DatasetData)itr.next();
510 if(idr.getName() == db)
511 {
512 java.util.ArrayList ar = new java.util.ArrayList();
513 ar.add(java.lang.Long.valueOf(idr.getId()));
514 var ims = browsefacil.getImagesForDatasets(sc,ar);
515 var itr2 = ims.iterator();
516 List<string> fs = new List<string>();
517 while (itr2.hasNext())
518 {
519 var im = (ImageData)itr2.next();
520 fs.Add(im.getName());
521 }
522 return fs;
523 }
524 }
525 return null;
526 }

◆ GetDatasetIds()

static List< long > BioLib.OMERO.GetDatasetIds ( long dbid)
static

Definition at line 552 of file OMERO.cs.

553 {
554 ReConnect();
555 var d = browsefacil.getDatasets(sc);
556 var itr = d.iterator();
557 while (itr.hasNext())
558 {
559 DatasetData idr = (DatasetData)itr.next();
560 if (dbid == idr.getId())
561 {
562 java.util.ArrayList ar = new java.util.ArrayList();
563 ar.add(java.lang.Long.valueOf(idr.getId()));
564 var imgs = browsefacil.getImagesForDatasets(sc, ar);
565 var itr2 = imgs.iterator();
566 List<long> str = new List<long>();
567 while (itr2.hasNext())
568 {
569 ImageData imageData = (ImageData)itr2.next();
570 str.Add(imageData.getId());
571 }
572 return str;
573 }
574 }
575 return null;
576 }

◆ GetDatasets()

static List< string > BioLib.OMERO.GetDatasets ( )
static

Definition at line 464 of file OMERO.cs.

465 {
466 ReConnect();
467 var d = browsefacil.getDatasets(sc);
468 var itr = d.iterator();
469 List<string> dbs = new List<string>();
470 while (itr.hasNext())
471 {
472 DatasetData dd = (DatasetData)itr.next();
473 dbs.Add(dd.getName());
474 }
475 return dbs;
476 }

◆ GetDatasetsData()

static List< DatasetData > BioLib.OMERO.GetDatasetsData ( )
static

Definition at line 477 of file OMERO.cs.

478 {
479 ReConnect();
480 var d = browsefacil.getDatasets(sc);
481 var itr = d.iterator();
482 List<DatasetData> dbs = new List<DatasetData>();
483 while (itr.hasNext())
484 {
485 DatasetData dd = (DatasetData)itr.next();
486 dbs.Add(dd);
487 }
488 return dbs;
489 }

◆ GetFolders()

static List< string > BioLib.OMERO.GetFolders ( )
static

Definition at line 490 of file OMERO.cs.

491 {
492 ReConnect();
493 var d = browsefacil.getFolders(sc);
494 var itr = d.iterator();
495 List<string> dbs = new List<string>();
496 while (itr.hasNext())
497 {
498 dbs.Add((string)itr.next());
499 }
500 return dbs;
501 }

◆ GetImage() [1/2]

static BioImage BioLib.OMERO.GetImage ( long id)
static

Definition at line 347 of file OMERO.cs.

348 {
349 string n = browsefacil.getImage(sc, id).getName();
350 return GetImage(n,id);
351 }

◆ GetImage() [2/2]

static BioImage BioLib.OMERO.GetImage ( string filename,
long dataset )
static

Definition at line 107 of file OMERO.cs.

108 {
109 ReConnect();
110 try
111 {
112 BioImage b = new BioImage("test.ome.tif");
113 java.util.Collection col = new java.util.ArrayList();
114 col.add(java.lang.Long.valueOf(dataset));
115 var uims = browsefacil.getImagesForDatasets(sc, col);
116 var itr = uims.iterator();
117 java.util.List li = new java.util.ArrayList();
118 java.util.ArrayList imgs = new java.util.ArrayList();
119 do
120 {
121 java.util.ArrayList list = new java.util.ArrayList();
122 ImageData o = (ImageData)itr.next();
123 string name = o.getName();
124 if (name != filename)
125 continue;
126 PixelsData pd = o.getDefaultPixels();
127 int xs = pd.getSizeX();
128 int ys = pd.getSizeY();
129 int zs = pd.getSizeZ();
130 int cs = pd.getSizeC();
131 int ts = pd.getSizeT();
132 long pid = o.getId();
133
134 b.Filename = name;
135 b.ID = name;
136 RawPixelsStorePrx store = gateway.getPixelsStore(sc);
137 long ind = o.getId();
138 long ll = pd.getId();
139 list.add(java.lang.Long.valueOf(ind));
140 try
141 {
142 var acq = metafacil.getChannelData(sc, ind);
143 int s = acq.size();
144 for (int i = 0; i < s; i++)
145 {
146 var ch = (ChannelData)acq.get(i);
147 var ac = metafacil.getImageAcquisitionData(sc, ind);
148 var chan = ch.asChannel();
149 AForge.Color color = AForge.Color.FromArgb(chan.getRed().getValue(), chan.getGreen().getValue(), chan.getBlue().getValue());
150 var px = pd.asPixels().getPixelsType();
151 int bits = px.getBitSize().getValue();
152 AForge.PixelFormat pxx = GetPixelFormat(bits);
153 AForge.Channel cch = null;
154 if (pxx == AForge.PixelFormat.Format8bppIndexed || pxx == AForge.PixelFormat.Format16bppGrayScale)
155 cch = new AForge.Channel(i, bits, 1);
156 else if (pxx == AForge.PixelFormat.Format24bppRgb || pxx == AForge.PixelFormat.Format48bppRgb)
157 cch = new AForge.Channel(i, bits, 3);
158 else if (pxx == AForge.PixelFormat.Format32bppArgb)
159 cch = new AForge.Channel(i, bits, 4);
160 cch.Fluor = ch.getFluor();
161 var em = ch.getEmissionWavelength(Omero::omero.model.enums.UnitsLength.NANOMETER);
162 if (em != null)
163 cch.Emission = (int)em.getValue();
164 cch.Color = color;
165 cch.Name = ch.getName();
166 if (cch.Name == null)
167 cch.Name = i.ToString();
168 b.Channels.Add(cch);
169 }
170 }
171 catch (Exception exx)
172 {
173 Console.WriteLine(exx.Message);
174 }
175 var stage = o.asImage().getStageLabel();
176
177 try
178 {
179 int i = 0;
180 while(true)
181 {
182 Omero.omero.RInt rint = rtypes.rint(i);
183 Image im = o.asImage();
184 im.setSeries(rint);
185 RInt rin = im.getSeries();
186 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
187 Pixels pxs = im.getPixels(0);
188 store.setPixelsId(pxs.getId().getValue(),true);
189 if(!store.requiresPixelsPyramid())
190 {
191 var pxto = pxs.getPixelsType();
192 int bitso = pxto.getBitSize().getValue();
193 int wo = pxs.getSizeX().getValue();
194 int ho = pxs.getSizeY().getValue();
195 px = GetPixelFormat(bitso);
196 double pxxo = pxs.getPhysicalSizeX().getValue();
197 double pyyo = pxs.getPhysicalSizeY().getValue();
198 double pzzo = 0;
199 var pzo = pxs.getPhysicalSizeZ();
200 if (pzo != null)
201 pzzo = pzo.getValue();
202 if (stage != null)
203 {
204 var sta = (StageLabel)session.getQueryService().get("StageLabel", o.asImage().getStageLabel().getId().getValue());
205 Length? sxxo = sta.getPositionX();
206 Length? syyo = sta.getPositionY();
207 Length? szzo = sta.getPositionZ();
208 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo * wo, pyyo * ho, pzzo, sxxo.getValue(), syyo.getValue(), szzo.getValue()));
209 }
210 else
211 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo * wo, pyyo * ho, pzzo, 0, 0, 0));
212 break;
213 }
214 else
215 {
216 b.Type = BioImage.ImageType.pyramidal;
217 }
218 if (i == store.getResolutionLevels())
219 break;
220 var ress = store.getResolutionDescriptions();
221 var re = ress[i];
222 var pxt = pxs.getPixelsType();
223 int bits = pxt.getBitSize().getValue();
224 int w = re.sizeX;
225 int h = re.sizeY;
226 px = GetPixelFormat(bits);
227 double pxx = pxs.getPhysicalSizeX().getValue();
228 double pyy = pxs.getPhysicalSizeY().getValue();
229 double pzz = 0;
230 var pz = pxs.getPhysicalSizeZ();
231 if(pz != null)
232 pzz = pz.getValue();
233 if (stage != null)
234 {
235 var sta = (StageLabel)session.getQueryService().get("StageLabel", o.asImage().getStageLabel().getId().getValue());
236 Length? sxx = sta.getPositionX();
237 Length? syy = sta.getPositionY();
238 Length? szz = sta.getPositionZ();
239 b.Resolutions.Add(new Resolution(w, h, px, pxx, pyy, pzz, sxx.getValue(), syy.getValue(), szz.getValue()));
240 }
241 else
242 b.Resolutions.Add(new Resolution(w, h, px, pxx, pyy, pzz, 0, 0, 0));
243 i++;
244 }
245 }
246 catch (Exception ex)
247 {
248 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
249 var pxt = pd.asPixels().getPixelsType();
250 int bits = pxt.getBitSize().getValue();
251 px = GetPixelFormat(bits);
252 double pxx = pd.asPixels().getPhysicalSizeX().getValue();
253 double pyy = pd.asPixels().getPhysicalSizeY().getValue();
254 double pzz = 0;
255 var pz = pd.asPixels().getPhysicalSizeZ();
256 if (pz != null)
257 pzz = pz.getValue();
258 if (stage != null)
259 {
260 if (stage.isLoaded())
261 {
262 Length? sxx = stage.getPositionX();
263 Length? syy = stage.getPositionY();
264 Length? szz = stage.getPositionZ();
265 b.Resolutions.Add(new Resolution(xs, ys, px, pxx, pyy, pzz, sxx.getValue(), syy.getValue(), szz.getValue()));
266 }
267 }
268 else
269 b.Resolutions.Add(new Resolution(xs, ys, px, pxx, pyy, pzz, 0, 0, 0));
270 }
271
272 for (int z = 0; z < zs; z++)
273 {
274 for (int c = 0; c < cs; c++)
275 {
276 for (int t = 0; t < ts; t++)
277 {
278 if (b.isPyramidal)
279 {
280 Pixels ps = pd.asPixels();
281 int chc = ps.sizeOfChannels();
282 store.setPixelsId(ps.getId().getValue(), true);
283 store.setResolutionLevel(0);
284 if (xs > 1920 || ys > 1080)
285 {
286 byte[] bts = store.getTile(z, c, t, 0, 0, 1920, 1080);
287 PixelsType pxt = ps.getPixelsType();
288 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
289 int bits = pxt.getBitSize().getValue();
290 px = GetPixelFormat(bits);
291 b.Buffers.Add(new AForge.Bitmap("", 1920, 1080, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
292 }
293 else
294 {
295 byte[] bts = store.getTile(z, c, t, 0, 0, xs, ys);
296 PixelsType pxt = ps.getPixelsType();
297 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
298 int bits = pxt.getBitSize().getValue();
299 px = GetPixelFormat(bits);
300 b.Buffers.Add(new AForge.Bitmap("", xs, ys, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
301 }
302 }
303 else
304 {
305 Pixels ps = pd.asPixels();
306 int chc = ps.sizeOfChannels();
307 store.setPixelsId(ps.getId().getValue(), true);
308 byte[] bts = store.getPlane(z, c, t);
309 PixelsType pxt = ps.getPixelsType();
310 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
311 int bits = pxt.getBitSize().getValue();
312 px = GetPixelFormat(bits);
313 b.Buffers.Add(new AForge.Bitmap("", xs, ys, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
314 }
315 }
316 }
317 }
318 b.UpdateCoords(zs, cs, ts);
319 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.SizeX * b.PhysicalSizeX, b.SizeY * b.PhysicalSizeY, b.SizeZ * b.PhysicalSizeZ));
320 b.bitsPerPixel = b.Buffers[0].BitsPerPixel;
321 b.series = o.getSeries();
322 b.imagesPerSeries = b.Buffers.Count;
323 b.rgbChannels = new int[b.Channels.Count];
324 b.rgbChannels[0] = 0;
325 b.rgbChannels[1] = 1;
326 b.rgbChannels[2] = 2;
327 BioImage.AutoThreshold(b, true);
328 if (b.bitsPerPixel > 8)
329 b.StackThreshold(true);
330 else
331 b.StackThreshold(false);
332 b.Tag = "OMERO";
333 if(b.isPyramidal)
334 {
335 b.SlideBase = new SlideBase(b, SlideImage.Open(b));
336 }
337 return b;
338 }
339 while (itr.hasNext());
340 }
341 catch (Exception e)
342 {
343 Console.WriteLine(e.ToString());
344 }
345 return null;
346 }

◆ GetNameFromID()

static string BioLib.OMERO.GetNameFromID ( long id)
static

Definition at line 430 of file OMERO.cs.

431 {
432 ReConnect();
433 return browsefacil.getImage(sc, id).getName();
434 }

◆ GetThumbnails()

static Dictionary< long, Pixbuf > BioLib.OMERO.GetThumbnails ( string[] filenames,
int width,
int height )
static

Definition at line 388 of file OMERO.cs.

389 {
390 ReConnect();
391 Dictionary<long, Pixbuf> dict = new Dictionary<long, Pixbuf>();
392 try
393 {
394 var meta = session.getMetadataService();
395 ExperimenterGroupI sec = (ExperimenterGroupI)session.getSecurityContexts().get(0);
396 RLong id = sec.getId();
397 SecurityContext sc = new SecurityContext(id.getValue());
398 // Get the thumbnail service
399 ThumbnailStorePrx store = gateway.getThumbnailService(sc);
400 // Access BrowseFacility
401 BrowseFacility facility = (BrowseFacility)gateway.getFacility(brFacility);
402 var uims = facility.getUserImages(sc);
403 var itr = uims.iterator();
404 List<Pixbuf> images = new List<Pixbuf>();
405 while (itr.hasNext())
406 {
407 var img = (ImageData)itr.next();
408 string name = img.getName();
409 for (int i = 0; i < filenames.Length; i++)
410 {
411 if(name == filenames[i])
412 {
413 // Set the pixels ID for the image
414 long pixelId = img.getDefaultPixels().getId();
415 store.setPixelsId(pixelId);
416 byte[] thumbnailBytes = store.getThumbnail(Omero::omero.rtypes.rint(width), Omero::omero.rtypes.rint(height));
417 Pixbuf pf = new Pixbuf(thumbnailBytes);
418 dict.Add(img.getId(), pf);
419 }
420 }
421 }
422 return dict;
423 }
424 catch (Exception e)
425 {
426 Console.WriteLine(e.Message);
427 return null;
428 }
429 }

◆ GetTile()

static Bitmap BioLib.OMERO.GetTile ( BioImage b,
ZCT coord,
int x,
int y,
int width,
int height,
int level )
static

Definition at line 352 of file OMERO.cs.

353 {
354 ReConnect();
355 var itr = images.iterator();
356 java.util.List li = new java.util.ArrayList();
357 java.util.ArrayList imgs = new java.util.ArrayList();
358 do
359 {
360 java.util.ArrayList list = new java.util.ArrayList();
361 ImageData o = (ImageData)itr.next();
362 string name = o.getName();
363 if (name != b.Filename)
364 continue;
365 PixelsData pd = o.getDefaultPixels();
366 int zs = pd.getSizeZ();
367 int cs = pd.getSizeC();
368 int ts = pd.getSizeT();
369 long pid = o.getId();
370 b.Filename = name;
371 b.ID = name;
372 long ind = o.getId();
373 long ll = pd.getId();
374 list.add(java.lang.Long.valueOf(ind));
375 Pixels ps = pd.asPixels();
376 int chc = ps.sizeOfChannels();
377 store.setPixelsId(ps.getId().getValue(), true);
378 store.setResolutionLevel(level);
379 byte[] bts = store.getTile(coord.Z, coord.C, coord.T, x, y, width, height);
380 PixelsType pxt = ps.getPixelsType();
381 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
382 int bits = pxt.getBitSize().getValue();
383 px = GetPixelFormat(bits);
384 return new AForge.Bitmap("", width, height, px, bts, coord, 0, null, false);
385 } while (itr.hasNext());
386 return null;
387 }

◆ ReConnect()

static void BioLib.OMERO.ReConnect ( )
static

Definition at line 91 of file OMERO.cs.

92 {
93 if (!gateway.isConnected())
94 {
95 client = new client(host, port);
96 session = client.createSession(username, password);
97 // Initialize OMERO client and gateway
98 gateway = new Gateway(new SimpleLogger());
99 LoginCredentials credentials = new LoginCredentials();
100 credentials.getServer().setHostname(host);
101 credentials.getServer().setPort(port);
102 credentials.getUser().setUsername(username);
103 credentials.getUser().setPassword(password);
104 experimenter = gateway.connect(credentials);
105 }
106 }

Member Data Documentation

◆ browsefacil

BrowseFacility BioLib.OMERO.browsefacil
static

Definition at line 37 of file OMERO.cs.

◆ client

client BioLib.OMERO.client
static

Definition at line 32 of file OMERO.cs.

◆ datasets

java.util.Collection BioLib.OMERO.datasets
static

Definition at line 41 of file OMERO.cs.

◆ experimenter

ExperimenterData BioLib.OMERO.experimenter
static

Definition at line 35 of file OMERO.cs.

◆ folders

java.util.Collection BioLib.OMERO.folders
static

Definition at line 42 of file OMERO.cs.

◆ gateway

Gateway BioLib.OMERO.gateway
static

Definition at line 34 of file OMERO.cs.

◆ host

string BioLib.OMERO.host
static

Definition at line 29 of file OMERO.cs.

◆ images

java.util.Collection BioLib.OMERO.images
static

Definition at line 43 of file OMERO.cs.

◆ meta

IMetadataPrx BioLib.OMERO.meta
static

Definition at line 36 of file OMERO.cs.

◆ metafacil

MetadataFacility BioLib.OMERO.metafacil
static

Definition at line 38 of file OMERO.cs.

◆ password

string BioLib.OMERO.password
static

Definition at line 30 of file OMERO.cs.

◆ port

int BioLib.OMERO.port
static

Definition at line 31 of file OMERO.cs.

◆ sc

SecurityContext BioLib.OMERO.sc
static

Definition at line 39 of file OMERO.cs.

◆ session

ServiceFactoryPrx BioLib.OMERO.session
static

Definition at line 33 of file OMERO.cs.

◆ store

Omero.omero.api.RawPixelsStorePrx BioLib.OMERO.store
static

Definition at line 40 of file OMERO.cs.

◆ username

string BioLib.OMERO.username
static

Definition at line 29 of file OMERO.cs.


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