Skip to content

Commit b485084

Browse files
committed
fixed bug in set bad sections and added example
1 parent 162baae commit b485084

File tree

6 files changed

+72
-46
lines changed

6 files changed

+72
-46
lines changed

DeepSlice/coord_post_processing/angle_methods.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def calculate_brain_center_coordinate(section, atlas_shape, axis):
77
"""
8-
Calculates the coordinate closest to the middle of the section as defined by the two
8+
Calculates the coordinate closest to the middle of the section as defined by the two
99
dimensions not orthogonal to the dimension along which the series is being aligned.
1010
for example, if the series is being aligned coronally then this will return the midpoint
1111
in X and Z as coronal series are spaced along the Y coordinate in the CCF.
@@ -39,7 +39,7 @@ def calculate_brain_center_coordinate(section, atlas_shape, axis):
3939
def calculate_angles(df):
4040
"""
4141
Calculates the Mediolateral and Dorsoventral angles for a series of predictions
42-
42+
4343
:param df: The dataframe containing the predictions
4444
:type df: pandas.DataFrame
4545
:return: a list of calculated ML and DV angles
@@ -107,7 +107,7 @@ def propagate_angles(df, method, species):
107107
# get the angles for each section in the dataset
108108
temp = df.copy()
109109
if "bad_section" in temp:
110-
temp = temp[~temp["bad_section"]]
110+
temp = temp[~temp["bad_section"].astype(bool)]
111111
DV_angle_list, ML_angle_list = calculate_angles(temp)
112112

113113

DeepSlice/main.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, species):
1919
xception_weights = metadata_loader.get_data_path(self.config["weight_file_paths"]["xception_imagenet"], self.metadata_path)
2020
weights = metadata_loader.get_data_path(self.config["weight_file_paths"][self.species]["primary"], self.metadata_path)
2121
self.model = neural_network.initialise_network(xception_weights, weights, self.species)
22-
22+
2323

2424

2525
def predict(
@@ -62,7 +62,7 @@ def predict(
6262
image_directory
6363
)
6464
primary_weights = metadata_loader.get_data_path(self.config["weight_file_paths"][self.species]["primary"], self.metadata_path)
65-
65+
6666
secondary_weights = metadata_loader.get_data_path(self.config["weight_file_paths"][self.species]["secondary"], self.metadata_path)
6767

6868
if secondary_weights == "None":
@@ -105,7 +105,7 @@ def set_bad_sections(self, bad_sections: list, auto = False):
105105
"""
106106
sets the bad sections for a given brain. Must be run after predict()
107107
108-
:param bad_sections: A list of bad sections to ignore when calculating angles and spacing
108+
:param bad_sections: A list of bad sections to ignore when calculating angles and spacing, the list just needs to contain a unique string for each section, for instance the section number. do not use a string which appears in multiple filenames
109109
:type bad_sections: list
110110
"""
111111
self.predictions = spacing_and_indexing.set_bad_sections_util(
@@ -154,7 +154,7 @@ def propagate_angles(self, method="weighted_mean"):
154154
self.predictions = angle_methods.propagate_angles(
155155
self.predictions, method, self.species
156156
)
157-
157+
158158

159159
def load_QUINT(self, filename):
160160
"""
@@ -178,9 +178,9 @@ def load_QUINT(self, filename):
178178
self.predictions = predictions
179179
xception_weights = metadata_loader.get_data_path(self.config["weight_file_paths"]["xception_imagenet"], self.metadata_path)
180180
weights = metadata_loader.get_data_path(self.config["weight_file_paths"][self.species]["primary"], self.metadata_path)
181-
self.model = neural_network.initialise_network(xception_weights, weights, self.species)
181+
self.model = neural_network.initialise_network(xception_weights, weights, self.species)
182+
182183

183-
184184

185185
def save_predictions(self, filename):
186186
"""

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ folderpath = 'examples/example_brain/GLTa/'
9494
#try with and without ensemble to find the model which best works for you
9595
#if you have section numbers included in the filename as _sXXX specify this :)
9696
Model.predict(folderpath, ensemble=True, section_numbers=True)
97+
#This is an optional stage if you have damaged sections, or hemibrains they may negatively effect the propagation for the entire dataset
98+
#simply set the bad sections here using a string which is unique to those each section you would like to label as bad. DeepSlice will
99+
#not include it in the propagation and instead it will infer its position based on neighbouring sections.
100+
Model.set_bad_sections(bad_sections=["_s094", "s199"])
97101
#If you would like to normalise the angles (you should)
98102
Model.propagate_angles()
99103
#To reorder your sections according to the section numbers

ds.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from DeepSlice import DSModel
2+
species = 'mouse' #available species are 'mouse' and 'rat'
3+
Model = DSModel(species)
4+
folderpath = 'examples/example_brain/GLTa/'
5+
#here you run the model on your folder
6+
#try with and without ensemble to find the model which best works for you
7+
#if you have section numbers included in the filename as _sXXX specify this :)
8+
Model.predict(folderpath, ensemble=True, section_numbers=True)
9+
#This is an optional stage if you have damaged sections, or hemibrains they may negatively effect the propagation for the entire dataset
10+
#simply set the bad sections here using a string which is unique to those each section you would like to label as bad. DeepSlice will
11+
#not include it in the propagation and instead it will infer its position based on neighbouring sections.
12+
Model.set_bad_sections(bad_sections=["_s094", "s199"])
13+
#If you would like to normalise the angles (you should)
14+
Model.propagate_angles()
15+
#To reorder your sections according to the section numbers
16+
Model.enforce_index_order()
17+
#alternatively if you know the precise spacing (ie; 1, 2, 4, indicates that section 3 has been left out of the series) Then you can use
18+
#Furthermore if you know the exact section thickness in microns this can be included instead of None
19+
#if your sections are numbered rostral to caudal you will need to specify a negative section_thickness
20+
Model.enforce_index_spacing(section_thickness = None)
21+
#now we save which will produce a json file which can be placed in the same directory as your images and then opened with QuickNII.
22+
Model.save_predictions(folderpath + 'MyResults')

0 commit comments

Comments
 (0)