Skip to content

Commit 041e3be

Browse files
committed
Allow scalar schan in create_pairwise_bilateral.
1 parent 3381ed4 commit 041e3be

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pydensecrf/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from numbers import Number
23
from logging import warning
34

45

@@ -142,8 +143,12 @@ def create_pairwise_bilateral(sdims, schan, img, chdim=-1):
142143
im_feat = np.rollaxis(img, chdim).astype(np.float32)
143144

144145
# scale image features per channel
145-
for i, s in enumerate(schan):
146-
im_feat[i] /= s
146+
# Allow for a single number in `schan` to broadcast across all channels:
147+
if isinstance(schan, Number):
148+
im_feat /= schan
149+
else:
150+
for i, s in enumerate(schan):
151+
im_feat[i] /= s
147152

148153
# create a mesh
149154
cord_range = [range(s) for s in im_feat.shape[1:]]

0 commit comments

Comments
 (0)