The function "OpenOME" opens a bioimage file, with options to specify the series, whether to display it in a tab, whether to add it to existing images, whether to tile the image, and the tile size.
The function "OpenOME" opens a bioimage file, with options to specify the series, whether to
6471 {
6472 if (file == null || file == "")
6473 throw new InvalidDataException("File is empty or null");
6474
6475 do
6476 {
6477 Thread.Sleep(10);
6478 } while (!initialized);
6479 Console.WriteLine("OpenOME " + file);
6480 reader = new ImageReader();
6481 if (tileSizeX == 0)
6482 tileSizeX = 1920;
6483 if (tileSizeY == 0)
6484 tileSizeY = 1080;
6485 progFile = file;
6488 b.Loading = true;
6489 if (b.meta == null)
6490 b.meta = service.createOMEXMLMetadata();
6491 string f = file.Replace("\\", "/");
6492 string cf = reader.getCurrentFile();
6493 if (cf != null)
6494 cf = cf.Replace("\\", "/");
6495 if (cf != f)
6496 {
6497 reader.close();
6498 reader.setMetadataStore(b.meta);
6499 try
6500 {
6501 Status = "Opening file " + b.Filename;
6502 reader.setId(f);
6503 }
6504 catch (Exception e)
6505 {
6506 Console.WriteLine(e.Message);
6507 return null;
6508 }
6509 }
6510
6511
6512 reader.setSeries(serie);
6513 int RGBChannelCount = reader.getRGBChannelCount();
6514
6515
6516 PixelFormat PixelFormat;
6517 try
6518 {
6519 PixelFormat =
GetPixelFormat(RGBChannelCount, b.meta.getPixelsType(serie));
6520 }
6521 catch (Exception)
6522 {
6523 PixelFormat =
GetPixelFormat(RGBChannelCount, reader.getBitsPerPixel());
6524 }
6525
6526 b.id = file;
6527 b.file = file;
6528 int SizeX, SizeY;
6529 SizeX = reader.getSizeX();
6530 SizeY = reader.getSizeY();
6531 int SizeZ = reader.getSizeZ();
6532 b.sizeC = reader.getSizeC();
6533 b.sizeZ = reader.getSizeZ();
6534 b.sizeT = reader.getSizeT();
6535 b.littleEndian = reader.isLittleEndian();
6536 b.seriesCount = reader.getSeriesCount();
6537 b.imagesPerSeries = reader.getImageCount();
6538 b.imRead = reader;
6539 List<Resolution> ress = new List<Resolution>();
6540 if (PixelFormat == PixelFormat.Format8bppIndexed || PixelFormat == PixelFormat.Format24bppRgb || PixelFormat == PixelFormat.Format32bppArgb)
6541 b.bitsPerPixel = 8;
6542 else
6543 b.bitsPerPixel = 16;
6544 b.series = serie;
6545 string order = reader.getDimensionOrder();
6546 if (vips && tile)
6548
6549 int i = 0;
6550 int sumSamples = 0;
6551 while (true)
6552 {
6553 Status = "Reading channels.";
6554 bool def = false;
6555 try
6556 {
6557 int s = b.meta.getChannelSamplesPerPixel(serie, i).getNumberValue().intValue();
6558 Channel ch = new Channel(i, b.bitsPerPixel, s);
6559 if (b.meta.getChannelSamplesPerPixel(serie, i) != null)
6560 {
6561 ch.SamplesPerPixel = s;
6562 sumSamples += s;
6563 def = true;
6564 b.Channels.Add(ch);
6565 }
6566 if (i == 0)
6567 {
6568 b.rgbChannels[0] = 0;
6569 }
6570 else
6571 if (i == 1)
6572 {
6573 b.rgbChannels[1] = 1;
6574 }
6575 else
6576 if (i == 2)
6577 {
6578 b.rgbChannels[2] = 2;
6579 }
6580
6581 if (!def)
6582 break;
6583 if (b.meta.getChannelName(serie, i) != null)
6584 ch.Name = b.meta.getChannelName(serie, i);
6585 if (b.meta.getChannelAcquisitionMode(serie, i) != null)
6586 ch.AcquisitionMode = b.meta.getChannelAcquisitionMode(serie, i).ToString();
6587 if (b.meta.getChannelID(serie, i) != null)
6588 ch.info.ID = b.meta.getChannelID(serie, i);
6589 if (b.meta.getChannelFluor(serie, i) != null)
6590 ch.Fluor = b.meta.getChannelFluor(serie, i);
6591 if (b.meta.getChannelColor(serie, i) != null)
6592 {
6593 ome.xml.model.primitives.Color cc = b.meta.getChannelColor(serie, i);
6594 ch.Color = Color.FromArgb(cc.getRed(), cc.getGreen(), cc.getBlue());
6595 }
6596 if (b.meta.getChannelIlluminationType(serie, i) != null)
6597 ch.IlluminationType = b.meta.getChannelIlluminationType(serie, i).ToString();
6598 if (b.meta.getChannelContrastMethod(serie, i) != null)
6599 ch.ContrastMethod = b.meta.getChannelContrastMethod(serie, i).ToString();
6600 if (b.meta.getChannelEmissionWavelength(serie, i) != null)
6601 ch.Emission = b.meta.getChannelEmissionWavelength(serie, i).value().intValue();
6602 if (b.meta.getChannelExcitationWavelength(serie, i) != null)
6603 ch.Excitation = b.meta.getChannelExcitationWavelength(serie, i).value().intValue();
6604 if (b.meta.getLightEmittingDiodePower(serie, i) != null)
6605 ch.LightSourceIntensity = b.meta.getLightEmittingDiodePower(serie, i).value().doubleValue();
6606 if (b.meta.getLightEmittingDiodeID(serie, i) != null)
6607 ch.DiodeName = b.meta.getLightEmittingDiodeID(serie, i);
6608 if (b.meta.getChannelLightSourceSettingsAttenuation(serie, i) != null)
6609 ch.LightSourceAttenuation = b.meta.getChannelLightSourceSettingsAttenuation(serie, i).toString();
6610
6611
6612 }
6613 catch (Exception e)
6614 {
6615 Console.WriteLine(e.Message);
6616 if (!def)
6617 break;
6618 }
6619 i++;
6620 }
6621 try
6622 {
6623 if (b.meta.getObjectiveNominalMagnification(serie, 0) != null)
6624 {
6625 b.Magnification = b.meta.getObjectiveNominalMagnification(serie, 0).intValue();
6626 }
6627 }
6628 catch (Exception e)
6629 {
6630 Console.WriteLine(e.Message);
6631 }
6632
6633
6634 if (b.Channels.Count == 0)
6635 {
6636 b.Channels.Add(new Channel(0, b.bitsPerPixel, RGBChannelCount));
6637 }
6638 try
6639 {
6640 Status = "Reading wells.";
6641 int wells = b.meta.getWellCount(0);
6642 if (wells > 0)
6643 {
6645 b.Plate = new WellPlate(b);
6646 tile = false;
6647 }
6648 }
6649 catch (Exception e)
6650 {
6651
6652 Console.WriteLine(e.Message);
6653 }
6654 if (reader.getResolutionCount() > 0)
6655 ress.AddRange(GetResolutions(b));
6656 Console.WriteLine("Done reading resolutions.");
6657 reader.setSeries(serie);
6658
6659 int pyramidCount = 0;
6660 int pyramidResolutions = 0;
6661 List<Tuple<int, int>> prs = new List<Tuple<int, int>>();
6662 Console.WriteLine("Determining pyramidal levels.");
6663
6664
6665 if (ress.Count > 1 && b.Type !=
ImageType.well)
6666 {
6667 if (ress[0].SizeX > ress[1].SizeX)
6668 {
6670 tile = true;
6671
6672 int? sr = null;
6673 for (int r = 0; r < ress.Count - 1; r++)
6674 {
6675 if (ress[r].SizeX > ress[r + 1].SizeX && ress[r].PixelFormat == ress[r + 1].PixelFormat)
6676 {
6677 if (sr == null)
6678 {
6679 sr = r;
6680 prs.Add(new Tuple<int, int>(r, 0));
6681 }
6682 }
6683 else
6684 {
6685 if (ress[prs[prs.Count - 1].Item1].PixelFormat == ress[r].PixelFormat)
6686 prs[prs.Count - 1] = new Tuple<int, int>(prs[prs.Count - 1].Item1, r);
6687 sr = null;
6688 }
6689 }
6690 pyramidCount = prs.Count;
6691 for (int p = 0; p < prs.Count; p++)
6692 {
6693 pyramidResolutions += (prs[p].Item2 - prs[p].Item1) + 1;
6694 }
6695 if (prs[serie].Item2 == 0)
6696 {
6697 prs[serie] = new Tuple<int, int>(prs[serie].Item1, b.seriesCount - 1);
6698 }
6699 }
6700 }
6702 {
6703 Console.WriteLine("Determining Label and Macro resolutions.");
6704 for (int p = 0; p < prs.Count; p++)
6705 {
6706 for (int r = prs[p].Item1; r < prs[p].Item2 + 1; r++)
6707 {
6708 b.Resolutions.Add(ress[r]);
6709 }
6710 }
6711
6712 if (ress.Count > b.Resolutions.Count)
6713 {
6714 b.LabelResolution = ress.Count - 1;
6715 b.Resolutions.Add(ress[ress.Count - 1]);
6716 b.MacroResolution = ress.Count - 2;
6717 b.Resolutions.Add(ress[ress.Count - 2]);
6718 }
6719 }
6720 if (b.Resolutions.Count == 0)
6721 b.Resolutions.AddRange(ress);
6722 try
6723 {
6724 string s = b.meta.getStageLabelName(serie);
6725 if (s != null)
6726 {
6727 Resolution res =
new Resolution(b.SizeX, b.SizeY, PixelFormat, b.PhysicalSizeX, b.PhysicalSizeY, b.PhysicalSizeZ,
6728 b.meta.getStageLabelX(serie).value().doubleValue(),
6729 b.meta.getStageLabelY(serie).value().doubleValue(),
6730 b.meta.getStageLabelZ(serie).value().doubleValue());
6731 }
6732 }
6733 catch (Exception e)
6734 {
6735 Console.WriteLine("No Stage Cooordinates");
6736 }
6737
6738 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.PhysicalSizeX * SizeX, b.PhysicalSizeY * SizeY, b.PhysicalSizeZ * SizeZ));
6739 int rc = b.meta.getROICount();
6740 for (int im = 0; im < rc; im++)
6741 {
6742 string roiID = b.meta.getROIID(im);
6743 string roiName = b.meta.getROIName(im);
6744 ZCT co = new ZCT(0, 0, 0);
6745 int scount = 1;
6746 try
6747 {
6748 scount = b.meta.getShapeCount(im);
6749 }
6750 catch (Exception e)
6751 {
6752 Console.WriteLine(e.Message.ToString());
6753 }
6754 for (int sc = 0; sc < scount; sc++)
6755 {
6756 Status =
"Reading ROI " + (sc + 1).
ToString() +
"/" + scount;
6757 string typ = b.meta.getShapeType(im, sc);
6759 an.roiID = roiID;
6760 an.roiName = roiName;
6761 an.shapeIndex = sc;
6762 if (typ == "Point")
6763 {
6764 an.type =
ROI.Type.Point;
6765 an.id = b.meta.getPointID(im, sc);
6766 double dx = b.meta.getPointX(im, sc).doubleValue();
6767 double dy = b.meta.getPointY(im, sc).doubleValue();
6769 an.coord = new ZCT();
6770 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPointTheZ(im, sc);
6771 if (nz != null)
6772 an.coord.Z = nz.getNumberValue().intValue();
6773 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPointTheC(im, sc);
6774 if (nc != null)
6775 an.coord.C = nc.getNumberValue().intValue();
6776 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPointTheT(im, sc);
6777 if (nt != null)
6778 an.coord.T = nt.getNumberValue().intValue();
6779 an.Text = b.meta.getPointText(im, sc);
6780 ome.units.quantity.Length fl = b.meta.getPointFontSize(im, sc);
6781 if (fl != null)
6782 an.fontSize = fl.value().intValue();
6783 ome.xml.model.enums.FontFamily ff = b.meta.getPointFontFamily(im, sc);
6784 if (ff != null)
6785 an.family = ff.name();
6786 ome.xml.model.primitives.Color col = b.meta.getPointStrokeColor(im, sc);
6787 if (col != null)
6788 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6789 ome.units.quantity.Length fw = b.meta.getPointStrokeWidth(im, sc);
6790 if (fw != null)
6791 an.strokeWidth = (float)fw.value().floatValue();
6792 ome.xml.model.primitives.Color colf = b.meta.getPointStrokeColor(im, sc);
6793 if (colf != null)
6794 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6795 }
6796 else
6797 if (typ == "Line")
6798 {
6799 an.type =
ROI.Type.Line;
6800 an.id = b.meta.getLineID(im, sc);
6801 double px1 = b.meta.getLineX1(im, sc).doubleValue();
6802 double py1 = b.meta.getLineY1(im, sc).doubleValue();
6803 double px2 = b.meta.getLineX2(im, sc).doubleValue();
6804 double py2 = b.meta.getLineY2(im, sc).doubleValue();
6805 List<PointD> pds = new List<PointD>();
6808 an.Points = pds;
6810 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLineTheZ(im, sc);
6811 if (nz != null)
6812 co.Z = nz.getNumberValue().intValue();
6813 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLineTheC(im, sc);
6814 if (nc != null)
6815 co.C = nc.getNumberValue().intValue();
6816 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLineTheT(im, sc);
6817 if (nt != null)
6818 co.T = nt.getNumberValue().intValue();
6819 an.coord = co;
6820 an.Text = b.meta.getLineText(im, sc);
6821 ome.units.quantity.Length fl = b.meta.getLineFontSize(im, sc);
6822 if (fl != null)
6823 an.fontSize = fl.value().intValue();
6824 ome.xml.model.enums.FontFamily ff = b.meta.getLineFontFamily(im, sc);
6825 if (ff != null)
6826 an.family = ff.name();
6827 ome.xml.model.primitives.Color col = b.meta.getLineStrokeColor(im, sc);
6828 if (col != null)
6829 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6830 ome.units.quantity.Length fw = b.meta.getLineStrokeWidth(im, sc);
6831 if (fw != null)
6832 an.strokeWidth = (float)fw.value().floatValue();
6833 ome.xml.model.primitives.Color colf = b.meta.getLineFillColor(im, sc);
6834 if (colf != null)
6835 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6836 }
6837 else
6838 if (typ == "Rectangle")
6839 {
6840 an.type =
ROI.Type.Rectangle;
6841 an.id = b.meta.getRectangleID(im, sc);
6842 double px = b.meta.getRectangleX(im, sc).doubleValue();
6843 double py = b.meta.getRectangleY(im, sc).doubleValue();
6844 double pw = b.meta.getRectangleWidth(im, sc).doubleValue();
6845 double ph = b.meta.getRectangleHeight(im, sc).doubleValue();
6846 an.BoundingBox = b.
ToStageSpace(
new RectangleD(px, py, pw, ph));
6847 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getRectangleTheZ(im, sc);
6848 if (nz != null)
6849 co.Z = nz.getNumberValue().intValue();
6850 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getRectangleTheC(im, sc);
6851 if (nc != null)
6852 co.C = nc.getNumberValue().intValue();
6853 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getRectangleTheT(im, sc);
6854 if (nt != null)
6855 co.T = nt.getNumberValue().intValue();
6856 an.coord = co;
6857
6858 an.Text = b.meta.getRectangleText(im, sc);
6859 ome.units.quantity.Length fl = b.meta.getRectangleFontSize(im, sc);
6860 if (fl != null)
6861 an.fontSize = fl.value().intValue();
6862 ome.xml.model.enums.FontFamily ff = b.meta.getRectangleFontFamily(im, sc);
6863 if (ff != null)
6864 an.family = ff.name();
6865 ome.xml.model.primitives.Color col = b.meta.getRectangleStrokeColor(im, sc);
6866 if (col != null)
6867 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6868 ome.units.quantity.Length fw = b.meta.getRectangleStrokeWidth(im, sc);
6869 if (fw != null)
6870 an.strokeWidth = (float)fw.value().floatValue();
6871 ome.xml.model.primitives.Color colf = b.meta.getRectangleFillColor(im, sc);
6872 if (colf != null)
6873 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6874 ome.xml.model.enums.FillRule fr = b.meta.getRectangleFillRule(im, sc);
6875
6876 }
6877 else
6878 if (typ == "Ellipse")
6879 {
6880 an.type =
ROI.Type.Ellipse;
6881 an.id = b.meta.getEllipseID(im, sc);
6882 double px = b.meta.getEllipseX(im, sc).doubleValue();
6883 double py = b.meta.getEllipseY(im, sc).doubleValue();
6884 double ew = b.meta.getEllipseRadiusX(im, sc).doubleValue();
6885 double eh = b.meta.getEllipseRadiusY(im, sc).doubleValue();
6886
6887 double w = ew * 2;
6888 double h = eh * 2;
6889 double x = px - ew;
6890 double y = py - eh;
6891 an.BoundingBox = b.
ToStageSpace(
new RectangleD(x, y, w, h));
6892 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getEllipseTheZ(im, sc);
6893 if (nz != null)
6894 co.Z = nz.getNumberValue().intValue();
6895 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getEllipseTheC(im, sc);
6896 if (nc != null)
6897 co.C = nc.getNumberValue().intValue();
6898 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getEllipseTheT(im, sc);
6899 if (nt != null)
6900 co.T = nt.getNumberValue().intValue();
6901 an.coord = co;
6902 an.Text = b.meta.getEllipseText(im, sc);
6903 ome.units.quantity.Length fl = b.meta.getEllipseFontSize(im, sc);
6904 if (fl != null)
6905 an.fontSize = fl.value().intValue();
6906 ome.xml.model.enums.FontFamily ff = b.meta.getEllipseFontFamily(im, sc);
6907 if (ff != null)
6908 an.family = ff.name();
6909 ome.xml.model.primitives.Color col = b.meta.getEllipseStrokeColor(im, sc);
6910 if (col != null)
6911 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6912 ome.units.quantity.Length fw = b.meta.getEllipseStrokeWidth(im, sc);
6913 if (fw != null)
6914 an.strokeWidth = (float)fw.value().floatValue();
6915 ome.xml.model.primitives.Color colf = b.meta.getEllipseFillColor(im, sc);
6916 if (colf != null)
6917 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6918 }
6919 else
6920 if (typ == "Polygon")
6921 {
6922 an.type =
ROI.Type.Polygon;
6923 an.id = b.meta.getPolygonID(im, sc);
6924 an.closed = true;
6925 string pxs = b.meta.getPolygonPoints(im, sc);
6928 if (pts.Length > 100)
6929 {
6930 an.type =
ROI.Type.Freeform;
6931 }
6933 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolygonTheZ(im, sc);
6934 if (nz != null)
6935 co.Z = nz.getNumberValue().intValue();
6936 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolygonTheC(im, sc);
6937 if (nc != null)
6938 co.C = nc.getNumberValue().intValue();
6939 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolygonTheT(im, sc);
6940 if (nt != null)
6941 co.T = nt.getNumberValue().intValue();
6942 an.coord = co;
6943 an.Text = b.meta.getPolygonText(im, sc);
6944 ome.units.quantity.Length fl = b.meta.getPolygonFontSize(im, sc);
6945 if (fl != null)
6946 an.fontSize = fl.value().intValue();
6947 ome.xml.model.enums.FontFamily ff = b.meta.getPolygonFontFamily(im, sc);
6948 if (ff != null)
6949 an.family = ff.name();
6950 ome.xml.model.primitives.Color col = b.meta.getPolygonStrokeColor(im, sc);
6951 if (col != null)
6952 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6953 ome.units.quantity.Length fw = b.meta.getPolygonStrokeWidth(im, sc);
6954 if (fw != null)
6955 an.strokeWidth = (float)fw.value().floatValue();
6956 ome.xml.model.primitives.Color colf = b.meta.getPolygonFillColor(im, sc);
6957 if (colf != null)
6958 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6959 }
6960 else
6961 if (typ == "Polyline")
6962 {
6963 an.type =
ROI.Type.Polyline;
6964 an.id = b.meta.getPolylineID(im, sc);
6965 string pxs = b.meta.getPolylinePoints(im, sc);
6967 for (int pi = 0; pi < pts.Length; pi++)
6968 {
6970 }
6972 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolylineTheZ(im, sc);
6973 if (nz != null)
6974 co.Z = nz.getNumberValue().intValue();
6975 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolylineTheC(im, sc);
6976 if (nc != null)
6977 co.C = nc.getNumberValue().intValue();
6978 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolylineTheT(im, sc);
6979 if (nt != null)
6980 co.T = nt.getNumberValue().intValue();
6981 an.coord = co;
6982 an.Text = b.meta.getPolylineText(im, sc);
6983 ome.units.quantity.Length fl = b.meta.getPolylineFontSize(im, sc);
6984 if (fl != null)
6985 an.fontSize = fl.value().intValue();
6986 ome.xml.model.enums.FontFamily ff = b.meta.getPolylineFontFamily(im, sc);
6987 if (ff != null)
6988 an.family = ff.name();
6989 ome.xml.model.primitives.Color col = b.meta.getPolylineStrokeColor(im, sc);
6990 if (col != null)
6991 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6992 ome.units.quantity.Length fw = b.meta.getPolylineStrokeWidth(im, sc);
6993 if (fw != null)
6994 an.strokeWidth = (float)fw.value().floatValue();
6995 ome.xml.model.primitives.Color colf = b.meta.getPolylineFillColor(im, sc);
6996 if (colf != null)
6997 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6998 }
6999 else
7000 if (typ == "Label")
7001 {
7002 an.type =
ROI.Type.Label;
7003 an.id = b.meta.getLabelID(im, sc);
7004 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLabelTheZ(im, sc);
7005 if (nz != null)
7006 co.Z = nz.getNumberValue().intValue();
7007 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLabelTheC(im, sc);
7008 if (nc != null)
7009 co.C = nc.getNumberValue().intValue();
7010 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLabelTheT(im, sc);
7011 if (nt != null)
7012 co.T = nt.getNumberValue().intValue();
7013 an.coord = co;
7014
7015 ome.units.quantity.Length fl = b.meta.getLabelFontSize(im, sc);
7016 if (fl != null)
7017 an.fontSize = fl.value().intValue();
7018 ome.xml.model.enums.FontFamily ff = b.meta.getLabelFontFamily(im, sc);
7019 if (ff != null)
7020 an.family = ff.name();
7021 ome.xml.model.primitives.Color col = b.meta.getLabelStrokeColor(im, sc);
7022 if (col != null)
7023 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7024 ome.units.quantity.Length fw = b.meta.getLabelStrokeWidth(im, sc);
7025 if (fw != null)
7026 an.strokeWidth = (float)fw.value().floatValue();
7027 ome.xml.model.primitives.Color colf = b.meta.getLabelFillColor(im, sc);
7028 if (colf != null)
7029 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7030 PointD p = new PointD(b.meta.getLabelX(im, sc).doubleValue(), b.meta.getLabelY(im, sc).doubleValue());
7032 an.Text = b.meta.getLabelText(im, sc);
7033 }
7034 else
7035 if (typ == "Mask")
7036 {
7037 byte[] bts = b.meta.getMaskBinData(im, sc);
7038 bool end = b.meta.getMaskBinDataBigEndian(im, sc).booleanValue();
7039 double h = b.meta.getMaskHeight(im, sc).doubleValue();
7040 double w = b.meta.getMaskWidth(im, sc).doubleValue();
7041 double x = b.meta.getMaskX(im, sc).doubleValue();
7042 double y = b.meta.getMaskY(im, sc).doubleValue();
7043 an =
ROI.CreateMask(co, bts, (
int)Math.Round(w / b.PhysicalSizeX), (
int)Math.Round(h / b.PhysicalSizeY),
new PointD(x * b.PhysicalSizeX, y * b.PhysicalSizeY), b.PhysicalSizeX, b.PhysicalSizeY);
7044 an.Text = b.meta.getMaskText(im, sc);
7045 an.id = b.meta.getMaskID(im, sc);
7046 an.BoundingBox = new RectangleD(an.X, an.Y, an.W, an.H);
7047 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getMaskTheZ(im, sc);
7048 if (nz != null)
7049 co.Z = nz.getNumberValue().intValue();
7050 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getMaskTheC(im, sc);
7051 if (nc != null)
7052 co.C = nc.getNumberValue().intValue();
7053 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getMaskTheT(im, sc);
7054 if (nt != null)
7055 co.T = nt.getNumberValue().intValue();
7056 an.coord = co;
7057
7058 ome.units.quantity.Length fl = b.meta.getMaskFontSize(im, sc);
7059 if (fl != null)
7060 an.fontSize = fl.value().intValue();
7061 ome.xml.model.enums.FontFamily ff = b.meta.getMaskFontFamily(im, sc);
7062 if (ff != null)
7063 an.family = ff.name();
7064 ome.xml.model.primitives.Color col = b.meta.getMaskStrokeColor(im, sc);
7065 if (col != null)
7066 an.strokeColor = Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
7067 ome.units.quantity.Length fw = b.meta.getMaskStrokeWidth(im, sc);
7068 if (fw != null)
7069 an.strokeWidth = (float)fw.value().floatValue();
7070 ome.xml.model.primitives.Color colf = b.meta.getMaskFillColor(im, sc);
7071 if (colf != null)
7072 an.fillColor = Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
7073 }
7074 b.Annotations.Add(an);
7075 }
7076 }
7077
7078 List<string> serFiles = new List<string>();
7079 serFiles.AddRange(reader.getSeriesUsedFiles());
7080
7081 b.Buffers = new List<Bitmap>();
7083 {
7084
7085 try
7086 {
7087
7088 string st = OpenSlideImage.DetectVendor(file);
7089 if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
7090 {
7091 Status = "Opening file with OpenSlide.";
7092 Console.WriteLine("Opening file with OpenSlide.");
7093 b.openSlideImage = OpenSlideImage.Open(file);
7094 b.openslideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file, true);
7095 }
7096 else
7097 {
7098 Status = "Opening file with BioFormats.";
7099 Console.WriteLine("Opening file with BioFormats.");
7101 }
7102 }
7103 catch (Exception e)
7104 {
7105 Console.WriteLine(e.Message.ToString());
7107 }
7108 tile = true;
7109 }
7110
7111 int pages = reader.getImageCount();
7112 bool inter = reader.isInterleaved();
7113 int z = 0;
7114 int c = 0;
7115 int t = 0;
7116 if (!tile)
7117 {
7118 Status = "Reading image planes.";
7119 try
7120 {
7121 for (int p = 0; p < pages; p++)
7122 {
7123 Progress = ((float)p / (float)pages) * 100;
7124 Bitmap bf;
7125 byte[] bytes = reader.openBytes(p);
7126 bf = new Bitmap(file, SizeX, SizeY, PixelFormat, bytes, new ZCT(z, c, t), p, null, b.littleEndian, inter);
7127 b.Buffers.Add(bf);
7128 }
7129 }
7130 catch (Exception ex)
7131 {
7132 Console.WriteLine(ex.Message);
7133 }
7134
7135 }
7136 else
7137 {
7138 Status = "Reading tiles.";
7139 b.imRead = reader;
7140 for (int p = 0; p < pages; p++)
7141 {
7142 Progress = ((float)p / (float)pages) * 100;
7143 b.Buffers.Add(b.
GetTile(b, p, b.Level, tilex, tiley, tileSizeX, tileSizeY));
7144 }
7145 }
7146 int pls;
7147 try
7148 {
7149 pls = b.meta.getPlaneCount(serie);
7150 }
7151 catch (Exception)
7152 {
7153 pls = 0;
7154 }
7155 if (pls == b.Buffers.Count)
7156 for (int bi = 0; bi < b.Buffers.Count; bi++)
7157 {
7158 Plane pl = new Plane();
7159 pl.Coordinate = new ZCT();
7160 double px = 0; double py = 0; double pz = 0;
7161 if (b.meta.getPlanePositionX(serie, bi) != null)
7162 px = b.meta.getPlanePositionX(serie, bi).value().doubleValue();
7163 if (b.meta.getPlanePositionY(serie, bi) != null)
7164 py = b.meta.getPlanePositionY(serie, bi).value().doubleValue();
7165 if (b.meta.getPlanePositionZ(serie, bi) != null)
7166 pz = b.meta.getPlanePositionZ(serie, bi).value().doubleValue();
7167 pl.Location = new AForge.Point3D(px, py, pz);
7168 int cc = 0; int zc = 0; int tc = 0;
7169 if (b.meta.getPlaneTheC(serie, bi) != null)
7170 cc = b.meta.getPlaneTheC(serie, bi).getNumberValue().intValue();
7171 if (b.meta.getPlaneTheZ(serie, bi) != null)
7172 zc = b.meta.getPlaneTheZ(serie, bi).getNumberValue().intValue();
7173 if (b.meta.getPlaneTheT(serie, bi) != null)
7174 tc = b.meta.getPlaneTheT(serie, bi).getNumberValue().intValue();
7175 pl.Coordinate = new ZCT(zc, cc, tc);
7176 if (b.meta.getPlaneDeltaT(serie, bi) != null)
7177 pl.Delta = b.meta.getPlaneDeltaT(serie, bi).value().doubleValue();
7178 if (b.meta.getPlaneExposureTime(serie, bi) != null)
7179 pl.Exposure = b.meta.getPlaneExposureTime(serie, bi).value().doubleValue();
7180 b.Buffers[bi].Plane = pl;
7181 }
7182
7183 if (RGBChannelCount >= 3)
7184 {
7185 b.sizeC = sumSamples / b.Channels[0].SamplesPerPixel;
7186 }
7187 string ord = reader.getDimensionOrder();
7188 if (ord == "XYZCT")
7190 else if (ord == "XYCZT")
7192 else if (ord == "XYTCZ")
7195 if (b.bitsPerPixel > 8)
7197 else
7199 try
7200 {
7202 reader.close();
7203 if (addToImages)
7204 Images.AddImage(b);
7205 }
7206 catch (Exception e)
7207 {
7208 Console.WriteLine(e.Message);
7209 }
7210 b.Loading = false;
7211 Recorder.Record(
BioLib.
Recorder.GetCurrentMethodInfo(),
false, file, serie, tab, addToImages, tile, tilex, tiley, tileSizeX, tileSizeY);
7212 return b;
7213 }
PointD ToStageSpace(PointD p)
Definition Bio.cs:3454
void UpdateBoundingBox()
Definition ROI.cs:1456
PointD[] stringToPoints(string s)
Definition ROI.cs:1419
void AddPoints(PointD[] p, bool convertPixelSpace=false, double physX=1, double physY=1)
Definition ROI.cs:1345
void UpdatePoint(PointD p, int i)
Definition ROI.cs:1285
Definition SlideBase.cs:15
openslide wrapper
Definition SlideImage.cs:19
static SlideImage Open(BioImage b)
Open.
Definition SlideImage.cs:73