DerThorsten / nifty

A nifty library for graph based image segmentation.
MIT License
41 stars 21 forks source link

Accept all np.unsignedinteger types in gridGraph, default to uint64 otherwise #109

Closed hanslovsky closed 7 years ago

hanslovsky commented 7 years ago

This is a possible solution to #105 without changing the data type for all subtypes of np.unsignedinteger.

import nifty.graph.rag as nrag
import numpy as np

This is an example:
dtypes = [np.uint8, np.uint16, np.uint32, np.uint64, np.int8, np.float32]
for dt in dtypes:
    a = np.zeros((1, 1, 1), dtype=dt)
    rag = nrag.gridRag( a )
    print( rag, type( rag ) )

Output:

#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D_uint8'>
#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D_uint16'>
#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D_uint32'>
#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D'>
#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D'>
#Nodes 1 #Edges 0 <class 'nifty.graph.rag.ExplicitLabelsGridRag3D'>

This is just an idea of how gridRag could be relaxed to accept more types/all unsigned integer types. If you have any concerns about how I implemented this, let me know.

DerThorsten commented 7 years ago

ty