Skip to content

Commit

Permalink
Catch and fix cases where incoming label matrix is not sequential.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjohncutler committed Aug 11, 2022
1 parent f60df97 commit 898d38d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ncolor/format_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
SKIMAGE_ENABLED = True
except:
SKIMAGE_ENABLED = False

def is_sequential(labels):
return np.all(np.diff(fastremap.unique(labels))==1)

def format_labels(labels, clean=False, min_area=9, despur=False, verbose=False, ignore=False):
"""
Expand Down
7 changes: 5 additions & 2 deletions ncolor/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import numpy as np
from numba import njit
import scipy
from .format_labels import format_labels
import scipy
from .format_labels import format_labels, is_sequential

def label(lab, n=4, conn=2, max_depth=5, offset=0):
# needs to be in standard label form
# but also needs to be in int32 data type to work properly; the formatting automatically
# puts it into the smallest datatype to save space
if not is_sequential(lab):
lab = format_labels(lab)

lut = get_lut(lab,n,conn,max_depth,offset)
return lut[lab]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools
from setuptools import setup

install_deps = ['numpy>=1.22.0', 'scipy', 'numba',
install_deps = ['numpy>=1.22.4', 'scipy', 'numba',
'fastremap','scikit-image','mahotas==1.4.12']

with open("README.md", "r") as fh:
Expand Down

0 comments on commit 898d38d

Please sign in to comment.