44import numpy as np
55from scipy .ndimage import median_filter , gaussian_filter , binary_fill_holes ,\
66 map_coordinates
7- from skimage import img_as_float , exposure , img_as_ubyte
7+ from skimage .util import img_as_float , img_as_ubyte
8+ from skimage import exposure
89from skimage import filters
910from skimage .measure import find_contours , approximate_polygon , points_in_poly
1011from skimage .transform import rescale
@@ -73,7 +74,7 @@ def dynamic_masking(image, method="edges", filter_size=7, threshold=0.005):
7374 """
7475 imcopy = np .copy (image )
7576 # stretch the histogram
76- image = exposure .rescale_intensity (img_as_float (image ), in_range = ( 0 , 1 ) )
77+ image = exposure .rescale_intensity (img_as_float (image ), in_range = 'image' )
7778 # blur the image, low-pass
7879 blurback = img_as_ubyte (gaussian_filter (image , filter_size ))
7980 if method == "edges" :
@@ -132,6 +133,7 @@ def mask_coordinates(image_mask, tolerance=1.5, min_length=10, plot=False):
132133
133134def prepare_mask_from_polygon (x , y , mask_coords ):
134135 """ Converts mask coordinates of the image mask
136+
135137 to the grid of 1/0 on the x,y grid
136138 Inputs:
137139 x,y : grid of x,y points
@@ -148,8 +150,8 @@ def prepare_mask_on_grid(
148150 x : np .ndarray ,
149151 y : np .ndarray ,
150152 image_mask : np .ndarray ,
151- )-> np .array :
152- """_summary_
153+ )-> np .ndarray :
154+ """Converts mask to the grid
153155
154156 Args:
155157 x (np.ndarray): x coordinates of vectors in pixels
@@ -371,7 +373,7 @@ def contrast_stretch(img, lower_limit = 2, upper_limit = 98):
371373
372374 lower = np .percentile (img , lower_limit )
373375 upper = np .percentile (img , upper_limit )
374- img = exposure .rescale_intensity (img , in_range = (lower , upper ))
376+ img = exposure .rescale_intensity (img , in_range = (lower , upper )) #type:ignore
375377 return img
376378
377379def threshold_binarize (img , threshold , max_val = 255 ):
@@ -472,65 +474,59 @@ def gen_lowpass_background(img_list, sigma = 3, resize = None):
472474 background += img
473475 return (background / len (img_list ))
474476
475-
476- def offset_image (img , offset_x , offset_y , pad = 'zero ' ):
477- """
478- Offset an image by padding.
477+ # Obsolete, to be removed in the future
478+ # def offset_image(img, offset_x, offset_y, pad='constant '):
479+ # """
480+ # Offset an image by padding.
479481
480- Parameters
481- ----------
482- img: image
483- a two dimensional array of float32 or float64,
484- but can be uint16, uint8 or similar type
485-
486- offset_x: int
487- offset an image by integer values. Positive values shifts
488- the image to the right and negative values shift to the left
489-
490- offset_y: int
491- offset an image by integer values. Positive values shifts
492- the image to the top and negative values shift to the bottom
493-
494- pad: str
495- pad the shift with zeros or a reflection of the shift
496-
497- Returns
498- -------
499- img: image
500- a transformed two dimensional array of the input image
482+ # Parameters
483+ # ----------
484+ # img: image
485+ # a two dimensional array of float32 or float64,
486+ # but can be uint16, uint8 or similar type
487+
488+ # offset_x: int
489+ # offset an image by integer values. Positive values shifts
490+ # the image to the right and negative values shift to the left
491+
492+ # offset_y: int
493+ # offset an image by integer values. Positive values shifts
494+ # the image to the top and negative values shift to the bottom
495+
496+ # pad: str
497+ # pad the shift with zeros or a reflection of the shift
498+
499+ # Returns
500+ # -------
501+ # img: image
502+ # a transformed two dimensional array of the input image
501503
502- """
503- if pad not in [
504- 'zero' , 'reflect'
505- ]:
506- raise ValueError (f'pad method not supported: { pad } ' )
507- end_y , end_x = img .shape
508- start_x = 0 ; start_y = 0
509- if offset_x > 0 :
510- offset_x1 = offset_x
511- offset_x2 = 0
512- else :
513- offset_x1 = 0
514- offset_x2 = offset_x * - 1
515- start_x = offset_x2
516- end_x += offset_x2
517- if offset_y > 0 :
518- offset_y1 = offset_y
519- offset_y2 = 0
520- else :
521- offset_y1 = 0
522- offset_y2 = offset_y * - 1
523- start_y = offset_y2
524- end_y += offset_y2
525- if pad == 'zero' :
526- pad = 'constant'
527- img = np .pad (
528- img ,
529- ((offset_y1 , offset_y2 ),
530- (offset_x1 , offset_x2 )),
531- mode = pad
532- )
533- return img [start_y :end_y , start_x :end_x ]
504+ # """
505+ # if pad not in [
506+ # 'zero', 'reflect'
507+ # ]:
508+ # raise ValueError(f'pad method not supported: {pad}')
509+ # end_y, end_x = img.shape
510+ # start_x = 0; start_y = 0
511+ # if offset_x > 0:
512+ # offset_x1 = offset_x
513+ # offset_x2 = 0
514+ # else:
515+ # offset_x1 = 0
516+ # offset_x2 = offset_x * -1
517+ # start_x = offset_x2
518+ # end_x += offset_x2
519+ # if offset_y > 0:
520+ # offset_y1 = offset_y
521+ # offset_y2 = 0
522+ # else:
523+ # offset_y1 = 0
524+ # offset_y2 = offset_y * -1
525+ # start_y = offset_y2
526+ # end_y += offset_y2
527+
528+ # img = np.pad(img, (offset_y1, offset_y2),(offset_x1, offset_x2)), mode=pad)
529+ # return img[start_y:end_y, start_x:end_x]
534530
535531
536532def stretch_image (img ,
0 commit comments