if False: print "non truncated" smoothed = denoising.nonLocalMean(wTruncate=0.0, **nlmp) vigra.impex.writeHDF5(smoothed, sPath, 'data') if False: print "truncated" smoothedT = denoising.nonLocalMean(wTruncate=0.15, **nlmp) vigra.impex.writeHDF5(smoothedT, stPath, 'data') if False: data = data.astype(numpy.float32) ew = vigra.filters.hessianOfGaussianEigenvalues(data, 4.0) ew = numpy.sort(ew, axis=3)[:, :, :, 2] vigra.impex.writeHDF5(ew, ewPath, 'data') if False: smoothedT = vigra.readHDF5(stPath, 'data').astype(numpy.float32) ews = vigra.filters.hessianOfGaussianEigenvalues(smoothedT, 4.0) ews = numpy.sort(ews, axis=3)[:, :, :, 2] vigra.impex.writeHDF5(ews, ewsPath, 'data') if False: ews = vigra.readHDF5(ewsPath, 'data') policy = denoising.RatioPolicy(sigma=1.0, meanRatio=0.95, varRatio=0.8) nlmp = dict(image=ews.astype(numpy.float64),
if False: print "truncated" smoothedT = denoising.nonLocalMean(wTruncate=0.15,**nlmp) vigra.impex.writeHDF5(smoothedT, stPath, 'data') if False: data=data.astype(numpy.float32) ew = vigra.filters.hessianOfGaussianEigenvalues(data, 4.0) ew = numpy.sort(ew,axis=3)[:, :, :, 2] vigra.impex.writeHDF5(ew, ewPath, 'data') if False: smoothedT = vigra.readHDF5(stPath, 'data').astype(numpy.float32) ews = vigra.filters.hessianOfGaussianEigenvalues(smoothedT, 4.0) ews = numpy.sort(ews,axis=3)[:, :, :, 2] vigra.impex.writeHDF5(ews, ewsPath, 'data') if False: ews = vigra.readHDF5(ewsPath, 'data') policy = denoising.RatioPolicy(sigma=1.0, meanRatio=0.95, varRatio=0.8)
def prepareMinMap(raw, pmap, sPre=0.8, sInt=5.0, mapInterval=0.5, scaleEw=4.0, ewBeta=0.01, tvWeightSoft=None, isotropicTvSoft=True, tvWeightHard=None, isotropicTvHard=True, sPost=0.6, visu=False ): """ """ print "prepare stuff" if tvWeightSoft is None and isotropicTvSoft: tvWeightSoft=5.0 elif tvWeightSoft is None and isotropicTvSoft==False: tvWeightSoft=25.0 if tvWeightHard is None and isotropicTvHard: tvWeightHard=0.7 elif tvWeightHard is None and isotropicTvHard==False: tvWeightHard=15.0 grayData = [] labelsData = [] # do minimalistic raw map presmoothing to remove artifacts if sPre>0.0001: rawG = vigra.filters.gaussianSmoothing(numpy.require(raw ,dtype=numpy.float32), sigma=sPre) else : rawG = numpy.require(image,dtype=numpy.float32) print "pmap integral" # get pmap integral pmapIntegral = vigra.filters.gaussianSmoothing(numpy.require(pmap, dtype=numpy.float32), sigma=sInt ) pmapIntegral = numpy.array(pmapIntegral) grayData.append([rawG,'rawG']) grayData.append([pmapIntegral,'pmapIntegral']) if visu: addHocViewer(grayData, labelsData, visu=visu) # remap integral pmapIntegral[pmapIntegral>mapInterval]=mapInterval pmapIntegral*=1.0/mapInterval print "soft tv" # do soft TV smoothing pmapTVSoft = denoise.tvBregman(pmap, weight=tvWeightSoft, isotropic=isotropicTvSoft).astype(numpy.float32) print "hard tv" # do hard heavy TV smoothing pmapTVHard = denoise.tvBregman(pmap, weight=tvWeightHard, isotropic=isotropicTvHard).astype(numpy.float32) grayData.append([pmapTVSoft,'pmapTVSoft']) grayData.append([pmapTVHard,'pmapTVHard']) if visu: addHocViewer(grayData, labelsData, visu=visu) # mix hard and soft according to pmap probability mixedPmap = numpy.empty(raw.shape) mixedPmap = (1.0 - pmapIntegral)*pmapTVHard + pmapIntegral*pmapTVSoft print "le min le max",mixedPmap.min(), mixedPmap.max() #grayData.append([mixedPmap,'mixedPmap']) #addHocViewer(grayData, labelsData, visu=visu) # add a tiny portion of eigenvalues of hessian give flat wide boundaries the min at the right position # but we only add this at places where the boundary is strong (in a hard fashion) aew = vigra.filters.hessianOfGaussianEigenvalues(numpy.require(raw, dtype=numpy.float32), scale=scaleEw).squeeze() sew = numpy.sort(aew,axis=3) ew = sew[:, :, :, 2] ew *= pmap**2 ew -= ew.min() ew /= ew.max() ew *= ewBeta mixedPmap+=ew grayData.append([mixedPmap,'mixedPmapWITHEW']) if visu: addHocViewer(grayData, labelsData, visu=visu) # do minimalistic final smoothing to remove artefacts if sPre>0.0001: mixedPmapG = vigra.filters.gaussianSmoothing(numpy.require(mixedPmap,dtype=numpy.float32), sigma=sPost) else : mixedPmapG = numpy.require(mixedPmap,dtype=numpy.float32) grayData.append([mixedPmapG,'finalSeedingMap']) if visu: addHocViewer(grayData, labelsData, visu=visu) return mixedPmapG
def prepareMinMap(raw, pmap, sPre=0.8, sInt=5.0, mapInterval=0.5, scaleEw=4.0, ewBeta=0.01, tvWeightSoft=None, isotropicTvSoft=True, tvWeightHard=None, isotropicTvHard=True, sPost=0.6, visu=False): """ """ print "prepare stuff" if tvWeightSoft is None and isotropicTvSoft: tvWeightSoft = 5.0 elif tvWeightSoft is None and isotropicTvSoft == False: tvWeightSoft = 25.0 if tvWeightHard is None and isotropicTvHard: tvWeightHard = 0.7 elif tvWeightHard is None and isotropicTvHard == False: tvWeightHard = 15.0 grayData = [] labelsData = [] # do minimalistic raw map presmoothing to remove artifacts if sPre > 0.0001: rawG = vigra.filters.gaussianSmoothing(numpy.require( raw, dtype=numpy.float32), sigma=sPre) else: rawG = numpy.require(image, dtype=numpy.float32) print "pmap integral" # get pmap integral pmapIntegral = vigra.filters.gaussianSmoothing(numpy.require( pmap, dtype=numpy.float32), sigma=sInt) pmapIntegral = numpy.array(pmapIntegral) grayData.append([rawG, 'rawG']) grayData.append([pmapIntegral, 'pmapIntegral']) if visu: addHocViewer(grayData, labelsData, visu=visu) # remap integral pmapIntegral[pmapIntegral > mapInterval] = mapInterval pmapIntegral *= 1.0 / mapInterval print "soft tv" # do soft TV smoothing pmapTVSoft = denoise.tvBregman(pmap, weight=tvWeightSoft, isotropic=isotropicTvSoft).astype( numpy.float32) print "hard tv" # do hard heavy TV smoothing pmapTVHard = denoise.tvBregman(pmap, weight=tvWeightHard, isotropic=isotropicTvHard).astype( numpy.float32) grayData.append([pmapTVSoft, 'pmapTVSoft']) grayData.append([pmapTVHard, 'pmapTVHard']) if visu: addHocViewer(grayData, labelsData, visu=visu) # mix hard and soft according to pmap probability mixedPmap = numpy.empty(raw.shape) mixedPmap = (1.0 - pmapIntegral) * pmapTVHard + pmapIntegral * pmapTVSoft print "le min le max", mixedPmap.min(), mixedPmap.max() #grayData.append([mixedPmap,'mixedPmap']) #addHocViewer(grayData, labelsData, visu=visu) # add a tiny portion of eigenvalues of hessian give flat wide boundaries the min at the right position # but we only add this at places where the boundary is strong (in a hard fashion) aew = vigra.filters.hessianOfGaussianEigenvalues(numpy.require( raw, dtype=numpy.float32), scale=scaleEw).squeeze() sew = numpy.sort(aew, axis=3) ew = sew[:, :, :, 2] ew *= pmap**2 ew -= ew.min() ew /= ew.max() ew *= ewBeta mixedPmap += ew grayData.append([mixedPmap, 'mixedPmapWITHEW']) if visu: addHocViewer(grayData, labelsData, visu=visu) # do minimalistic final smoothing to remove artefacts if sPre > 0.0001: mixedPmapG = vigra.filters.gaussianSmoothing(numpy.require( mixedPmap, dtype=numpy.float32), sigma=sPost) else: mixedPmapG = numpy.require(mixedPmap, dtype=numpy.float32) grayData.append([mixedPmapG, 'finalSeedingMap']) if visu: addHocViewer(grayData, labelsData, visu=visu) return mixedPmapG