Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added standard error of the mean to statistics_of_labelled_pixels #267

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyclesperanto_prototype/_tier9/_push_regionprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def push_regionprops(props : Union[dict, RegionProperties], first_row_index : in
# MAX_DISTANCE_TO_CENTROID = 34
props['max_distance_to_centroid'],
# MAX_MEAN_DISTANCE_TO_CENTROID_RATIO = 35
props['mean_max_distance_to_centroid_ratio']
props['mean_max_distance_to_centroid_ratio'],
# STANDARD_ERROR_INTENSITY = 36
props['standard_error_intensity']
]

matrix = np.asarray(list).T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def statistics_of_labelled_pixels(intensity_image : Image = None, label_image :
power(sum_dim, result_vector, 0.5)
region_props['standard_deviation_intensity'] = pull(result_vector)[0]

# standard error intensity
region_props['standard_error_intensity'] = region_props['standard_deviation_intensity'] / np.sqrt(region_props['area'])

crop(max_statistics, result_vector, measurements_start_x, 4, 0)
region_props['max_distance_to_centroid'] = pull(result_vector)[0]
crop(max_statistics, result_vector, measurements_start_x, 5, 0)
Expand Down
17 changes: 12 additions & 5 deletions tests/test_statistics_of_labelled_pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ def test_statistics_of_labelled_pixels():
[0.65403885, 0.65403885, 0.6666667],
# MAX_DISTANCE_TO_CENTROID(34),
[0.74535596, 0.745356, 1.],
# MAX_MEAN_DISTANCE_TO_CENTROID_RATIO(35);
[1.1396203, 1.1396204, 1.5]
# MAX_MEAN_DISTANCE_TO_CENTROID_RATIO(35),
[1.1396203, 1.1396204, 1.5],
# STANDARD_ERROR_INTENSITY(36);
[0.27216553, 0.27216551, 0.4714043]
]
))

Expand Down Expand Up @@ -205,8 +207,10 @@ def test_statistics_of_labelled_pixels_3d():
[0.65403885, 0.65403885, 0.6666667],
# MAX_DISTANCE_TO_CENTROID(34),
[0.74535596, 0.745356, 1.],
# MAX_MEAN_DISTANCE_TO_CENTROID_RATIO(35);
[1.1396203, 1.1396204, 1.5]
# MAX_MEAN_DISTANCE_TO_CENTROID_RATIO(35),
[1.1396203, 1.1396204, 1.5],
# STANDARD_ERROR_INTENSITY(36);
[0.27216553, 0.27216551, 0.4714043]
]
))

Expand All @@ -226,7 +230,7 @@ def test_statistics_of_labelled_pixels_3d():
assert (np.allclose(a, b, 0.0001))


def test_standard_deviation():
def test_standard_deviation_and_standard_error():
import numpy as np

image = np.asarray([
Expand All @@ -243,11 +247,14 @@ def test_standard_deviation():

print("numpy standard deviation", np.std(image))
print("numpy variance", np.var(image))
print("numpy standard error", np.std(image) / np.sqrt(image.size))

stats = cle.statistics_of_labelled_pixels(image, labels)

print("std", stats['standard_deviation_intensity'][0])
print("sterr", stats['standard_error_intensity'][0])

from numpy import testing
testing.assert_almost_equal(stats['standard_deviation_intensity'][0], 2.58, decimal=1)
testing.assert_almost_equal(stats['standard_error_intensity'][0], 0.86, decimal=1)