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

Update dataset.py #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
def extract_brain_region(image, segmentation, outside_value=0):
brain_voxels = np.where(segmentation != outside_value)
minZidx = int(np.min(brain_voxels[0]))
maxZidx = int(np.max(brain_voxels[0]))
maxZidx = int(np.max(brain_voxels[0]))+1
minXidx = int(np.min(brain_voxels[1]))
maxXidx = int(np.max(brain_voxels[1]))
maxXidx = int(np.max(brain_voxels[1]))+1
minYidx = int(np.min(brain_voxels[2]))
maxYidx = int(np.max(brain_voxels[2]))
maxYidx = int(np.max(brain_voxels[2]))+1

# resize images
resizer = (slice(minZidx, maxZidx), slice(minXidx, maxXidx), slice(minYidx, maxYidx))
Expand All @@ -49,7 +49,7 @@ def cut_off_values_upper_lower_percentile(image, mask=None, percentile_lower=0.2
res = np.copy(image)
res[(res < cut_off_lower) & (mask !=0)] = cut_off_lower
res[(res > cut_off_upper) & (mask !=0)] = cut_off_upper
return image
return res


def run(folder, out_folder, id, name, return_if_no_seg=True):
Expand Down Expand Up @@ -87,11 +87,11 @@ def run(folder, out_folder, id, name, return_if_no_seg=True):
# time this code was initially written. In order to not break anything we will keep it like it was
brain_voxels = np.where(brain_mask != 0)
minZidx = int(np.min(brain_voxels[0]))
maxZidx = int(np.max(brain_voxels[0]))
maxZidx = int(np.max(brain_voxels[0]))+1
minXidx = int(np.min(brain_voxels[1]))
maxXidx = int(np.max(brain_voxels[1]))
maxXidx = int(np.max(brain_voxels[1]))+1
minYidx = int(np.min(brain_voxels[2]))
maxYidx = int(np.max(brain_voxels[2]))
maxYidx = int(np.max(brain_voxels[2]))+1
with open(os.path.join(out_folder, "%03.0d.pkl" % id), 'w') as f:
dp = {}
dp['orig_shp'] = original_shape
Expand Down