Skip to content

Commit

Permalink
Merge pull request #42 from tjof2/perf-improve
Browse files Browse the repository at this point in the history
Major refactor and performance improvement
  • Loading branch information
tjof2 committed May 22, 2020
2 parents c213de3 + 403d140 commit ab74a9f
Show file tree
Hide file tree
Showing 32 changed files with 1,238 additions and 1,533 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ cmake_install.cmake
# Programs
PGURE-SVT

# Output TIFF files
*CLEANED.tif

# Directories
build
winbuild
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
77 changes: 36 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project (PGURE-SVT)
set (PGURE-SVT_VERSION_MAJOR 0)
set (PGURE-SVT_VERSION_MINOR 4)
set (PGURE-SVT_VERSION_PATCH 3)
set (PGURE-SVT_VERSION_FULL "${PGURE-SVT_VERSION_MAJOR}.${PGURE-SVT_VERSION_MINOR}.${PGURE-SVT_VERSION_PATCH}")

message(STATUS "Configuring PGURE-SVT ${PGURE-SVT_VERSION_FULL}")

set(OS unix)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_aux/Modules/")

option(BUILD_LIBRARY "Build the shared library" ON)
option(BUILD_PYTHON "Install Python wrapper as a package" ON)
option(BUILD_PYTHON_DIST "Build Python distribution" OFF)
option(BUILD_EXECUTABLE "Build a standalone executable" OFF)
option(USE_OPENBLAS "Whether to use BLAS or OpenBLAS" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/")

include(CheckIncludeFileCXX)
include(CheckLibraryExists)
enable_language(C)

########################################

# Look for packages
project (PGURE-SVT)
set (PGURE-SVT_VERSION_FULL "0.4.3")
message(STATUS "Configuring PGURE-SVT ${PGURE-SVT_VERSION_FULL}")

option(USE_OPENBLAS "Whether to use BLAS or OpenBLAS" ON)
option(USE_OPENMP "Whether to use OpenMP" ON)
option(BUILD_EXECUTABLE "Build a standalone executable" ON)
option(BUILD_LIBRARY "Build the shared library" ON)
option(BUILD_PYTHON_DIST "Build Python distribution" OFF)
option(INSTALL_PYTHON "Install Python wrapper as a package" OFF)

########################################

find_package(OpenMP)
include(FindArmadillo)
include(FindTiff)
Expand All @@ -35,12 +33,12 @@ include(FindNLOPT)

if(NLOPT_FOUND)
set(SVT_LIBS ${SVT_LIBS} ${NLOPT_LIBRARIES})
set(SVT_INCL ${SVT_INCL} ${NLOPT_INCLUDE_DIR})
set(SVT_INCL ${SVT_INCL} ${NLOPT_INCLUDE_DIR})
endif()

if(!TIFF_FOUND)
if(BUILD_EXECUTABLE)
message(SEND_ERROR "ERROR: libtiff not found; Standalone program will not be compiled")
message(SEND_ERROR "ERROR: libtiff not found; Standalone program cannot be compiled")
endif()
else()
set(SVT_LIBS ${SVT_LIBS} ${TIFF_LIBRARIES})
Expand Down Expand Up @@ -69,52 +67,52 @@ if(LAPACK_FOUND)
endif()

if(ARMADILLO_FOUND)
set(SVT_LIBS ${SVT_LIBS} ${ARMADILLO_LIBRARIES})
set(SVT_LIBS ${SVT_LIBS} ${ARMADILLO_LIBRARIES})
message(STATUS "Armadillo config: ${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
endif()

message(STATUS ${SVT_LIBS})

########################################

# Enable OpenMP
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -Wall -march=native -std=c++17")
# enable std::thread
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
if (OPENMP_FOUND)
# Enable OpenMP & std::thread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -pthread -std=c++17 -DARMA_DONT_USE_WRAPPER ")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -march=native")

if (OPENMP_FOUND AND USE_OPENMP)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

########################################

# Build executable
if(BUILD_EXECUTABLE AND TIFF_FOUND)
add_executable(PGURE-SVT src/medfilter.c src/PGURE-SVT-bin.cpp)
target_link_libraries(PGURE-SVT ${SVT_LIBS})
install(TARGETS PGURE-SVT DESTINATION bin)
endif()

# Build library
if(BUILD_LIBRARY)
add_library(pguresvt SHARED src/medfilter.c src/PGURE-SVT-lib.cpp)
target_link_libraries(pguresvt ${SVT_LIBS})
install(TARGETS pguresvt DESTINATION lib)
endif()

# Install Python package
########################################

# Build Python package
find_program(PYTHON "python")
if((BUILD_PYTHON OR BUILD_PYTHON_DIST) AND PYTHON)
if(BUILD_PYTHON_DIST AND PYTHON)
set(PYTHONLIBRARYPATH "${CMAKE_INSTALL_PREFIX}/lib")

set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
set(DEPS "${CMAKE_CURRENT_BINARY_DIR}/pguresvt/*.py")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")

configure_file(${SETUP_PY_IN} ${SETUP_PY})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pguresvt/pguresvt.py.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pguresvt/pguresvt.py
${CMAKE_CURRENT_BINARY_DIR}/pguresvt/pguresvt.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pguresvt/__init__.py.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pguresvt/__init__.py
${CMAKE_CURRENT_BINARY_DIR}/pguresvt/__init__.py)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pguresvt/hspysvt.py
Expand All @@ -133,15 +131,12 @@ if((BUILD_PYTHON OR BUILD_PYTHON_DIST) AND PYTHON)

add_custom_target(python ALL DEPENDS ${OUTPUT})

if(BUILD_PYTHON)
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)")
endif()

if(BUILD_PYTHON_DIST)
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} sdist bdist_wheel)")
message(STATUS "Building Python distribution")
execute_process(COMMAND ${PYTHON} ${SETUP_PY} sdist bdist_wheel)

#set(PYTHON_WHEEL "${CMAKE_CURRENT_BINARY_DIR}/dist/pguresvt-${PGURE-SVT_VERSION_FULL}-py3-none-any.whl")
#install(CODE "execute_process(COMMAND auditwheel repair ${PYTHON_WHEEL})")
# Install Python package
if(INSTALL_PYTHON)
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)")
endif()

endif()
2 changes: 1 addition & 1 deletion examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pguresvt import hspysvt

# Load example dataset
s = hs.load("./examples/examplesequence.tif")
s = hs.load("./example.tif")

# Take the first 15 frames, and plot the result
s = s.inav[:15]
Expand Down
File renamed without changes.
File renamed without changes.
68 changes: 0 additions & 68 deletions examples/param.svt

This file was deleted.

31 changes: 31 additions & 0 deletions examples/param_example.svt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Example parameter file for PGURE-SVT
# To use the default values of a parameter, comment
# out the line using the '#' symbol.

##### REQUIRED #####
filename : ./example.tif # TIFF file to be denoised
start_frame : 1 # Start frame
end_frame : 25 # End frame

##### OPTIONAL #####
patch_size : 16 # Patch size in pixels (default = 4)
patch_overlap : 2 # Patch overlap in pixels (default = 1)
trajectory_length : 15 # Trajectory of each patch in frames, must be odd (default = 15)

# Setting a negative value will enable automatic estimation of that parameter
noise_alpha : 0.1 # Detector gain noise parameter (default = -1)
noise_mu : 0.1 # Detector offset noise parameter (default = -1)
noise_sigma : 0.1 # Gaussian noise parameter (default = -1)

optimize_pgure : false # Optimize lambda using PGURE approach (default = true)
lambda : 0.15 # Singular value threshold to use if not optimizing (ignored if optimize_pgure = true)
#tolerance : 1E-7 # Relative tolerance of PGURE optimization (default = 1E-7)

motion_estimation : true # Use ARPS motion estimation to reduce blurring (default = true)
#motion_neighbourhood : 7 # Size of ARPS motion estimation neighbourhood in pixels (default = 7)
#median_filter : 5 # Size of median filter for ARPS in pixels (default = 5)

#hot_pixel : 10 # Hot pixel threshold detection (default = 10)
exponential_weighting : true # Use exponential singular value weighting (default = true)
random_seed : 1 # Random seed (default = -1, i.e. no seed)
#num_threads : 4 # OpenMP num_threads (default = 4)
31 changes: 31 additions & 0 deletions examples/param_nanoparticle.svt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Example parameter file for PGURE-SVT
# To use the default values of a parameter, comment
# out the line using the '#' symbol.

##### REQUIRED #####
filename : ./nanoparticle.tif # TIFF file to be denoised
start_frame : 1 # Start frame
end_frame : 50 # End frame

##### OPTIONAL #####
patch_size : 16 # Patch size in pixels (default = 4)
patch_overlap : 2 # Patch overlap in pixels (default = 1)
trajectory_length : 15 # Trajectory of each patch in frames, must be odd (default = 15)

# Setting a negative value will enable automatic estimation of that parameter
noise_alpha : 0.1 # Detector gain noise parameter (default = -1)
noise_mu : 0.1 # Detector offset noise parameter (default = -1)
noise_sigma : 0.1 # Gaussian noise parameter (default = -1)

optimize_pgure : false # Optimize lambda using PGURE approach (default = true)
lambda : 0.15 # Singular value threshold to use if not optimizing (ignored if optimize_pgure = true)
#tolerance : 1E-7 # Relative tolerance of PGURE optimization (default = 1E-7)

motion_estimation : true # Use ARPS motion estimation to reduce blurring (default = true)
#motion_neighbourhood : 7 # Size of ARPS motion estimation neighbourhood in pixels (default = 7)
#median_filter : 5 # Size of median filter for ARPS in pixels (default = 5)

#hot_pixel : 10 # Hot pixel threshold detection (default = 10)
exponential_weighting : true # Use exponential singular value weighting (default = true)
random_seed : 1 # Random seed (default = -1, i.e. no seed)
#num_threads : 4 # OpenMP num_threads (default = 4)
68 changes: 0 additions & 68 deletions examples/param_se.svt

This file was deleted.

Loading

0 comments on commit ab74a9f

Please sign in to comment.