Я ожидаю, что мне понадобится сумма значений NPS, разделенная на общее количество пикселей. Однако я могу получить правильную оценку только путем деления среднего значения на общее количество пикселей.
Может ли кто-нибудь указать мне, почему это так?
См. примеры кода ниже.
"SUM:"
Код: Выделить всё
import numpy as np
from scipy.fftpack import fft2, fftshift
# Generate a random 128x128 image
image = np.random.rand(128, 128)*100
# Subtract the mean of the image
image = image - np.mean(image)
# Compute the 2D Fourier transform of the image
F = fft2(image)
# Shift the zero frequency component to the center
F_shifted = fftshift(F)
# Calculate the Noise Power Spectrum (NPS)
NPS = np.abs(F_shifted)**2
# Calculate the total power in the NPS
total_power = np.sum(NPS)
# The total power in the NPS corresponds to the sum of the squared deviations
# from the mean in the spatial domain. For an image of size NxN:
N = image.shape[0]
variance_from_nps = total_power / (N * N)
# Compute the standard deviation from the variance
sigma_from_nps = np.sqrt(variance_from_nps)
# Compute the standard deviation directly from the image
sd_direct = np.std(image)
print(f"Standard Deviation from NPS: {sigma_from_nps}")
print(f"Standard Deviation directly from the image: {sd_direct}")
Стандартное отклонение непосредственно от изображения: 28,84542394629358
"Среднее:"
Код: Выделить всё
import numpy as np
from scipy.fftpack import fft2, fftshift
# Generate a random 128x128 image
image = np.random.rand(128, 128)*100
# Subtract the mean of the image
image = image - np.mean(image)
# Compute the 2D Fourier transform of the image
F = fft2(image)
# Shift the zero frequency component to the center
F_shifted = fftshift(F)
# Calculate the Noise Power Spectrum (NPS)
NPS = np.abs(F_shifted)**2
# Calculate the total power in the NPS
total_power = np.mean(NPS)
# The total power in the NPS corresponds to the sum of the squared deviations
# from the mean in the spatial domain. For an image of size NxN:
N = image.shape[0]
variance_from_nps = total_power / (N * N)
# Compute the standard deviation from the variance
sigma_from_nps = np.sqrt(variance_from_nps)
# Compute the standard deviation directly from the image
sd_direct = np.std(image)
print(f"Standard Deviation from NPS: {sigma_from_nps}")
print(f"Standard Deviation directly from the image: {sd_direct}")
Стандартное отклонение непосредственно от изображения: 28,894608971414826
Подробнее здесь: https://stackoverflow.com/questions/787 ... ean-of-nps