diff --git a/pyproject.toml b/pyproject.toml index 75c19842..f3b3b48e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ test = [ "pytest-sugar>=0.9.6", "pytest-cython>=0.2.0", "nanopyx[jupyter]", + "numba" ] jupyter = [ "nbformat>=4.2.0", diff --git a/src/nanopyx/__liquid_engine__.py b/src/nanopyx/__liquid_engine__.py index ed4ba21d..dcd4a892 100644 --- a/src/nanopyx/__liquid_engine__.py +++ b/src/nanopyx/__liquid_engine__.py @@ -268,13 +268,6 @@ def _store_results(self, arg_repr, arg_score, run_type, t2run): Stores the results of a run """ - # Re-read the benchmark file in case it has been updated - try: - with open(self._benchmark_filepath) as f: - self._benchmarks = yaml.load(f, Loader=yaml.FullLoader) - except FileNotFoundError: - self._benchmarks = self._benchmarks - # Check if the run type has been run, and if not create empty info run_type_benchs = self._benchmarks[run_type] if arg_repr not in run_type_benchs: @@ -284,19 +277,15 @@ def _store_results(self, arg_repr, arg_score, run_type, t2run): c = run_type_benchs[arg_repr] assert c[0] == arg_score, "arg_score mismatch" - - # if run failed, t2run is np.inf - if np.isinf(t2run): - c.append(np.nan) - else: - c.append(t2run) + + c.append(t2run) self._dump_run_times() def _dump_run_times( self, ): - """We might need to wrap this into a multiprocessing.Queue if we find it blocking""" + # TODO We might need to wrap this into a multiprocessing.Queue if we find it blocking with open(self._benchmark_filepath, "w") as f: yaml.dump(self._benchmarks, f) diff --git a/src/nanopyx/core/analysis/cross_correlation_elastic.py b/src/nanopyx/core/analysis/cross_correlation_elastic.py index 4ea2402d..c3196af1 100644 --- a/src/nanopyx/core/analysis/cross_correlation_elastic.py +++ b/src/nanopyx/core/analysis/cross_correlation_elastic.py @@ -1,7 +1,7 @@ import numpy as np from math import sqrt from skimage.filters import gaussian -from scipy.interpolate import interp2d +from scipy.interpolate import bisplrep, bisplev # replacement for interp2d see: https://gist.github.com/ev-br/8544371b40f414b7eaf3fe6217209bff from .ccm import calculate_ccm_from_ref from .estimate_shift import GetMaxOptimizer @@ -252,8 +252,11 @@ def calculate_translation_mask_vector_field( y_translation = np.array(y_translation) x_translation = np.array(x_translation) - y_interp = interp2d(y_translation[:, 0], y_translation[:, 1], y_translation[:, 2]) - x_interp = interp2d(x_translation[:, 0], x_translation[:, 1], x_translation[:, 2]) + + y_spline = bisplrep(y_translation[:, 0], y_translation[:, 1], y_translation[:, 2],kx=1, ky=1, s=0) # bspline representation + x_spline = bisplrep(x_translation[:, 0], x_translation[:, 1], x_translation[:, 2],kx=1, ky=1, s=0) + x_interp = lambda x, y: bisplev(x, y, x_spline).T # bspline evaluation + y_interp = lambda x, y: bisplev(x, y, y_spline).T translation_matrix = np.zeros((height, width * 2)) translation_matrix_x = np.zeros((height, width)) diff --git a/src/nanopyx/core/transform/_le_interpolation_bicubic.pyx b/src/nanopyx/core/transform/_le_interpolation_bicubic.pyx index 382afc6c..27ca98d6 100644 --- a/src/nanopyx/core/transform/_le_interpolation_bicubic.pyx +++ b/src/nanopyx/core/transform/_le_interpolation_bicubic.pyx @@ -47,8 +47,6 @@ class ShiftAndMagnify(LiquidEngine): :return: The shifted and magnified image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, magnification_row, magnification_col, run_type=run_type) # tag-end @@ -70,8 +68,6 @@ class ShiftAndMagnify(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, magnification_row, magnification_col) # tag-end @@ -109,8 +105,8 @@ class ShiftAndMagnify(LiquidEngine): self.get_work_group(dc, (n_slices, image.shape[1]*magnification_row, image.shape[2]*magnification_col)), input_opencl, output_opencl, - np.float32(shift_row[0]), - np.float32(shift_col[0]), + np.float32(shift_row), + np.float32(shift_col), np.float32(magnification_row), np.float32(magnification_col)).wait() @@ -127,7 +123,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -144,16 +140,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -170,16 +166,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -196,16 +192,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="static"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -222,16 +218,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="dynamic"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -248,9 +244,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="guided"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -287,8 +283,6 @@ class ShiftScaleRotate(LiquidEngine): :return: The shifted, magnified and rotated image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, scale_row, scale_col, angle, run_type=run_type) # tag-end @@ -312,8 +306,6 @@ class ShiftScaleRotate(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, scale_row, scale_col, angle) # tag-end @@ -367,11 +359,11 @@ class ShiftScaleRotate(LiquidEngine): input_opencl.release() output_opencl.release() - return image_out + return np.asarray(image_out, dtype=np.float32) # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -399,15 +391,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -435,15 +427,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -471,15 +463,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -507,15 +499,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -543,8 +535,8 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out diff --git a/src/nanopyx/core/transform/_le_interpolation_catmull_rom.pyx b/src/nanopyx/core/transform/_le_interpolation_catmull_rom.pyx index 0eab7c04..72fb8086 100644 --- a/src/nanopyx/core/transform/_le_interpolation_catmull_rom.pyx +++ b/src/nanopyx/core/transform/_le_interpolation_catmull_rom.pyx @@ -51,8 +51,6 @@ class ShiftAndMagnify(LiquidEngine): :return: The shifted and magnified image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, magnification_row, magnification_col, run_type=run_type) # tag-end @@ -74,8 +72,6 @@ class ShiftAndMagnify(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, magnification_row, magnification_col) # tag-end @@ -113,8 +109,8 @@ class ShiftAndMagnify(LiquidEngine): self.get_work_group(dc, (n_slices, image.shape[1]*magnification_row, image.shape[2]*magnification_col)), input_opencl, output_opencl, - np.float32(shift_row[0]), - np.float32(shift_col[0]), + np.float32(shift_row), + np.float32(shift_col), np.float32(magnification_row), np.float32(magnification_col)).wait() @@ -131,7 +127,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -148,16 +144,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -174,16 +170,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -200,16 +196,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="static"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -226,16 +222,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="dynamic"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -252,9 +248,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="guided"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -299,8 +295,6 @@ class ShiftScaleRotate(LiquidEngine): :return: The shifted, magnified and rotated image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, scale_row, scale_col, angle, run_type=run_type) # tag-end @@ -324,8 +318,6 @@ class ShiftScaleRotate(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, scale_row, scale_col, angle) # tag-end @@ -352,6 +344,10 @@ class ShiftScaleRotate(LiquidEngine): prg = cl.Program(cl_ctx, code).build() knl = prg.shiftScaleRotate + print(dc.name) + print(knl.get_work_group_info(cl.kernel_work_group_info.PREFERRED_WORK_GROUP_SIZE_MULTIPLE,dc)) + print(knl.get_work_group_info(cl.kernel_work_group_info.WORK_GROUP_SIZE,dc)) + for i in range(0, image.shape[0], max_slices): if image.shape[0] - i >= max_slices: n_slices = max_slices @@ -384,7 +380,7 @@ class ShiftScaleRotate(LiquidEngine): # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -412,15 +408,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -448,15 +444,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -484,15 +480,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -520,15 +516,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -556,8 +552,8 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out diff --git a/src/nanopyx/core/transform/_le_interpolation_catmull_rom_.py b/src/nanopyx/core/transform/_le_interpolation_catmull_rom_.py index 526ce4eb..91b65941 100644 --- a/src/nanopyx/core/transform/_le_interpolation_catmull_rom_.py +++ b/src/nanopyx/core/transform/_le_interpolation_catmull_rom_.py @@ -98,8 +98,8 @@ def _njit_interpolate(image, r, c, rows, cols): def shift_magnify( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, magnification_row: float, magnification_col: float, ) -> np.ndarray: @@ -122,9 +122,9 @@ def shift_magnify( image_out = np.zeros((nFrames, rowsM, colsM), dtype=np.float32) for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row image_out[f, i, j] = _interpolate(image[f, :, :], row, col, rows, cols) return image_out @@ -133,8 +133,8 @@ def shift_magnify( @njit(cache=True, parallel=True) def njit_shift_magnify( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, magnification_row: float, magnification_col: float, ) -> np.ndarray: @@ -157,9 +157,9 @@ def njit_shift_magnify( image_out = np.zeros((nFrames, rowsM, colsM), dtype=np.float32) for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row image_out[f, i, j] = _njit_interpolate(image[f, :, :], row, col, rows, cols) return image_out diff --git a/src/nanopyx/core/transform/_le_interpolation_lanczos.pyx b/src/nanopyx/core/transform/_le_interpolation_lanczos.pyx index 2de150ef..7e3dd057 100644 --- a/src/nanopyx/core/transform/_le_interpolation_lanczos.pyx +++ b/src/nanopyx/core/transform/_le_interpolation_lanczos.pyx @@ -46,8 +46,6 @@ class ShiftAndMagnify(LiquidEngine): :return: The shifted and magnified image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, magnification_row, magnification_col, run_type=run_type) # tag-end @@ -69,8 +67,6 @@ class ShiftAndMagnify(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, magnification_row, magnification_col) # tag-end @@ -108,8 +104,8 @@ class ShiftAndMagnify(LiquidEngine): self.get_work_group(dc, (n_slices, image.shape[1]*magnification_row, image.shape[2]*magnification_col)), input_opencl, output_opencl, - np.float32(shift_row[0]), - np.float32(shift_col[0]), + np.float32(shift_row), + np.float32(shift_col), np.float32(magnification_row), np.float32(magnification_col)).wait() @@ -126,7 +122,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -143,16 +139,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -169,16 +165,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -195,16 +191,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="static"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -221,16 +217,16 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="dynamic"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -247,9 +243,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="guided"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -286,8 +282,6 @@ class ShiftScaleRotate(LiquidEngine): :return: The shifted, magnified and rotated image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, scale_row, scale_col, angle, run_type=run_type) # tag-end @@ -311,8 +305,6 @@ class ShiftScaleRotate(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, scale_row, scale_col, angle) # tag-end @@ -335,7 +327,7 @@ class ShiftScaleRotate(LiquidEngine): output_opencl = cl.Buffer(cl_ctx, mf.WRITE_ONLY, image_out[0:max_slices,:,:].nbytes) cl.enqueue_copy(cl_queue, input_opencl, image[0:max_slices,:,:]).wait() - code = self._get_cl_code("_le_interpolation_lanczos_.cl", device['DP']) + code = self._get_cl_code("_le_interpolation_lanczos_.cl", False) prg = cl.Program(cl_ctx, code).build() knl = prg.shiftScaleRotate @@ -371,7 +363,7 @@ class ShiftScaleRotate(LiquidEngine): # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -399,15 +391,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -435,15 +427,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -471,15 +463,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -507,15 +499,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -543,8 +535,8 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out diff --git a/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor.pyx b/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor.pyx index 4b0cce5d..09e7321c 100644 --- a/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor.pyx +++ b/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor.pyx @@ -55,8 +55,6 @@ class ShiftAndMagnify(LiquidEngine): :return: The shifted and magnified image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, magnification_row, magnification_col, run_type=run_type) # tag-end @@ -78,8 +76,6 @@ class ShiftAndMagnify(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, magnification_row, magnification_col) # tag-end @@ -118,8 +114,8 @@ class ShiftAndMagnify(LiquidEngine): self.get_work_group(dc, (n_slices, image.shape[1]*magnification_row, image.shape[2]*magnification_col)), input_opencl, output_opencl, - np.float32(shift_row[0]), - np.float32(shift_col[0]), + np.float32(shift_row), + np.float32(shift_col), np.float32(magnification_row), np.float32(magnification_col)).wait() @@ -137,7 +133,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-start: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded #@LiquidEngine._logger(logger) - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -154,9 +150,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -164,7 +160,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(colsM)", "prange(colsM)") #@LiquidEngine._logger(logger) - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -181,9 +177,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -191,7 +187,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(colsM)", 'prange(colsM, schedule="static")') #@LiquidEngine._logger(logger) - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -208,9 +204,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="static"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -218,7 +214,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(colsM)", 'prange(colsM, schedule="dynamic")') #@LiquidEngine._logger(logger) - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -235,9 +231,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="dynamic"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -245,7 +241,7 @@ class ShiftAndMagnify(LiquidEngine): # tag-copy: _le_interpolation_nearest_neighbor.ShiftAndMagnify._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(colsM)", 'prange(colsM, schedule="guided")') #@LiquidEngine._logger(logger) - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float magnification_row, float magnification_col) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float magnification_row, float magnification_col) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -262,9 +258,9 @@ class ShiftAndMagnify(LiquidEngine): with nogil: for f in range(nFrames): for j in prange(colsM, schedule="guided"): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -282,8 +278,8 @@ class ShiftAndMagnify(LiquidEngine): def _run_njit( self, image=np.zeros((1,10,10),dtype=np.float32), - shift_row=np.zeros((1,),dtype=np.float32), - shift_col=np.zeros((1,),dtype=np.float32), + shift_row=0.0, + shift_col=0.0, magnification_row=1, magnification_col=1) -> np.ndarray: image_out = _njit_shift_magnify(image, shift_row, shift_col, magnification_row, magnification_col) return image_out @@ -321,8 +317,6 @@ class ShiftScaleRotate(LiquidEngine): :return: The shifted, magnified and rotated image """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return self._run(image, shift_row, shift_col, scale_row, scale_col, angle, run_type=run_type) # tag-end @@ -347,8 +341,6 @@ class ShiftScaleRotate(LiquidEngine): :rtype: [[run_time, run_type_name, return_value], ...] """ image = check_image(image) - shift_row = value2array(shift_row, image.shape[0]) - shift_col = value2array(shift_col, image.shape[0]) return super().benchmark(image, shift_row, shift_col, scale_row, scale_col, angle) # tag-end @@ -408,7 +400,7 @@ class ShiftScaleRotate(LiquidEngine): # tag-end # tag-start: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded - def _run_unthreaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_unthreaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -436,15 +428,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded"); replace("range(cols)", "prange(cols)") - def _run_threaded(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -472,15 +464,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in prange(cols): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_static"); replace("range(cols)", "prange(cols, schedule='static')") - def _run_threaded_static(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_static(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -508,15 +500,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in prange(cols, schedule='static'): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_dynamic"); replace("range(cols)", "prange(cols, schedule='dynamic')") - def _run_threaded_dynamic(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_dynamic(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -544,15 +536,15 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in prange(cols, schedule='dynamic'): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out # tag-end # tag-copy: _le_interpolation_nearest_neighbor.ShiftScaleRotate._run_unthreaded; replace("_run_unthreaded", "_run_threaded_guided"); replace("range(cols)", "prange(cols, schedule='guided')") - def _run_threaded_guided(self, float[:,:,:] image, float[:] shift_row, float[:] shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: + def _run_threaded_guided(self, float[:,:,:] image, float shift_row, float shift_col, float scale_row, float scale_col, float angle) -> np.ndarray: cdef int nFrames = image.shape[0] cdef int rows = image.shape[1] cdef int cols = image.shape[2] @@ -580,8 +572,8 @@ class ShiftScaleRotate(LiquidEngine): for f in range(nFrames): for j in prange(cols, schedule='guided'): for i in range(rows): - col = (a*(j-center_col-shift_col[f])+b*(i-center_row-shift_row[f])) + center_col - row = (c*(j-center_col-shift_col[f])+d*(i-center_row-shift_row[f])) + center_row + col = (a*(j-center_col-shift_col)+b*(i-center_row-shift_row)) + center_col + row = (c*(j-center_col-shift_col)+d*(i-center_row-shift_row)) + center_row _image_out[f, i, j] = _c_interpolate(&_image_in[f, 0, 0], row, col, rows, cols) return image_out @@ -598,8 +590,8 @@ class ShiftScaleRotate(LiquidEngine): def _run_njit( self, image=np.zeros((1,10,10),dtype=np.float32), - shift_row=np.zeros((1,),dtype=np.float32), - shift_col=np.zeros((1,),dtype=np.float32), + shift_row=0.0, + shift_col=0.0, scale_row=1, scale_col=1, angle=0) -> np.ndarray: image_out = _njit_shift_magnify_rotate(image, shift_row, shift_col, scale_row, scale_col, angle) return image_out diff --git a/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor_.py b/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor_.py index 0bac11a6..38c9b39c 100644 --- a/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor_.py +++ b/src/nanopyx/core/transform/_le_interpolation_nearest_neighbor_.py @@ -50,8 +50,8 @@ def _njit_interpolate(image, row, col, rows, cols): def shift_magnify( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, magnification_row: float, magnification_col: float, ) -> np.ndarray: @@ -74,9 +74,9 @@ def shift_magnify( image_out = np.zeros((nFrames, rowsM, colsM), dtype=np.float32) for f in range(nFrames): for j in range(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row image_out[f, i, j] = _interpolate(image[f, :, :], row, col, rows, cols) return image_out @@ -85,8 +85,8 @@ def shift_magnify( @njit(cache=True, parallel=True) def njit_shift_magnify( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, magnification_row: float, magnification_col: float, ) -> np.ndarray: @@ -109,9 +109,9 @@ def njit_shift_magnify( image_out = np.zeros((nFrames, rowsM, colsM), dtype=np.float32) for f in range(nFrames): for j in prange(colsM): - col = j / magnification_col - shift_col[f] + col = j / magnification_col - shift_col for i in range(rowsM): - row = i / magnification_row - shift_row[f] + row = i / magnification_row - shift_row image_out[f, i, j] = _njit_interpolate(image[f, :, :], row, col, rows, cols) return image_out @@ -119,8 +119,8 @@ def njit_shift_magnify( def shift_scale_rotate( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, scale_row: float, scale_col: float, angle: float, @@ -176,8 +176,8 @@ def shift_scale_rotate( for f in range(nFrames): for j in range(cols): for i in range(rows): - col = (a * (j - center_col - shift_col[f]) + b * (i - center_row - shift_row[f])) + center_col - row = (c * (j - center_col - shift_col[f]) + d * (i - center_row - shift_row[f])) + center_row + col = (a * (j - center_col - shift_col) + b * (i - center_row - shift_row)) + center_col + row = (c * (j - center_col - shift_col) + d * (i - center_row - shift_row)) + center_row image_out[f, i, j] = _interpolate(image[f, :, :], row, col, rows, cols) return image_out @@ -186,8 +186,8 @@ def shift_scale_rotate( @njit(cache=True, parallel=True) def njit_shift_scale_rotate( image: np.ndarray, - shift_row: np.ndarray, - shift_col: np.ndarray, + shift_row: float, + shift_col: float, scale_row: float, scale_col: float, angle: float, @@ -223,8 +223,8 @@ def njit_shift_scale_rotate( for f in range(nFrames): for j in prange(cols): for i in range(rows): - col = (a * (j - center_col - shift_col[f]) + b * (i - center_row - shift_row[f])) + center_col - row = (c * (j - center_col - shift_col[f]) + d * (i - center_row - shift_row[f])) + center_row + col = (a * (j - center_col - shift_col) + b * (i - center_row - shift_row)) + center_col + row = (c * (j - center_col - shift_col) + d * (i - center_row - shift_row)) + center_row image_out[f, i, j] = _njit_interpolate(image[f, :, :], row, col, rows, cols) return image_out diff --git a/src/nanopyx/core/transform/_le_radiality.pyx b/src/nanopyx/core/transform/_le_radiality.pyx index 83663da9..78785146 100644 --- a/src/nanopyx/core/transform/_le_radiality.pyx +++ b/src/nanopyx/core/transform/_le_radiality.pyx @@ -268,12 +268,12 @@ class Radiality(LiquidEngine): image_out = np.zeros((nFrames, h*magnification, w*magnification), dtype=np.float32) - x_ring_coords = np.asarray(xRingCoordinates) - y_ring_coords = np.asarray(yRingCoordinates) + x_ring_coords = np.asarray(xRingCoordinates, dtype=np.float32) + y_ring_coords = np.asarray(yRingCoordinates, dtype=np.float32) # Calculate maximum number of slices that can fit in the GPU - size_per_slice = 2*image[0,:,:].nbytes + image_interp[0,:,:].nbytes + imGx[0,:,:].nbytes + imGy[0,:,:].nbytes + x_ring_coords.nbytes + y_ring_coords.nbytes - max_slices = int((device["device"].global_mem_size // (size_per_slice))/mem_div) + size_per_slice = 2*image[0,:,:].nbytes + image_interp[0,:,:].nbytes + imGx[0,:,:].nbytes + imGy[0,:,:].nbytes + max_slices = int(((x_ring_coords.nbytes + y_ring_coords.nbytes)+(device["device"].global_mem_size // size_per_slice))/mem_div) max_slices = self._check_max_slices(image, max_slices) # Initialize Buffers @@ -328,7 +328,7 @@ class Radiality(LiquidEngine): np.int32(border), np.int32(h), np.int32(w) - ) + ).wait() cl.enqueue_copy(cl_queue, image_out[i:i+n_slices,:,:], imRad_out).wait() diff --git a/tests/test_esrrf.py b/tests/test_esrrf.py index 7c5ec68e..0cae5620 100644 --- a/tests/test_esrrf.py +++ b/tests/test_esrrf.py @@ -9,8 +9,8 @@ def test_rgc(downloader): small_dataset = dataset[:10,:20,:20] crsm = CRShiftAndMagnify() - grc = GradientRobertsCross(testing=True) - rgc = RadialGradientConvergence(testing=True) + grc = GradientRobertsCross(testing=True,clear_benchmarks=True) + rgc = RadialGradientConvergence(testing=True,clear_benchmarks=True) small_dataset_interp = crsm.run(small_dataset, 0, 0, 5, 5) gradient_col, gradient_row = grc.run(small_dataset) diff --git a/tests/test_mandelbrot.py b/tests/test_mandelbrot.py index 0ed10010..770bc33c 100644 --- a/tests/test_mandelbrot.py +++ b/tests/test_mandelbrot.py @@ -2,7 +2,7 @@ # flake8: noqa: E501 def test_mandelbrot_benchmark(plt): - mb = MandelbrotBenchmark(testing=True) + mb = MandelbrotBenchmark(testing=True,clear_benchmarks=True) values = mb.benchmark(128) images = [] diff --git a/tests/test_srrf.py b/tests/test_srrf.py index d7170566..55d8aea5 100644 --- a/tests/test_srrf.py +++ b/tests/test_srrf.py @@ -10,7 +10,7 @@ def test_radiality(downloader): interp = CRShiftAndMagnify() small_dataset_interp = interp.run(small_dataset,0,0,5,5) - liquid_rad = Radiality(testing=True) + liquid_rad = Radiality(testing=True,clear_benchmarks=True) imRad = liquid_rad.benchmark(small_dataset,small_dataset_interp) def test_srrf(downloader): diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 23040440..b990540b 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -10,9 +10,9 @@ def test_interpolation_nearest_neighbor_ShiftAndMagnify(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.ones(nFrames, dtype=np.float32) * 2 - shift_col = np.ones(nFrames, dtype=np.float32) * 5 - SM = NNShiftAndMagnify(testing=True) + shift_row = 5.0 + shift_col = 5.0 + SM = NNShiftAndMagnify(testing=True, clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M) images = [] @@ -49,9 +49,9 @@ def test_interpolation_bicubic_ShiftAndMagnify(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.ones(nFrames, dtype=np.float32) * 2 - shift_col = np.ones(nFrames, dtype=np.float32) * 5 - SM = BCShiftAndMagnify(testing=True) + shift_row = 5.0 + shift_col = 5.0 + SM = BCShiftAndMagnify(testing=True, clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M) images = [] @@ -88,9 +88,9 @@ def test_interpolation_catmull_rom_ShiftAndMagnify(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.ones(nFrames, dtype=np.float32) * 2 - shift_col = np.ones(nFrames, dtype=np.float32) * 5 - SM = CRShiftAndMagnify(testing=True) + shift_row = 5.0 + shift_col = 5.0 + SM = CRShiftAndMagnify(testing=True, clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M) images = [] @@ -127,9 +127,9 @@ def test_interpolation_lanczos_ShiftAndMagnify(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.ones(nFrames, dtype=np.float32) * 2 - shift_col = np.ones(nFrames, dtype=np.float32) * 5 - SM = LZShiftAndMagnify(testing=True) + shift_row = 5.0 + shift_col = 5.0 + SM = LZShiftAndMagnify(testing=True, clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M) images = [] @@ -166,10 +166,10 @@ def test_interpolation_nearest_neighbor_ShiftScaleRotate(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.arange(nFrames, dtype=np.float32) * 0.5 - shift_col = np.arange(nFrames, dtype=np.float32) * -0.5 + shift_row = 5.0 + shift_col = 5.0 angle = np.pi / 4 - SM = NNShiftScaleRotate(testing=True) + SM = NNShiftScaleRotate(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M, angle) images = [] @@ -205,10 +205,10 @@ def test_interpolation_bicubic_ShiftScaleRotate(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.arange(nFrames, dtype=np.float32) * 0.5 - shift_col = np.arange(nFrames, dtype=np.float32) * -0.5 + shift_row = 5.0 + shift_col = 5.0 angle = np.pi / 4 - SM = BCShiftScaleRotate(testing=True) + SM = BCShiftScaleRotate(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M, angle) images = [] @@ -244,10 +244,10 @@ def test_interpolation_catmull_rom_ShiftScaleRotate(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.arange(nFrames, dtype=np.float32) * 0.5 - shift_col = np.arange(nFrames, dtype=np.float32) * -0.5 + shift_row = 5.0 + shift_col = 5.0 angle = np.pi / 4 - SM = CRShiftScaleRotate(testing=True) + SM = CRShiftScaleRotate(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M, angle) images = [] @@ -283,10 +283,10 @@ def test_interpolation_lanzcos_ShiftScaleRotate(plt): M = 4 nFrames = 3 image = get_simplex_noise(64, 32, frames=nFrames, amplitude=1000) - shift_row = np.arange(nFrames, dtype=np.float32) * 0.5 - shift_col = np.arange(nFrames, dtype=np.float32) * -0.5 + shift_row = 5.0 + shift_col = 5.0 angle = np.pi / 4 - SM = LZShiftScaleRotate(testing=True) + SM = LZShiftScaleRotate(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, shift_row, shift_col, M, M, angle) images = [] @@ -295,7 +295,7 @@ def test_interpolation_lanzcos_ShiftScaleRotate(plt): # unzip the values for run_time, title, image in bench_values: - run_times.append(run_time) + run_times.append(run_time) titles.append(title) images.append(image) diff --git a/tests/test_transforms_2.py b/tests/test_transforms_2.py index f8b59f45..38fa324d 100644 --- a/tests/test_transforms_2.py +++ b/tests/test_transforms_2.py @@ -11,7 +11,7 @@ def test_interpolation_nearest_neighbor_PolarTransform_linear(plt,compare): M = 4 nFrames = 3 image = get_simplex_noise(64, 64, frames=nFrames, amplitude=1000) - SM = NNPolarTransform(testing=True) + SM = NNPolarTransform(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, (100,100), 'linear') skimage_linear = warp_polar(image, output_shape=(100,100), channel_axis=0, order=0) @@ -48,7 +48,7 @@ def test_interpolation_nearest_neighbor_PolarTransform_log(plt,compare): M = 4 nFrames = 3 image = get_simplex_noise(64, 64, frames=nFrames, amplitude=1000) - SM = NNPolarTransform(testing=True) + SM = NNPolarTransform(testing=True,clear_benchmarks=True) bench_values = SM.benchmark(image, (100,100), 'log') skimage_linear = warp_polar(image, output_shape=(100,100), channel_axis=0, scaling='log', order=0)