From 471df66955b2cc1e585b97d446171039b0a91bf4 Mon Sep 17 00:00:00 2001 From: kapoorlab Date: Tue, 22 Aug 2023 07:13:54 +0200 Subject: [PATCH] default pass --- src/oneat/NEATModels/neat_densevollnet.py | 7 ++----- src/oneat/NEATModels/neat_vollnet.py | 8 ++------ src/oneat/NEATUtils/utils.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/oneat/NEATModels/neat_densevollnet.py b/src/oneat/NEATModels/neat_densevollnet.py index d191cf0..9b8a37b 100644 --- a/src/oneat/NEATModels/neat_densevollnet.py +++ b/src/oneat/NEATModels/neat_densevollnet.py @@ -1,7 +1,7 @@ from oneat.NEATUtils import plotters import numpy as np from oneat.NEATUtils import utils -from oneat.NEATUtils.utils import save_volume, pad_timelapse, get_nearest_volume, load_json, volumeyoloprediction, normalizeFloatZeroOne, GenerateVolumeMarkers, MakeForest,save_volume_csv, volume_dynamic_nms +from oneat.NEATUtils.utils import save_volume, create_sub_image, pad_timelapse, get_nearest_volume, load_json, volumeyoloprediction, normalizeFloatZeroOne, GenerateVolumeMarkers, MakeForest,save_volume_csv, volume_dynamic_nms from keras import callbacks import os import sys @@ -314,10 +314,7 @@ def predict(self, print(f'zero padded image shape ${self.image.shape}') self.second_pass_predict() if self.remove_markers == None: - self.pad_width = (self.config['imagey'], self.config['imagex']) - self.image = np.zeros([self.originalimage.shape[0], self.originalimage.shape[1], self.originalimage.shape[2] + self.pad_width[0], self.originalimage.shape[3] + self.pad_width[1] ]) - for i in range(self.originalimage.shape[0]): - self.image[i,:] = pad_timelapse(self.originalimage[i,:], self.pad_width) + self.image = create_sub_image(self.originalimage,self.config['imagez'],self.config['imagey'], self.config['imagex']) self.default_pass_predict() diff --git a/src/oneat/NEATModels/neat_vollnet.py b/src/oneat/NEATModels/neat_vollnet.py index e11f588..a056042 100644 --- a/src/oneat/NEATModels/neat_vollnet.py +++ b/src/oneat/NEATModels/neat_vollnet.py @@ -1,7 +1,7 @@ from oneat.NEATUtils import plotters import numpy as np from oneat.NEATUtils import utils -from oneat.NEATUtils.utils import save_volume, pad_timelapse, get_nearest_volume, load_json, volumeyoloprediction, normalizeFloatZeroOne, GenerateVolumeMarkers, MakeForest,save_volume_csv, volume_dynamic_nms +from oneat.NEATUtils.utils import save_volume, create_sub_image, pad_timelapse, get_nearest_volume, load_json, volumeyoloprediction, normalizeFloatZeroOne, GenerateVolumeMarkers, MakeForest,save_volume_csv, volume_dynamic_nms from keras import callbacks import os import sys @@ -311,12 +311,8 @@ def predict(self, print(f'zero padded image shape ${self.image.shape}') self.second_pass_predict() if self.remove_markers == None: - self.pad_width = (self.config['imagey'], self.config['imagex']) - self.image = np.zeros([self.originalimage.shape[0], self.originalimage.shape[1], self.originalimage.shape[2] + self.pad_width[0], self.originalimage.shape[3] + self.pad_width[1] ]) - for i in range(self.originalimage.shape[0]): - self.image[i,:] = pad_timelapse(self.originalimage[i,:], self.pad_width) - self.image = self.originalimage + self.image = create_sub_image(self.originalimage,self.config['imagez'],self.config['imagey'], self.config['imagex']) self.default_pass_predict() diff --git a/src/oneat/NEATUtils/utils.py b/src/oneat/NEATUtils/utils.py index 864702a..d790e65 100644 --- a/src/oneat/NEATUtils/utils.py +++ b/src/oneat/NEATUtils/utils.py @@ -398,6 +398,21 @@ def load_full_training_data(directory, filename, axes=None, verbose=True): return (X, Y), axes +def create_sub_image(image, n, m, p): + + t, z, y, x = image.shape + + z_remainder = z % n + y_remainder = y % m + x_remainder = x % p + + new_z = z - z_remainder + new_y = y - y_remainder + new_x = x - x_remainder + + sub_image = image[:, :new_z, :new_y, :new_x] + + return sub_image def pad_timelapse(image, pad_width):