Skip to content

Commit

Permalink
added a cmake file
Browse files Browse the repository at this point in the history
  • Loading branch information
elgw committed Mar 8, 2024
1 parent 97dbeb7 commit f32476c
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 4 deletions.
123 changes: 123 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#
# This is a file to be interpreted by cmake (https://cmake.org/)
# Please note that all dependencies have to be available first.
#

# To uninstall:
#
# sudo xargs --interactive rm < install_manifest.txt
#
# Please note that this will remove also the libraries that might be
# used by other programs.

cmake_minimum_required(VERSION 3.9)

project(nd2tool
DESCRIPTION "convert Nikon nd2 files to tif"
LANGUAGES C)

set (CMAKE_C_STANDARD 11)

option (ENABLE_NATIVE_OPTIMIZATION "Enable non-portable optimizations" OFF)

#
# Default build type is RELEASE
#
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

#
# Add source files
#
add_executable(nd2tool
src/main.c
src/nd2tool.c
src/tiff_util.c
src/json_util.c
src/srgb_from_lambda.c
src/nd2tool_util.c)

#
# Add headers
#
target_include_directories(nd2tool PRIVATE include/)

#
# Add Nikon's library
#
target_link_libraries(nd2tool "${CMAKE_SOURCE_DIR}/lib/liblimfile.so")
target_link_libraries(nd2tool "${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.so")
# Copy it to the build dir upon compilation
add_custom_command(TARGET nd2tool POST_BUILD # Adds a post-build event to MyTest
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/lib/*.so" # <--this is in-file
$<TARGET_FILE_DIR:nd2tool>) # <--this is out-file path

#
# Link time optimization
#

# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
message("Enabling IPO")
set_property(TARGET nd2tool PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_JOBS 8)
else()
message(WARNING "IPO is not supported: ${output}")
endif()

#
# Architecture optimizations
#
if(ENABLE_NATIVE_OPTIMIZATION)
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
CHECK_C_COMPILER_FLAG("-mtune=native" COMPILER_SUPPORTS_MTUNE_NATIVE)
if(COMPILER_SUPPORTS_MTUNE_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
endif()
endif()


#
# Math library, if needed
#

find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(nd2tool ${MATH_LIBRARY})
endif()

#
# TIFF
#
target_link_libraries(nd2tool tiff)

#
# cJSON
#
target_link_libraries(nd2tool cjson)

# Enable -flto (GCC) and similar if available, see
# https://cmake.org/cmake/help/latest/policy/CMP0069.html
check_ipo_supported(RESULT result)
if(result)
message("Enabling IPO")
set_property(DIRECTORY PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

include(GNUInstallDirs)
install(TARGETS nd2tool)
install(FILES "${CMAKE_SOURCE_DIR}/doc/nd2tool.1"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1/" )
install(FILES
"${CMAKE_SOURCE_DIR}/lib/liblimfile.so"
"${CMAKE_SOURCE_DIR}/lib/libnd2readsdk-shared.so"
TYPE LIB )
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nd2tool
# nd2tool v0.1.6

## Introduction
Provides the command line tool, [**nd2tool**](doc/nd2tool.txt), that
Expand All @@ -23,7 +23,16 @@ moment it only supports loops over XY, Color and Z, i.e., not over
time. It is furthermore limited to nd2 files where the image data is
stored as 16-bit unsigned int.

## Example usage
## Usage

See the [man page](doc/nd2tool.txt) for the full documentation
(i.e. `man nd2tool`) or use `nd2tool --help` for a quick recap.

### Basic usage -- conversion
This will convert an nd2 file to a set of tif files. The output will
be a folder named after the nd2 file, but without the `.nd2`
extension.

```
$ nd2tool iiQV015_20220630_001.nd2
3 FOV in 4 channels:
Expand All @@ -44,8 +53,57 @@ Writing to iiQV015_20220630_001/SpGold_001.tif
Writing to iiQV015_20220630_001/dapi_003.tif
```

See the [man page](doc/nd2tool.txt) for the full documentation
(i.e. `man nd2tool`) or use `nd2tool --help` for a quick recap.
### Export the coordinates from multi-FOV images

Coordinates are useful for stitching, detection of overlapping
regions, detection of mechanical instabilities etc. The example
command below gives output in a comma separated format (CSV).


``` shell
$ nd2tool --coord iMS441_20191016_001.nd2
FOV, Channel, Z, X_um, Y_um, Z_um
1, 1, 1, -3523.100000, 4802.500000, 2120.857777
1, 1, 2, -3523.100000, 4802.500000, 2121.457777
1, 1, 3, -3523.100000, 4802.500000, 2122.057777
...
```

### Generation of deconvolution script
nd2tool can generate scripts to use with
[deconwolf](https://www.github.com/elgw/deconwolf/). Either it creates
a script that has to be edited manually **--deconwolf** or it asks for
the key parameters interactively with **--deconwolfx** as in the
example below:

``` shell
$ nd2tool --deconwolfx iMS441_20191016_001.nd2
Writing to deconwolf_iMS441_20191016_001.nd2.sh
Enter the number of iterations to use
dapi (default=50)
> 50
A647 (default=50)
> 75
Enter any extra arguments to deconwolf
> --gpu
```

For this file the generated file was:

``` shell
cat deconwolf_iMS441_20191016_001.nd2.sh
#!/bin/env bash
set -e # abort on errors

# PSF Generation
dw_bw --lambda 385.000000 --resxy 108.333333 --resz 600.000000 --NA 1.400000 --ni 1.515000 'iMS441_20191016_001/PSF_dapi.tif'
dw_bw --lambda 710.000000 --resxy 108.333333 --resz 600.000000 --NA 1.400000 --ni 1.515000 'iMS441_20191016_001/PSF_A647.tif'
iter_dapi=50
iter_A647=75
xargs="--gpu"
dw "$xargs" --iter $iter_dapi 'iMS441_20191016_001/dapi_001.tif' 'iMS441_20191016_001/PSF_dapi.tif'
dw "$xargs" --iter $iter_A647 'iMS441_20191016_001/A647_001.tif' 'iMS441_20191016_001/PSF_A647.tif'
```

## Installation

Expand Down Expand Up @@ -114,3 +172,5 @@ data](https://jsonformatter.org/json-viewer) Copy and paste the
JSON output from nd2tool (**--meta-file**, **--meta-frame**,
**--meta-exp**) here for a quick overview. See also [JSON
specification](https://www.json.org/) if you are new to this.
- [deconwolf](https://www.github.com/elgw/deconwolf/) for deconvolution of wide
field images (and possibly also other modalities).

0 comments on commit f32476c

Please sign in to comment.