loli / medpy

Medical image processing in Python
http://loli.github.io/medpy/
GNU General Public License v3.0
559 stars 136 forks source link

Update binary.py #117

Closed harshamarupudi56 closed 7 months ago

harshamarupudi56 commented 8 months ago

Changed numpy.bool to bool to prevent deprecation error.

harshamarupudi56 commented 8 months ago

Alternative versions of functions if you are interested:

def dice_coefficient(im1, im2):

im1 = np.asarray(im1).astype(bool)
im2 = np.asarray(im2).astype(bool)

intersection = np.logical_and(im1, im2)
dice_score = 2. * intersection.sum() / (im1.sum() + im2.sum())

return dice_score

def jaccard_index(img1,img2): img1 = np.asarray(img1).astype(bool) img2 = np.asarray(img2).astype(bool)

intersection = np.logical_and(img1, img2)
union = np.logical_or(img1, img2)
jaccard = intersection.sum() / union.sum()

return jaccard 
StellarStorm commented 7 months ago

Hi @harshamarupudi56, thanks for the contribution! This was included in #113 so I'll close this, but thanks for identifying this problem and providing a fix!