Skip to content

Commit

Permalink
Pre-processing finished
Browse files Browse the repository at this point in the history
  • Loading branch information
NikDrummond committed Jul 9, 2022
1 parent 16135aa commit e08f938
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 98 deletions.
8 changes: 8 additions & 0 deletions Image_Processing/Image_Class.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from tqdm import tqdm
from copy import deepcopy
import numpy as np

def update_defaults(defaults, kwargs):
""" Update default class arguments"""
Expand Down Expand Up @@ -125,3 +126,10 @@ def read_Image(path):
return N_all
else:
raise TypeError('input is not a file or directory')

def save_mask(mask,f_name):
"""
Save an array mask as a tiff
"""
mask = mask.astype(np.uint16)
tiff.imwrite(f_name,mask,imagej = True)
32 changes: 18 additions & 14 deletions Image_Processing/Image_Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def add_hull(N,t = 0, order = 'x,y'):
N.hull = convexHull(N.points)
return N

def threshold(N, apply = True, inplace = True, **kwargs):
def threshold(N, t = None, apply = True, inplace = True, **kwargs):
"""
Threshold an image using Generalised Histogram Thresholding
Expand All @@ -62,23 +62,27 @@ def threshold(N, apply = True, inplace = True, **kwargs):
else:
raise TypeError('Input type not recognised')

n,x = image_hist(N.array)
t = GHT(n,x,**kwargs)[0]
im = N.array

if apply == False:
return t
else:
im = N.array.copy()
if t is None:

mask = im > t
mask = np.array(mask).astype(bool)
im[mask == False] = 0
n,x = image_hist(im)
t = GHT(n,x,**kwargs)[0]

if inplace == False:
return im
if apply == False:
return t
else:
N.array = im
return N
im = N.array.copy()

mask = im > t
mask = np.array(mask).astype(bool)
im[mask == False] = 0

if inplace == False:
return im
else:
N.array = im
return N

def blur_image(N, sigma = 8, inplace = True):
"""
Expand Down
165 changes: 81 additions & 84 deletions examples.ipynb

Large diffs are not rendered by default.

Binary file added mask.tiff
Binary file not shown.

0 comments on commit e08f938

Please sign in to comment.