PCA Color Augmentation

Core Vision Operations DS practice problem on Onlearn.

Difficulty: hard.

Topics: PCA Color Augmentation, Eigenvalue Decomposition, Principal Components, Covariance Matrix, RGB Channel Correlation, Jittering, Linear Algebra, Computer Vision, Statistical Learning, Data Preprocessing, Multivariate Analysis, Matrix Decompositions, Color Space Transformations, Dimensionality Reduction, Data Augmentation, Feature Engineering.

Implement the PCA color distortion technique used in AlexNet for data augmentation. This method applies PCA to the RGB pixel values of natural images, then adds multiples of the principal components with magnitudes proportional to the corresponding eigenvalues times a random variable. Given an RGB image (H, W, 3), compute the principal components of RGB values and apply the color distortion with specified alpha values. The alpha array is ordered to correspond to the principal components sorted by eigenvalue in descending order (i.e., alpha[0] pairs with the largest eigenvalue). Clamp the final pixel values to the valid range [0, 255].