diff --git a/cmake/FindFANN.cmake b/cmake/FindFANN.cmake new file mode 100644 index 0000000..d72b595 --- /dev/null +++ b/cmake/FindFANN.cmake @@ -0,0 +1,82 @@ +# +# Windows users: define the GLEW_PATH environment variable to point +# to the directory containing: +# include/fann.h +# lib/*fann.lib + + +# FANN_FOUND - system has fann +# FANN_INCLUDE_DIRS - the fann include directory +# FANN_LIBRARIES - Link these to use fann +# FANN_DEFINITIONS - Compiler switches required for using fann +# + +if(FANN_LIBRARIES AND FANN_INCLUDE_DIRS) + set(FANN_FOUND TRUE) +else() + find_path(FANN_INCLUDE_DIR + NAMES + fann.h + PATHS + $ENV{FANN_PATH}/include + ${FANN_DIR}/include + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + set( _libraries fann doublefann fixedfann floatfann ) + + foreach( _lib ${_libraries} ) + string( TOUPPER ${_lib} _name ) + + find_library(${_name}_LIBRARY + NAMES + ${_lib} + PATHS + $ENV{FANN_PATH}/lib + ${FANN_DIR}/lib + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + endforeach() + + + set(FANN_INCLUDE_DIRS + ${FANN_INCLUDE_DIR} + ) + + set(FANN_LIBRARIES + ${FANN_LIBRARIES} + ${FANN_LIBRARY} + ${DOUBLEFANN_LIBRARY} + ${FIXEDFANN_LIBRARY} + ${FLOATFANN_LIBRARY} + ) + + if( UNIX ) + set( FANN_LIBRARIES ${FANN_LIBRARIES} m ) + endif() + + if(FANN_INCLUDE_DIRS AND FANN_LIBRARIES) + set(FANN_FOUND TRUE) + endif() + + if(FANN_FOUND) + if(NOT FANN_FIND_QUIETLY) + message(STATUS "Found FANN:") + message(STATUS "FANN_INCLUDE_DIRS: ${FANN_INCLUDE_DIRS}") + message(STATUS "FANN_LIBRARIES: ${FANN_LIBRARIES}") + endif() + else() + if(FANN_FIND_REQUIRED) + message(FATAL_ERROR "Could not find FANN") + endif() + endif() + + mark_as_advanced(FANN_INCLUDE_DIRS FANN_LIBRARIES) +endif() diff --git a/cmake/FindGLEW.cmake b/cmake/FindGLEW.cmake new file mode 100644 index 0000000..9475809 --- /dev/null +++ b/cmake/FindGLEW.cmake @@ -0,0 +1,69 @@ +# +# Windows users: define the GLEW_PATH environment variable to point +# to the root glew directory, which contains: +# lib/Release/Win32/glew32.lib AND/OR lib/Release/x64/glew32.lib +# include/GL/glew.h + +#Try to find GLEW library and include path. +# Once done this will define +# +# GLEW_FOUND +# GLEW_INCLUDE_DIR +# GLEW_LIBRARY +# + +IF (WIN32) + FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h + $ENV{GLEW_PATH}/include + $ENV{PROGRAMFILES}/GLEW/include + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include + DOC "The directory where GL/glew.h resides") + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + FIND_LIBRARY( GLEW_LIBRARY + NAMES glew GLEW glew32 glew32s + PATHS + $ENV{GLEW_PATH}/lib/Release/x64 + $ENV{PROGRAMFILES}/GLEW/lib + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib + DOC "The GLEW library") + else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + FIND_LIBRARY( GLEW_LIBRARY + NAMES glew GLEW glew32 glew32s + PATHS + $ENV{GLEW_PATH}/lib/Release/Win32 + $ENV{PROGRAMFILES}/GLEW/lib + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib + DOC "The GLEW library") + endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) +ELSE (WIN32) + FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h + /usr/include + /usr/local/include + /sw/include + /opt/local/include + DOC "The directory where GL/glew.h resides") + FIND_LIBRARY( GLEW_LIBRARY + NAMES GLEW glew + PATHS + /usr/lib64 + /usr/lib + /usr/local/lib64 + /usr/local/lib + /sw/lib + /opt/local/lib + DOC "The GLEW library") +ENDIF (WIN32) + +IF (GLEW_INCLUDE_DIR) + SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") +ELSE (GLEW_INCLUDE_DIR) + SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") +ENDIF (GLEW_INCLUDE_DIR) + +MARK_AS_ADVANCED( + GLEW_FOUND + GLEW_INCLUDE_DIR + GLEW_LIBRARY +) \ No newline at end of file diff --git a/cmake/FindGLUT.cmake b/cmake/FindGLUT.cmake new file mode 100644 index 0000000..25b2cbb --- /dev/null +++ b/cmake/FindGLUT.cmake @@ -0,0 +1,186 @@ +#.rst: +# FindGLUT +# -------- +# +# try to find glut library and include files. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the :prop_tgt:`IMPORTED` targets: +# +# ``GLUT::GLUT`` +# Defined if the system has GLUT. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module sets the following variables: +# +# :: +# +# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc. +# GLUT_LIBRARIES, the libraries to link against +# GLUT_FOUND, If false, do not try to use GLUT. +# +# Also defined, but not for general use are: +# +# :: +# +# GLUT_glut_LIBRARY = the full path to the glut library. +# GLUT_Xmu_LIBRARY = the full path to the Xmu library. +# GLUT_Xi_LIBRARY = the full path to the Xi Library. + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (WIN32) + find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h + PATHS $ENV{GLUT_ROOT_PATH}/include ) + + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + find_library( GLUT_glut_LIBRARY NAMES freeglut + PATHS + $ENV{GLUT_ROOT_PATH}/lib/x64 + + NO_DEFAULT_PATH + ) + else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut + PATHS + ${OPENGL_LIBRARY_DIR} + $ENV{GLUT_ROOT_PATH}/lib + ) + endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + +else () + + if (APPLE) + find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR}) + find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX") + find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX") + + if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) + add_library(GLUT::Cocoa UNKNOWN IMPORTED) + # Cocoa should always be a Framework, but we check to make sure. + if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(GLUT::Cocoa PROPERTIES + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}") + else() + set_target_properties(GLUT::Cocoa PROPERTIES + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") + endif() + endif() + else () + + if (BEOS) + + set(_GLUT_INC_DIR /boot/develop/headers/os/opengl) + set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86) + + else() + + find_library( GLUT_Xi_LIBRARY Xi + /usr/openwin/lib + ) + + find_library( GLUT_Xmu_LIBRARY Xmu + /usr/openwin/lib + ) + + if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi) + add_library(GLUT::Xi UNKNOWN IMPORTED) + set_target_properties(GLUT::Xi PROPERTIES + IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}") + endif() + + if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu) + add_library(GLUT::Xmu UNKNOWN IMPORTED) + set_target_properties(GLUT::Xmu PROPERTIES + IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}") + endif() + + endif () + + find_path( GLUT_INCLUDE_DIR GL/glut.h + /usr/include/GL + /usr/openwin/share/include + /usr/openwin/include + /opt/graphics/OpenGL/include + /opt/graphics/OpenGL/contrib/libglut + ${_GLUT_INC_DIR} + ) + + find_library( GLUT_glut_LIBRARY glut + /usr/openwin/lib + ${_GLUT_glut_LIB_DIR} + ) + + unset(_GLUT_INC_DIR) + unset(_GLUT_glut_LIB_DIR) + + endif () + +endif () + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) + +if (GLUT_FOUND) + # Is -lXi and -lXmu required on all platforms that have it? + # If not, we need some way to figure out what platform we are on. + set( GLUT_LIBRARIES + ${GLUT_glut_LIBRARY} + ${GLUT_Xmu_LIBRARY} + ${GLUT_Xi_LIBRARY} + ${GLUT_cocoa_LIBRARY} + ) + + if(NOT TARGET GLUT::GLUT) + add_library(GLUT::GLUT UNKNOWN IMPORTED) + set_target_properties(GLUT::GLUT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}") + if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") + else() + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") + endif() + + if(TARGET GLUT::Xmu) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu) + endif() + + if(TARGET GLUT::Xi) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi) + endif() + + if(TARGET GLUT::Cocoa) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa) + endif() + endif() + + #The following deprecated settings are for backwards compatibility with CMake1.4 + set (GLUT_LIBRARY ${GLUT_LIBRARIES}) + set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) +endif() + +mark_as_advanced( + GLUT_INCLUDE_DIR + GLUT_glut_LIBRARY + GLUT_Xmu_LIBRARY + GLUT_Xi_LIBRARY + ) diff --git a/matlab/stimLoadAgilent.m b/matlab/stimLoadAgilent.m new file mode 100644 index 0000000..67d4748 --- /dev/null +++ b/matlab/stimLoadAgilent.m @@ -0,0 +1,16 @@ +%Loads a standard Agilent ResPro binary file +% stimLoadAgilent(filename) +function S = stimLoadAgilent(filename) + + fid = fopen(filename); + fseek(fid, 9, 'bof'); + Z = fread(fid, 1, 'uint16'); + fseek(fid, 13, 'cof'); + X = fread(fid, 1, 'uint16'); + Y = fread(fid, 1, 'uint16'); + + fseek(fid, 1020, 'bof'); + + S = reshape(fread(fid, [X, Y * Z], 'float32'), [X, Y, Z]); + + \ No newline at end of file diff --git a/matlab/stimROC.m b/matlab/stimROC.m new file mode 100644 index 0000000..d4a7ce5 --- /dev/null +++ b/matlab/stimROC.m @@ -0,0 +1,69 @@ +function [TPR, FPR, AUC] = stimROC(C, T) +%build an ROC curve +% C - class labels as an array of binary values (1 = true positive) +% T - threshold used for classification + + %sort the thresholds in descending order and get the indices + [~, I] = sort(T, 'descend'); + + %sort the class labels in the same order as the thresholds + Cs = C(I); + + %calculate the number of measurements + M = size(C, 2); + + %calculate the number of positives + P = nnz(C); + + %calculate the number of negatives + N = M - P; + + %if all examples are positives or negatives, return a perfect score? + if P == M + error('ERROR: no positive observations'); + end + if P == 0 + error('ERROR: no negative observations'); + end + + %allocate space for the ROC curve + TPR = zeros(1, M); + FPR = zeros(1, M); + + + + %calculate the number of inflection points + ip = 0; + for i = 2:M + if Cs(i) ~= Cs(i-1) + ip = ip + 1; + end + end + + %initialize the true and false positive rates to zero + TP = 0; + FP = 0; + for i = 1:M + if Cs(i) == 1 + TP = TP + 1; + else + FP = FP + 1; + end + + TPR(i) = TP / P; + FPR(i) = FP / N; + end + + %calculate the area under the ROC curve + AUC = 0; + for i = 2:M + w = FPR(i) - FPR(i-1); + h = TPR(i); + AUC = AUC + w * h; + end + + + + + + \ No newline at end of file diff --git a/stim/envi/agilent_binary.h b/stim/envi/agilent_binary.h index 8e1c718..8662329 100644 --- a/stim/envi/agilent_binary.h +++ b/stim/envi/agilent_binary.h @@ -19,10 +19,10 @@ class agilent_binary{ protected: std::string fname; - T* ptr; - size_t R[3]; - static const size_t header = 1020; - double Z[2]; + T* ptr; //pointer to the image data + size_t R[3]; //size of the binary image in X, Y, and Z + static const size_t header = 1020; //header size + double Z[2]; //range of z values (position or wavelength) public: size_t size(){ @@ -136,6 +136,43 @@ public: return header; } + /// Subtract the mean from each pixel. Generally used for centering an interferogram. + void meancenter(){ + size_t Z = R[2]; //store the number of bands + size_t XY = R[0] * R[1]; //store the number of pixels in the image + T sum = (T)0; + T mean; + for(size_t xy = 0; xy < XY; xy++){ //for each pixel + sum = 0; + for(size_t z = 0; z < Z; z++){ //for each band + sum += ptr[ z * XY + xy ]; //add the band value to a running sum + } + mean = sum / (T)Z; //calculate the pixel mean + for(size_t z = 0; z < Z; z++){ + ptr[ z * XY + xy ] -= mean; //subtract the mean from each band + } + } + } + + /// adds n bands of zero padding to the end of the file + void zeropad(size_t n){ + size_t newZ = R[2] + n; + T* temp = (T*) calloc(R[0] * R[1] * newZ, sizeof(T)); //allocate space for the new image + memcpy(temp, ptr, size() * sizeof(T)); //copy the old data to the new image + + free(ptr); //free the old data + ptr = temp; //swap in the new data + R[2] = newZ; //set the z-dimension to the new zero value + } + + //pads to the nearest power-of-two + void zeropad(){ + size_t newZ = pow(2, ceil(log(R[2])/log(2))); //find the nearest power-of-two + size_t n = newZ - R[2]; //calculate the number of bands to add + std::cout<<"band padding: "<* background){ size_t N = size(); //calculate the number of values to be ratioed -- libgit2 0.21.4