private static Stack<Matrix> getAllSubMatrix(Matrix matrix) {
        Stack<Matrix> matrixStack = new Stack<>();

        for (int x = 0; x < matrix.data.length; x++)
            for (int y = 0; y < matrix.data[x].length; y++)
                for (int i = 0; i < matrix.data.length; i++) {
                    for (int j = 0; j < matrix.data[i].length; j++) {

                        Matrix subMatrix = null;
                        try {
                            subMatrix = matrix.getSubMatrix(x, y, i + 1, j + 1);
                            if ((subMatrix == null)) {
                                continue;
                            }
                            if (matrixStack.contains(subMatrix)) {
                                continue;
                            }

                            matrixStack.add(subMatrix);
                        } catch (Exception e) {
                        }

                    }

                }


        return matrixStack;
    }