Skip to content

Commit 96cdb90

Browse files
committed
Fixed bug in map_class_ids (fixes #53).
1 parent 42c0425 commit 96cdb90

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spectral/algorithms/spatial.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ def map_class_ids(src_class_image, dest_class_image, unlabeled=None):
709709
cmap[i] = i
710710
if i in dest_ids:
711711
dest_ids.remove(i)
712+
else:
713+
unlabeled = []
712714
N_src = len(src_ids)
713715
N_dest = len(dest_ids)
714716

@@ -732,7 +734,14 @@ def map_class_ids(src_class_image, dest_class_image, unlabeled=None):
732734
unmapped.remove(old)
733735
dest_available.remove(new)
734736
for old in unmapped:
735-
cmap[old] = old
737+
# The list of target classes has been exhausted. Pick the
738+
# smallest dest value that isn't already used.
739+
def next_id():
740+
from itertools import count
741+
for ii in count():
742+
if ii not in unlabeled and ii not in cmap.values():
743+
return ii
744+
cmap[old] = next_id()
736745
break
737746
cmap[src_ids[i]] = dest_ids[j]
738747
unmapped.remove(src_ids[i])

0 commit comments

Comments
 (0)