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 }