Returns the ROI.
450 {
452 data = File.ReadAllBytes(path);
453 size = data.Length;
454 if (getByte(0) != 73 || getByte(1) != 111)
455 throw new IOException("This is not an ImageJ ROI");
457 int type = getByte(
TYPE);
458 int subtype = getShort(
SUBTYPE);
459 int top = getShort(
TOP);
460 int left = getShort(
LEFT);
461 int bottom = getShort(
BOTTOM);
462 int right = getShort(
RIGHT);
463 int width = right - left;
464 int height = bottom - top;
466 if (n == 0)
468 int options = getShort(
OPTIONS);
471 int channel = 0, slice = 0, frame = 0;
472 int overlayLabelColor = 0;
473 int overlayFontSize = 0;
474 int group = 0;
475 int imageOpacity = 0;
476 int imageSize = 0;
478 bool drawOffset = subPixelResolution && (options &
DRAW_OFFSET) != 0;
479 bool scaleStrokeWidth = true;
480 if (version >= 228)
482
483 bool subPixelRect = version >= 223 && subPixelResolution && (type == rect || type == oval);
484 double xd = 0.0, yd = 0.0, widthd = 0.0, heightd = 0.0;
485 if (subPixelRect) {
488 widthd = getFloat(
WIDTHD);
490 roi.subPixel = true;
491 }
492
493 if (hdr2Offset > 0 && hdr2Offset +
IMAGE_SIZE + 4 <= size)
494 {
502 group = getByte(hdr2Offset +
GROUP);
503 }
504
505 if (name != null && name.EndsWith(".roi"))
506 name = name.Substring(0, name.Length - 4);
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533 switch (type)
534 {
535 case 1:
536 if (subPixelRect)
538 else
541 if (arcSize > 0)
542 throw new NotSupportedException("Type rounded rectangle not supported.");
543 break;
544 case 2:
545 if (subPixelRect)
546 roi =
BioGTK.
ROI.
CreateEllipse(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), xd, yd, widthd, heightd);
547 else
548 roi =
BioGTK.
ROI.
CreateEllipse(
new AForge.ZCT(slice - 1, channel - 1, frame - 1), left, top, width, height);
549 break;
550 case 3:
551 float x1 = getFloat(
X1);
552 float y1 = getFloat(
Y1);
553 float x2 = getFloat(
X2);
554 float y2 = getFloat(
Y2);
555
556 if (subtype ==
ARROW)
557 {
558 throw new NotSupportedException("Type arrow not supported.");
559
560
561
562
563
564
565
566
567
568
569
570 }
571 else
572 {
573 roi =
ROI.
CreateLine(
new AForge.ZCT(slice, channel, frame),
new AForge.PointD(x1, y1),
new AForge.PointD(x2, y2));
574
575 }
576
577 break;
578 case 0:
579 case 5:
580 case 6:
581 case 7:
582 case 8:
583 case 9:
584 case 10:
585
586
587
588 if (n == 0 || n < 0) break;
589 int[] x = new int[n];
590 int[] y = new int[n];
591 float[] xf = null;
592 float[] yf = null;
594 int base2 = base1 + 2 * n;
595 int xtmp, ytmp;
596 for (int i = 0; i < n; i++)
597 {
598 xtmp = getShort(base1 + i * 2);
599 if (xtmp < 0) xtmp = 0;
600 ytmp = getShort(base2 + i * 2);
601 if (ytmp < 0) ytmp = 0;
602 x[i] = left + xtmp;
603 y[i] = top + ytmp;
604 }
605 if (subPixelResolution)
606 {
607 xf = new float[n];
608 yf = new float[n];
610 base2 = base1 + 4 * n;
611 for (int i = 0; i < n; i++)
612 {
613 xf[i] = getFloat(base1 + i * 4);
614 yf[i] = getFloat(base2 + i * 4);
615 }
616 }
617 if (type == point)
618 {
619
620 if (subPixelResolution)
621 {
623 }
624 else
626 if (version >= 226)
627 {
628
630 }
631
632
633
634
636 break;
637 }
638 if (type == polygon)
640 else if (type == freehand)
641 {
644 {
645 throw new NotSupportedException("ROI type not supported.");
646
647
648
649
650
651
652
653
654
655
656
657
658 }
659 }
660 else if (type == traced)
662 else if (type == polyline)
664 else if (type == freeline)
666 else if (type == angle)
668 else
670 if (subPixelResolution)
671 {
673
674
675 }
676 else
678 break;
679 default:
680 throw new IOException("Unrecognized ROI type: " + type);
681 }
682 if (roi == null)
683 return null;
684 roi.roiName = getRoiName();
685
686
687 if (version >= 218)
688 {
689 getStrokeWidthAndColor(roi, hdr2Offset, scaleStrokeWidth);
690
691
692
693
694
695
696
697 }
698
699 if (version >= 218 && subtype ==
TEXT)
700 {
701 getTextRoi(roi, version);
703 }
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723 if (version >= 228 && group > 0)
724 roi.serie = group;
725
726 roi.coord.Z = position;
727 if (channel > 0 || slice > 0 || frame > 0)
728 roi.coord = new AForge.ZCT(slice - 1, channel - 1, frame - 1);
729
730
731
733 {
734 for (
int i = 0; i < roi.
PointsD.Count; i++)
735 {
739 }
740 }
742 roi.closed = true;
743 return roi;
744 }
PointD ToStageSpace(PointD p)
Definition Bio.cs:3512
static int ROTATED_RECT
Definition ImageJ.cs:396
static int ROUNDED_RECT_ARC_SIZE
Definition ImageJ.cs:371
static int SCALE_STROKE_WIDTH
Definition ImageJ.cs:412
static int YD
Definition ImageJ.cs:357
static int POSITION
Definition ImageJ.cs:372
static int STROKE_WIDTH
Definition ImageJ.cs:361
static int TEXT
Definition ImageJ.cs:392
static int ELLIPSE
Definition ImageJ.cs:394
static int LEFT
Definition ImageJ.cs:348
static int Y1
Definition ImageJ.cs:353
static int TYPE
Definition ImageJ.cs:346
static int SIZE
Definition ImageJ.cs:360
static int RIGHT
Definition ImageJ.cs:350
static int SUBTYPE
Definition ImageJ.cs:365
static int X1
Definition ImageJ.cs:352
static int ARROW
Definition ImageJ.cs:393
static int N_COORDINATES
Definition ImageJ.cs:351
static int Y2
Definition ImageJ.cs:355
static int X2
Definition ImageJ.cs:354
static int WIDTHD
Definition ImageJ.cs:358
static int T_POSITION
Definition ImageJ.cs:378
static int VERSION_OFFSET
Definition ImageJ.cs:345
static int HEIGHTD
Definition ImageJ.cs:359
static int IMAGE_SIZE
Definition ImageJ.cs:385
static int BOTTOM
Definition ImageJ.cs:349
static int OVERLAY_LABEL_COLOR
Definition ImageJ.cs:381
static int Z_POSITION
Definition ImageJ.cs:377
static int SUB_PIXEL_RESOLUTION
Definition ImageJ.cs:406
static int IMAGE_OPACITY
Definition ImageJ.cs:384
static int DRAW_OFFSET
Definition ImageJ.cs:407
static int XD
Definition ImageJ.cs:356
static int C_POSITION
Definition ImageJ.cs:376
static int COORDINATES
Definition ImageJ.cs:374
static int GROUP
Definition ImageJ.cs:383
static int HEADER2_OFFSET
Definition ImageJ.cs:373
static int OPTIONS
Definition ImageJ.cs:366
static int OVERLAY_FONT_SIZE
Definition ImageJ.cs:382
static int TOP
Definition ImageJ.cs:347
static int SHAPE_ROI_SIZE
Definition ImageJ.cs:362
Definition ImageView.cs:23
static BioImage SelectedImage
Definition ImageView.cs:1559
void AddPoints(PointD[] p)
Definition Bio.cs:1025
bool subPixel
Definition Bio.cs:569
static ROI CreateEllipse(ZCT coord, double x, double y, double w, double h)
Definition Bio.cs:916
static ROI CreateLine(ZCT coord, PointD x1, PointD x2)
Definition Bio.cs:879
Type
Definition Bio.cs:394
void UpdateBoundingBox()
Definition Bio.cs:1125
List< PointD > PointsD
Definition Bio.cs:524
Type type
Definition Bio.cs:520
static ROI CreateRectangle(ZCT coord, double x, double y, double w, double h)
Definition Bio.cs:898