autoformat code and add missing imports

This commit is contained in:
2021-07-12 15:54:50 +02:00
parent 85e2edb8a5
commit 93c84e731d
4 changed files with 47 additions and 24 deletions

View File

@@ -8,8 +8,9 @@ def extend_dim(array):
ones = np.ones((array.shape[0], 1))
return np.append(array, ones, axis=1)
def remove_dim(array):
return array[:,:-1]
return array[:, :-1]
class SituImage:
@@ -32,7 +33,7 @@ class SituImage:
self.files = file_list
self.data = None
self.nucleaus_channel = nucleaus_channel
def get_data(self):
if self.data is None:
self._load_image()
@@ -45,8 +46,8 @@ class SituImage:
Returns:
numpy.array: The loaded image of shape (focus_level, width, height)
'''
return self.get_data()[channel,:,:,:]
return self.get_data()[channel, :, :, :]
def _load_image(self):
'''
Loads the channels of an image from seperate files and returns them as numpy array.
@@ -64,7 +65,7 @@ class SituImage:
channels.append(np.array(Image.open(file)))
image_list.append(channels)
self.data = np.array(image_list)
def unload_image(self):
'''
Unloads the image data to free up memory
@@ -83,7 +84,7 @@ class SituImage:
Returns:
image: The image of the specified focus level and channel
'''
img = Image.fromarray(self.get_data()[0,0,:,:])
img = Image.fromarray(self.get_data()[0, 0, :, :])
img.show()
return img
@@ -107,9 +108,10 @@ class SituImage:
np.array: The peaks found by this method as np.array of shape (n, 2)
'''
img = img_as_float(self.get_data()[channel, focus_level, :, :])
peaks = blob_dog(img, min_sigma=min_sigma, max_sigma=max_sigma, threshold=threshold)
peaks = blob_dog(img, min_sigma=min_sigma,
max_sigma=max_sigma, threshold=threshold)
return peaks[:, 0:2]
def show_channel_peaks(self, channel, focus_level=0, min_sigma=0.75, max_sigma=3, threshold=0.1):
'''
Returns and shows the found. Uses get_channel_peaks internally.
@@ -128,11 +130,13 @@ class SituImage:
Returns:
image: The image of the specified focus level and channel with encircled peaks.
'''
peaks = self.get_channel_peaks(channel, focus_level, min_sigma, max_sigma, threshold)
peaks = self.get_channel_peaks(
channel, focus_level, min_sigma, max_sigma, threshold)
img = Image.fromarray(self.get_data()[channel, focus_level, :, :])
draw = ImageDraw.Draw(img)
for x, y in zip(peaks[:,0], peaks[:,1]):
draw.ellipse((x - 5, y - 5, x + 5, y + 5), outline ='white', width = 3)
for x, y in zip(peaks[:, 0], peaks[:, 1]):
draw.ellipse((x - 5, y - 5, x + 5, y + 5),
outline='white', width=3)
img.show()
return img
return img