diff options
| author | Tomas Kulhanek <tomas.kulhanek@stfc.ac.uk> | 2019-02-28 16:24:01 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-28 16:24:01 +0000 |
| commit | 879c87c5709ee194a8c7a2207f5a21d4a757f723 (patch) | |
| tree | eddf7bc14a998ffabc7e9e01f0cca2ac44b1d88a /Wrappers/Python/ccpi | |
| parent | 4c728cf72345f7ab7967380cb536529fd9b1403d (diff) | |
| parent | 68e6f3397e8a450854f39a5d514e1f747b9031a4 (diff) | |
| download | regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.gz regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.bz2 regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.xz regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.zip | |
Merge pull request #104 from vais-ral/newdirstructure
New directory structure, Merged other changes. The build script checks old and new structure.
Diffstat (limited to 'Wrappers/Python/ccpi')
| -rw-r--r-- | Wrappers/Python/ccpi/__init__.py | 0 | ||||
| -rw-r--r-- | Wrappers/Python/ccpi/filters/__init__.py | 0 | ||||
| -rw-r--r-- | Wrappers/Python/ccpi/filters/regularisers.py | 214 | ||||
| -rw-r--r-- | Wrappers/Python/ccpi/supp/__init__.py | 0 | ||||
| -rw-r--r-- | Wrappers/Python/ccpi/supp/qualitymetrics.py | 65 |
5 files changed, 0 insertions, 279 deletions
diff --git a/Wrappers/Python/ccpi/__init__.py b/Wrappers/Python/ccpi/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/Wrappers/Python/ccpi/__init__.py +++ /dev/null diff --git a/Wrappers/Python/ccpi/filters/__init__.py b/Wrappers/Python/ccpi/filters/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/Wrappers/Python/ccpi/filters/__init__.py +++ /dev/null diff --git a/Wrappers/Python/ccpi/filters/regularisers.py b/Wrappers/Python/ccpi/filters/regularisers.py deleted file mode 100644 index 588ea32..0000000 --- a/Wrappers/Python/ccpi/filters/regularisers.py +++ /dev/null @@ -1,214 +0,0 @@ -""" -script which assigns a proper device core function based on a flag ('cpu' or 'gpu') -""" - -from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU, PATCHSEL_CPU, NLTV_CPU -try: - from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU, PATCHSEL_GPU - gpu_enabled = True -except ImportError: - gpu_enabled = False -from ccpi.filters.cpu_regularisers import NDF_INPAINT_CPU, NVM_INPAINT_CPU - -def ROF_TV(inputData, regularisation_parameter, iterations, - time_marching_parameter,device='cpu'): - if device == 'cpu': - return TV_ROF_CPU(inputData, - regularisation_parameter, - iterations, - time_marching_parameter) - elif device == 'gpu' and gpu_enabled: - return TV_ROF_GPU(inputData, - regularisation_parameter, - iterations, - time_marching_parameter) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) - -def FGP_TV(inputData, regularisation_parameter,iterations, - tolerance_param, methodTV, nonneg, printM, device='cpu'): - if device == 'cpu': - return TV_FGP_CPU(inputData, - regularisation_parameter, - iterations, - tolerance_param, - methodTV, - nonneg, - printM) - elif device == 'gpu' and gpu_enabled: - return TV_FGP_GPU(inputData, - regularisation_parameter, - iterations, - tolerance_param, - methodTV, - nonneg, - printM) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def SB_TV(inputData, regularisation_parameter, iterations, - tolerance_param, methodTV, printM, device='cpu'): - if device == 'cpu': - return TV_SB_CPU(inputData, - regularisation_parameter, - iterations, - tolerance_param, - methodTV, - printM) - elif device == 'gpu' and gpu_enabled: - return TV_SB_GPU(inputData, - regularisation_parameter, - iterations, - tolerance_param, - methodTV, - printM) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def FGP_dTV(inputData, refdata, regularisation_parameter, iterations, - tolerance_param, eta_const, methodTV, nonneg, printM, device='cpu'): - if device == 'cpu': - return dTV_FGP_CPU(inputData, - refdata, - regularisation_parameter, - iterations, - tolerance_param, - eta_const, - methodTV, - nonneg, - printM) - elif device == 'gpu' and gpu_enabled: - return dTV_FGP_GPU(inputData, - refdata, - regularisation_parameter, - iterations, - tolerance_param, - eta_const, - methodTV, - nonneg, - printM) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def TNV(inputData, regularisation_parameter, iterations, tolerance_param): - return TNV_CPU(inputData, - regularisation_parameter, - iterations, - tolerance_param) -def NDF(inputData, regularisation_parameter, edge_parameter, iterations, - time_marching_parameter, penalty_type, device='cpu'): - if device == 'cpu': - return NDF_CPU(inputData, - regularisation_parameter, - edge_parameter, - iterations, - time_marching_parameter, - penalty_type) - elif device == 'gpu' and gpu_enabled: - return NDF_GPU(inputData, - regularisation_parameter, - edge_parameter, - iterations, - time_marching_parameter, - penalty_type) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def Diff4th(inputData, regularisation_parameter, edge_parameter, iterations, - time_marching_parameter, device='cpu'): - if device == 'cpu': - return Diff4th_CPU(inputData, - regularisation_parameter, - edge_parameter, - iterations, - time_marching_parameter) - elif device == 'gpu' and gpu_enabled: - return Diff4th_GPU(inputData, - regularisation_parameter, - edge_parameter, - iterations, - time_marching_parameter) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) - -def PatchSelect(inputData, searchwindow, patchwindow, neighbours, edge_parameter, device='cpu'): - if device == 'cpu': - return PATCHSEL_CPU(inputData, - searchwindow, - patchwindow, - neighbours, - edge_parameter) - elif device == 'gpu' and gpu_enabled: - return PATCHSEL_GPU(inputData, - searchwindow, - patchwindow, - neighbours, - edge_parameter) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) - -def NLTV(inputData, H_i, H_j, H_k, Weights, regularisation_parameter, iterations): - return NLTV_CPU(inputData, - H_i, - H_j, - H_k, - Weights, - regularisation_parameter, - iterations) - -def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations, - LipshitzConst, device='cpu'): - if device == 'cpu': - return TGV_CPU(inputData, - regularisation_parameter, - alpha1, - alpha0, - iterations, - LipshitzConst) - elif device == 'gpu' and gpu_enabled: - return TGV_GPU(inputData, - regularisation_parameter, - alpha1, - alpha0, - iterations, - LipshitzConst) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def LLT_ROF(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, - time_marching_parameter, device='cpu'): - if device == 'cpu': - return LLT_ROF_CPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter) - elif device == 'gpu' and gpu_enabled: - return LLT_ROF_GPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter) - else: - if not gpu_enabled and device == 'gpu': - raise ValueError ('GPU is not available') - raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ - .format(device)) -def NDF_INP(inputData, maskData, regularisation_parameter, edge_parameter, iterations, - time_marching_parameter, penalty_type): - return NDF_INPAINT_CPU(inputData, maskData, regularisation_parameter, - edge_parameter, iterations, time_marching_parameter, penalty_type) - -def NVM_INP(inputData, maskData, SW_increment, iterations): - return NVM_INPAINT_CPU(inputData, maskData, SW_increment, iterations) diff --git a/Wrappers/Python/ccpi/supp/__init__.py b/Wrappers/Python/ccpi/supp/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/Wrappers/Python/ccpi/supp/__init__.py +++ /dev/null diff --git a/Wrappers/Python/ccpi/supp/qualitymetrics.py b/Wrappers/Python/ccpi/supp/qualitymetrics.py deleted file mode 100644 index f44d832..0000000 --- a/Wrappers/Python/ccpi/supp/qualitymetrics.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8 -*- -""" -A class for some standard image quality metrics -""" -import numpy as np - -class QualityTools: - def __init__(self, im1, im2): - if im1.size != im2.size: - print ('Error: Sizes of images/volumes are different') - raise SystemExit - self.im1 = im1 # image or volume - 1 - self.im2 = im2 # image or volume - 2 - def nrmse(self): - """ Normalised Root Mean Square Error """ - rmse = np.sqrt(np.sum((self.im2 - self.im1) ** 2) / float(self.im1.size)) - max_val = max(np.max(self.im1), np.max(self.im2)) - min_val = min(np.min(self.im1), np.min(self.im2)) - return 1 - (rmse / (max_val - min_val)) - def rmse(self): - """ Root Mean Square Error """ - rmse = np.sqrt(np.sum((self.im1 - self.im2) ** 2) / float(self.im1.size)) - return rmse - def ssim(self, window, k=(0.01, 0.03), l=255): - from scipy.signal import fftconvolve - """See https://ece.uwaterloo.ca/~z70wang/research/ssim/""" - # Check if the window is smaller than the images. - for a, b in zip(window.shape, self.im1.shape): - if a > b: - return None, None - # Values in k must be positive according to the base implementation. - for ki in k: - if ki < 0: - return None, None - - c1 = (k[0] * l) ** 2 - c2 = (k[1] * l) ** 2 - window = window/np.sum(window) - - mu1 = fftconvolve(self.im1, window, mode='valid') - mu2 = fftconvolve(self.im2, window, mode='valid') - mu1_sq = mu1 * mu1 - mu2_sq = mu2 * mu2 - mu1_mu2 = mu1 * mu2 - sigma1_sq = fftconvolve(self.im1 * self.im1, window, mode='valid') - mu1_sq - sigma2_sq = fftconvolve(self.im2 * self.im2, window, mode='valid') - mu2_sq - sigma12 = fftconvolve(self.im1 * self.im2, window, mode='valid') - mu1_mu2 - - if c1 > 0 and c2 > 0: - num = (2 * mu1_mu2 + c1) * (2 * sigma12 + c2) - den = (mu1_sq + mu2_sq + c1) * (sigma1_sq + sigma2_sq + c2) - ssim_map = num / den - else: - num1 = 2 * mu1_mu2 + c1 - num2 = 2 * sigma12 + c2 - den1 = mu1_sq + mu2_sq + c1 - den2 = sigma1_sq + sigma2_sq + c2 - ssim_map = np.ones(np.shape(mu1)) - index = (den1 * den2) > 0 - ssim_map[index] = (num1[index] * num2[index]) / (den1[index] * den2[index]) - index = (den1 != 0) & (den2 == 0) - ssim_map[index] = num1[index] / den1[index] - mssim = ssim_map.mean() - return mssim, ssim_map |
