大气湍流模拟算法
大氣湍流模糊的算法模擬(python語言實現)
** 簡介 **:
為了深入研究大氣湍流的成因以及其對成像質量的影響,前蘇聯學者Kolmogorov 提出了湍流模型,該模型得到了很多實驗的支持,并且廣泛應用于天文成像仿真過程。 該理論認為大氣湍流引起的波前畸變來自大氣折射率的變化,正是這種折射率的隨機變化導致了光波位相分布的隨機起伏。通常從空間和時間兩方面來描述大氣湍流的強弱:
(1)大氣相干長度 r0 表征了大氣湍流的空間強度。它的物理意義是:在直徑為 r0 的圓內,由大氣湍流引起的波前畸變的方差為 1 rad2。
(2)格林伍德頻率 fG 表征了大氣湍流的時間強度。它的物理意義是:大氣湍流引起的波前畸變中高于格林伍德頻率的成分的方差為 1 rad2
兩種仿真方式
第一種方式,整體扭曲,局部模糊,算法流程如下:
具體的代碼實現:
import numpy as np import cv2 from skimage.transform import PiecewiseAffineTransform, warp import matplotlib.pyplot as pltdef DistortBlur(img, S, sigma_kernel_vertor_field, sigma_blur_image, N=15, M_distortion=1000, M_blur=50):"""Return an artificially distorted image.:param img: np array - image=(h, w, 3):param S: float - distortion strength:param sigma_kernel_vertor_field: float - std of the kernel when smoothing the vector field a each iteration:param N: int - half size of the patch:param M_distortion: int - number of iterations for generating vector field patches:param M_blur: int - number of iterations for performing high blur in random patches:return:"""assert (N % 2) == 1, "N must be odd!."img_height, img_width, img_channel = img.shape# generate the grid of the src imagesrc_cols = np.arange(0, img_width)src_rows = np.arange(0, img_height)src_cols, src_rows = np.meshgrid(src_cols, src_rows)src = np.dstack([src_cols.flat, src_rows.flat])[0]# generate the vector fieldvector_field = np.zeros(shape=(img_height, img_width, 2), dtype=np.float32)for i in range(M_distortion):x = np.random.randint(low=0, high=img_width - 2 * N) + Ny = np.random.randint(low=0, high=img_height - 2 * N) + Nvector_field_current_patch_x = np.random.randn(2 * N, 2 * N)vector_field_current_patch_y = np.random.randn(2 * N, 2 * N)vector_field_current_patch_x = S * cv2.GaussianBlur(vector_field_current_patch_x,ksize=(N // 2, N // 2),sigmaX=sigma_kernel_vertor_field)vector_field_current_patch_y = S * cv2.GaussianBlur(vector_field_current_patch_y,ksize=(N // 2, N // 2),sigmaX=sigma_kernel_vertor_field)vector_field[y - N:y + N, x - N:x + N, 0] = vector_field[y - N:y + N, x - N:x + N,0] + vector_field_current_patch_xvector_field[y - N:y + N, x - N:x + N, 1] = vector_field[y - N:y + N, x - N:x + N,1] + vector_field_current_patch_yvector_field[:, :, 0] = cv2.GaussianBlur(vector_field[:, :, 0],ksize=(N // 2, N // 2),sigmaX=sigma_kernel_vertor_field)vector_field[:, :, 1] = cv2.GaussianBlur(vector_field[:, :, 1],ksize=(N // 2, N // 2),sigmaX=sigma_kernel_vertor_field)# generate the grid of the ouput imagedst_cols = np.arange(0, img_width)dst_rows = np.arange(0, img_height)dst_cols, dst_rows = np.meshgrid(dst_cols, dst_rows)dst_cols, dst_rows = dst_cols.astype('float32'), dst_rows.astype('float32')dst_rows += vector_field[:, :, 0]dst_cols += vector_field[:, :, 1]dst = np.dstack([dst_cols.flat, dst_rows.flat])[0]# compute the transformtform = PiecewiseAffineTransform()step = 20src, dst = src[step // 2:-1:step], dst[step // 2:-1:step]tform.estimate(src, dst)# perform the transformdistorded_image = warp(img, tform, output_shape=(img_height, img_width))# blur the image globallydistorded_image = cv2.GaussianBlur(distorded_image, (N, N), sigma_blur_image)# blur the image in random patchfor i in range(M_blur):x = np.random.randint(low=0, high=img_width - 2 * N) + Ny = np.random.randint(low=0, high=img_height - 2 * N) + Ncurrent_patch = distorded_image[y - N:y + N, x - N:x + N, :]current_patch = cv2.GaussianBlur(current_patch, (N, N), sigma_blur_image)distorded_image[y - (N - 1) // 2:y + (N - 1) // 2 + 1,x - (N - 1) // 2:x + (N - 1) // 2 + 1, :] = current_patch[(N - 1) // 2 + 1:3 * (N - 1) // 2 + 2,(N - 1) // 2 + 1:3 * (N - 1) // 2 + 2, :]# blur the image globallydistorded_image = cv2.GaussianBlur(distorded_image, (N, N), sigma_blur_image / 10)return distorded_image網絡模擬(自己詳見論文吧!這個還挺有用的)
參考文獻為《Accelerating Atmospheric Turbulence Simulation via Learned
Phase-to-Space Transform》:鏈接: link.
** 如果覺得有用就點個贊吧 **
總結
- 上一篇: 评价星星三级样式:好、一般、差
- 下一篇: bga封装扇出_0.5间距BGA封装,怎