# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file."""Restoration computation module------------------------------"""# pylint: disable=invalid-name # Allows short reference names like x, y, ...# Note:# ----# All dataset classes must also be imported in the cdl.computation.param module.from__future__importannotationsimportguidata.datasetasgdsimportpywtfromskimageimportmorphologyfromskimage.restorationimportdenoise_bilateral,denoise_tv_chambolle,denoise_waveletfromcdl.computation.imageimportWrap11Func,dst_11,restore_data_outside_roifromcdl.computation.image.morphologyimportMorphologyParamfromcdl.configimport_fromcdl.objimportImageObj
[docs]classDenoiseTVParam(gds.DataSet):"""Total Variation denoising parameters"""weight=gds.FloatItem(_("Denoising weight"),default=0.1,min=0,nonzero=True,help=_("The greater weight, the more denoising ""(at the expense of fidelity to input)."),)eps=gds.FloatItem("Epsilon",default=0.0002,min=0,nonzero=True,help=_("Relative difference of the value of the cost function that ""determines the stop criterion. The algorithm stops when: ""(E_(n-1) - E_n) < eps * E_0"),)max_num_iter=gds.IntItem(_("Max. iterations"),default=200,min=0,nonzero=True,help=_("Maximal number of iterations used for the optimization"),)
[docs]defcompute_denoise_tv(src:ImageObj,p:DenoiseTVParam)->ImageObj:"""Compute Total Variation denoising with :py:func:`skimage.restoration.denoise_tv_chambolle` Args: src: input image object p: parameters Returns: Output image object """returnWrap11Func(denoise_tv_chambolle,weight=p.weight,eps=p.eps,max_num_iter=p.max_num_iter)(src)
[docs]classDenoiseBilateralParam(gds.DataSet):"""Bilateral filter denoising parameters"""sigma_spatial=gds.FloatItem("σ<sub>spatial</sub>",default=1.0,min=0,nonzero=True,unit="pixels",help=_("Standard deviation for range distance. ""A larger value results in averaging of pixels ""with larger spatial differences."),)modes=("constant","edge","symmetric","reflect","wrap")mode=gds.ChoiceItem(_("Mode"),list(zip(modes,modes)),default="constant")cval=gds.FloatItem("cval",default=0,help=_("Used in conjunction with mode 'constant', ""the value outside the image boundaries."),)