The function "OpenOME" opens a bioimage file, with options to specify the series, whether to.
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.
6163 {
6165 throw new InvalidDataException("File is empty or null");
6166
6167 do
6168 {
6169 Thread.Sleep(10);
6170 } while (!initialized);
6171 Console.WriteLine(
"OpenOME " +
file);
6172 reader = new ImageReader();
6173 Progress pr = Progress.Create(
file,
"Opening OME",
"Opening OME file.");
6174
6175 Application.Invoke(delegate
6176 {
6177 pr.Show();
6178 pr.Present();
6179 });
6180 if (tileSizeX == 0)
6181 tileSizeX = 1920;
6182 if (tileSizeY == 0)
6183 tileSizeY = 1080;
6188 b.Loading = true;
6189 if (b.meta == null)
6190 b.meta = service.createOMEXMLMetadata();
6191 string f =
file.Replace(
"\\",
"/");
6192 string cf = reader.getCurrentFile();
6193 if (cf != null)
6194 cf = cf.Replace("\\", "/");
6195 if (cf != f)
6196 {
6197 reader.close();
6198 reader.setMetadataStore(b.meta);
6199 try
6200 {
6201 reader.setId(f);
6202 }
6203 catch (Exception e)
6204 {
6205 Console.WriteLine(e.Message);
6206 return null;
6207 }
6208
6209 pr.Status = "Reading Metadata";
6210 }
6211
6212
6213 reader.setSeries(serie);
6215
6216
6217 PixelFormat PixelFormat;
6218 try
6219 {
6221 }
6222 catch (Exception)
6223 {
6225 }
6226
6230 SizeX = reader.getSizeX();
6231 SizeY = reader.getSizeY();
6232 int SizeZ = reader.getSizeZ();
6233 b.sizeC = reader.getSizeC();
6234 b.sizeZ = reader.getSizeZ();
6235 b.sizeT = reader.getSizeT();
6236 b.littleEndian = reader.isLittleEndian();
6237 b.seriesCount = reader.getSeriesCount();
6238 b.imagesPerSeries = reader.getImageCount();
6239 b.bitsPerPixel = reader.getBitsPerPixel();
6240 b.series = serie;
6241 string order = reader.getDimensionOrder();
6242
6243
6244 int i = 0;
6245 pr.Status = "Reading Channels";
6246 int sumSamples = 0;
6247 while (true)
6248 {
6249 Channel ch = new Channel(i, b.bitsPerPixel, 1);
6250 bool def = false;
6251 try
6252 {
6253 if (b.meta.getChannelSamplesPerPixel(serie, i) != null)
6254 {
6255 int s = b.meta.getChannelSamplesPerPixel(serie, i).getNumberValue().intValue();
6256 ch.SamplesPerPixel = s;
6257 sumSamples += s;
6258 def = true;
6259 }
6260 if (b.meta.getChannelName(serie, i) != null)
6261 ch.Name = b.meta.getChannelName(serie, i);
6262 if (b.meta.getChannelAcquisitionMode(serie, i) != null)
6263 ch.AcquisitionMode = b.meta.getChannelAcquisitionMode(serie, i).ToString();
6264 if (b.meta.getChannelID(serie, i) != null)
6265 ch.info.ID = b.meta.getChannelID(serie, i);
6266 if (b.meta.getChannelFluor(serie, i) != null)
6267 ch.Fluor = b.meta.getChannelFluor(serie, i);
6268 if (b.meta.getChannelColor(serie, i) != null)
6269 {
6270 ome.xml.model.primitives.Color cc = b.meta.getChannelColor(serie, i);
6271 ch.Color =
Color.FromArgb(cc.getRed(), cc.getGreen(), cc.getBlue());
6272 }
6273 if (b.meta.getChannelIlluminationType(serie, i) != null)
6274 ch.IlluminationType = b.meta.getChannelIlluminationType(serie, i).ToString();
6275 if (b.meta.getChannelContrastMethod(serie, i) != null)
6276 ch.ContrastMethod = b.meta.getChannelContrastMethod(serie, i).ToString();
6277 if (b.meta.getChannelEmissionWavelength(serie, i) != null)
6278 ch.Emission = b.meta.getChannelEmissionWavelength(serie, i).value().intValue();
6279 if (b.meta.getChannelExcitationWavelength(serie, i) != null)
6280 ch.Excitation = b.meta.getChannelExcitationWavelength(serie, i).value().intValue();
6281 if (b.meta.getLightEmittingDiodePower(serie, i) != null)
6282 ch.LightSourceIntensity = b.meta.getLightEmittingDiodePower(serie, i).value().doubleValue();
6283 if (b.meta.getLightEmittingDiodeID(serie, i) != null)
6284 ch.DiodeName = b.meta.getLightEmittingDiodeID(serie, i);
6285 if (b.meta.getChannelLightSourceSettingsAttenuation(serie, i) != null)
6286 ch.LightSourceAttenuation = b.meta.getChannelLightSourceSettingsAttenuation(serie, i).toString();
6287
6288 }
6289 catch (Exception e)
6290 {
6291 Console.WriteLine(e.Message);
6292 }
6293
6294 if (!def)
6295 break;
6296 else
6297 b.Channels.Add(ch);
6298 if (i == 0)
6299 {
6300 b.rgbChannels[0] = 0;
6301 }
6302 else
6303 if (i == 1)
6304 {
6305 b.rgbChannels[1] = 1;
6306 }
6307 else
6308 if (i == 2)
6309 {
6310 b.rgbChannels[2] = 2;
6311 }
6312 i++;
6313 }
6314
6315 if (b.Channels.Count == 0)
6316 {
6318 }
6319
6320
6322 {
6323 b.sizeC = sumSamples / b.Channels[0].SamplesPerPixel;
6324 }
6325 b.Coords = new int[b.SizeZ, b.SizeC, b.SizeT];
6326
6327 int resc = reader.getResolutionCount();
6328
6329 try
6330 {
6331 int wells = b.meta.getWellCount(0);
6332 if(wells>0)
6333 {
6335 b.Plate = new WellPlate(b);
6336 tile = false;
6337 }
6338 }
6339 catch (Exception)
6340 {
6341
6342 }
6343 List<Resolution> rss = new List<Resolution>();
6344 for (int s = 0; s < b.seriesCount; s++)
6345 {
6346 reader.setSeries(s);
6347 for (int r = 0; r < reader.getResolutionCount(); r++)
6348 {
6350 try
6351 {
6352 int rgbc = reader.getRGBChannelCount();
6353 int bps = reader.getBitsPerPixel();
6354 PixelFormat px;
6355 try
6356 {
6358 }
6359 catch (Exception)
6360 {
6362 }
6363 res.PixelFormat = px;
6364 res.SizeX = reader.getSizeX();
6365 res.SizeY = reader.getSizeY();
6366 if (b.meta.getPixelsPhysicalSizeX(r) != null)
6367 {
6368 res.PhysicalSizeX = b.meta.getPixelsPhysicalSizeX(r).value().doubleValue();
6369 }
6370 else
6371 res.PhysicalSizeX = (96 / 2.54) / 1000;
6372 if (b.meta.getPixelsPhysicalSizeY(r) != null)
6373 {
6374 res.PhysicalSizeY = b.meta.getPixelsPhysicalSizeY(r).value().doubleValue();
6375 }
6376 else
6377 res.PhysicalSizeY = (96 / 2.54) / 1000;
6378
6379 if (b.meta.getStageLabelX(r) != null)
6380 res.StageSizeX = b.meta.getStageLabelX(r).value().doubleValue();
6381 if (b.meta.getStageLabelY(r) != null)
6382 res.StageSizeY = b.meta.getStageLabelY(r).value().doubleValue();
6383 if (b.meta.getStageLabelZ(r) != null)
6384 res.StageSizeZ = b.meta.getStageLabelZ(r).value().doubleValue();
6385 else
6386 res.StageSizeZ = 1;
6387 if (b.meta.getPixelsPhysicalSizeZ(r) != null)
6388 {
6389 res.PhysicalSizeZ = b.meta.getPixelsPhysicalSizeZ(r).value().doubleValue();
6390 }
6391 else
6392 {
6393 res.PhysicalSizeZ = 1;
6394 }
6395 }
6396 catch (Exception e)
6397 {
6398 Console.WriteLine("No Stage Coordinates. PhysicalSize:(" + res.PhysicalSizeX + "," + res.PhysicalSizeY + "," + res.PhysicalSizeZ + ")");
6399 }
6400 rss.Add(res);
6401 }
6402 }
6403 reader.setSeries(serie);
6404
6405 int pyramidCount = 0;
6406 int pyramidResolutions = 0;
6407 List<Tuple<int, int>> prs = new List<Tuple<int, int>>();
6408
6409
6410 if (rss.Count > 1 && b.Type !=
ImageType.well)
6411 {
6413 {
6415 tile = true;
6416
6417 int? sr = null;
6418 for (int r = 0; r < rss.Count - 1; r++)
6419 {
6420 if (rss[r].
SizeX > rss[r + 1].
SizeX && rss[r].PixelFormat == rss[r + 1].PixelFormat)
6421 {
6422 if (sr == null)
6423 {
6424 sr = r;
6425 prs.Add(new Tuple<int, int>(r, 0));
6426 }
6427 }
6428 else
6429 {
6430 if(rss[prs[prs.Count - 1].Item1].PixelFormat == rss[r].PixelFormat)
6431 prs[prs.Count - 1] = new Tuple<int, int>(prs[prs.Count - 1].Item1, r);
6432 sr = null;
6433 }
6434 }
6435 pyramidCount = prs.Count;
6436 for (int p = 0; p < prs.Count; p++)
6437 {
6438 pyramidResolutions += (prs[p].Item2 - prs[p].Item1)+1;
6439 }
6440
6441 if (prs[serie].Item2 == 0)
6442 {
6443 prs[serie] = new Tuple<int, int>(prs[serie].Item1, rss.Count);
6444 }
6445 for (int r = prs[serie].Item1; r < prs[serie].Item2; r++)
6446 {
6447 b.Resolutions.Add(rss[r]);
6448 }
6449 }
6450 else
6451 {
6452 b.Resolutions.AddRange(rss);
6453 }
6454 }
6455 else
6456 b.Resolutions.AddRange(rss);
6457
6458
6459 if(rss.Count - pyramidResolutions == 2)
6460 {
6461 b.Resolutions.Add(rss[rss.Count - 2]);
6462 b.Resolutions.Add(rss[rss.Count - 1]);
6463 }
6464
6465 b.Volume =
new VolumeD(
new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ),
new Point3D(b.PhysicalSizeX *
SizeX, b.PhysicalSizeY *
SizeY, b.PhysicalSizeZ *
SizeZ));
6466 pr.Status = "Reading ROIs";
6467 int rc = b.meta.getROICount();
6468 for (int im = 0; im < rc; im++)
6469 {
6470 string roiID = b.meta.getROIID(im);
6471 string roiName = b.meta.getROIName(im);
6472 ZCT co = new ZCT(0, 0, 0);
6473 int scount = 1;
6474 try
6475 {
6476 scount = b.meta.getShapeCount(im);
6477 }
6478 catch (Exception e)
6479 {
6480 Console.WriteLine(e.Message.ToString());
6481 }
6482 for (int sc = 0; sc < scount; sc++)
6483 {
6484 string type = b.meta.getShapeType(im, sc);
6485 ROI an = new ROI();
6486 an.roiID = roiID;
6487 an.roiName = roiName;
6488 an.shapeIndex = sc;
6489 if (type == "Point")
6490 {
6491 an.type = ROI.Type.Point;
6492 an.id = b.meta.getPointID(im, sc);
6493 double dx = b.meta.getPointX(im, sc).doubleValue();
6494 double dy = b.meta.getPointY(im, sc).doubleValue();
6495 an.AddPoint(b.ToStageSpace(new PointD(dx, dy)));
6496 an.coord = new ZCT();
6497 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPointTheZ(im, sc);
6498 if (nz != null)
6499 an.coord.Z = nz.getNumberValue().intValue();
6500 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPointTheC(im, sc);
6501 if (nc != null)
6502 an.coord.C = nc.getNumberValue().intValue();
6503 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPointTheT(im, sc);
6504 if (nt != null)
6505 an.coord.T = nt.getNumberValue().intValue();
6506 an.Text = b.meta.getPointText(im, sc);
6507 ome.units.quantity.Length fl = b.meta.getPointFontSize(im, sc);
6508 if (fl != null)
6509 an.fontSize = fl.value().intValue();
6510 ome.xml.model.enums.FontFamily ff = b.meta.getPointFontFamily(im, sc);
6511 if (ff != null)
6512 an.family = ff.name();
6513 ome.xml.model.primitives.Color col = b.meta.getPointStrokeColor(im, sc);
6514 if (col != null)
6515 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6516 ome.units.quantity.Length fw = b.meta.getPointStrokeWidth(im, sc);
6517 if (fw != null)
6518 an.strokeWidth = (float)fw.value().floatValue();
6519 ome.xml.model.primitives.Color colf = b.meta.getPointStrokeColor(im, sc);
6520 if (colf != null)
6521 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6522 }
6523 else
6524 if (type == "Line")
6525 {
6526 an.type = ROI.Type.Line;
6527 an.id = b.meta.getLineID(im, sc);
6528 double px1 = b.meta.getLineX1(im, sc).doubleValue();
6529 double py1 = b.meta.getLineY1(im, sc).doubleValue();
6530 double px2 = b.meta.getLineX2(im, sc).doubleValue();
6531 double py2 = b.meta.getLineY2(im, sc).doubleValue();
6532 an.AddPoint(b.ToStageSpace(new PointD(px1, py1)));
6533 an.AddPoint(b.ToStageSpace(new PointD(px2, py2)));
6534 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLineTheZ(im, sc);
6535 if (nz != null)
6536 co.Z = nz.getNumberValue().intValue();
6537 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLineTheC(im, sc);
6538 if (nc != null)
6539 co.C = nc.getNumberValue().intValue();
6540 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLineTheT(im, sc);
6541 if (nt != null)
6542 co.T = nt.getNumberValue().intValue();
6543 an.coord = co;
6544 an.Text = b.meta.getLineText(im, sc);
6545 ome.units.quantity.Length fl = b.meta.getLineFontSize(im, sc);
6546 if (fl != null)
6547 an.fontSize = fl.value().intValue();
6548 ome.xml.model.enums.FontFamily ff = b.meta.getLineFontFamily(im, sc);
6549 if (ff != null)
6550 an.family = ff.name();
6551 ome.xml.model.primitives.Color col = b.meta.getLineStrokeColor(im, sc);
6552 if (col != null)
6553 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6554 ome.units.quantity.Length fw = b.meta.getLineStrokeWidth(im, sc);
6555 if (fw != null)
6556 an.strokeWidth = (float)fw.value().floatValue();
6557 ome.xml.model.primitives.Color colf = b.meta.getLineFillColor(im, sc);
6558 if (colf != null)
6559 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6560 }
6561 else
6562 if (type == "Rectangle")
6563 {
6564 an.type = ROI.Type.Rectangle;
6565 an.id = b.meta.getRectangleID(im, sc);
6566 double px = b.meta.getRectangleX(im, sc).doubleValue();
6567 double py = b.meta.getRectangleY(im, sc).doubleValue();
6568 double pw = b.meta.getRectangleWidth(im, sc).doubleValue();
6569 double ph = b.meta.getRectangleHeight(im, sc).doubleValue();
6570 an.Rect = b.ToStageSpace(new RectangleD(px, py, pw, ph));
6571 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getRectangleTheZ(im, sc);
6572 if (nz != null)
6573 co.Z = nz.getNumberValue().intValue();
6574 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getRectangleTheC(im, sc);
6575 if (nc != null)
6576 co.C = nc.getNumberValue().intValue();
6577 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getRectangleTheT(im, sc);
6578 if (nt != null)
6579 co.T = nt.getNumberValue().intValue();
6580 an.coord = co;
6581
6582 an.Text = b.meta.getRectangleText(im, sc);
6583 ome.units.quantity.Length fl = b.meta.getRectangleFontSize(im, sc);
6584 if (fl != null)
6585 an.fontSize = fl.value().intValue();
6586 ome.xml.model.enums.FontFamily ff = b.meta.getRectangleFontFamily(im, sc);
6587 if (ff != null)
6588 an.family = ff.name();
6589 ome.xml.model.primitives.Color col = b.meta.getRectangleStrokeColor(im, sc);
6590 if (col != null)
6591 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6592 ome.units.quantity.Length fw = b.meta.getRectangleStrokeWidth(im, sc);
6593 if (fw != null)
6594 an.strokeWidth = (float)fw.value().floatValue();
6595 ome.xml.model.primitives.Color colf = b.meta.getRectangleFillColor(im, sc);
6596 if (colf != null)
6597 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6598 ome.xml.model.enums.FillRule fr = b.meta.getRectangleFillRule(im, sc);
6599 }
6600 else
6601 if (type == "Ellipse")
6602 {
6603 an.type = ROI.Type.Ellipse;
6604 an.id = b.meta.getEllipseID(im, sc);
6605 double px = b.meta.getEllipseX(im, sc).doubleValue();
6606 double py = b.meta.getEllipseY(im, sc).doubleValue();
6607 double ew = b.meta.getEllipseRadiusX(im, sc).doubleValue();
6608 double eh = b.meta.getEllipseRadiusY(im, sc).doubleValue();
6609
6610 double w = ew * 2;
6611 double h = eh * 2;
6612 double x = px - ew;
6613 double y = py - eh;
6614 an.Rect = b.ToStageSpace(new RectangleD(x, y, w, h));
6615 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getEllipseTheZ(im, sc);
6616 if (nz != null)
6617 co.Z = nz.getNumberValue().intValue();
6618 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getEllipseTheC(im, sc);
6619 if (nc != null)
6620 co.C = nc.getNumberValue().intValue();
6621 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getEllipseTheT(im, sc);
6622 if (nt != null)
6623 co.T = nt.getNumberValue().intValue();
6624 an.coord = co;
6625 an.Text = b.meta.getEllipseText(im, sc);
6626 ome.units.quantity.Length fl = b.meta.getEllipseFontSize(im, sc);
6627 if (fl != null)
6628 an.fontSize = fl.value().intValue();
6629 ome.xml.model.enums.FontFamily ff = b.meta.getEllipseFontFamily(im, sc);
6630 if (ff != null)
6631 an.family = ff.name();
6632 ome.xml.model.primitives.Color col = b.meta.getEllipseStrokeColor(im, sc);
6633 if (col != null)
6634 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6635 ome.units.quantity.Length fw = b.meta.getEllipseStrokeWidth(im, sc);
6636 if (fw != null)
6637 an.strokeWidth = (float)fw.value().floatValue();
6638 ome.xml.model.primitives.Color colf = b.meta.getEllipseFillColor(im, sc);
6639 if (colf != null)
6640 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6641 }
6642 else
6643 if (type == "Polygon")
6644 {
6645 an.type = ROI.Type.Polygon;
6646 an.id = b.meta.getPolygonID(im, sc);
6647 an.closed = true;
6648 string pxs = b.meta.getPolygonPoints(im, sc);
6649 PointD[] pts = an.stringToPoints(pxs);
6650 pts = b.ToStageSpace(pts);
6651 if (pts.Length > 100)
6652 {
6653 an.type = ROI.Type.Freeform;
6654 }
6655 an.AddPoints(pts);
6656 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolygonTheZ(im, sc);
6657 if (nz != null)
6658 co.Z = nz.getNumberValue().intValue();
6659 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolygonTheC(im, sc);
6660 if (nc != null)
6661 co.C = nc.getNumberValue().intValue();
6662 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolygonTheT(im, sc);
6663 if (nt != null)
6664 co.T = nt.getNumberValue().intValue();
6665 an.coord = co;
6666 an.Text = b.meta.getPolygonText(im, sc);
6667 ome.units.quantity.Length fl = b.meta.getPolygonFontSize(im, sc);
6668 if (fl != null)
6669 an.fontSize = fl.value().intValue();
6670 ome.xml.model.enums.FontFamily ff = b.meta.getPolygonFontFamily(im, sc);
6671 if (ff != null)
6672 an.family = ff.name();
6673 ome.xml.model.primitives.Color col = b.meta.getPolygonStrokeColor(im, sc);
6674 if (col != null)
6675 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6676 ome.units.quantity.Length fw = b.meta.getPolygonStrokeWidth(im, sc);
6677 if (fw != null)
6678 an.strokeWidth = (float)fw.value().floatValue();
6679 ome.xml.model.primitives.Color colf = b.meta.getPolygonFillColor(im, sc);
6680 if (colf != null)
6681 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6682 }
6683 else
6684 if (type == "Polyline")
6685 {
6686 an.type = ROI.Type.Polyline;
6687 an.id = b.meta.getPolylineID(im, sc);
6688 string pxs = b.meta.getPolylinePoints(im, sc);
6689 PointD[] pts = an.stringToPoints(pxs);
6690 for (int pi = 0; pi < pts.Length; pi++)
6691 {
6692 pts[pi] = b.ToStageSpace(pts[pi]);
6693 }
6694 an.AddPoints(an.stringToPoints(pxs));
6695 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getPolylineTheZ(im, sc);
6696 if (nz != null)
6697 co.Z = nz.getNumberValue().intValue();
6698 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getPolylineTheC(im, sc);
6699 if (nc != null)
6700 co.C = nc.getNumberValue().intValue();
6701 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getPolylineTheT(im, sc);
6702 if (nt != null)
6703 co.T = nt.getNumberValue().intValue();
6704 an.coord = co;
6705 an.Text = b.meta.getPolylineText(im, sc);
6706 ome.units.quantity.Length fl = b.meta.getPolylineFontSize(im, sc);
6707 if (fl != null)
6708 an.fontSize = fl.value().intValue();
6709 ome.xml.model.enums.FontFamily ff = b.meta.getPolylineFontFamily(im, sc);
6710 if (ff != null)
6711 an.family = ff.name();
6712 ome.xml.model.primitives.Color col = b.meta.getPolylineStrokeColor(im, sc);
6713 if (col != null)
6714 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6715 ome.units.quantity.Length fw = b.meta.getPolylineStrokeWidth(im, sc);
6716 if (fw != null)
6717 an.strokeWidth = (float)fw.value().floatValue();
6718 ome.xml.model.primitives.Color colf = b.meta.getPolylineFillColor(im, sc);
6719 if (colf != null)
6720 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6721 }
6722 else
6723 if (type == "Label")
6724 {
6725 an.type = ROI.Type.Label;
6726 an.id = b.meta.getLabelID(im, sc);
6727
6728 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getLabelTheZ(im, sc);
6729 if (nz != null)
6730 co.Z = nz.getNumberValue().intValue();
6731 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getLabelTheC(im, sc);
6732 if (nc != null)
6733 co.C = nc.getNumberValue().intValue();
6734 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getLabelTheT(im, sc);
6735 if (nt != null)
6736 co.T = nt.getNumberValue().intValue();
6737 an.coord = co;
6738
6739 ome.units.quantity.Length fl = b.meta.getLabelFontSize(im, sc);
6740 if (fl != null)
6741 an.fontSize = fl.value().intValue();
6742 ome.xml.model.enums.FontFamily ff = b.meta.getLabelFontFamily(im, sc);
6743 if (ff != null)
6744 an.family = ff.name();
6745 ome.xml.model.primitives.Color col = b.meta.getLabelStrokeColor(im, sc);
6746 if (col != null)
6747 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6748 ome.units.quantity.Length fw = b.meta.getLabelStrokeWidth(im, sc);
6749 if (fw != null)
6750 an.strokeWidth = (float)fw.value().floatValue();
6751 ome.xml.model.primitives.Color colf = b.meta.getLabelFillColor(im, sc);
6752 if (colf != null)
6753 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6754 PointD p = new PointD(b.meta.getLabelX(im, sc).doubleValue(), b.meta.getLabelY(im, sc).doubleValue());
6755 an.AddPoint(b.ToStageSpace(p));
6756 an.Text = b.meta.getLabelText(im, sc);
6757 }
6758 else
6759 if (type == "Mask")
6760 {
6761 byte[] bts = b.meta.getMaskBinData(im, sc);
6762 bool end = b.meta.getMaskBinDataBigEndian(im, sc).booleanValue();
6763 an = ROI.CreateMask(co, bts, b.Resolutions[0].SizeX, b.Resolutions[0].SizeY,new PointD(b.StageSizeX,b.StageSizeY),b.PhysicalSizeX,b.PhysicalSizeY);
6764 an.Text = b.meta.getMaskText(im, sc);
6765 an.id = b.meta.getMaskID(im, sc);
6766 ome.xml.model.primitives.NonNegativeInteger nz = b.meta.getMaskTheZ(im, sc);
6767 if (nz != null)
6768 co.Z = nz.getNumberValue().intValue();
6769 ome.xml.model.primitives.NonNegativeInteger nc = b.meta.getMaskTheC(im, sc);
6770 if (nc != null)
6771 co.C = nc.getNumberValue().intValue();
6772 ome.xml.model.primitives.NonNegativeInteger nt = b.meta.getMaskTheT(im, sc);
6773 if (nt != null)
6774 co.T = nt.getNumberValue().intValue();
6775 an.coord = co;
6776
6777 ome.units.quantity.Length fl = b.meta.getMaskFontSize(im, sc);
6778 if (fl != null)
6779 an.fontSize = fl.value().intValue();
6780 ome.xml.model.enums.FontFamily ff = b.meta.getMaskFontFamily(im, sc);
6781 if (ff != null)
6782 an.family = ff.name();
6783 ome.xml.model.primitives.Color col = b.meta.getMaskStrokeColor(im, sc);
6784 if (col != null)
6785 an.strokeColor =
Color.FromArgb(col.getAlpha(), col.getRed(), col.getGreen(), col.getBlue());
6786 ome.units.quantity.Length fw = b.meta.getMaskStrokeWidth(im, sc);
6787 if (fw != null)
6788 an.strokeWidth = (float)fw.value().floatValue();
6789 ome.xml.model.primitives.Color colf = b.meta.getMaskFillColor(im, sc);
6790 if (colf != null)
6791 an.fillColor =
Color.FromArgb(colf.getAlpha(), colf.getRed(), colf.getGreen(), colf.getBlue());
6792 }
6793 b.Annotations.Add(an);
6794 }
6795 }
6796
6797 List<string> serFiles = new List<string>();
6798 serFiles.AddRange(reader.getSeriesUsedFiles());
6799
6800 b.Buffers = new List<Bitmap>();
6802 try
6803 {
6804 string st = OpenSlideImage.DetectVendor(
file);
6805 if (st !=
null && !
file.EndsWith(
"ome.tif") && useOpenSlide)
6806 {
6807 b.openSlideImage = OpenSlideImage.Open(
file);
6809 }
6810 else
6811 {
6813 }
6814 }
6815 catch (Exception e)
6816 {
6817 Console.WriteLine(e.Message.ToString());
6819 }
6820
6821
6822 int pages = reader.getImageCount();
6823 bool inter = reader.isInterleaved();
6824 int z = 0;
6825 int c = 0;
6826 int t = 0;
6827 pr.Status = "Reading Image Data";
6828 if (!tile)
6829 {
6830 try
6831 {
6832 for (int p = 0; p < pages; p++)
6833 {
6835 pr.ProgressValue = (float)p / (float)pages;
6836 byte[] bytes = reader.openBytes(p);
6837 bf =
new Bitmap(
file,
SizeX,
SizeY, PixelFormat, bytes,
new ZCT(z, c, t), p,
null, b.littleEndian, inter);
6838 b.Buffers.Add(bf);
6839 }
6840 }
6841 catch (Exception)
6842 {
6843
6845 try
6846 {
6847 string st = OpenSlideImage.DetectVendor(
file);
6848 if (st !=
null && !
file.EndsWith(
"ome.tif") && useOpenSlide)
6849 {
6850 b.openSlideImage = OpenSlideImage.Open(
file);
6852 }
6853 else
6854 {
6856 }
6857 }
6858 catch (Exception e)
6859 {
6860 Console.WriteLine(e.Message.ToString());
6862 }
6863 b.imRead = reader;
6864 for (int p = 0; p < pages; p++)
6865 {
6866 b.Buffers.Add(
GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6868 }
6869 }
6870
6871 }
6872 else
6873 {
6874 b.imRead = reader;
6875 for (int p = 0; p < pages; p++)
6876 {
6877 b.Buffers.Add(
GetTile(b, p, serie, tilex, tiley, tileSizeX, tileSizeY));
6879 }
6880 }
6881 int pls;
6882 try
6883 {
6884 pls = b.meta.getPlaneCount(serie);
6885 }
6886 catch (Exception)
6887 {
6888 pls = 0;
6889 }
6890 pr.Status = "Reading Plane Data";
6891 if (pls == b.Buffers.Count)
6892 for (int bi = 0; bi < b.Buffers.Count; bi++)
6893 {
6894 Plane pl = new Plane();
6895 pl.Coordinate = new ZCT();
6896 double px = 0; double py = 0; double pz = 0;
6897 if (b.meta.getPlanePositionX(serie, bi) != null)
6898 px = b.meta.getPlanePositionX(serie, bi).value().doubleValue();
6899 if (b.meta.getPlanePositionY(serie, bi) != null)
6900 py = b.meta.getPlanePositionY(serie, bi).value().doubleValue();
6901 if (b.meta.getPlanePositionZ(serie, bi) != null)
6902 pz = b.meta.getPlanePositionZ(serie, bi).value().doubleValue();
6903 pl.Location = new AForge.Point3D(px, py, pz);
6904 int cc = 0; int zc = 0; int tc = 0;
6905 if (b.meta.getPlaneTheC(serie, bi) != null)
6906 cc = b.meta.getPlaneTheC(serie, bi).getNumberValue().intValue();
6907 if (b.meta.getPlaneTheZ(serie, bi) != null)
6908 zc = b.meta.getPlaneTheZ(serie, bi).getNumberValue().intValue();
6909 if (b.meta.getPlaneTheT(serie, bi) != null)
6910 tc = b.meta.getPlaneTheT(serie, bi).getNumberValue().intValue();
6911 pl.Coordinate = new ZCT(zc, cc, tc);
6912 if (b.meta.getPlaneDeltaT(serie, bi) != null)
6913 pl.Delta = b.meta.getPlaneDeltaT(serie, bi).value().doubleValue();
6914 if (b.meta.getPlaneExposureTime(serie, bi) != null)
6915 pl.Exposure = b.meta.getPlaneExposureTime(serie, bi).value().doubleValue();
6916 b.Buffers[bi].Plane = pl;
6917 }
6918
6919 b.UpdateCoords(b.SizeZ, b.SizeC, b.SizeT, order);
6920
6921 do
6922 {
6923 Thread.Sleep(50);
6924 } while (b.Buffers[b.Buffers.Count - 1].Stats == null);
6925 b.SetLabelMacroResolutions();
6928 if (b.bitsPerPixel > 8)
6929 b.StackThreshold(true);
6930 else
6931 b.StackThreshold(false);
6932 if (!tile)
6933 {
6934
6935 bool stop = false;
6936 do
6937 {
6938 try
6939 {
6940 reader.close();
6941 stop = true;
6942 }
6943 catch (Exception e)
6944 {
6945 Console.WriteLine(e.Message);
6946 }
6947 } while (!stop);
6948 }
6949 if (addToImages)
6950 Images.AddImage(b, tab);
6951 b.Loading = false;
6952
6953 Application.Invoke(delegate
6954 {
6955 pr.Hide();
6956 });
6957 Console.WriteLine(
"Opening complete " +
file);
6958 return b;
6959 }
AForge.Color Color
Definition Bio.cs:22
openslide wrapper
Definition SlideImage.cs:20
static SlideImage Open(BioImage b)
Open.
Definition SlideImage.cs:74
SlideBase SlideBase
Definition Bio.cs:2418
OpenSlideBase OpenSlideBase
Definition Bio.cs:2416
int SizeZ
Definition Bio.cs:2639