最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

signal processing - How do I simulate image magnification using Angular Spectrum Method? - Stack Overflow

programmeradmin3浏览0评论

I have written a code that forms the image of an input image at some distance z. All the parameters I have used (pixel size, no. of pixels, z, etc.) are mentioned later in the question. The objective of the program is simulate magnification in an optical system using Fresnel propagation under spherical wave illumination give as:

$$u_{inp}=\exp(i\beta{(x^2+y^2)})$$

with varying curvatures $(\beta)$. The final image that I am getting is too distorted. If I adjust some parameters, I can no longer magnify the image. What is it that I am not implementing correctly. I have already tried simulating this magnification process using a 4F system and I didn't encounter such problem.

To keep things simple, I have started with an image of a line on a plain background.

This particular case of the output image is for:

$p=1\mu m$
$N_{pixels}= 200$
$\lambda=700 nm$

and this is the closest I've got where the output image at least resembles what I am doing, (except for $z=0$ or $\beta = 0$ which is just $M_{magnification}=1$)

and here's the code:

import numpy as np
from numpy.fft import fftshift, ifftshift, fft2, ifft2
import matplotlib.pyplot as plt
import cv2

def fresnel_magnification(img, p, N, ld, b, z):
    # pixel dimensions
    dx, dy = p, p

    # Spatial dimensions
    Lx, Ly = N * dx, N * dy

    # Image Grid
    m, n = np.meshgrid(np.arange(-N / 2, N / 2), np.arange(-N / 2, N / 2))
    x, y = m * dx, n * dy

    # Frequency Grid (Fixed)
    fx, fy = np.arange(-N / 2, N / 2) / Lx, np.arange(-N / 2, N / 2) / Ly
    fx, fy = np.meshgrid(fx, fy)

    # Wavelength and Propagation Constant
    k = 2 * np.pi / ld

    # Image Loading
    g1 = cv2.resize(img, (N, N))

    # Beta factor adjustment
    b = b * 1e+10

    # Applying Illumination function
    u_inp = np.exp(1j * b * (x ** 2 + y ** 2))
    # u_inp /= np.max(u_inp)
    g1 = u_inp * g1

    # ASM Propagation: g1 to g2
    alpha = np.sqrt(k ** 2 - 4 * np.pi ** 2 * (fx ** 2 + fy ** 2) + 0j)
    G1 = fftshift(fft2(ifftshift(g1)))
    H = np.exp(1j * alpha * z)
    G2 = G1 * H
    g2 = fftshift(ifft2(ifftshift(G2)))

    plt.figure(figsize=(10, 6))
    plt.subplot(1, 2, 1)
    plt.imshow(np.abs(g1), cmap='gray')

    plt.subplot(1, 2, 2)
    plt.imshow(np.abs(g2), cmap='gray')

    plt.show()

    return np.abs(g2)

fresnel_magnification(cv2.imread('test3.jpg', 0), 1e-6, 200, 700e-9, 1., 1e-5)

Can someone please tell me the algorithm to carry out this operation. I don't want the code, just the algorithm would be fine. But if what I am doing is already correct, except a few changes, please suggest me those.

发布评论

评论列表(0)

  1. 暂无评论