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 }