Morphology
Base
convolve_2d(image, kernel)
Convolves image
with kernel
, padding by replicating border pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Note
np.flip
is used to give same result as convn
with replicate padding in MATLAB.
Source code in coppafish/utils/morphology/base.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
dilate(image, kernel)
Dilates image
with kernel
, using zero padding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/utils/morphology/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
ensure_odd_kernel(kernel, pad_location='start')
This ensures all dimensions of kernel
are odd by padding even dimensions with zeros.
Replicates MATLAB way of dealing with even kernels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel |
np.ndarray
|
|
required |
pad_location |
str
|
One of the following, indicating where to pad with zeros -
|
'start'
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Example
If pad_location
is 'start'
then [[5,4];[3,1]]
becomes [[0,0,0],[0,5,4],[0,3,1]]
.
Source code in coppafish/utils/morphology/base.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
ftrans2(b, t=None)
Produces a 2D convolve kernel that corresponds to the 1D convolve kernel, b
, using the transform, t
.
Copied from MATLAB ftrans2
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
np.ndarray
|
|
required |
t |
Optional[np.ndarray]
|
|
None
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/utils/morphology/base.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
hanning_diff(r1, r2)
Gets difference of two hanning window 2D convolve kernel.
Central positive, outer negative with sum of 0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r1 |
int
|
radius in pixels of central positive hanning convolve kernel. |
required |
r2 |
int
|
radius in pixels of outer negative hanning convolve kernel. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/utils/morphology/base.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
top_hat(image, kernel)
Does tophat filtering of image
with kernel
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/utils/morphology/base.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
Filter
imfilter(image, kernel, padding=0, corr_or_conv='corr', oa=True)
Copy of MATLAB imfilter
function with 'output_size'
equal to 'same'
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
padding |
Union[float, str]
|
One of the following, indicated which padding to be used.
|
0
|
corr_or_conv |
str
|
|
'corr'
|
oa |
bool
|
Whether to use oaconvolve or scipy.ndimage.convolve. scipy.ndimage.convolve seems to be quicker for smoothing in extract step (3s vs 20s for 50 z-planes). |
True
|
Returns:
Type | Description |
---|---|
np.ndarray
|
|
Source code in coppafish/utils/morphology/filter.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
imfilter_coords(image, kernel, coords, padding=0, corr_or_conv='corr')
Copy of MATLAB imfilter
function with 'output_size'
equal to 'same'
.
Only finds result of filtering at specific locations but still filters entire image.
Note
image and image2 need to be np.int8 and kernel needs to be int otherwise will get cython error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
coords |
np.ndarray
|
|
required |
padding |
Union[float, str]
|
One of the following, indicated which padding to be used.
|
0
|
corr_or_conv |
str
|
|
'corr'
|
Returns:
Type | Description |
---|---|
Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]
|
|
Source code in coppafish/utils/morphology/filter.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
Filter Optimised
get_shifts_from_kernel(kernel)
Returns where kernel is positive as shifts in y, x and z.
I.e. kernel=jnp.ones((3,3,3))
would return y_shifts = x_shifts = z_shifts = -1, 0, 1
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernel |
jnp.ndarray
|
int [kernel_szY x kernel_szX x kernel_szY] |
required |
Returns:
Type | Description |
---|---|
jnp.ndarray
|
|
jnp.ndarray
|
|
jnp.ndarray
|
|
Source code in coppafish/utils/morphology/filter_optimised.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
imfilter_coords(image, kernel, coords, padding=0, corr_or_conv='corr')
Copy of MATLAB imfilter
function with 'output_size'
equal to 'same'
.
Only finds result of filtering at specific locations.
Note
image and image2 need to be np.int8 and kernel needs to be int otherwise will get cython error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
|
required |
kernel |
np.ndarray
|
|
required |
coords |
np.ndarray
|
|
required |
padding |
Union[float, str]
|
One of the following, indicated which padding to be used.
|
0
|
corr_or_conv |
str
|
|
'corr'
|
Returns:
Type | Description |
---|---|
Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]
|
|
Source code in coppafish/utils/morphology/filter_optimised.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
manual_convolve(image, y_kernel_shifts, x_kernel_shifts, z_kernel_shifts, coords)
Finds result of convolution at specific locations indicated by coords
with binary kernel.
I.e. instead of convolving whole image
, just find result at these points
.
Note
image needs to be padded before this function is called otherwise get an error when go out of bounds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
jnp.ndarray
|
|
required |
y_kernel_shifts |
jnp.ndarray
|
|
required |
x_kernel_shifts |
jnp.asarray
|
|
required |
z_kernel_shifts |
jnp.ndarray
|
|
required |
coords |
jnp.ndarray
|
|
required |
Returns:
Type | Description |
---|---|
jnp.ndarray
|
|
Source code in coppafish/utils/morphology/filter_optimised.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|