Commit 29165fa9f11d4dfef9775edef9d4fcab9f174644
1 parent
35a7195f
added ROC curve calculations and padding to agilent_binary
Showing
6 changed files
with
463 additions
and
4 deletions
Show diff stats
1 | +# | |
2 | +# Windows users: define the GLEW_PATH environment variable to point | |
3 | +# to the directory containing: | |
4 | +# include/fann.h | |
5 | +# lib/*fann.lib | |
6 | + | |
7 | + | |
8 | +# FANN_FOUND - system has fann | |
9 | +# FANN_INCLUDE_DIRS - the fann include directory | |
10 | +# FANN_LIBRARIES - Link these to use fann | |
11 | +# FANN_DEFINITIONS - Compiler switches required for using fann | |
12 | +# | |
13 | + | |
14 | +if(FANN_LIBRARIES AND FANN_INCLUDE_DIRS) | |
15 | + set(FANN_FOUND TRUE) | |
16 | +else() | |
17 | + find_path(FANN_INCLUDE_DIR | |
18 | + NAMES | |
19 | + fann.h | |
20 | + PATHS | |
21 | + $ENV{FANN_PATH}/include | |
22 | + ${FANN_DIR}/include | |
23 | + /usr/include | |
24 | + /usr/local/include | |
25 | + /opt/local/include | |
26 | + /sw/include | |
27 | + ) | |
28 | + | |
29 | + set( _libraries fann doublefann fixedfann floatfann ) | |
30 | + | |
31 | + foreach( _lib ${_libraries} ) | |
32 | + string( TOUPPER ${_lib} _name ) | |
33 | + | |
34 | + find_library(${_name}_LIBRARY | |
35 | + NAMES | |
36 | + ${_lib} | |
37 | + PATHS | |
38 | + $ENV{FANN_PATH}/lib | |
39 | + ${FANN_DIR}/lib | |
40 | + /usr/lib | |
41 | + /usr/local/lib | |
42 | + /opt/local/lib | |
43 | + /sw/lib | |
44 | + ) | |
45 | + | |
46 | + endforeach() | |
47 | + | |
48 | + | |
49 | + set(FANN_INCLUDE_DIRS | |
50 | + ${FANN_INCLUDE_DIR} | |
51 | + ) | |
52 | + | |
53 | + set(FANN_LIBRARIES | |
54 | + ${FANN_LIBRARIES} | |
55 | + ${FANN_LIBRARY} | |
56 | + ${DOUBLEFANN_LIBRARY} | |
57 | + ${FIXEDFANN_LIBRARY} | |
58 | + ${FLOATFANN_LIBRARY} | |
59 | + ) | |
60 | + | |
61 | + if( UNIX ) | |
62 | + set( FANN_LIBRARIES ${FANN_LIBRARIES} m ) | |
63 | + endif() | |
64 | + | |
65 | + if(FANN_INCLUDE_DIRS AND FANN_LIBRARIES) | |
66 | + set(FANN_FOUND TRUE) | |
67 | + endif() | |
68 | + | |
69 | + if(FANN_FOUND) | |
70 | + if(NOT FANN_FIND_QUIETLY) | |
71 | + message(STATUS "Found FANN:") | |
72 | + message(STATUS "FANN_INCLUDE_DIRS: ${FANN_INCLUDE_DIRS}") | |
73 | + message(STATUS "FANN_LIBRARIES: ${FANN_LIBRARIES}") | |
74 | + endif() | |
75 | + else() | |
76 | + if(FANN_FIND_REQUIRED) | |
77 | + message(FATAL_ERROR "Could not find FANN") | |
78 | + endif() | |
79 | + endif() | |
80 | + | |
81 | + mark_as_advanced(FANN_INCLUDE_DIRS FANN_LIBRARIES) | |
82 | +endif() | ... | ... |
1 | +# | |
2 | +# Windows users: define the GLEW_PATH environment variable to point | |
3 | +# to the root glew directory, which contains: | |
4 | +# lib/Release/Win32/glew32.lib AND/OR lib/Release/x64/glew32.lib | |
5 | +# include/GL/glew.h | |
6 | + | |
7 | +#Try to find GLEW library and include path. | |
8 | +# Once done this will define | |
9 | +# | |
10 | +# GLEW_FOUND | |
11 | +# GLEW_INCLUDE_DIR | |
12 | +# GLEW_LIBRARY | |
13 | +# | |
14 | + | |
15 | +IF (WIN32) | |
16 | + FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h | |
17 | + $ENV{GLEW_PATH}/include | |
18 | + $ENV{PROGRAMFILES}/GLEW/include | |
19 | + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include | |
20 | + DOC "The directory where GL/glew.h resides") | |
21 | + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
22 | + FIND_LIBRARY( GLEW_LIBRARY | |
23 | + NAMES glew GLEW glew32 glew32s | |
24 | + PATHS | |
25 | + $ENV{GLEW_PATH}/lib/Release/x64 | |
26 | + $ENV{PROGRAMFILES}/GLEW/lib | |
27 | + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin | |
28 | + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib | |
29 | + DOC "The GLEW library") | |
30 | + else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
31 | + FIND_LIBRARY( GLEW_LIBRARY | |
32 | + NAMES glew GLEW glew32 glew32s | |
33 | + PATHS | |
34 | + $ENV{GLEW_PATH}/lib/Release/Win32 | |
35 | + $ENV{PROGRAMFILES}/GLEW/lib | |
36 | + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin | |
37 | + ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib | |
38 | + DOC "The GLEW library") | |
39 | + endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
40 | +ELSE (WIN32) | |
41 | + FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h | |
42 | + /usr/include | |
43 | + /usr/local/include | |
44 | + /sw/include | |
45 | + /opt/local/include | |
46 | + DOC "The directory where GL/glew.h resides") | |
47 | + FIND_LIBRARY( GLEW_LIBRARY | |
48 | + NAMES GLEW glew | |
49 | + PATHS | |
50 | + /usr/lib64 | |
51 | + /usr/lib | |
52 | + /usr/local/lib64 | |
53 | + /usr/local/lib | |
54 | + /sw/lib | |
55 | + /opt/local/lib | |
56 | + DOC "The GLEW library") | |
57 | +ENDIF (WIN32) | |
58 | + | |
59 | +IF (GLEW_INCLUDE_DIR) | |
60 | + SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") | |
61 | +ELSE (GLEW_INCLUDE_DIR) | |
62 | + SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") | |
63 | +ENDIF (GLEW_INCLUDE_DIR) | |
64 | + | |
65 | +MARK_AS_ADVANCED( | |
66 | + GLEW_FOUND | |
67 | + GLEW_INCLUDE_DIR | |
68 | + GLEW_LIBRARY | |
69 | +) | |
0 | 70 | \ No newline at end of file | ... | ... |
1 | +#.rst: | |
2 | +# FindGLUT | |
3 | +# -------- | |
4 | +# | |
5 | +# try to find glut library and include files. | |
6 | +# | |
7 | +# IMPORTED Targets | |
8 | +# ^^^^^^^^^^^^^^^^ | |
9 | +# | |
10 | +# This module defines the :prop_tgt:`IMPORTED` targets: | |
11 | +# | |
12 | +# ``GLUT::GLUT`` | |
13 | +# Defined if the system has GLUT. | |
14 | +# | |
15 | +# Result Variables | |
16 | +# ^^^^^^^^^^^^^^^^ | |
17 | +# | |
18 | +# This module sets the following variables: | |
19 | +# | |
20 | +# :: | |
21 | +# | |
22 | +# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc. | |
23 | +# GLUT_LIBRARIES, the libraries to link against | |
24 | +# GLUT_FOUND, If false, do not try to use GLUT. | |
25 | +# | |
26 | +# Also defined, but not for general use are: | |
27 | +# | |
28 | +# :: | |
29 | +# | |
30 | +# GLUT_glut_LIBRARY = the full path to the glut library. | |
31 | +# GLUT_Xmu_LIBRARY = the full path to the Xmu library. | |
32 | +# GLUT_Xi_LIBRARY = the full path to the Xi Library. | |
33 | + | |
34 | +#============================================================================= | |
35 | +# Copyright 2001-2009 Kitware, Inc. | |
36 | +# | |
37 | +# Distributed under the OSI-approved BSD License (the "License"); | |
38 | +# see accompanying file Copyright.txt for details. | |
39 | +# | |
40 | +# This software is distributed WITHOUT ANY WARRANTY; without even the | |
41 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
42 | +# See the License for more information. | |
43 | +#============================================================================= | |
44 | +# (To distribute this file outside of CMake, substitute the full | |
45 | +# License text for the above reference.) | |
46 | + | |
47 | +if (WIN32) | |
48 | + find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h | |
49 | + PATHS $ENV{GLUT_ROOT_PATH}/include ) | |
50 | + | |
51 | + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
52 | + find_library( GLUT_glut_LIBRARY NAMES freeglut | |
53 | + PATHS | |
54 | + $ENV{GLUT_ROOT_PATH}/lib/x64 | |
55 | + | |
56 | + NO_DEFAULT_PATH | |
57 | + ) | |
58 | + else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
59 | + find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut | |
60 | + PATHS | |
61 | + ${OPENGL_LIBRARY_DIR} | |
62 | + $ENV{GLUT_ROOT_PATH}/lib | |
63 | + ) | |
64 | + endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) | |
65 | + | |
66 | +else () | |
67 | + | |
68 | + if (APPLE) | |
69 | + find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR}) | |
70 | + find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX") | |
71 | + find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX") | |
72 | + | |
73 | + if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) | |
74 | + add_library(GLUT::Cocoa UNKNOWN IMPORTED) | |
75 | + # Cocoa should always be a Framework, but we check to make sure. | |
76 | + if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$") | |
77 | + set_target_properties(GLUT::Cocoa PROPERTIES | |
78 | + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}") | |
79 | + else() | |
80 | + set_target_properties(GLUT::Cocoa PROPERTIES | |
81 | + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") | |
82 | + endif() | |
83 | + endif() | |
84 | + else () | |
85 | + | |
86 | + if (BEOS) | |
87 | + | |
88 | + set(_GLUT_INC_DIR /boot/develop/headers/os/opengl) | |
89 | + set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86) | |
90 | + | |
91 | + else() | |
92 | + | |
93 | + find_library( GLUT_Xi_LIBRARY Xi | |
94 | + /usr/openwin/lib | |
95 | + ) | |
96 | + | |
97 | + find_library( GLUT_Xmu_LIBRARY Xmu | |
98 | + /usr/openwin/lib | |
99 | + ) | |
100 | + | |
101 | + if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi) | |
102 | + add_library(GLUT::Xi UNKNOWN IMPORTED) | |
103 | + set_target_properties(GLUT::Xi PROPERTIES | |
104 | + IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}") | |
105 | + endif() | |
106 | + | |
107 | + if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu) | |
108 | + add_library(GLUT::Xmu UNKNOWN IMPORTED) | |
109 | + set_target_properties(GLUT::Xmu PROPERTIES | |
110 | + IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}") | |
111 | + endif() | |
112 | + | |
113 | + endif () | |
114 | + | |
115 | + find_path( GLUT_INCLUDE_DIR GL/glut.h | |
116 | + /usr/include/GL | |
117 | + /usr/openwin/share/include | |
118 | + /usr/openwin/include | |
119 | + /opt/graphics/OpenGL/include | |
120 | + /opt/graphics/OpenGL/contrib/libglut | |
121 | + ${_GLUT_INC_DIR} | |
122 | + ) | |
123 | + | |
124 | + find_library( GLUT_glut_LIBRARY glut | |
125 | + /usr/openwin/lib | |
126 | + ${_GLUT_glut_LIB_DIR} | |
127 | + ) | |
128 | + | |
129 | + unset(_GLUT_INC_DIR) | |
130 | + unset(_GLUT_glut_LIB_DIR) | |
131 | + | |
132 | + endif () | |
133 | + | |
134 | +endif () | |
135 | + | |
136 | +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) | |
137 | + | |
138 | +if (GLUT_FOUND) | |
139 | + # Is -lXi and -lXmu required on all platforms that have it? | |
140 | + # If not, we need some way to figure out what platform we are on. | |
141 | + set( GLUT_LIBRARIES | |
142 | + ${GLUT_glut_LIBRARY} | |
143 | + ${GLUT_Xmu_LIBRARY} | |
144 | + ${GLUT_Xi_LIBRARY} | |
145 | + ${GLUT_cocoa_LIBRARY} | |
146 | + ) | |
147 | + | |
148 | + if(NOT TARGET GLUT::GLUT) | |
149 | + add_library(GLUT::GLUT UNKNOWN IMPORTED) | |
150 | + set_target_properties(GLUT::GLUT PROPERTIES | |
151 | + INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}") | |
152 | + if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$") | |
153 | + set_target_properties(GLUT::GLUT PROPERTIES | |
154 | + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") | |
155 | + else() | |
156 | + set_target_properties(GLUT::GLUT PROPERTIES | |
157 | + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") | |
158 | + endif() | |
159 | + | |
160 | + if(TARGET GLUT::Xmu) | |
161 | + set_property(TARGET GLUT::GLUT APPEND | |
162 | + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu) | |
163 | + endif() | |
164 | + | |
165 | + if(TARGET GLUT::Xi) | |
166 | + set_property(TARGET GLUT::GLUT APPEND | |
167 | + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi) | |
168 | + endif() | |
169 | + | |
170 | + if(TARGET GLUT::Cocoa) | |
171 | + set_property(TARGET GLUT::GLUT APPEND | |
172 | + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa) | |
173 | + endif() | |
174 | + endif() | |
175 | + | |
176 | + #The following deprecated settings are for backwards compatibility with CMake1.4 | |
177 | + set (GLUT_LIBRARY ${GLUT_LIBRARIES}) | |
178 | + set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) | |
179 | +endif() | |
180 | + | |
181 | +mark_as_advanced( | |
182 | + GLUT_INCLUDE_DIR | |
183 | + GLUT_glut_LIBRARY | |
184 | + GLUT_Xmu_LIBRARY | |
185 | + GLUT_Xi_LIBRARY | |
186 | + ) | ... | ... |
1 | +%Loads a standard Agilent ResPro binary file | |
2 | +% stimLoadAgilent(filename) | |
3 | +function S = stimLoadAgilent(filename) | |
4 | + | |
5 | + fid = fopen(filename); | |
6 | + fseek(fid, 9, 'bof'); | |
7 | + Z = fread(fid, 1, 'uint16'); | |
8 | + fseek(fid, 13, 'cof'); | |
9 | + X = fread(fid, 1, 'uint16'); | |
10 | + Y = fread(fid, 1, 'uint16'); | |
11 | + | |
12 | + fseek(fid, 1020, 'bof'); | |
13 | + | |
14 | + S = reshape(fread(fid, [X, Y * Z], 'float32'), [X, Y, Z]); | |
15 | + | |
16 | + | |
0 | 17 | \ No newline at end of file | ... | ... |
1 | +function [TPR, FPR, AUC] = stimROC(C, T) | |
2 | +%build an ROC curve | |
3 | +% C - class labels as an array of binary values (1 = true positive) | |
4 | +% T - threshold used for classification | |
5 | + | |
6 | + %sort the thresholds in descending order and get the indices | |
7 | + [~, I] = sort(T, 'descend'); | |
8 | + | |
9 | + %sort the class labels in the same order as the thresholds | |
10 | + Cs = C(I); | |
11 | + | |
12 | + %calculate the number of measurements | |
13 | + M = size(C, 2); | |
14 | + | |
15 | + %calculate the number of positives | |
16 | + P = nnz(C); | |
17 | + | |
18 | + %calculate the number of negatives | |
19 | + N = M - P; | |
20 | + | |
21 | + %if all examples are positives or negatives, return a perfect score? | |
22 | + if P == M | |
23 | + error('ERROR: no positive observations'); | |
24 | + end | |
25 | + if P == 0 | |
26 | + error('ERROR: no negative observations'); | |
27 | + end | |
28 | + | |
29 | + %allocate space for the ROC curve | |
30 | + TPR = zeros(1, M); | |
31 | + FPR = zeros(1, M); | |
32 | + | |
33 | + | |
34 | + | |
35 | + %calculate the number of inflection points | |
36 | + ip = 0; | |
37 | + for i = 2:M | |
38 | + if Cs(i) ~= Cs(i-1) | |
39 | + ip = ip + 1; | |
40 | + end | |
41 | + end | |
42 | + | |
43 | + %initialize the true and false positive rates to zero | |
44 | + TP = 0; | |
45 | + FP = 0; | |
46 | + for i = 1:M | |
47 | + if Cs(i) == 1 | |
48 | + TP = TP + 1; | |
49 | + else | |
50 | + FP = FP + 1; | |
51 | + end | |
52 | + | |
53 | + TPR(i) = TP / P; | |
54 | + FPR(i) = FP / N; | |
55 | + end | |
56 | + | |
57 | + %calculate the area under the ROC curve | |
58 | + AUC = 0; | |
59 | + for i = 2:M | |
60 | + w = FPR(i) - FPR(i-1); | |
61 | + h = TPR(i); | |
62 | + AUC = AUC + w * h; | |
63 | + end | |
64 | + | |
65 | + | |
66 | + | |
67 | + | |
68 | + | |
69 | + | |
0 | 70 | \ No newline at end of file | ... | ... |
stim/envi/agilent_binary.h
... | ... | @@ -19,10 +19,10 @@ class agilent_binary{ |
19 | 19 | |
20 | 20 | protected: |
21 | 21 | std::string fname; |
22 | - T* ptr; | |
23 | - size_t R[3]; | |
24 | - static const size_t header = 1020; | |
25 | - double Z[2]; | |
22 | + T* ptr; //pointer to the image data | |
23 | + size_t R[3]; //size of the binary image in X, Y, and Z | |
24 | + static const size_t header = 1020; //header size | |
25 | + double Z[2]; //range of z values (position or wavelength) | |
26 | 26 | |
27 | 27 | public: |
28 | 28 | size_t size(){ |
... | ... | @@ -136,6 +136,43 @@ public: |
136 | 136 | return header; |
137 | 137 | } |
138 | 138 | |
139 | + /// Subtract the mean from each pixel. Generally used for centering an interferogram. | |
140 | + void meancenter(){ | |
141 | + size_t Z = R[2]; //store the number of bands | |
142 | + size_t XY = R[0] * R[1]; //store the number of pixels in the image | |
143 | + T sum = (T)0; | |
144 | + T mean; | |
145 | + for(size_t xy = 0; xy < XY; xy++){ //for each pixel | |
146 | + sum = 0; | |
147 | + for(size_t z = 0; z < Z; z++){ //for each band | |
148 | + sum += ptr[ z * XY + xy ]; //add the band value to a running sum | |
149 | + } | |
150 | + mean = sum / (T)Z; //calculate the pixel mean | |
151 | + for(size_t z = 0; z < Z; z++){ | |
152 | + ptr[ z * XY + xy ] -= mean; //subtract the mean from each band | |
153 | + } | |
154 | + } | |
155 | + } | |
156 | + | |
157 | + /// adds n bands of zero padding to the end of the file | |
158 | + void zeropad(size_t n){ | |
159 | + size_t newZ = R[2] + n; | |
160 | + T* temp = (T*) calloc(R[0] * R[1] * newZ, sizeof(T)); //allocate space for the new image | |
161 | + memcpy(temp, ptr, size() * sizeof(T)); //copy the old data to the new image | |
162 | + | |
163 | + free(ptr); //free the old data | |
164 | + ptr = temp; //swap in the new data | |
165 | + R[2] = newZ; //set the z-dimension to the new zero value | |
166 | + } | |
167 | + | |
168 | + //pads to the nearest power-of-two | |
169 | + void zeropad(){ | |
170 | + size_t newZ = pow(2, ceil(log(R[2])/log(2))); //find the nearest power-of-two | |
171 | + size_t n = newZ - R[2]; //calculate the number of bands to add | |
172 | + std::cout<<"band padding: "<<n<<std::endl; | |
173 | + zeropad(n); //add the padding | |
174 | + } | |
175 | + | |
139 | 176 | /// Calculate the absorbance spectrum from the transmission spectrum given a background |
140 | 177 | void absorbance(stim::agilent_binary<T>* background){ |
141 | 178 | size_t N = size(); //calculate the number of values to be ratioed | ... | ... |