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