Implement the PCA color distortion technique used in AlexNet for data augmentation. This method applies PCA to the RGB pixel values of the image, then adds the same multiples of the principal components to every pixel. Given an RGB image (H, W, 3), compute the principal components of RGB values and apply the color distortion with specified alpha values:
where the columns of are the eigenvectors of the covariance matrix of the RGB values and holds the matching eigenvalues. Each component is scaled by , its coefficient times the standard deviation along that component (the original AlexNet paper scales by itself; use the square root here).
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).
Eigenvectors are only defined up to sign, so use np.linalg.eigh on the covariance matrix (computed with np.cov) to fix the sign convention. Decomposing with np.linalg.svd or np.linalg.eig returns sign-flipped second and third components and will not match the expected values.
Clamp the final pixel values to the valid range [0, 255].