'Detecting a "skewed" image via FFT2
I have the following distorted image which I've computed by reshaping the image to have one more row and one less column than it's supposed to.
nr = true_nr+1
nc = true_nc-1
img = stream[:nr*nc].reshape((nr, nc, 3))
from skimage.color import rgb2gray
dark_image_grey = rgb2gray(img)
Here is its resulting FFT2 transform:
dark_image_grey_fourier = np.fft.fftshift(np.fft.fft2(dark_image_grey))
plt.figure(num=None, figsize=(8, 6), dpi=80)
fft_image = np.log(abs(dark_image_grey_fourier))
plt.imshow(fft_image, cmap='gray');
Notice above that because of the diagonal skew of the image, the lighter regions of the fourier spectrum run at a 45 degree angle to the x/y frequency axes.
I'm trying to figure out how to estimate that this is indeed skewed, compared to the FFT2 for the undistorted image:
One thought I had was to fit a isotropic 2D Gaussian to the data, centered at the center pixel, and then examine the 2D covariance matrix to see if the off-diagonal terms are non-zero. But I'm not sure if there is a more elegant solution that is admitted by the Fourier transform itself. Any suggestions?
Solution 1:[1]
You can use 2D principal component analysis (PCA) on the 2D FFT data to figure out how much the image is skewed and in which direction.
PCA is normally applied to a collection of points. To apply it to your FFT data, consider the energy of each bit to be point density, i.e., consider a bin (fx,fy) with energy E to represent E points at position (fx,fy).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt Timmermans |



