Quantization through Piecewise-Affine Regularization: Optimization and Statistical Guarantees