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

fix #72 #73

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
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
32 changes: 16 additions & 16 deletions pyCHX/chx_generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from scipy.special import erf

from skimage.filters import prewitt
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk

from modest_image import imshow
import matplotlib.cm as mcm
Expand Down Expand Up @@ -1918,9 +1918,9 @@ def create_ring_mask( shape, r1, r2, center, mask=None):
'''

m = np.zeros( shape, dtype= bool)
rr,cc = circle( center[1], center[0], r2, shape=shape )
rr,cc = disk( center[1], center[0], r2, shape=shape )
m[rr,cc] = 1
rr,cc = circle( center[1], center[0], r1,shape=shape )
rr,cc = disk( center[1], center[0], r1,shape=shape )
m[rr,cc] = 0
if mask is not None:
m += mask
Expand Down Expand Up @@ -2884,7 +2884,7 @@ def create_polygon_mask( image, xcorners, ycorners ):


'''
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk
imy, imx = image.shape
bst_mask = np.zeros_like( image , dtype = bool)
rr, cc = polygon( ycorners,xcorners)
Expand All @@ -2906,7 +2906,7 @@ def create_rectangle_mask( image, xcorners, ycorners ):


'''
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk
imy, imx = image.shape
bst_mask = np.zeros_like( image , dtype = bool)
rr, cc = polygon( ycorners,xcorners)
Expand Down Expand Up @@ -2954,18 +2954,18 @@ def create_multi_rotated_rectangle_mask( image, center=None, length=100, width=

def create_wedge( image, center, radius, wcors, acute_angle=True) :
'''YG develop at June 18, 2017, @CHX
Create a wedge by a combination of circle and a triangle defined by center and wcors
Create a wedge by a combination of disk and a triangle defined by center and wcors
wcors: [ [x1,x2,x3...], [y1,y2,y3..]

'''
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk
imy, imx = image.shape
cy,cx = center
x = [cx] + list(wcors[0])
y = [cy] + list(wcors[1])

maskc = np.zeros_like( image , dtype = bool)
rr, cc = circle( cy, cx, radius, shape = image.shape)
rr, cc = disk( cy, cx, radius, shape = image.shape)
maskc[rr,cc] =1

maskp = np.zeros_like( image , dtype = bool)
Expand All @@ -2982,20 +2982,20 @@ def create_wedge( image, center, radius, wcors, acute_angle=True) :


def create_cross_mask( image, center, wy_left=4, wy_right=4, wx_up=4, wx_down=4,
center_circle = True, center_radius=10
center_disk = True, center_radius=10
):
'''
Give image and the beam center to create a cross-shaped mask
wy_left: the width of left h-line
wy_right: the width of rigth h-line
wx_up: the width of up v-line
wx_down: the width of down v-line
center_circle: if True, create a circle with center and center_radius
center_disk: if True, create a disk with center and center_radius

Return:
the cross mask
'''
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
cx,cy = center
Expand Down Expand Up @@ -3033,7 +3033,7 @@ def create_cross_mask( image, center, wy_left=4, wy_right=4, wx_up=4, wx_down=4
bst_mask[rr,cc] =1

if center_radius!=0:
rr, cc = circle( cy, cx, center_radius, shape = bst_mask.shape)
rr, cc = disk( cy, cx, center_radius, shape = bst_mask.shape)
bst_mask[rr,cc] =1


Expand Down Expand Up @@ -3370,22 +3370,22 @@ def create_hot_pixel_mask(img, threshold, center=None, center_radius=300, outer_
threshold: the threshold above which will be considered as hot pixels
center: optional, default=None
else, as a two-element list (beam center), i.e., [center_x, center_y]
if center is not None, the hot pixel will not include a circle region
if center is not None, the hot pixel will not include a disk region
which is defined by center and center_radius ( in unit of pixel)
Output:
a bool types numpy array (mask), 1 is good and 0 is excluded

'''
bst_mask = np.ones_like( img , dtype = bool)
if center is not None:
from skimage.draw import circle
from skimage.draw import disk
imy, imx = img.shape
cy,cx = center
rr, cc = circle( cy, cx, center_radius,shape=img.shape )
rr, cc = disk( cy, cx, center_radius,shape=img.shape )
bst_mask[rr,cc] =0
if outer_radius:
bst_mask = np.zeros_like( img , dtype = bool)
rr2, cc2 = circle( cy, cx, outer_radius,shape=img.shape )
rr2, cc2 = disk( cy, cx, outer_radius,shape=img.shape )
bst_mask[rr2,cc2] =1
bst_mask[rr,cc] =0
hmask = np.ones_like( img )
Expand Down
2 changes: 1 addition & 1 deletion pyCHX/chx_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from IPython.core.magics.display import Javascript
from skbeam.core.utils import multi_tau_lags
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk
from modest_image import imshow
# edit handlers here to switch to PIMS or dask
# this does the databroker import
Expand Down
32 changes: 16 additions & 16 deletions pyCHX/v2/_commonspeckle/chx_generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from scipy.special import erf

from skimage.filters import prewitt
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk

# from modest_image import imshow #common
import matplotlib.cm as mcm
Expand Down Expand Up @@ -2259,9 +2259,9 @@ def create_ring_mask(shape, r1, r2, center, mask=None):
"""

m = np.zeros(shape, dtype=bool)
rr, cc = circle(center[1], center[0], r2, shape=shape)
rr, cc = disk(center[1], center[0], r2, shape=shape)
m[rr, cc] = 1
rr, cc = circle(center[1], center[0], r1, shape=shape)
rr, cc = disk(center[1], center[0], r1, shape=shape)
m[rr, cc] = 0
if mask is not None:
m += mask
Expand Down Expand Up @@ -3356,7 +3356,7 @@ def create_polygon_mask(image, xcorners, ycorners):


"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
bst_mask = np.zeros_like(image, dtype=bool)
Expand All @@ -3379,7 +3379,7 @@ def create_rectangle_mask(image, xcorners, ycorners):


"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
bst_mask = np.zeros_like(image, dtype=bool)
Expand Down Expand Up @@ -3441,19 +3441,19 @@ def create_multi_rotated_rectangle_mask(

def create_wedge(image, center, radius, wcors, acute_angle=True):
"""YG develop at June 18, 2017, @CHX
Create a wedge by a combination of circle and a triangle defined by center and wcors
Create a wedge by a combination of disk and a triangle defined by center and wcors
wcors: [ [x1,x2,x3...], [y1,y2,y3..]

"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
cy, cx = center
x = [cx] + list(wcors[0])
y = [cy] + list(wcors[1])

maskc = np.zeros_like(image, dtype=bool)
rr, cc = circle(cy, cx, radius, shape=image.shape)
rr, cc = disk(cy, cx, radius, shape=image.shape)
maskc[rr, cc] = 1

maskp = np.zeros_like(image, dtype=bool)
Expand All @@ -3475,7 +3475,7 @@ def create_cross_mask(
wy_right=4,
wx_up=4,
wx_down=4,
center_circle=True,
center_disk=True,
center_radius=10,
):
"""
Expand All @@ -3484,12 +3484,12 @@ def create_cross_mask(
wy_right: the width of rigth h-line
wx_up: the width of up v-line
wx_down: the width of down v-line
center_circle: if True, create a circle with center and center_radius
center_disk: if True, create a disk with center and center_radius

Return:
the cross mask
"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
cx, cy = center
Expand Down Expand Up @@ -3527,7 +3527,7 @@ def create_cross_mask(
bst_mask[rr, cc] = 1

if center_radius != 0:
rr, cc = circle(cy, cx, center_radius, shape=bst_mask.shape)
rr, cc = disk(cy, cx, center_radius, shape=bst_mask.shape)
bst_mask[rr, cc] = 1

full_mask = ~bst_mask
Expand Down Expand Up @@ -3848,23 +3848,23 @@ def create_hot_pixel_mask(
threshold: the threshold above which will be considered as hot pixels
center: optional, default=None
else, as a two-element list (beam center), i.e., [center_x, center_y]
if center is not None, the hot pixel will not include a circle region
if center is not None, the hot pixel will not include a disk region
which is defined by center and center_radius ( in unit of pixel)
Output:
a bool types numpy array (mask), 1 is good and 0 is excluded

"""
bst_mask = np.ones_like(img, dtype=bool)
if center is not None:
from skimage.draw import circle
from skimage.draw import disk

imy, imx = img.shape
cy, cx = center
rr, cc = circle(cy, cx, center_radius, shape=img.shape)
rr, cc = disk(cy, cx, center_radius, shape=img.shape)
bst_mask[rr, cc] = 0
if outer_radius:
bst_mask = np.zeros_like(img, dtype=bool)
rr2, cc2 = circle(cy, cx, outer_radius, shape=img.shape)
rr2, cc2 = disk(cy, cx, outer_radius, shape=img.shape)
bst_mask[rr2, cc2] = 1
bst_mask[rr, cc] = 0
hmask = np.ones_like(img)
Expand Down
2 changes: 1 addition & 1 deletion pyCHX/v2/_commonspeckle/chx_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from IPython.core.magics.display import Javascript
from skbeam.core.utils import multi_tau_lags
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk

# from modest_image import imshow #common
# edit handlers here to switch to PIMS or dask
Expand Down
32 changes: 16 additions & 16 deletions pyCHX/v2/_futurepyCHX/chx_generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from scipy.special import erf

from skimage.filters import prewitt
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk

from modest_image import imshow
import matplotlib.cm as mcm
Expand Down Expand Up @@ -2259,9 +2259,9 @@ def create_ring_mask(shape, r1, r2, center, mask=None):
"""

m = np.zeros(shape, dtype=bool)
rr, cc = circle(center[1], center[0], r2, shape=shape)
rr, cc = disk(center[1], center[0], r2, shape=shape)
m[rr, cc] = 1
rr, cc = circle(center[1], center[0], r1, shape=shape)
rr, cc = disk(center[1], center[0], r1, shape=shape)
m[rr, cc] = 0
if mask is not None:
m += mask
Expand Down Expand Up @@ -3356,7 +3356,7 @@ def create_polygon_mask(image, xcorners, ycorners):


"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
bst_mask = np.zeros_like(image, dtype=bool)
Expand All @@ -3379,7 +3379,7 @@ def create_rectangle_mask(image, xcorners, ycorners):


"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
bst_mask = np.zeros_like(image, dtype=bool)
Expand Down Expand Up @@ -3441,19 +3441,19 @@ def create_multi_rotated_rectangle_mask(

def create_wedge(image, center, radius, wcors, acute_angle=True):
"""YG develop at June 18, 2017, @CHX
Create a wedge by a combination of circle and a triangle defined by center and wcors
Create a wedge by a combination of disk and a triangle defined by center and wcors
wcors: [ [x1,x2,x3...], [y1,y2,y3..]

"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
cy, cx = center
x = [cx] + list(wcors[0])
y = [cy] + list(wcors[1])

maskc = np.zeros_like(image, dtype=bool)
rr, cc = circle(cy, cx, radius, shape=image.shape)
rr, cc = disk(cy, cx, radius, shape=image.shape)
maskc[rr, cc] = 1

maskp = np.zeros_like(image, dtype=bool)
Expand All @@ -3475,7 +3475,7 @@ def create_cross_mask(
wy_right=4,
wx_up=4,
wx_down=4,
center_circle=True,
center_disk=True,
center_radius=10,
):
"""
Expand All @@ -3484,12 +3484,12 @@ def create_cross_mask(
wy_right: the width of rigth h-line
wx_up: the width of up v-line
wx_down: the width of down v-line
center_circle: if True, create a circle with center and center_radius
center_disk: if True, create a disk with center and center_radius

Return:
the cross mask
"""
from skimage.draw import line_aa, line, polygon, circle
from skimage.draw import line_aa, line, polygon, disk

imy, imx = image.shape
cx, cy = center
Expand Down Expand Up @@ -3527,7 +3527,7 @@ def create_cross_mask(
bst_mask[rr, cc] = 1

if center_radius != 0:
rr, cc = circle(cy, cx, center_radius, shape=bst_mask.shape)
rr, cc = disk(cy, cx, center_radius, shape=bst_mask.shape)
bst_mask[rr, cc] = 1

full_mask = ~bst_mask
Expand Down Expand Up @@ -3848,23 +3848,23 @@ def create_hot_pixel_mask(
threshold: the threshold above which will be considered as hot pixels
center: optional, default=None
else, as a two-element list (beam center), i.e., [center_x, center_y]
if center is not None, the hot pixel will not include a circle region
if center is not None, the hot pixel will not include a disk region
which is defined by center and center_radius ( in unit of pixel)
Output:
a bool types numpy array (mask), 1 is good and 0 is excluded

"""
bst_mask = np.ones_like(img, dtype=bool)
if center is not None:
from skimage.draw import circle
from skimage.draw import disk

imy, imx = img.shape
cy, cx = center
rr, cc = circle(cy, cx, center_radius, shape=img.shape)
rr, cc = disk(cy, cx, center_radius, shape=img.shape)
bst_mask[rr, cc] = 0
if outer_radius:
bst_mask = np.zeros_like(img, dtype=bool)
rr2, cc2 = circle(cy, cx, outer_radius, shape=img.shape)
rr2, cc2 = disk(cy, cx, outer_radius, shape=img.shape)
bst_mask[rr2, cc2] = 1
bst_mask[rr, cc] = 0
hmask = np.ones_like(img)
Expand Down
2 changes: 1 addition & 1 deletion pyCHX/v2/_futurepyCHX/chx_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from IPython.core.magics.display import Javascript
from skbeam.core.utils import multi_tau_lags
from skimage.draw import line_aa, line, polygon, ellipse, circle
from skimage.draw import line_aa, line, polygon, ellipse, disk
from modest_image import imshow

# edit handlers here to switch to PIMS or dask
Expand Down