A Python package dedicated to sharing functions and classes for common image processing and statistical tools. This includes Sorensen–Dice coefficient (Dice) score and plotting functions.
A. Kline, PyLogik, 2022
- Integration with Jupyter Lab/Jupyter Notebooks
- Built-in plotting functionality for image comparisons
Install the package through pip:
$ pip install pylogik
from pylogik.image import im_analysis
Options for reading in images:
-
Matplotlib -
plt.imread()
-
OpenCV -
cv2.imread()
-
Pillow -
Image.open()
-
scikit-image -
io.imread()
# read in your data
im1 = cv2.imread('example_im1.png')
im2 = cv2.imread('example_im2.png')
The mathematical formalism of the Dice score is denoted by the equation:
where
Performing the calculation using a function in PyLogik
:
dice = im_analysis.dice_score(pred, true, k=1)
Note:
pred
- array of the predicted segmentationtrue
- array of the ground truth segmentationk
- value to perform matching on (default = 1)- Returns: dice score (float)
imshowpair
returns the array and image associated with a dice score comparison of 2 logical images. Colors are prespecified as magenta and green but can be adjusted by the user.
im_analysis.imshowpair(pred, true, color1 = (124,252,0), color2 = (255,0,252), show_fig = True):
Note:
pred
- array of the predicted segmentationtrue
- array of the ground truth segmentationcolor1
- first color to show unique values from first imagecolor2
- second color to show unique values from second image- Returns: array and graphical plot
This package offers a user friendly dice score calculation and dice score plotting functionality to showcase the intersection and complement of each image relative to the other. This package will be continually built on to incorporate other statistical and image processing functionality