private INDArray asMatrix(BytePointer bytes, long length) throws IOException {
        PIXA pixa;
        pixa = pixaReadMemMultipageTiff(bytes, length);
        INDArray data;
        INDArray currentD;
        INDArrayIndex[] index = null;
        switch (this.multiPageMode) {
            case MINIBATCH:
                data = Nd4j.create(pixa.n(), 1, pixa.pix(0).h(), pixa.pix(0).w());
                break;
            case CHANNELS:
                data = Nd4j.create(1, pixa.n(), pixa.pix(0).h(), pixa.pix(0).w());
                break;
            case FIRST:
                data = Nd4j.create(1, 1, pixa.pix(0).h(), pixa.pix(0).w());
                PIX pix = pixa.pix(0);
                currentD = asMatrix(convert(pix));
                pixDestroy(pix);
                index = new INDArrayIndex[]{NDArrayIndex.point(0), NDArrayIndex.point(0),NDArrayIndex.all(),NDArrayIndex.all()};
                data.put(index , currentD.get(NDArrayIndex.all(), NDArrayIndex.all(),NDArrayIndex.all()));
                return data;
            default: throw new UnsupportedOperationException("Unsupported MultiPageMode: " + multiPageMode);
        }
        for (int i = 0; i < pixa.n(); i++) {
            PIX pix = pixa.pix(i);
            currentD = asMatrix(convert(pix));
            pixDestroy(pix);
            //TODO to change when 16-bit image is supported
            switch (this.multiPageMode) {
                case MINIBATCH:
                    index = new INDArrayIndex[]{NDArrayIndex.point(i), NDArrayIndex.all(),NDArrayIndex.all(),NDArrayIndex.all()};
                    break;
                case CHANNELS:
                    index = new INDArrayIndex[]{NDArrayIndex.all(), NDArrayIndex.point(i),NDArrayIndex.all(),NDArrayIndex.all()};
                    break;
                default: throw new UnsupportedOperationException("Unsupported MultiPageMode: " + multiPageMode);
            }
            data.put(index , currentD.get(NDArrayIndex.all(), NDArrayIndex.all(),NDArrayIndex.all()));
        }

        return data;
    }
private INDArray asMatrix ( BytePointer bytes , long length ) throws IOException { PIXA pixa ; pixa = pixaReadMemMultipageTiff ( bytes , length ) ; INDArray data ; INDArray currentD ; INDArrayIndex [ ] index = null ; switch ( this . multiPageMode ) { case MINIBATCH : data = Nd4j . create ( pixa . n ( ) , 1 , pixa . pix ( 0 ) . h ( ) , pixa . pix ( 0 ) . w ( ) ) ; break ; case CHANNELS : data = Nd4j . create ( 1 , pixa . n ( ) , pixa . pix ( 0 ) . h ( ) , pixa . pix ( 0 ) . w ( ) ) ; break ; case FIRST : data = Nd4j . create ( 1 , 1 , pixa . pix ( 0 ) . h ( ) , pixa . pix ( 0 ) . w ( ) ) ; PIX pix = pixa . pix ( 0 ) ; currentD = asMatrix ( convert ( pix ) ) ; pixDestroy ( pix ) ; index = new INDArrayIndex [ ] { NDArrayIndex . point ( 0 ) , NDArrayIndex . point ( 0 ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) } ; data . put ( index , currentD . get ( NDArrayIndex . all ( ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) ) ) ; return data ; default : throw new UnsupportedOperationException ( "Unsupported MultiPageMode: " + multiPageMode ) ; } for ( int i = 0 ; i < pixa . n ( ) ; i ++ ) { PIX pix = pixa . pix ( i ) ; currentD = asMatrix ( convert ( pix ) ) ; pixDestroy ( pix ) ; switch ( this . multiPageMode ) { case MINIBATCH : index = new INDArrayIndex [ ] { NDArrayIndex . point ( i ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) } ; break ; case CHANNELS : index = new INDArrayIndex [ ] { NDArrayIndex . all ( ) , NDArrayIndex . point ( i ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) } ; break ; default : throw new UnsupportedOperationException ( "Unsupported MultiPageMode: " + multiPageMode ) ; } data . put ( index , currentD . get ( NDArrayIndex . all ( ) , NDArrayIndex . all ( ) , NDArrayIndex . all ( ) ) ) ; } return data ; }
Read multipage tiff and load into INDArray

@param bytes
@return INDArray
@throws IOException