Стандартное отклонение значений пикселей от 2D NPS – сумма или среднее значение NPS?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Стандартное отклонение значений пикселей от 2D NPS – сумма или среднее значение NPS?

Сообщение Anonymous »

Я пытаюсь оценить стандартное отклонение значений пикселей в пространственной области на основе 2D NPS в Python.
Я ожидаю, что мне понадобится сумма значений 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}")
Стандартное отклонение от NPS: 3692,2142651255785
Стандартное отклонение непосредственно от изображения: 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}")
Стандартное отклонение от NPS: 28,894608971414826
Стандартное отклонение непосредственно от изображения: 28,894608971414826

Подробнее здесь: https://stackoverflow.com/questions/787 ... ean-of-nps
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»