@@ -462,7 +462,16 @@ private double calculateCentroids(final ImagePlus imp, final double min,
462
462
final double max )
463
463
{
464
464
final ImageStack stack = imp .getImageStack ();
465
- final Rectangle r = stack .getRoi ();
465
+ int rx = 0 ; int ry = 0 ; int rwidth = 0 ; int rheight = 0 ;
466
+ if (imp .getRoi () == null ) {
467
+ rwidth = imp .getWidth ();
468
+ rheight = imp .getHeight ();
469
+ } else {
470
+ rx = imp .getRoi ().getBounds ().x ;
471
+ ry = imp .getRoi ().getBounds ().y ;
472
+ rwidth = imp .getRoi ().getBounds ().width ;
473
+ rheight = imp .getRoi ().getBounds ().height ;
474
+ }
466
475
// 2D centroids
467
476
sliceCentroids = new double [2 ][al ];
468
477
// pixel counters
@@ -473,8 +482,8 @@ private double calculateCentroids(final ImagePlus imp, final double min,
473
482
meanDensity = new double [al ];
474
483
weightedCentroids = new double [2 ][al ];
475
484
final double pixelArea = vW * vH ;
476
- final int roiXEnd = r . x + r . width ;
477
- final int roiYEnd = r . y + r . height ;
485
+ final int roiXEnd = rx + rwidth ;
486
+ final int roiYEnd = ry + rheight ;
478
487
for (int s = startSlice ; s <= endSlice ; s ++) {
479
488
IJ .showStatus ("Calculating centroids..." );
480
489
IJ .showProgress (s - startSlice , endSlice );
@@ -486,8 +495,8 @@ private double calculateCentroids(final ImagePlus imp, final double min,
486
495
double wSumX = 0 ;
487
496
double wSumY = 0 ;
488
497
final ImageProcessor ip = stack .getProcessor (s );
489
- for (int y = r . y ; y < roiYEnd ; y ++) {
490
- for (int x = r . x ; x < roiXEnd ; x ++) {
498
+ for (int y = ry ; y < roiYEnd ; y ++) {
499
+ for (int x = rx ; x < roiXEnd ; x ++) {
491
500
final double pixel = ip .get (x , y );
492
501
if (pixel >= min && pixel <= max ) {
493
502
count ++;
@@ -533,7 +542,16 @@ private void calculateMoments(final ImagePlus imp, final double min,
533
542
final double max )
534
543
{
535
544
final ImageStack stack = imp .getImageStack ();
536
- final Rectangle r = stack .getRoi ();
545
+ int rx = 0 ; int ry = 0 ; int rwidth = 0 ; int rheight = 0 ;
546
+ if (imp .getRoi () == null ) {
547
+ rwidth = imp .getWidth ();
548
+ rheight = imp .getHeight ();
549
+ } else {
550
+ rx = imp .getRoi ().getBounds ().x ;
551
+ ry = imp .getRoi ().getBounds ().y ;
552
+ rwidth = imp .getRoi ().getBounds ().width ;
553
+ rheight = imp .getRoi ().getBounds ().height ;
554
+ }
537
555
theta = new double [al ];
538
556
for (int s = startSlice ; s <= endSlice ; s ++) {
539
557
IJ .showStatus ("Calculating Ix and Iy..." );
@@ -543,16 +561,16 @@ private void calculateMoments(final ImagePlus imp, final double min,
543
561
double sxxs = 0 ;
544
562
double syys = 0 ;
545
563
double sxys = 0 ;
546
- final int roiXEnd = r . x + r . width ;
547
- final int roiYEnd = r . y + r . height ;
564
+ final int roiXEnd = rx + rwidth ;
565
+ final int roiYEnd = ry + rheight ;
548
566
if (emptySlices [s ]) {
549
567
theta [s ] = Double .NaN ;
550
568
continue ;
551
569
}
552
570
final ImageProcessor ip = stack .getProcessor (s );
553
571
double sumAreaFractions = 0 ;
554
- for (int y = r . y ; y < roiYEnd ; y ++) {
555
- for (int x = r . x ; x < roiXEnd ; x ++) {
572
+ for (int y = ry ; y < roiYEnd ; y ++) {
573
+ for (int x = rx ; x < roiXEnd ; x ++) {
556
574
final double pixel = ip .get (x , y );
557
575
if (pixel >= min && pixel <= max ) {
558
576
final double xVw = x * vW ;
@@ -615,7 +633,16 @@ private double[][] calculateAngleMoments(final ImagePlus imp,
615
633
final double min , final double max , final double [] angles )
616
634
{
617
635
final ImageStack stack = imp .getImageStack ();
618
- final Rectangle r = stack .getRoi ();
636
+ int rx = 0 ; int ry = 0 ; int rwidth = 0 ; int rheight = 0 ;
637
+ if (imp .getRoi () == null ) {
638
+ rwidth = imp .getWidth ();
639
+ rheight = imp .getHeight ();
640
+ } else {
641
+ rx = imp .getRoi ().getBounds ().x ;
642
+ ry = imp .getRoi ().getBounds ().y ;
643
+ rwidth = imp .getRoi ().getBounds ().width ;
644
+ rheight = imp .getRoi ().getBounds ().height ;
645
+ }
619
646
final double [] I1 = new double [al ];
620
647
final double [] I2 = new double [al ];
621
648
final double [] Ip = new double [al ];
@@ -654,15 +681,15 @@ private double[][] calculateAngleMoments(final ImagePlus imp,
654
681
double maxRadCentreS = 0 ;
655
682
final double cosTheta = Math .cos (angles [s ]);
656
683
final double sinTheta = Math .sin (angles [s ]);
657
- final int roiYEnd = r . y + r . height ;
658
- final int roiXEnd = r . x + r . width ;
684
+ final int roiYEnd = ry + rheight ;
685
+ final int roiXEnd = rx + rwidth ;
659
686
final double xC = sliceCentroids [0 ][s ];
660
687
final double yC = sliceCentroids [1 ][s ];
661
688
final double cS = cslice [s ];
662
689
double sumAreaFractions = 0 ;
663
- for (int y = r . y ; y < roiYEnd ; y ++) {
690
+ for (int y = ry ; y < roiYEnd ; y ++) {
664
691
final double yYc = y * vH - yC ;
665
- for (int x = r . x ; x < roiXEnd ; x ++) {
692
+ for (int x = rx ; x < roiXEnd ; x ++) {
666
693
final double pixel = ip .get (x , y );
667
694
if (pixel >= min && pixel <= max ) {
668
695
final double areaFraction = doPartialVolume ? filledFraction (
@@ -749,7 +776,16 @@ private void calculateThickness3D(final ImagePlus imp, final double min,
749
776
maxCortThick3D = new double [al ];
750
777
meanCortThick3D = new double [al ];
751
778
stdevCortThick3D = new double [al ];
752
- final Rectangle r = imp .getProcessor ().getRoi ();
779
+ int rx = 0 ; int ry = 0 ; int rwidth = 0 ; int rheight = 0 ;
780
+ if (imp .getRoi () == null ) {
781
+ rwidth = imp .getWidth ();
782
+ rheight = imp .getHeight ();
783
+ } else {
784
+ rx = imp .getRoi ().getBounds ().x ;
785
+ ry = imp .getRoi ().getBounds ().y ;
786
+ rwidth = imp .getRoi ().getBounds ().width ;
787
+ rheight = imp .getRoi ().getBounds ().height ;
788
+ }
753
789
754
790
// convert to binary
755
791
final ImagePlus binaryImp = convertToBinary (imp , min , max );
@@ -768,10 +804,10 @@ private void calculateThickness3D(final ImagePlus imp, final double min,
768
804
double sumPix = 0 ;
769
805
double sliceMax = 0 ;
770
806
double pixCount = 0 ;
771
- final int roiXEnd = r . x + r . width ;
772
- final int roiYEnd = r . y + r . height ;
773
- for (int y = r . y ; y < roiYEnd ; y ++) {
774
- for (int x = r . x ; x < roiXEnd ; x ++) {
807
+ final int roiXEnd = rx + rwidth ;
808
+ final int roiYEnd = ry + rheight ;
809
+ for (int y = ry ; y < roiYEnd ; y ++) {
810
+ for (int x = rx ; x < roiXEnd ; x ++) {
775
811
final float pixel = Float .intBitsToFloat (ip .get (x , y ));
776
812
if (pixel > 0 ) {
777
813
pixCount ++;
@@ -785,8 +821,8 @@ private void calculateThickness3D(final ImagePlus imp, final double min,
785
821
maxCortThick3D [s ] = sliceMax ;
786
822
787
823
double sumSquares = 0 ;
788
- for (int y = r . y ; y < roiYEnd ; y ++) {
789
- for (int x = r . x ; x < roiXEnd ; x ++) {
824
+ for (int y = ry ; y < roiYEnd ; y ++) {
825
+ for (int x = rx ; x < roiXEnd ; x ++) {
790
826
final float pixel = Float .intBitsToFloat (ip .get (x , y ));
791
827
if (pixel > 0 ) {
792
828
final double d = sliceMean - pixel ;
@@ -1035,7 +1071,16 @@ public void run() {
1035
1071
}
1036
1072
final ImageProcessor ip = impT .getImageStack ().getProcessor (s );
1037
1073
final ImagePlus sliceImp = new ImagePlus (" " + s , ip );
1038
- final Rectangle r = ip .getRoi ();
1074
+ int rx = 0 ; int ry = 0 ; int rwidth = 0 ; int rheight = 0 ;
1075
+ if (sliceImp .getRoi () == null ) {
1076
+ rwidth = sliceImp .getWidth ();
1077
+ rheight = sliceImp .getHeight ();
1078
+ } else {
1079
+ rx = sliceImp .getRoi ().getBounds ().x ;
1080
+ ry = sliceImp .getRoi ().getBounds ().y ;
1081
+ rwidth = sliceImp .getRoi ().getBounds ().width ;
1082
+ rheight = sliceImp .getRoi ().getBounds ().height ;
1083
+ }
1039
1084
// binarise
1040
1085
final ImagePlus binaryImp = convertToBinary (sliceImp , min , max );
1041
1086
final Calibration cal = impT .getCalibration ();
@@ -1047,10 +1092,10 @@ public void run() {
1047
1092
double sumPix = 0 ;
1048
1093
double sliceMax = 0 ;
1049
1094
double pixCount = 0 ;
1050
- final double roiXEnd = r . x + r . width ;
1051
- final double roiYEnd = r . y + r . height ;
1052
- for (int y = r . y ; y < roiYEnd ; y ++) {
1053
- for (int x = r . x ; x < roiXEnd ; x ++) {
1095
+ final double roiXEnd = rx + rwidth ;
1096
+ final double roiYEnd = ry + rheight ;
1097
+ for (int y = ry ; y < roiYEnd ; y ++) {
1098
+ for (int x = rx ; x < roiXEnd ; x ++) {
1054
1099
final float pixel = Float .intBitsToFloat (thickIp .get (x , y ));
1055
1100
if (pixel > 0 ) {
1056
1101
pixCount ++;
@@ -1064,8 +1109,8 @@ public void run() {
1064
1109
maxThick [s ] = sliceMax ;
1065
1110
1066
1111
double sumSquares = 0 ;
1067
- for (int y = r . y ; y < roiYEnd ; y ++) {
1068
- for (int x = r . x ; x < roiXEnd ; x ++) {
1112
+ for (int y = ry ; y < roiYEnd ; y ++) {
1113
+ for (int x = rx ; x < roiXEnd ; x ++) {
1069
1114
final float pixel = Float .intBitsToFloat (thickIp .get (x , y ));
1070
1115
if (pixel > 0 ) {
1071
1116
final double d = sliceMean - pixel ;
0 commit comments