from misas.fastai_model import Fastai2_model
def label_func(x):
pass
def acc_seg(input, target):
pass
def diceComb(input, targs):
pass
def diceLV(input, targs):
pass
def diceMY(input, targs):
pass
def img():
"""
Opens the sample image as a PIL image
"""
return Image.open("example/kaggle/images/1-frame014-slice005.png").convert("RGB")
#img = lambda: Image.open("example/kaggle/images/1-frame014-slice005.png")
def trueMask():
"""
Opens the true mask as a PIL image
"""
return Image.open("example/kaggle/masks/1-frame014-slice005.png").convert("I")
#trueMask = lambda: Image.open("example/kaggle/masks/1-frame014-slice005.png")
trainedModel = Fastai2_model("chfc-cmi/cmr-seg-tl", "cmr_seg_base")
Define a default color map for the sample image derived from viridis
and a default color map for the true map derived from plasma
but setting the color for class "0" to completely transparent.
This makes sense if class "0" is the background.
series = get_rotation_series(img(), trainedModel, truth=trueMask())
plot_series(series, overlay_truth = True)
results = eval_rotation_series(img(), trueMask(), trainedModel, components=['bg','LV','MY'])
plot_eval_series(results)
You can easily generate gifs by plotting multiple frames
gif_series(
get_rotation_series(img(),trainedModel,start=0,end=360,step=5),
"example/kaggle/rotation.gif",
duration=500,
param_name="degrees"
)
series = get_crop_series(img(), trainedModel, truth=trueMask(), step=10)
plot_series(series,nrow=3,figsize=(16,15), overlay_truth = True) #,overlay_truth=True)
results = eval_crop_series(img(), trueMask(), trainedModel, components=['bg','LV','MY'])
plot_eval_series(results)
Cropping and comparing to the full original mask might not be desired. In this case it is possible to crop the mask as well. All pixels in the cropped area are set to 0 (commonly the background class). As soon as a class is completely missing, the dice score might jump to 1 because not predicting the class is correct in that case.
gif_series(
get_crop_series(img(),trainedModel,start=0,end=256,step=5),
"example/kaggle/crop.gif",
duration=500,
param_name="pixels"
)
series = get_brightness_series(img(), trainedModel, truth=trueMask(), start=1/8, end=16)
plot_series(series, nrow=3, figsize=(12,6), overlay_truth = True)
results = eval_bright_series(img(), trueMask(), trainedModel, start=0, end=1.05, components=['bg','LV','MY'])
plot_eval_series(results)
gif_series(
get_brightness_series(img(), trainedModel, step = np.sqrt(2)),
"example/kaggle/brightness.gif",
duration=500,
param_name="brightness"
)
series = get_contrast_series(img(), trainedModel, truth=trueMask(), start=1/8, end=16)
plot_series(series, nrow=3, figsize=(12,8), overlay_truth = True)
results = eval_contrast_series(img(), trueMask(), trainedModel, start=0.25, end=8, step=np.sqrt(2), components=['bg','LV','MY'])
plot_eval_series(results)
gif_series(
get_contrast_series(img(), trainedModel,step=np.sqrt(2)),
"example/kaggle/contrast.gif",
duration=500,
param_name="contrast"
)
series = get_zoom_series(img(), trainedModel, truth=trueMask())
plot_series(series, nrow=2, figsize=(16,8), overlay_truth = True)