Buggy code:
public > getLayoutFromMultiSeriesFile ( final String multiSeriesFile , final double increaseOverlap , final boolean ignoreCalibration ) { } protected ArrayList < ImageCollectionElement > getLayoutFromFile ( final String directory , final String layoutFile ) { } protected ArrayList < ImageCollectionElement > getAllFilesInDirectory ( final String directory , final boolean confirmFiles ) { } protected ArrayList < ImageCollectionElement > getGridLayout ( final GridType grid , final int gridSizeX , final int gridSizeY , final double overlap , final String directory , final String filenames , final int startI , final int startX , final int startY ) { final int gridType = grid . getType ( ) ; final int gridOrder = grid . getOrder ( ) ; String replaceX = "{" ; String replaceY = "{" ; String replaceI = "{" ; int numXValues = 0 ; int numYValues = 0 ; int numIValues = 0 ; if ( ( grid . getType ( ) ) < 4 ) { int i1 = filenames . indexOf ( "{i" ) ; int i2 = filenames . indexOf ( "i}" ) ; if ( ( i1 >= 0 ) && ( i2 > 0 ) ) { numIValues = i2 - i1 ; for ( int i = 0 ; i < numIValues ; i ++ ) replaceI += "i" ; replaceI += "}" ; } else { replaceI = "\\\\\\\\" ; } } else { int x1 = filenames . indexOf ( "{x" ) ; int x2 = filenames . indexOf ( "x}" ) ; if ( ( x1 >= 0 ) && ( x2 > 0 ) ) { numXValues = x2 - x1 ; for ( int i = 0 ; i < numXValues ; i ++ ) replaceX += "x" ; replaceX += "}" ; } else { replaceX = "\\\\\\\\" ; } int y1 = filenames . indexOf ( "{y" ) ; int y2 = filenames . indexOf ( "y}" ) ; if ( ( y1 >= 0 ) && ( y2 > 0 ) ) { numYValues = y2 - y1 ; for ( int i = 0 ; i < numYValues ; i ++ ) replaceY += "y" ; replaceY += "}" ; } else { replaceY = "\\\\\\\\" ; } } final ImageCollectionElement [ ] [ ] gridLayout = new ImageCollectionElement [ gridSizeX ] [ gridSizeY ] ; if ( ( grid . getType ( ) ) < 4 ) { final int [ ] position = new int [ 2 ] ; for ( int i = 0 ; i < ( gridSizeX * gridSizeY ) ; ++ i ) { getPosition ( position , i , gridType , gridOrder , gridSizeX , gridSizeY ) ; final String file = filenames . replace ( replaceI , Stitching_Grid . getLeadingZeros ( numIValues , ( i + startI ) ) ) ; gridLayout [ position [ 0 ] ] [ position [ 1 ] ] = new ImageCollectionElement ( new File ( directory , file ) , i ) ; } } else { int i = 0 ; for ( int y = 0 ; y < gridSizeY ; ++ y ) for ( int x = 0 ; x < gridSizeX ; ++ x ) { final String file = filenames . replace ( replaceX , Stitching_Grid . getLeadingZeros ( numXValues , ( x + startX ) ) ) . replace ( replaceY , Stitching_Grid . getLeadingZeros ( numYValues , ( y + startY ) ) ) ; gridLayout [ x ] [ y ] = new ImageCollectionElement ( new File ( directory , file ) , ( i ++ ) ) ; } } int minWidth = Integer . MAX_VALUE ; int minHeight = Integer . MAX_VALUE ; int minDepth = Integer . MAX_VALUE ; boolean is2d = false ; boolean is3d = false ; for ( int y = 0 ; y < gridSizeY ; ++ y ) for ( int x = 0 ; x < gridSizeX ; ++ x ) { IJ . log ( ( ( ( ( ( ( "Loading<seq2seq4repair_space>(" + x ) + ",<seq2seq4repair_space>" ) + y ) + "):<seq2seq4repair_space>" ) + ( gridLayout [ x ] [ y ] . getFile ( ) . getAbsolutePath ( ) ) ) + "<seq2seq4repair_space>...<seq2seq4repair_space>" ) ) ; long time = System . currentTimeMillis ( ) ; final ImagePlus imp = gridLayout [ x ] [ y ] . open ( ) ; time = ( System . currentTimeMillis ( ) ) - time ; if ( imp == null ) return null ; if ( ( imp . getNSlices ( ) ) > 1 ) { IJ . log ( ( ( ( ( ( ( ( ( ( ( ( ( "" + ( imp . getWidth ( ) ) ) + "x" ) + ( imp . getHeight ( ) ) ) + "x" ) + ( imp . getNSlices ( ) ) ) + "px,<seq2seq4repair_space>channels=" ) + ( imp . getNChannels ( ) ) ) + ",<seq2seq4repair_space>timepoints=" ) + ( imp . getNFrames ( ) ) ) + "<seq2seq4repair_space>(" ) + time ) + "<seq2seq4repair_space>ms)" ) ) ; is3d = true ; } else { IJ . log ( ( ( ( ( ( ( ( ( ( ( "" + ( imp . getWidth ( ) ) ) + "x" ) + ( imp . getHeight ( ) ) ) + "px,<seq2seq4repair_space>channels=" ) + ( imp . getNChannels ( ) ) ) + ",<seq2seq4repair_space>timepoints=" ) + ( imp . getNFrames ( ) ) ) + "<seq2seq4repair_space>(" ) + time ) + "<seq2seq4repair_space>ms)" ) ) ; is2d = true ; } if ( is2d && is3d ) { IJ . log ( "Some<seq2seq4repair_space>images<seq2seq4repair_space>are<seq2seq4repair_space>2d,<seq2seq4repair_space>some<seq2seq4repair_space>are<seq2seq4repair_space>3d<seq2seq4repair_space>...<seq2seq4repair_space>cannot<seq2seq4repair_space>proceed" ) ; return null ; } if ( ( imp . getWidth ( ) ) < minWidth ) minWidth = imp . getWidth ( ) ; if ( ( imp . getHeight ( ) ) < minHeight ) minHeight = imp . getHeight ( ) ; if ( ( imp . getNSlices ( ) ) < minDepth ) minDepth = imp . getNSlices ( ) ; } final int dimensionality ; if ( is3d ) dimensionality = 3 ; else dimensionality = 2 ; int xoffset = 0 ; int yoffset = 0 ; int zoffset = 0 ; final ArrayList < ImageCollectionElement > elements = new ArrayList < ImageCollectionElement > ( ) ; for ( int y = 0 ; y < gridSizeY ; y ++ ) { if ( y == 0 ) yoffset = 0 ; else <START_BUG> yoffset += ( ( int ) ( minWidth * ( 1 - overlap ) ) ) ; <END_BUG>

Fix:
yoffset += ( ( int ) ( minHeight * ( 1 - overlap ) ) ) ;