Skip to content

Commit

Permalink
Fixed manual gamma filtering. this refs #9
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Mar 15, 2022
1 parent e38b302 commit fc44066
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 116 deletions.
16 changes: 0 additions & 16 deletions ImagingReso.egg-info/PKG-INFO

This file was deleted.

15 changes: 0 additions & 15 deletions ImagingReso.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion ImagingReso.egg-info/dependency_links.txt

This file was deleted.

6 changes: 0 additions & 6 deletions ImagingReso.egg-info/requires.txt

This file was deleted.

1 change: 0 additions & 1 deletion ImagingReso.egg-info/top_level.txt

This file was deleted.

2 changes: 1 addition & 1 deletion NeuNorm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.1"
__version__ = "1.5.2"


class DataType:
Expand Down
1 change: 1 addition & 0 deletions NeuNorm/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def make_tif(data=[], metadata=[], file_name=''):
new_image = Image.fromarray(data)
new_image.save(file_name, tiffinfo=metadata)


def make_fits(data=[], file_name=''):
'''create fits file'''
fits.writeto(file_name, data, overwrite=True)
3 changes: 2 additions & 1 deletion NeuNorm/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def load_fits(file_name):
return tmp
except OSError:
raise OSError("Unable to read the FITS file provided!")



def load_tiff(file_name):
'''load tiff image
Expand Down
13 changes: 6 additions & 7 deletions NeuNorm/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import time
from scipy.ndimage import convolve
from scipy.ndimage import median_filter

from NeuNorm.loader import load_hdf, load_tiff, load_fits
from NeuNorm.exporter import make_fits, make_tif
Expand Down Expand Up @@ -356,7 +357,7 @@ def _auto_gamma_filtering(self, data=None):

return data_gamma_filtered

def _manual_gamma_filtering(self, data=None, manual_gamma_threshold=0.1):
def _manual_gamma_filtering(self, data=None, manual_gamma_threshold=0.95):
"""perform manual gamma filtering on the data
This algoritm uses the manual_gamma_threshold value to estimate if a pixel is a gamma or not.
Expand All @@ -379,13 +380,11 @@ def _manual_gamma_filtering(self, data=None, manual_gamma_threshold=0.1):
raise ValueError("Data array is empty!")

data_gamma_filtered = np.copy(data)
mean_counts = np.mean(data_gamma_filtered)
gamma_indexes = np.where(manual_gamma_threshold * data_gamma_filtered > mean_counts)

mean_kernel = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]]) / 8.0
convolved_data = convolve(data_gamma_filtered, mean_kernel, mode='constant')

data_gamma_filtered[gamma_indexes] = convolved_data[gamma_indexes]
radius = 2
median_counts = median_filter(data_gamma_filtered, radius, mode='grid-wrap')
gamma_indexes = np.where(manual_gamma_threshold * data_gamma_filtered > median_counts)
data_gamma_filtered[gamma_indexes] = median_counts[gamma_indexes]

return data_gamma_filtered

Expand Down
6 changes: 5 additions & 1 deletion tests/NeuNorm/loading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ def test_gamma_filtered_works(self):
o_norm = Normalization()
o_norm.load(folder=path, data_type='sample', manual_gamma_filter=True, auto_gamma_filter=False)
_expected_sample = np.ones((5, 5))
_expected_sample[0, 0] = 0.375
_expected_sample[0, 0] = 4
_expected_sample[:, 2] = 2
_expected_sample[:, 3] = 3
_expected_sample[:, 4] = 4
_returned_sample = o_norm.data['sample']['data']

print(f"_expected_sample: {_expected_sample}")
print(f"_returned_sample: {_returned_sample}")

self.assertTrue((_expected_sample == _returned_sample).all())

# gamma filter is False
Expand Down
Loading

0 comments on commit fc44066

Please sign in to comment.