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 }