├── CMakeLists.txt
├── LICENSE
├── README.md
├── apodize.c
├── assemble.c
├── bs_ave.c
├── bs_init.c
├── bs_red.c
├── bs_snrt.c
├── calc_subfields.c
├── chkphase.c
├── ctracker.c
├── entry.c
├── entry.h
├── fileops.c
├── fileops.h
├── free_vect.c
├── getinfo.c
├── init_matrix.c
├── init_shift.c
├── inlines.h
├── iwlspr.c
├── mpi_master_rec.c
├── mpi_mastering.c
├── mpi_setmoddata.c
├── mpi_setslavetype.c
├── mpi_shutdown.c
├── mpi_slaving.c
├── mpifuncts.h
├── opts.h
├── phs_init.c
├── putslaveinfo.c
├── radial.c
├── reconstruct.c
├── rpr.c
├── speckle_admin.h
├── speckle_core.h
├── speckle_math.h
├── stats.c
├── subfielding.c
├── surfit.c
└── w_func.c
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.4)
2 |
3 | PROJECT(deblurTC)
4 |
5 | MARK_AS_ADVANCED(CLEAR CMAKE_VERBOSE_MAKEFILE)
6 | OPTION(CMAKE_VERBOSE_MAKEFILE "if all commands will be echoed to the console during the make" ON)
7 |
8 | OPTION(ENABLE_DEBUG "enable debug support" OFF)
9 | OPTION(ENABLE_X86_64 "enable x86_64 specific optimizations" OFF)
10 |
11 | IF (ENABLE_DEBUG)
12 | SET (OPT_FLAGS "-DDEBUG -O0 -g -Wall -W -fno-inline")
13 | ELSEIF (ENABLE_X86_64)
14 | SET (OPT_FLAGS "-O5 -march=k8 -mfpmath=sse -m64 -ffast-math -pipe")
15 | ELSE()
16 | SET (OPT_FLAGS "-O5 -ffast-math") # This is the default
17 | ENDIF()
18 |
19 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS}")
20 |
21 | SET(MATH_LIBRARY "-lm")
22 |
23 | MARK_AS_ADVANCED(CMAKE_C_FLAGS)
24 |
25 | MACRO(CHECK_REQUIRED_LIB2 upper lower header lower2 header2)
26 | FIND_PATH(${upper}_INCLUDE_PATH ${header} $ENV{${upper}DIR}/include ${INCLUDE_DIRS})
27 | IF(${upper}_INCLUDE_PATH)
28 | ELSE (${upper}_INCLUDE_PATH)
29 | FIND_PATH(${upper}_INCLUDE_PATH ${header2} $ENV{${upper}DIR}/include ${INCLUDE_DIRS})
30 | ENDIF(${upper}_INCLUDE_PATH)
31 |
32 | IF(${upper}_INCLUDE_PATH)
33 | FIND_LIBRARY(${upper}_LIBRARY NAMES ${lower} ${lower2} PATHS $ENV{${upper}DIR}/lib ${LIB_DIRS})
34 | IF(${upper}_LIBRARY)
35 | ELSE(${upper}_LIBRARY)
36 | MESSAGE(SEND_ERROR "ERROR: ${upper} not found. please install ${upper} first!")
37 | ENDIF(${upper}_LIBRARY)
38 | ELSE(${upper}_INCLUDE_PATH)
39 | MESSAGE(SEND_ERROR "ERROR: ${upper} not found. please install ${upper} first!")
40 | ENDIF(${upper}_INCLUDE_PATH)
41 | ENDMACRO(CHECK_REQUIRED_LIB2)
42 |
43 | MACRO(CHECK_REQUIRED_LIB upper lower header)
44 | CHECK_REQUIRED_LIB2(${upper} ${lower} ${header} "" "")
45 | ENDMACRO(CHECK_REQUIRED_LIB)
46 |
47 | #
48 | # this looks for GSL support
49 | # it will define the following values
50 | #
51 | # GSL_INCLUDE_PATH = where gsl/gsl_linalg.h can be found
52 | # GSL_LIBRARY = the library to link against (gsl)
53 | # GSL_CBLAS_LIBRARY = the library to link against (gslcblas)
54 |
55 | FIND_PATH(GSL_INCLUDE_PATH gsl/gsl_linalg.h
56 | $ENV{GSLDIR}/include $ENV{HOME}/include /usr/local/include /usr/include)
57 |
58 | FIND_LIBRARY(GSL_LIBRARY
59 | NAMES gsl
60 | PATHS $ENV{GSLDIR}/lib $ENV{HOME}/lib /usr/lib /usr/lib64 /usr/local/lib)
61 |
62 | FIND_LIBRARY(GSL_CBLAS_LIBRARY
63 | NAMES gslcblas
64 | PATHS $ENV{GSLDIR}/lib $ENV{HOME}/lib /usr/lib /usr/lib64 /usr/local/lib)
65 |
66 | IF(GSL_LIBRARY)
67 | ELSE(GSL_LIBRARY)
68 | MESSAGE(SEND_ERROR "ERROR: GSL not found. GSL is now required to use deblurTC")
69 | ENDIF(GSL_LIBRARY)
70 |
71 | #
72 | # this looks for FFTW3 support
73 | # it will define the following values
74 | #
75 | # FFTW_INCLUDE_PATH = where fftw3.h can be found
76 | # FFTW_LIBRARY = the library to link against (fftw3)
77 |
78 | FIND_PATH(FFTW_INCLUDE_PATH fftw3.h
79 | $ENV{FFTWDIR}/include $ENV{HOME}/include /usr/local/include /usr/include)
80 |
81 | FIND_LIBRARY(FFTW_LIBRARY
82 | NAMES fftw3
83 | PATHS $ENV{FFTWDIR}/lib $ENV{HOME}/lib /usr/lib /usr/lib64 /usr/local/lib)
84 |
85 | IF(FFTW_LIBRARY)
86 | ELSE(FFTW_LIBRARY)
87 | MESSAGE(SEND_ERROR "ERROR: FFTW not found. FFTW is now required to use deblurTC")
88 | ENDIF(FFTW_LIBRARY)
89 |
90 | # find mpi
91 | INCLUDE(${CMAKE_ROOT}/Modules/FindMPI.cmake)
92 |
93 | set(deblurTC_source_files
94 | apodize.c assemble.c bs_ave.c bs_init.c
95 | bs_red.c bs_snrt.c calc_subfields.c
96 | chkphase.c ctracker.c entry.c
97 | free_vect.c getinfo.c
98 | init_matrix.c init_shift.c iwlspr.c
99 | mpi_master_rec.c
100 | mpi_mastering.c mpi_setmoddata.c mpi_setslavetype.c
101 | mpi_shutdown.c mpi_slaving.c phs_init.c
102 | putslaveinfo.c radial.c
103 | reconstruct.c rpr.c
104 | stats.c subfielding.c surfit.c
105 | w_func.c
106 | )
107 |
108 | set(deblurTC_source_files ${deblurTC_source_files} fileops.c)
109 |
110 | ADD_EXECUTABLE(deblurTC ${deblurTC_source_files})
111 | SET_TARGET_PROPERTIES(deblurTC PROPERTIES LINKER_LANGUAGE C)
112 |
113 | INCLUDE_DIRECTORIES(${deblurTC_SOURCE_DIR} ${FFTW_INCLUDE_PATH} ${GSL_INCLUDE_PATH} ${MPI_INCLUDE_PATH})
114 |
115 | TARGET_LINK_LIBRARIES(deblurTC ${MATH_LIBRARY} ${FFTW_LIBRARY} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
116 |
117 | INSTALL_TARGETS(/bin deblurTC)
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | == Background ==
3 | ================
4 |
5 | This package performs image deblurring and alignment using a series of images
6 | (from dozens to thousands). This method is highly effective for series of many
7 | low exposure images that contiain blurring or spatial shifting of an object of
8 | interest. This task has classically been carried out using cross-correlation for
9 | and subsequent averaging. However, this method fails when the images are too
10 | noisy; perfect alignment of frames is impossible in this case and the benefit
11 | of averaging is limited. deblurTC utilizes a method in which alignment of images
12 | is implicit; in other words, alignment of the different frames is a direct
13 | result of the mathematical transforms used.
14 |
15 | Written in C and utilizing MPI for parallelization, this scientific computing
16 | package is suitable for a computing cluster. This package was originally
17 | developed and used for speckle interferometry by astrophysics studying the sun
18 | and was originally coded by Friedrich Wöger and Oskar von der Lühe II:
19 | http://proceedings.spiedigitallibrary.org/proceeding.aspx?articleid=1336991
20 |
21 | This package was developed and altered by Blake Milner and Wen Jiang as part of
22 | a project through Discovery Park at Purdue.
23 |
24 | The portions of this code pertaining to astrophysics (such as telescope
25 | diffraction, modeling of atmospheric aberrations, etc.) has been stripped out
26 | to allow for general use.
27 |
28 | This method first transforms all frames into their Bispectrum - a type of 4-D
29 | power spectrum that is the Fourier Transform of the Triple Correlation (related
30 | to regular correlation used to register images). The Bispectrum is insensitive
31 | to translations of the original object. From this Bispectral average, the phase
32 | component of the original object can be reconstructed in an iterative fashion,
33 | thus undoing any effects due to translation or blurring of the image. The
34 | averaged Bispectrum can then be combined with the reconstructed phase and
35 | transformed back into the space domain, producing a single, deblurred image
36 | that is a composite of all frames.
37 |
38 | The method has been well-established since the 60's in the field of
39 | astrophysics:
40 | http://adsabs.harvard.edu/abs/1993A%26A...278..328H
41 |
42 | Other papers detailing the original code base and the mathemetical theory
43 | behind this method:
44 |
45 | * Speckle Masking (using bispectrum) paper:
46 | Lohmann, A. W., Weigelt, G., Wirnitzer, B., “Speckle masking in astronomy:
47 | triple correlation theory and applications,” Applied Optics, Vol. 22, Issue 24, pp. 4028-4037 (1983).
48 |
49 | * Paper discussing phase recovery algorithm:
50 | Matson, C., “Weighted-least-squares phase reconstruction from the bispectrum,” J. Opt. Soc., Vol. 8, No. 12 (1991).
51 |
52 | * Paper by authors:
53 | Woeger, F. and von der Luehe, O., “KISIP: A Software Package for Speckle Interferometry of Adaptive Optics Corrected Solar Data,” SPIE 7019 (2008).
54 |
55 | * Speckle Interferometry paper by authors (including kisip):
56 | Woeger, F., von der Luehe, O., and Reardon, K., “Speckle interferometry with adaptive optics corrected solar data,” Astronomy & Astrophysics 488, 375-381 (2008).
57 |
58 | * Thesis discussing speckle reconstruction and kisip:
59 | Mikurda, K., “High Resolution Spectroscopy of Photospheric Bright Points,” Albert-Ludwigs University (2005).
60 |
61 |
62 |
63 |
64 | == Installation instructions ==
65 | ===============================
66 |
67 |
68 | Requirements:
69 | * OpenMPI -- An open Message Passing Interface Library
70 | * FFTW -- Fastest Fourier Transform in the West
71 | * GSL -- The GNU Scientific Library
72 | * CMake -- A cross-platform, open-source build system
73 |
74 | Building and installing:
75 |
76 | ```bash
77 | ccmake CMakeLists.txt
78 | cmake CMakeLists.txt
79 | make
80 | make install
81 | ```
82 |
83 | == Usage ==
84 | ===========
85 |
86 | Command-line usage:
87 |
88 | ```bash
89 | ./deblurTC _SWITCH_ _ARG_ ... _FRAMES_
90 | ```
91 |
92 |
93 | Image format:
94 |
95 | Unfortunately, this software package does not yet support typical image
96 | formats. Image inputs must be a plain, binary, greyscale image format that
97 | uses 4 bytes for each pixel.
98 |
99 |
100 |
101 | Command-line options:
102 |
103 | --o (-output) _NAME_
104 |
105 | name of output file
106 |
107 | --x (-xsize) _XSIZE_
108 |
109 | number of x-pixels in each frame
110 |
111 | --y (-ysize) _YSIZE_
112 |
113 | number of y-pixels in each frame
114 |
115 | --h (-headersize) _HSIZE_
116 |
117 | number of bytes in header of each frame (will be skipped)
118 |
119 | --s (-subsize) _SSIZE_
120 |
121 | side length of square subfields used to dissect image, later sent to
122 | different slave nodes. Must be a power of two - otherwise, will be rounded
123 | to nearest power of two.
124 |
125 | --v (-bs1length) _BS1LENGTH_
126 |
127 | length in u-direction of bispectrum (translates to increased resolution of
128 | final image).
129 |
130 | --u (-bs2length) _BS1LENGTH_
131 |
132 | length in v-direction of bispectrum (translates to increased resolution of
133 | final image).
134 |
135 | --r (-maxrad) _MAXRAD_
136 |
137 | maximum phase reconstruction radius (translates to increased resolution of
138 | final image).
139 |
140 | --p (-maxiter) _MAXITER_
141 |
142 | maximum number of iterations for phase reconstruction algorithm.
143 |
144 | --e (-weightexp) _WEXP_
145 |
146 | value of exponential power used during phase reconstruction (Advanced).
147 |
148 | --a (-apod) _APOD_
149 |
150 | percent of field that is windowed before transformation to bispectrum
151 | (between 0 and 100). Image must be apodized to prevent artifacts in final
152 | image, though too much may degrade quality.
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/apodize.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 | /* creates a either a hamming or hanning window based on the value of alpha fed in */
61 | void hanming(float *res, int nx, int ny, float alpha)
62 | {
63 | /* For a Hamming use alpha = 0.53836 */
64 | /* For a Hanning use alpha = 0.5 */
65 | /* Initialise helpers */
66 | int i, j;
67 | float fact;
68 | float *w1, *w2;
69 |
70 | /* Initialise constants */
71 | double pi = 3.141592654;
72 | double two_pi = 2.0 * pi;
73 |
74 | nx = (nx > 0) ? nx : 1;
75 | ny = (ny > 0) ? ny : 1;
76 |
77 | /* Initialize window arrays */
78 | w1 = (float *) (malloc(nx * sizeof(float)));
79 | for (i = 0; i < nx; i++) {
80 | w1[i] = alpha +
81 | (alpha - 1.) *
82 | ((float)
83 | (cos((double) (two_pi * ((float) i) / ((float) nx)))));
84 | }
85 | if (ny > 1) {
86 | w2 = (float *) (malloc(ny * sizeof(float)));
87 | for (i = 0; i < ny; i++) {
88 | w2[i] = alpha +
89 | (alpha - 1.) *
90 | ((float)
91 | (cos((double) (two_pi * ((float) i) / ((float) ny)))));
92 | }
93 | }
94 |
95 | /* Set window */
96 | for (j = 0; j < ny; j++) {
97 | fact = (ny > 1) ? w2[j] : 1.0;
98 | for (i = 0; i < nx; i++) {
99 | res[j * nx + i] = fact * w1[i];
100 | }
101 | }
102 |
103 | free(w1);
104 | if (ny > 1)
105 | free(w2);
106 | }
107 |
108 |
109 | void frachamming(float *res, int nx, int ny, float frac, int maxk, int *sh)
110 | {
111 | int i, j;
112 | int nxf, nyf, nxfh, nyfh;
113 | long N, l;
114 | float *wx, *wy;
115 | float *Hx, *Hy;
116 | float m = 0, maximum;
117 |
118 | fftw_complex *in, *out;
119 | fftw_plan fft, fftb;
120 |
121 | N = nx * ny;
122 | nxf = 2 * (int) ((frac * nx + 1) / 2);
123 | nyf = 2 * (int) ((frac * ny + 1) / 2);
124 |
125 | if (nxf == 0) {
126 | for (i = 0; i < nx * ny; i++)
127 | res[i] = 1.0;
128 | }
129 | else {
130 | wx = (float *) malloc(nx * sizeof(float));
131 | wy = (float *) malloc(ny * sizeof(float));
132 | Hx = (float *) malloc(nxf * sizeof(float));
133 | Hy = (float *) malloc(nyf * sizeof(float));
134 | nxfh = nxf / 2;
135 | nyfh = nyf / 2;
136 | /* get hamming values */
137 | hanming(Hx, nxf, 1, 0.5);
138 | hanming(Hy, nyf, 1, 0.5);
139 | /* init the vectors to 1.0 (for values in the middle!) */
140 | for (i = 0; i < nx; i++) {
141 | wx[i] = 1.0;
142 | }
143 | for (i = 0; i < ny; i++) {
144 | wy[i] = 1.0;
145 | }
146 | /* set hamming values */
147 | for (i = 0; i < nxfh; i++) {
148 | wx[i] = Hx[i];
149 | wx[(nx - nxfh) + i] = Hx[nxfh + i];
150 | }
151 | for (i = 0; i < nyfh; i++) {
152 | wy[i] = Hy[i];
153 | wy[(ny - nyfh) + i] = Hy[nyfh + i];
154 | }
155 | /* compute the tensor product */
156 | for (j = 0; j < ny; j++) {
157 | for (i = 0; i < nx; i++) {
158 | res[j * nx + i] = wy[j] * wx[i];
159 | }
160 | }
161 | free(wx);
162 | free(wy);
163 | free(Hx);
164 | free(Hy);
165 | }
166 |
167 | /* this isn't ever used in KISIP since maxk is always fed in as 0 */
168 | if ((maxk != 0) && (sh != NULL)) {
169 | // allocate memory for fourier transform
170 | in = fftw_malloc(N * sizeof(fftw_complex));
171 | out = fftw_malloc(N * sizeof(fftw_complex));
172 | fft = fftw_plan_dft_2d(nx, ny, in, out, -1, FFTW_ESTIMATE);
173 | fftb = fftw_plan_dft_2d(nx, ny, out, in, +1, FFTW_ESTIMATE);
174 |
175 | // set input matrix
176 | for (l = 0; l < N; l++) {
177 | in[l][0] = (double) res[l];
178 | in[l][1] = 0.0;
179 | }
180 | // execute FFT
181 | fftw_execute(fft);
182 | // Now set phases at shifts to zero. This follows:
183 | // Christoph Keller: Opt. Apod. for Speckle Imaging of ext. sourc.
184 | // ASP Conference Series #183 (1998)
185 | // Shifts are relative to centered spectrum!
186 | for (i = 1; i < maxk; i++) {
187 | shift_idx(nx / 2 + sh[2 * i], ny / 2 + sh[2 * i + 1], nx / 2,
188 | ny / 2, nx, ny, l);
189 | out[l][0] = 0.0;
190 | out[l][1] = 0.0;
191 | shift_idx(nx / 2 - sh[2 * i], ny / 2 - sh[2 * i + 1], nx / 2,
192 | ny / 2, nx, ny, l);
193 | out[l][0] = 0.0;
194 | out[l][1] = 0.0;
195 | }
196 | // execute reFFT
197 | fftw_execute(fftb);
198 | // set result matrix
199 | for (l = 0; l < N; l++) {
200 | res[l] = (float) in[l][0];
201 | }
202 | // free memory
203 | fftw_cleanup();
204 | //fftw_destroy_plan(fft);
205 | //fftw_destroy_plan(fftb);
206 | fftw_free(in);
207 | fftw_free(out);
208 | }
209 |
210 | // find max and normalize
211 | maximum = res[0];
212 | for (l = 0; l < N; l++) {
213 | if (res[l] > maximum)
214 | maximum = res[l];
215 | }
216 | for (l = 0; l < N; l++) {
217 | res[l] /= maximum;
218 | m += res[l] * res[l];
219 | }
220 | m /= N;
221 | m = sqrt(m);
222 | for (l = 0; l < N; l++) {
223 | res[l] /= m;
224 | }
225 | }
226 |
227 |
228 | float *ellmask(int nx, int ny, int *ori, int len_x, int len_y)
229 | {
230 | int i;
231 | float aspect;
232 | vect *v;
233 | float *result;
234 |
235 | v = (vect *) malloc(sizeof(vect));
236 | v->size = len_x;
237 | v->res_vec = (float *) malloc(len_x * sizeof(float));
238 |
239 | for (i = 0; i < len_x; i++) {
240 | (v)->res_vec[i] = 1.0;
241 | }
242 |
243 | aspect = (float) len_y / len_x;
244 | result = rad2im(v, nx, ny, ori, aspect);
245 |
246 | free_vect(&v);
247 | return (result);
248 | }
249 |
250 |
251 | void assmask(float *res, int nx, int ny, float frac)
252 | {
253 | // Initialise helpers
254 | int i, j;
255 | long offx, offy;
256 | float *temp;
257 |
258 | // set offsets for window
259 | offx = 0;
260 | offy = 0;
261 | //offx = (int) rint(frac / 2 * nx);
262 | //offy = (int) rint(frac / 2 * ny);
263 |
264 | temp = (float *) malloc((nx - 2 * offx) * (ny - 2 * offy) * sizeof(float));
265 | hanming(temp, (nx - 2 * offx), (ny - 2 * offy), 0.5);
266 |
267 | memset(res, 0, nx * ny * sizeof(float));
268 |
269 | for (j = offy; j < ny - offy; j++) {
270 | for (i = offx; i < nx - offx; i++) {
271 | res[j * nx + i] =
272 | temp[(j - offy) * (nx - 2 * offx) + (i - offx)];
273 | }
274 | }
275 | free(temp);
276 | }
277 |
--------------------------------------------------------------------------------
/assemble.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /* =====================================================================
63 | **
64 | ** Reassemble the Image
65 | ** This is basically putting together the phases and amplitudes.
66 | ** Then a retransformation FFT is performed.
67 | **
68 | ** =====================================================================
69 | */
70 |
71 | void assemble(int nx, int ny, float *amp, float *phs, float *rec, maininfo info)
72 | {
73 | float *mask = ellmask(nx, ny, NULL, info.tc.max_rad, info.tc.max_rad);
74 |
75 | static int INIT = 0;
76 | static long N;
77 | static fftw_complex *in;
78 | static fftw_complex *out;
79 | fftw_plan fft;
80 |
81 | long i, j;
82 | long r1, r2, r3;
83 |
84 | if (INIT == 0) {
85 | N = nx * ny;
86 | in = fftw_malloc(N * sizeof(fftw_complex));
87 | out = fftw_malloc(N * sizeof(fftw_complex));
88 | INIT = 1;
89 | } else if (N / nx != ny) {
90 | fftw_cleanup();
91 | fftw_free(in);
92 | fftw_free(out);
93 | N = nx * ny;
94 | in = fftw_malloc(N * sizeof(fftw_complex));
95 | out = fftw_malloc(N * sizeof(fftw_complex));
96 | INIT = 1;
97 | }
98 | fft = fftw_plan_dft_2d(nx, ny, in, out, +1, FFTW_ESTIMATE);
99 |
100 | for (j = 0; j < ny; j++) {
101 | for (i = 0; i < nx; i++) {
102 | idx(i, j, nx, r1);
103 | shift_idx(i, j, nx / 2, ny / 2, nx, ny, r2);
104 | phs_idx(i, j, nx, r3);
105 | in[r2][0] = amp[r1] * phs[r3] * mask[r1];
106 | in[r2][1] = amp[r1] * phs[r3 + 1] * mask[r1];
107 | }
108 | }
109 | fftw_execute(fft);
110 | for (j = 0; j < ny; j++) {
111 | for (i = 0; i < nx; i++) {
112 | idx(i, j, nx, r1);
113 | rec[r1] = (float) out[r1][0];
114 | }
115 | }
116 |
117 | fftw_cleanup();
118 | free(mask);
119 | }
120 |
--------------------------------------------------------------------------------
/bs_ave.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | /*
66 | * bs_ave: compute the average bispectrum of an image series
67 | *
68 | * images: pointer to series of images
69 | * win: apodization window for the fourier transform of the images
70 | * nx, ny: size of images
71 | * nfr: # of frames
72 | * index: pointer to matrix with bispectrum elements to be used
73 | * bs: BiSpectrum output
74 | * w: Weight output
75 | */
76 |
77 | float *bs_ave(float *images, float *win, slaveinfo l, long *index,
78 | long bs_cnt, float *bsc, float *wc, float *amp, int maxk,
79 | int *shifts)
80 | {
81 | long i, j, k, m; // loop & helper variables
82 | long i1, i2, i3; // index variables
83 | double t1, t2, t3, t4; // temporary real variables
84 | float ct1[2], ct2[2]; // temporary complex variables
85 | long nx, ny, nxh, nyh; // half of subfield size
86 | long nfr, N, cnt; // # of pixels in one image, loop variable
87 | double s = 0; // mean intensity in image
88 | long u1, u2, v1, v2; // bispectrum vectors
89 | fftw_complex *im1; // temporary matrices
90 | fftw_complex *im2;
91 | float *bsr, *bsi; // used for calculation of SNR
92 | float *origin; // phase values around origin (needed for init)
93 |
94 | fftw_plan fftimage; // plan for fourier transform
95 |
96 | nfr = l.nrofframes;
97 | nx = l.sfsizex;
98 | ny = l.sfsizey;
99 | nxh = nx / 2;
100 | nyh = ny / 2;
101 | N = nx * ny; // subfield size in pixels
102 |
103 | origin = (float *) calloc(2 * maxk, sizeof(float));
104 |
105 | im1 = fftw_malloc(N * sizeof(fftw_complex));
106 | im2 = fftw_malloc(N * sizeof(fftw_complex));
107 |
108 | // setting up resultant matrices
109 | bsr = (float *) calloc(bs_cnt, sizeof(float));
110 | bsi = (float *) calloc(bs_cnt, sizeof(float));
111 |
112 | fftimage = fftw_plan_dft_2d(nx, ny, im1, im2, -1, FFTW_ESTIMATE);
113 |
114 | for (k = 0; k < nfr; k++) {
115 | // set a helper index
116 | m = k * N;
117 | // Calculate the mean of the image
118 | stats(&images[m], N, 0, &s, NULL);
119 | // store the windowed image in image1
120 | for (j = 0; j < ny; j++) {
121 | for (i = 0; i < nx; i++) {
122 | idx(i, j, nx, i1);
123 | im1[i1][0] = (double) ((images[i1 + m] - s) * win[i1] + s); // problem here, with image
124 | im1[i1][1] = 0.0;
125 |
126 | }
127 | }
128 | // a) do FFT(imagei,-1)
129 | // write the result into im2 (see fftw_plan fftimage)
130 | // b) shift the image, so low frequencies are in the origin
131 | // write the results back into im1, scaled with
132 | // 1/(nx*ny) (not done by FFTW but by IDL does, thanks
133 | // Alexandra Tritschler for the hint!)
134 | fftw_execute(fftimage);
135 | for (j = 0; j < ny; j++) { // iterates through subfield pixels
136 | for (i = 0; i < nx; i++) {
137 | idx(i, j, nx, i1); // jump to pixel position
138 | shift_idx(i, j, nxh, nyh, nx, ny, i2);
139 | im1[i1][0] = im2[i2][0] / N; // complex part
140 | im1[i1][1] = im2[i2][1] / N; // imaginary part
141 | amp[i1] +=
142 | (float) (sqrt
143 | (im1[i1][0] * im1[i1][0] + // why are these so large??
144 | im1[i1][1] * im1[i1][1]) / nfr);
145 | }
146 | }
147 | // phase around origin
148 | for (cnt = 0; cnt < maxk; cnt++) {
149 | idx(nxh + shifts[2 * cnt], nyh + shifts[2 * cnt + 1], nx, i1);
150 | origin[2 * cnt] += im1[i1][0];
151 | origin[2 * cnt + 1] += im1[i1][1];
152 | }
153 | // calculate the mean raw bispectrum fast in non redundant matrix
154 | for (cnt = 0; cnt < bs_cnt; cnt++) {
155 | // get vectors
156 | u1 = index[0 + cnt * 4];
157 | u2 = index[1 + cnt * 4];
158 | v1 = index[2 + cnt * 4];
159 | v2 = index[3 + cnt * 4];
160 | // get matrix indices of vectors
161 | idx(nxh - u1, nyh + u2, nx, i1);
162 | idx(nxh - v1, nyh + v2, nx, i2);
163 | idx(nxh - u1 - v1, nyh + u2 + v2, nx, i3);
164 | // calculate bispectrum i(u)*i(v)*conj(i(u+v))
165 | // (a+ib)(c+id)=((ac-bd)+i(bc+ad))
166 | ct1[0] = im1[i1][0] * im1[i2][0] - im1[i1][1] * im1[i2][1];
167 | ct1[1] = im1[i1][1] * im1[i2][0] + im1[i1][0] * im1[i2][1];
168 | // (a+ib)(c-id)=((ac+bd)+i(bc-ad))
169 | ct2[0] = ct1[0] * im1[i3][0] + ct1[1] * im1[i3][1];
170 | ct2[1] = ct1[1] * im1[i3][0] - ct1[0] * im1[i3][1];
171 | // assign values
172 | bsc[2 * cnt] += ct2[0];
173 | // bsc[2*cnt] += ct2[0] // noise terms attached
174 | // - ((im1[i1][0]*im1[i1][0] + im1[i1][1]*im1[i1][1])
175 | // +(im1[i2][0]*im1[i2][0] + im1[i2][1]*im1[i2][1])
176 | // +(im1[i3][0]*im1[i3][0] + im1[i3][1]*im1[i3][1]));
177 | bsc[2 * cnt + 1] += ct2[1];
178 | bsr[cnt] += bsc[2 * cnt] * bsc[2 * cnt];
179 | bsi[cnt] += bsc[2 * cnt + 1] * bsc[2 * cnt + 1];
180 | }
181 | }
182 |
183 | // phase around origin is averaged and normalized
184 | for (cnt = 0; cnt < maxk; cnt++) {
185 | t1 = cmod(&origin[2 * cnt]);
186 | origin[2 * cnt] /= t1;
187 | origin[2 * cnt + 1] /= t1;
188 | }
189 |
190 | // create bispectrum SNR (weights) and mean in non-redundant matrices
191 | for (cnt = 0; cnt < bs_cnt; cnt++) {
192 | // calculate SNR
193 | // sum of 2 normally - distributed random variables (real & imaginary part)
194 | t1 = bsc[2 * cnt] / nfr;
195 | t1 *= t1; // (squared) mean real part
196 | t2 = bsc[2 * cnt + 1] / nfr;
197 | t2 *= t2; // (squared) mean imaginary part
198 | t3 = fabs(bsr[cnt] - nfr * t1) / (nfr - 1); // variance of real part
199 | t4 = fabs(bsi[cnt] - nfr * t2) / (nfr - 1); // variance of imaginary part
200 | wc[cnt] = (float) sqrt(t1 + t2) * sqrt(nfr) / sqrt(t3 + t4); // => SNR of MEAN absolute
201 |
202 | // make mean and normalize the phases if nonzero
203 | if ((bsc[2 * cnt] != 0.0) || (bsc[2 * cnt + 1] != 0.0)) {
204 | t1 = cmod(&bsc[2 * cnt]);
205 | bsc[2 * cnt] /= t1;
206 | bsc[2 * cnt + 1] /= t1;
207 | }
208 | }
209 |
210 | fftw_free(im1);
211 | fftw_free(im2);
212 | free(bsr);
213 | free(bsi);
214 |
215 | fftw_cleanup();
216 |
217 | return (origin);
218 | }
219 |
--------------------------------------------------------------------------------
/bs_init.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | /*
66 | * bs_init: initialise the bispectrum matrices
67 | * 1. determine the indices for the bispectrum elements to be used
68 | * note: this depends on
69 | * a) the diffraction limit in px (or a percentage thereof)
70 | * b) the limit entered for the size of u in x direction
71 | * c) the limit entered for the length of u, v and u+v
72 | * 2. determine the overall number of elements in bispectrum
73 | * 3. return the index matrix
74 | *
75 | * bs_cnt: # of elements in bispectrum (return value)
76 | * bs_mr: see 1. a)
77 | * bs_l1: see 1. b)
78 | * bs_l2: see 1. c)
79 | */
80 |
81 | long *bs_init(long *bs_cnt, slaveinfo l)
82 | {
83 | long i; // loop variable
84 | long limit; // helper variable
85 | long mrs, l2s; // squared limits
86 | long u1, u2, v1, v2, uv1, uv2; // u, v and u+v vector components
87 | long u1s, u2s, v1s, v2s, uv1s, uv2s; // squared vector components
88 | long *d; // circle with radius l.bs_mr
89 | long *index = NULL; // returned matrix
90 |
91 | d = (long *) malloc((l.max_rad + 1) * sizeof(long));
92 |
93 | mrs = l.max_rad * l.max_rad;
94 | l2s = l.l2 * l.l2;
95 |
96 | // set (quarter-)circle
97 | for (i = 0; i <= l.max_rad; i++) {
98 | d[i] = (long) sqrt((float) (mrs - i * i));
99 | }
100 |
101 | /*
102 | * Define the parts of the bispectrum to be evaluated
103 | * Store the indices in a one dimensional array for later use by the
104 | * bispectrum algorithm
105 | */
106 |
107 | i = 0;
108 | for (u1 = 0; u1 <= l.l1; u1++) {
109 | u1s = u1 * u1;
110 |
111 | for (u2 = -d[u1]; u2 <= d[u1]; u2++) {
112 | u2s = u2 * u2;
113 | for (v1 = u1; v1 <= l.max_rad; v1++) {
114 | v1s = v1 * v1;
115 | uv1 = u1 + v1;
116 | uv1s = uv1 * uv1;
117 | // set negative limit for v2
118 | if ((u1 == v1) && (u2 != 0))
119 | limit = -abs(u2);
120 | else
121 | limit = -1;
122 | for (v2 = -l.max_rad; v2 <= limit; v2++) {
123 | v2s = v2 * v2;
124 | uv2 = u2 + v2;
125 | uv2s = uv2 * uv2;
126 | if (((uv1s + uv2s) <= mrs) &&
127 | ((v1s + v2s) <= mrs) &&
128 | (((u1s + u2s) <= l2s) ||
129 | ((v1s + v2s) <= l2s) || ((uv1s + uv2s) <= l2s))) {
130 | // reallocation of index in chunks of MEMCHUNK
131 | if (i % MEMCHUNK == 0)
132 | index = (long *) realloc(index, 4 * (i + MEMCHUNK) * sizeof(long));
133 | index[0 + i * 4] = u1;
134 | index[1 + i * 4] = u2;
135 | index[2 + i * 4] = v1;
136 | index[3 + i * 4] = v2;
137 | i++;
138 | }
139 | }
140 | // set positive limit for v2
141 | if (u1 == v1)
142 | limit = abs(u2);
143 | else
144 | limit = 0;
145 | for (v2 = limit; v2 <= l.max_rad; v2++) {
146 | v2s = v2 * v2;
147 | uv2 = u2 + v2;
148 | uv2s = uv2 * uv2;
149 | if (((uv1s + uv2s) <= mrs) &&
150 | ((v1s + v2s) <= mrs) &&
151 | (((u1s + u2s) <= l2s) ||
152 | ((v1s + v2s) <= l2s) || ((uv1s + uv2s) <= l2s))) {
153 | // reallocation of index in chunks of MEMCHUNK
154 | if (i % MEMCHUNK == 0)
155 | index = (long *) realloc(index, 4 * (i + MEMCHUNK) * sizeof(long));
156 | index[0 + i * 4] = u1;
157 | index[1 + i * 4] = u2;
158 | index[2 + i * 4] = v1;
159 | index[3 + i * 4] = v2;
160 | i++;
161 | }
162 | }
163 | }
164 | }
165 | }
166 | // optimum memory usage
167 | *bs_cnt = i;
168 | index = (long *) realloc(index, 4 * (*bs_cnt) * sizeof(long));
169 |
170 | free(d);
171 |
172 | return (index);
173 | }
174 |
--------------------------------------------------------------------------------
/bs_red.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | void bs_red(long *index, long bs_cnt, slaveinfo l, float *bsc, float *wc,
66 | float **bs, float **w)
67 | {
68 | long u1, u2, v1, v2; // bs vector indices
69 | long cnt; // loop variables
70 | long i1, i2; // index variable
71 | long l2s; // squared limit
72 |
73 | l2s = l.l2 * l.l2;
74 |
75 | (*bs) =
76 | (float *) calloc(2 * (l.l1 + 1) * (2 * (l.l2 + 1)) *
77 | (2 * (l.max_rad + 1)) * (2 * (l.max_rad + 1)),
78 | sizeof(float));
79 | (*w) =
80 | (float *) calloc((l.l1 + 1) * (2 * (l.l2 + 1)) *
81 | (2 * (l.max_rad + 1)) * (2 * (l.max_rad + 1)),
82 | sizeof(float));
83 |
84 | // create redundant matrices (eq. readin.f)
85 | for (cnt = 0; cnt < bs_cnt; cnt++) {
86 | // get vectors
87 | u1 = index[0 + cnt * 4];
88 | u2 = index[1 + cnt * 4];
89 | v1 = index[2 + cnt * 4];
90 | v2 = index[3 + cnt * 4];
91 | // use symmetries to fill bispectrum and weights matrices
92 | if ((u1 * u1 + u2 * u2) <= l2s) {
93 | mbs_idx(u1, u2, v1, v2, l.l1, l.l2, l.max_rad, i1);
94 | i2 = i1 / 2;
95 | (*bs)[i1] = bsc[2 * cnt];
96 | (*bs)[i1 + 1] = bsc[2 * cnt + 1];
97 | (*w)[i2] = wc[cnt];
98 | }
99 | if ((v1 * v1 + v2 * v2) <= l2s) {
100 | mbs_idx(v1, v2, u1, u2, l.l1, l.l2, l.max_rad, i1);
101 | i2 = i1 / 2;
102 | (*bs)[i1] = bsc[2 * cnt];
103 | (*bs)[i1 + 1] = bsc[2 * cnt + 1];
104 | (*w)[i2] = wc[cnt];
105 | }
106 | if (((u1 + v1) * (u1 + v1) + (u2 + v2) * (u2 + v2)) <= l2s) {
107 | mbs_idx(u1 + v1, u2 + v2, -u1, -u2, l.l1, l.l2, l.max_rad, i1);
108 | i2 = i1 / 2;
109 | (*bs)[i1] = bsc[2 * cnt];
110 | (*bs)[i1 + 1] = -bsc[2 * cnt + 1];
111 | (*w)[i2] = wc[cnt];
112 | mbs_idx(u1 + v1, u2 + v2, -v1, -v2, l.l1, l.l2, l.max_rad, i1);
113 | i2 = i1 / 2;
114 | (*bs)[i1] = bsc[2 * cnt];
115 | (*bs)[i1 + 1] = -bsc[2 * cnt + 1];
116 | (*w)[i2] = wc[cnt];
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/bs_snrt.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | static int bs_snrt_cf(const void *p1, const void *p2)
66 | {
67 | int i = *((int *) p1);
68 | int j = *((int *) p2);
69 |
70 | if (i > j)
71 | return (1);
72 | if (i < j)
73 | return (-1);
74 |
75 | return (0);
76 | }
77 |
78 |
79 | void bs_snrt(float *wc, long bs_cnt, slaveinfo * l)
80 | {
81 | float *tmp = malloc(sizeof(float) * bs_cnt);
82 | // copy data to tmp vector (because qsort is in place)
83 | memcpy(tmp, wc, bs_cnt * sizeof(float));
84 | // sort weights ascending (average case: O(bs_cnt*ln(bs_cnt)))
85 | qsort((void *) tmp, bs_cnt, sizeof(float), bs_snrt_cf);
86 | // reset the threshold
87 | (l)->snr = tmp[(long) ((1.0 - (l)->snr) * bs_cnt)];
88 | free(tmp);
89 | }
90 |
--------------------------------------------------------------------------------
/calc_subfields.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #include "speckle_admin.h"
57 |
58 |
59 | void calc_subfields(int szx, int szy, float sfs, maininfo * result)
60 | {
61 | /* helper variables */
62 | int pot; /* power for subfield size */
63 |
64 | /* start subfielding if wanted */
65 | if (sfs != 0) {
66 | /* raw subfield size in x/y */
67 | (*result).subfields.ssizex = (int) sfs;
68 | (*result).subfields.ssizey = (int) sfs;
69 |
70 | /* rescale raw size to a power of two */
71 | pot = 0;
72 | while ((*result).subfields.ssizex > 0) {
73 | (*result).subfields.ssizex =
74 | (int) (((float) (*result).subfields.ssizex) / 2);
75 | pot += 1;
76 | }
77 | (*result).subfields.ssizex = pow(2, pot);
78 |
79 | pot = 0;
80 | while ((*result).subfields.ssizey > 0) {
81 | (*result).subfields.ssizey =
82 | (int) (((float) (*result).subfields.ssizey) / 2);
83 | pot += 1;
84 | }
85 | (*result).subfields.ssizey = pow(2, pot);
86 |
87 | /* find number of subfields, overall size reconstr. and border offsets */
88 |
89 | (*result).subfields.nfrx = (int) (2 * szx / (*result).subfields.ssizex - 1);
90 | (*result).subfields.nsizex = (int) ((float) ((*result).subfields.ssizex) *
91 | (float) ((*result).subfields.nfrx + 1) / 2);
92 | (*result).subfields.offx = (int) (szx - (*result).subfields.nsizex) / 2;
93 |
94 | (*result).subfields.nfry = (int) (2 * szy / (*result).subfields.ssizey - 1);
95 | (*result).subfields.nsizey = (int) ((float) ((*result).subfields.ssizey) *
96 | (float) ((*result).subfields.nfry + 1) / 2);
97 | (*result).subfields.offy = (int) (szy - (*result).subfields.nsizey) / 2; // offset makes the border!
98 | /* if not wanted set subfield size to frame size */
99 | } else {
100 | (*result).subfields.ssizex = szx;
101 | (*result).subfields.ssizey = szy;
102 | (*result).subfields.nsizex = szx;
103 | (*result).subfields.nsizey = szy;
104 | (*result).subfields.nfrx = 1;
105 | (*result).subfields.nfry = 1;
106 | (*result).subfields.offx = 0;
107 | (*result).subfields.offy = 0;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/chkphase.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | float chkphase(slaveinfo l, float *phs)
63 | {
64 | static long INIT = 0;
65 | static float *old = NULL, *new = NULL;
66 |
67 | float *tmp = NULL;
68 | long i;
69 | float t, var = 0.0;
70 |
71 | if (INIT / l.sfsizex != l.sfsizey) {
72 | if (old != NULL)
73 | free(old);
74 | if (new != NULL)
75 | free(new);
76 | INIT = l.sfsizex * l.sfsizex;
77 | old = (float *) calloc(INIT, sizeof(float));
78 | new = (float *) calloc(INIT, sizeof(float));
79 | }
80 |
81 | for (i = 0; i < INIT; i++) {
82 | new[i] = atan2(phs[2 * i + 1], phs[2 * i]);
83 | t = (old[i] - new[i]);
84 | var += t * t;
85 | }
86 |
87 | // some fun stuff: pointer bending!
88 | tmp = old;
89 | old = new;
90 | new = tmp;
91 | tmp = NULL;
92 |
93 | return (var);
94 | }
95 |
--------------------------------------------------------------------------------
/ctracker.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | void ctracker(float *ref, float *in, int nx, int ny, int nfr, float *out)
62 | {
63 | /*
64 | * Declaration of local variables
65 | */
66 | static int nxh = 0, nyh = 0; /* coordinates of origin */
67 | static float *win = NULL; /* apodisation window */
68 | static float *fit = NULL; /* fitted surface */
69 | static double *temp1 = NULL; /* temporary data storage space */
70 | static double *temp2 = NULL; /* temporary data storage space */
71 | static double *ccr = NULL; /* cross correlation */
72 | static fftw_complex *fref = NULL; /* FFT of reference img */
73 | static fftw_complex *fimage = NULL; /* FFT of image */
74 | static fftw_complex *fccr = NULL; /* FFT of cross cor */
75 |
76 | long k, l; /* helper variables */
77 | long i; /* index counter variable */
78 | long N; /* total number of pixels in subfield */
79 |
80 | double maxval; /* value of max of cross correlation */
81 | long maxpos = 0; /* vector position of maximum */
82 | int mx, my; /* x and y position of max */
83 | double mval; /* mean intensity value */
84 | fftw_plan fftref; /* planning to FFT mean */
85 | fftw_plan fftimage; /* planning to FFT image */
86 | fftw_plan crosscor; /* planning to FFT cross cor */
87 |
88 | /*
89 | * Initialize local variables
90 | */
91 | N = nx * ny;
92 |
93 | if ((nxh == 0) || (nyh == 0)) {
94 | // Allocate memory
95 | nxh = nx / 2;
96 | nyh = ny / 2;
97 | win = (float *) malloc(N * sizeof(float));
98 | fit = (float *) malloc(N * sizeof(float));
99 | temp1 = (double *) malloc(N * sizeof(double));
100 | temp2 = (double *) malloc(N * sizeof(double));
101 | ccr = (double *) malloc(N * sizeof(double));
102 | fref = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
103 | fimage = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
104 | fccr = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
105 | hanming(win, nx, ny, 0.5);
106 | }
107 | else if ((nxh != nx / 2) || (nyh != ny / 2)) {
108 | // Clear all used memory
109 | free(win);
110 | free(fit);
111 | free(temp1);
112 | free(temp2);
113 | free(ccr);
114 | fftw_free(fref);
115 | fftw_free(fimage);
116 | fftw_free(fccr);
117 | // Allocate memory
118 | nxh = nx / 2;
119 | nyh = ny / 2;
120 | win = (float *) malloc(N * sizeof(float));
121 | hanming(win, nx, ny, 0.5);
122 | fit = (float *) malloc(N * sizeof(float));
123 | temp1 = (double *) malloc(N * sizeof(double));
124 | temp2 = (double *) malloc(N * sizeof(double));
125 | ccr = (double *) malloc(N * sizeof(double));
126 | fref = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
127 | fimage = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
128 | fccr = fftw_malloc(nx * (nyh + 1) * sizeof(fftw_complex));
129 | }
130 |
131 | memset(temp1, 0.0, N * sizeof(double));
132 | memset(temp2, 0.0, N * sizeof(double));
133 | memset(ccr, 0.0, N * sizeof(double));
134 | memset(fref, 0.0, nx * (nyh + 1) * sizeof(fftw_complex));
135 | memset(fimage, 0.0, nx * (nyh + 1) * sizeof(fftw_complex));
136 | memset(fccr, 0.0, nx * (nyh + 1) * sizeof(fftw_complex));
137 | fftref = fftw_plan_dft_r2c_2d(nx, ny, temp1, fref, FFTW_ESTIMATE);
138 | fftimage = fftw_plan_dft_r2c_2d(nx, ny, temp2, fimage, FFTW_ESTIMATE);
139 | crosscor = fftw_plan_dft_c2r_2d(nx, ny, fccr, ccr, FFTW_ESTIMATE);
140 |
141 | /*
142 | * Set reference frame if present. If not present, then set first image
143 | * as reference. Reference is stored in temp1. Then calculate FFT(Reference, -1)
144 | */
145 | if (ref != NULL) {
146 | surfit(ref, nx, ny, 2, fit);
147 | stats(fit, N, 0.0, &mval, NULL);
148 | for (i = 0; i < N; i++) {
149 | temp1[i] = (double) (win[i] * (ref[i] - fit[i])) + mval;
150 | }
151 | }
152 | else {
153 | surfit(in, nx, ny, 2, fit);
154 | stats(fit, N, 0.0, &mval, NULL);
155 | for (i = 0; i < N; i++) {
156 | temp1[i] = (double) (win[i] * (in[i] - fit[i])) + mval;
157 | }
158 | }
159 | fftw_execute(fftref);
160 |
161 | /*
162 | * Loop through burst
163 | */
164 | for (l = 0; l < nfr; l++) {
165 | /* index variable for image frame */
166 | k = l * N;
167 | /*
168 | * Initialize Images. Surface fit image. Store resultant image in dtemp2.
169 | *
170 | * Surface fit
171 | */
172 | surfit(&in[k], nx, ny, 2, fit);
173 | stats(fit, N, 0.0, &mval, NULL);
174 | /* Counter variable for image frame */
175 | for (i = 0; i < N; i++) {
176 | temp2[i] = (double) (win[i] * (in[i + k] - fit[i])) + mval;
177 | }
178 | /*
179 | * Do FFT(Image,-1)
180 | */
181 | fftw_execute(fftimage);
182 | /*
183 | * Calculation of FFT(Image,-1)*Conj(FFT(Reference,-1))
184 | */
185 | for (i = 0; i < nx * (nyh + 1); i++) {
186 | fccr[i][0] = fimage[i][0] * fref[i][0]
187 | + fimage[i][1] * fref[i][1];
188 | fccr[i][1] = fimage[i][1] * fref[i][0]
189 | - fimage[i][0] * fref[i][1];
190 | }
191 | /*
192 | * Calculation of FFT(FFT(Image,-1)*Conj(FFT(Reference,-1)),+1)
193 | */
194 | fftw_execute(crosscor);
195 | /*
196 | * Find maximum
197 | */
198 | maxval = ccr[0];
199 | for (i = 0; i < N; i++) {
200 | if (ccr[i] > maxval) {
201 | maxpos = i;
202 | maxval = ccr[i];
203 | }
204 | }
205 | /*
206 | * Convert information about max into relevant values
207 | * Assign displacements to output variable
208 | */
209 |
210 | mx = (int) (maxpos % nx);
211 | if (mx > nxh){
212 | mx -= nx;
213 | }
214 |
215 | /* setting max displacement to zero */
216 | out[2 * l] = 0;
217 | //out[2 * l] = mx;
218 | my = (int) (maxpos / nx);
219 | if (my > nyh){
220 | my -= ny;
221 | }
222 |
223 | /* setting max displacement to zero */
224 | //out[2 * l + 1] = my;
225 | out[2 * l + 1] = 0;
226 | }
227 |
228 | fftw_cleanup();
229 | }
230 |
--------------------------------------------------------------------------------
/entry.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * Look at Header file for more details
39 | */
40 |
41 | #include "entry.h"
42 |
43 | int main(int argc, char *argv[])
44 | {
45 |
46 | /* Shutdown Flag */
47 | int go_flag = GO;
48 |
49 | /* Declare important MPI variables here */
50 | int rank; /* Rank of processor */
51 | int number; /* Number of available processors */
52 |
53 | /* Initialize MPI */
54 | MPI_Init(&argc, &argv);
55 | /* Get rank */
56 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
57 | /* Get the total number of processors */
58 | MPI_Comm_size(MPI_COMM_WORLD, &number);
59 |
60 | /* Tell mpifuncts rank and number */
61 | #ifdef DEBUG
62 | fprintf(stderr, "Initializing MPI [processors = %3d, rank = %3d].\n",number,rank);
63 | #endif
64 |
65 | mpi_setmoddata(number, rank);
66 |
67 | /*
68 | * MASTER PROCESS
69 | */
70 | if (rank == 0) {
71 | /* start MPI */
72 | mpi_mastering(argc, argv);
73 | mpi_shutdown();
74 | /*
75 | * SLAVES PROCESSES
76 | */
77 | } else {
78 | while (go_flag != NOGO) {
79 | go_flag = mpi_slaving();
80 | }
81 | }
82 |
83 | /* Terminate MPI */
84 | MPI_Finalize();
85 |
86 | return 0;
87 | }
88 |
--------------------------------------------------------------------------------
/entry.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 13.10.2003
46 | *
47 | * ---------------------------------------------
48 | * Header for the KI SIP v6 Speckle Library in C
49 | * ---------------------------------------------
50 | *
51 | * The GUI uses GraphApp.
52 | * Internet: http://enchantia.com/software/graphapp
53 | *
54 | * This is a parallized version using MPI.
55 | * An MPI Library can be downloaded at various places,
56 | * since MPI is just defines a standard for functions.
57 | *
58 | * Download for example at
59 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
60 | *
61 | */
62 |
63 | #ifndef KISIP_ENTRY_H
64 | #define KISIP_ENTRY_H
65 |
66 | #include
67 | #include
68 | #include
69 | #include "mpifuncts.h"
70 |
71 | #ifndef GO
72 | #define GO 1
73 | #endif
74 |
75 | #ifndef NOGO
76 | #define NOGO 0
77 | #endif
78 |
79 | #endif /* KISIP_ENTRY_H */
80 |
--------------------------------------------------------------------------------
/fileops.c:
--------------------------------------------------------------------------------
1 | /*
2 | * File operations routines
3 | */
4 |
5 | #include "fileops.h"
6 |
7 | /*****************************************************************************
8 | * readims: read image data from file with name "file" *
9 | *****************************************************************************/
10 |
11 | int readims(char **filenames, maininfo* info, float *data){
12 | FILE *inputfile;
13 | size_t num_pixels = info->xsize * info->ysize;
14 | int i;
15 |
16 | for(i = 0; i < info->nrofframes; i++){
17 | inputfile = fopen(filenames[i], "r");
18 |
19 | if (inputfile != NULL) {
20 | /* Get offset out of the way in case it is present */
21 | fseek(inputfile, info->headeroffset, SEEK_SET);
22 |
23 | /* Read in the data in big chunks */
24 | fread(data + i*num_pixels, num_pixels * sizeof(float), 1, inputfile);
25 |
26 | fclose(inputfile);
27 |
28 | /* return success */
29 | return GO;
30 | } else {
31 | fprintf(stderr, "ERROR: file %s not found.\n", filenames[i]);
32 | return NOGO;
33 | }
34 | }
35 |
36 | return(GO);
37 | }
38 |
39 |
40 | /*****************************************************************************
41 | * savefloat: write float image data to file *
42 | *****************************************************************************/
43 |
44 | int savefloat(char filename[], long size, maininfo info, float *data)
45 | {
46 | FILE *savefile = fopen(filename, "w");
47 |
48 | if (savefile != NULL) {
49 | /* Write data in one big chunks */
50 | fwrite(data, size * sizeof(float), 1, savefile);
51 |
52 | fclose(savefile);
53 |
54 | /* return success */
55 | return GO;
56 | } else {
57 | fprintf(stderr, "ERROR: reconstruction could not be saved.\n");
58 | /* return NO success */
59 | return NOGO;
60 | }
61 |
62 | return(NOGO);
63 | }
64 |
--------------------------------------------------------------------------------
/fileops.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Header for file operations module
3 | */
4 |
5 | #ifndef _KISIP_FILEOPS_H
6 | #define _KISIP_FILEOPS_H
7 |
8 | #include "speckle_admin.h"
9 |
10 | int readims(char **filenames, maininfo* info, float *data);
11 | int savefloat(char filename[], long size, maininfo info, float *data);
12 |
13 | #endif /* _KISIP_FILEOPS_H */
14 |
15 |
--------------------------------------------------------------------------------
/free_vect.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | void free_vect(vect ** v)
62 | {
63 | if ((*v)->res_vec != NULL) {
64 | free((*v)->res_vec);
65 | (*v)->res_vec = NULL;
66 | }
67 | if ((*v) != NULL) {
68 | free((*v));
69 | (*v) = NULL;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/getinfo.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #include "speckle_admin.h"
57 | #include "opts.h"
58 |
59 | int getinfo(maininfo* out, int argc, char** argv)
60 | {
61 | char ch;
62 | int i;
63 | int xPresent = 0;
64 | int yPresent = 0;
65 |
66 | /* Create default values for when no argument is given */
67 | strcpy(out->savefiles, DEFAULT_SAVEFILE);
68 | out->xsize = DEFAULT_XSIZE;
69 | out->ysize = DEFAULT_YSIZE;
70 | out->headeroffset = DEFAULT_HEADERSIZE;
71 | out->tc.sfs = DEFAULT_SFS;
72 | out->tc.l1 = DEFAULT_BSAXISLENGTH;
73 | out->tc.l2 = DEFAULT_BSLENGTH;
74 | out->tc.max_rad = DEFAULT_MAXRAD;
75 | out->tc.max_iterations = DEFAULT_MAXITER;
76 | out->tc.snr = DEFAULT_SNR;
77 | out->tc.eps = DEFAULT_EXP;
78 | out->tc.limApod = DEFAULT_APODLIM;
79 |
80 | while ((ch = getopt_long(argc, argv, "oxyfsvwrpnea:", options, NULL)) != -1){
81 | switch (ch) {
82 | case 'o':
83 | strcpy(out->savefiles, optarg);
84 | break;
85 | case 'x':
86 | out->xsize = atoi(optarg);
87 | xPresent = 1;
88 | break;
89 | case 'y':
90 | out->ysize = atoi(optarg);
91 | yPresent = 1;
92 | break;
93 | case 'h':
94 | out->headeroffset = atoi(optarg);
95 | break;
96 | case 's':
97 | out->tc.sfs = (float) atof(optarg);
98 | break;
99 | case 'v':
100 | out->tc.l1 = (int) atoi(optarg);
101 | break;
102 | case 'w':
103 | out->tc.l2 = (int) atoi(optarg);
104 | break;
105 | case 'r':
106 | out->tc.max_rad = (int) atoi(optarg);
107 | break;
108 | case 'p':
109 | out->tc.max_iterations = atoi(optarg);
110 | break;
111 | case 'n':
112 | out->tc.snr = (float) atof(optarg) / 100.0;
113 | break;
114 | case 'e':
115 | out->tc.eps = (float) atof(optarg);
116 | break;
117 | case 'a':
118 | out->tc.limApod = (float) atof(optarg) / 100.0;
119 | break;
120 | default:
121 | fprintf(stderr, "Command-line switch not recognized.\n");
122 | break;
123 | }
124 | }
125 |
126 | argc -= optind;
127 | argv += optind;
128 |
129 | if(argc == 0){
130 | fprintf(stderr, "ERROR: no image files provided.\n");
131 | return(NOGO);
132 | }
133 | else{
134 | out->imagefiles = malloc(argc * sizeof(char*));
135 | }
136 |
137 | // interpret arguments without options as input image files
138 | out->nrofframes = argc;
139 | for(i = 0; i < out->nrofframes; i++){
140 | out->imagefiles[i] = malloc(ZEILENLAENGE * sizeof(char));
141 | strcpy(out->imagefiles[i], argv[i]);
142 | }
143 |
144 | if( !xPresent || !yPresent ){
145 | fprintf(stderr, "ERROR: pixels in x- and y-direction required.\n");
146 | return(NOGO);
147 | }
148 |
149 |
150 | return(GO);
151 | }
152 |
--------------------------------------------------------------------------------
/init_matrix.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | void init_matrix(int nx, int ny, int deg, gsl_matrix ** ut, gsl_matrix ** kk)
62 | {
63 | /* important static variables */
64 | static int init_done = 0;
65 | static gsl_matrix *out_ut;
66 | static gsl_matrix *out_kk;
67 | static int n1, n2, n3;
68 |
69 | /* helper variables */
70 | unsigned long nrcoeffs = (deg + 1) * (deg + 2) / 2;
71 | unsigned long n = nx * ny;
72 | long i, k, l;
73 | unsigned long j;
74 | int sig;
75 | gsl_vector *vx;
76 | gsl_vector *vy;
77 | gsl_matrix *tmp1;
78 | gsl_matrix *tmp2;
79 | gsl_permutation *p;
80 |
81 | /* Initialise fit matrix if needed */
82 | if ((init_done == 1) &&
83 | ((n1 != nx) || (n2 != ny) || (n3 != deg) ||
84 | ((*out_ut).size1 != nrcoeffs) || ((*out_ut).size2 != n) ||
85 | ((*out_kk).size1 != nrcoeffs) || ((*out_kk).size2 != n))) {
86 | /* free memory */
87 | gsl_matrix_free(out_ut);
88 | gsl_matrix_free(out_kk);
89 | /* set init flag */
90 | init_done = 0;
91 | }
92 | if (init_done == 0) {
93 | // set control values
94 | n1 = nx;
95 | n2 = ny;
96 | n3 = deg;
97 | /* init helper variables */
98 | vx = gsl_vector_calloc(nx);
99 | vy = gsl_vector_calloc(ny);
100 | tmp1 = gsl_matrix_calloc(nrcoeffs, nrcoeffs);
101 | tmp2 = gsl_matrix_calloc(nrcoeffs, nrcoeffs);
102 | p = gsl_permutation_calloc(nrcoeffs);
103 | /* allocate memory for fit matrix */
104 | out_ut = gsl_matrix_calloc(nrcoeffs, n);
105 | out_kk = gsl_matrix_calloc(nrcoeffs, n);
106 | /* Initialise the base matrix which has the grid inside: *
107 | * it has as many rows as paramters to be fitted and the *
108 | * grid for each of the parameters */
109 | for (i = 0; i < nx; i++) {
110 | gsl_vector_set(vx, i, i);
111 | }
112 | for (i = 0; i < ny; i++) {
113 | gsl_vector_set(vy, i, i);
114 | }
115 | i = 0;
116 | for (k = 0; k <= deg; k++) {
117 | for (l = 0; l <= deg; l++) {
118 | if ((k + l) <= deg) {
119 | for (j = 0; j < n; j++) {
120 | gsl_matrix_set(out_ut, i, j,
121 | pow(gsl_vector_get
122 | (vx, (int) j % nx),
123 | k) * pow(gsl_vector_get(vy,
124 | (int) j
125 | / nx),
126 | l));
127 | }
128 | i++;
129 | }
130 | }
131 | }
132 | /* Invert the base matrix squared and multiply. This *
133 | * will result in 1/a^2 * a = 1/a and gives us the *
134 | * base for the least squares fit */
135 | gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, out_ut, out_ut, 0.0,
136 | tmp1);
137 | gsl_linalg_LU_decomp(tmp1, p, &sig);
138 | gsl_linalg_LU_invert(tmp1, p, tmp2);
139 | gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, tmp2, out_ut, 0.0,
140 | out_kk);
141 | /* Free some memory */
142 | gsl_vector_free(vx);
143 | gsl_vector_free(vy);
144 | gsl_matrix_free(tmp1);
145 | gsl_matrix_free(tmp2);
146 | gsl_permutation_free(p);
147 | /* set init flag */
148 | init_done = 1;
149 | }
150 | /* Set the pointers right */
151 | *ut = out_ut;
152 | *kk = out_kk;
153 | }
154 |
--------------------------------------------------------------------------------
/init_shift.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | *************EXTENDED KNOX-THOMPSON PART FOR PHASE RECONSTRUCTION************
64 | ****************************************************************************/
65 | /*
66 | ** Compute shifts that will be utilized to calculate the Knox-Thompson
67 | ** Cross Spectra.
68 | ** Input:
69 | ** nxh: half of field size in x direction
70 | ** nyh: half of field size in y direction
71 | ** len: maximum length of shift vector
72 | ** NOTE: for KT this may not be higher than the
73 | ** seeing limit!
74 | ** maxk: number of shifts computed
75 | ** shifts: pointer to resultant array
76 | **
77 | ** written by Friedrich Woeger
78 | **
79 | ** last change: 14. 10. 03
80 | */
81 |
82 | void init_shift(int nxh, int nyh, int len, int *maxk, int **shifts)
83 | {
84 | // helper variables
85 | int limit;
86 | int count;
87 | int rad;
88 | int i, j;
89 | int x, y;
90 |
91 | if (len == 1) {
92 | // set count value and allocate memory for original Knox-Thompson shifts
93 | count = 6;
94 | (*shifts) = (int *) realloc((*shifts), count * sizeof(int));
95 | (*shifts)[0] = 0;
96 | (*shifts)[1] = 0;
97 | (*shifts)[2] = 1;
98 | (*shifts)[3] = 0;
99 | (*shifts)[4] = 0;
100 | (*shifts)[5] = 1;
101 | } else {
102 | // set count value and allocate memory for zero shifts
103 | count = 2;
104 | (*shifts) = (int *) realloc((*shifts), count * sizeof(int));
105 | (*shifts)[0] = 0;
106 | (*shifts)[1] = 0;
107 |
108 | // limit = minimum of half of window size, since we start in the middle
109 | limit = (nxh <= nyh) ? nxh : nyh;
110 |
111 | // Begin computation
112 | for (rad = 1; rad <= len; rad++) {
113 |
114 | if (rad >= limit)
115 | break;
116 |
117 | for (i = 0; i <= rad; i++) {
118 | for (j = 0; j < 4 * i; j++) {
119 | if (j <= i) {
120 | x = i;
121 | y = j;
122 | }
123 | if ((j > i) && (j <= 3 * i)) {
124 | x = 2 * i - j;
125 | y = i;
126 | }
127 | if ((j > 3 * i) && (j <= 4 * i)) {
128 | x = -i;
129 | y = 4 * i - j;
130 | }
131 |
132 | if (rad < len) {
133 | if (((x * x + y * y) <= (rad * rad))
134 | && ((x * x + y * y) > (rad - 1) * (rad - 1))) {
135 | (*shifts) =
136 | (int *) realloc((*shifts),
137 | (count + 2) * sizeof(int));
138 | (*shifts)[count] = x;
139 | (*shifts)[count + 1] = y;
140 | count += 2;
141 | }
142 | }
143 | else {
144 | if (((x * x + y * y) < (rad * rad))
145 | && ((x * x + y * y) > (rad - 1) * (rad - 1))) {
146 | (*shifts) =
147 | (int *) realloc((*shifts),
148 | (count + 2) * sizeof(int));
149 | (*shifts)[count] = x;
150 | (*shifts)[count + 1] = y;
151 | count += 2;
152 | }
153 | }
154 | }
155 | }
156 | }
157 | }
158 |
159 | *maxk = (int) count / 2;
160 | }
161 |
--------------------------------------------------------------------------------
/inlines.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #ifndef KISIP_INLINES_H
37 | #define KISIP_INLINES_H
38 |
39 |
40 | /*
41 | * Definitions for inline complex functions
42 | * cadd - complex addition r = a + b
43 | * csub - complex subtraction r = a - b
44 | * cmul - complex multiplication r = a * b
45 | * cdiv - complex division r = a / b
46 | * conj - complex conjugate r = a*
47 | * cmod - modulus |a|
48 | * ccpy - complex copy r = a
49 | */
50 |
51 | #define cadd(a,b,r) \
52 | { \
53 | *(r) = *(a) + *(b); \
54 | *((r)+1) = *((a)+1) + *((b)+1); \
55 | }
56 | #define csub(a,b,r) \
57 | { \
58 | *(r) = *(a) - *(b) ; \
59 | *((r)+1) = *((a)+1) - *((b)+1); \
60 | }
61 | #define cmul(a,b,r) \
62 | { \
63 | float t1, t2; \
64 | t1 = *(a) ; t2 = *((a) + 1); \
65 | *(r) = *(b)*t1 - *((b)+1)*t2; \
66 | *((r)+1) = *((b)+1)*t1 + *(b)*t2; \
67 | }
68 | #define cdiv(a,b,r) \
69 | { \
70 | float t1, t2, denom; \
71 | t1 = *(b) ; t2 = *((b) + 1); \
72 | denom = t1*t1 + t2*t2; \
73 | if (denom == 0.0) { \
74 | *(r) = 0.0; \
75 | *((r)+1) = 0.0; \
76 | } else { \
77 | *(r) = (*(a)*t1 + *((a)+1)*t2)/denom; \
78 | *((r)+1) = (*((a)+1)*t1 - *(a)*t2)/denom; \
79 | } \
80 | }
81 | #define csqr(a,r) \
82 | { \
83 | double t1, t2, t3, t4, t5, t6, t7; \
84 | t1 = *(a); t2 = *((a)+1); \
85 | if ((t1 == 0.0) && (t2 == 0.0)) { \
86 | *(r) = 0.0; \
87 | *((r)+1) = 0.0; \
88 | } else { \
89 | if ((t3 = fabs(t1)) >= (t4 = fabs(t2))) \
90 | {t5 = t4/t3; t6 = sqrt(t3)*sqrt(0.5*(1.0+sqrt(1.0+t5*t5)));} \
91 | else \
92 | {t5 = t3/t4; t6 = sqrt(t4)*sqrt(0.5*(t5+sqrt(1.0+t5*t5)));} \
93 | if (t1 >= 0.0) \
94 | {*(r) = (float)t6; *(r+1) = (float)(t2/(2.0*t6));} \
95 | else \
96 | {t7 = (t2 >= 0.0) ? t6 : -t6; *(r) = (float)(t2/(2.0*t7)); *(r+1) = (float)t7;} \
97 | } \
98 | }
99 | #define conj(a,r) \
100 | { \
101 | *(r) = *(a); \
102 | *((r)+1) = -(*((a)+1)); \
103 | }
104 | #define ccpy(a,r) \
105 | { \
106 | *(r) = *(a); \
107 | *((r)+1) = *((a)+1); \
108 | }
109 | #define cmod(a) ((float)(sqrt((double)(*(a)*(*(a)) + *((a)+1)*(*((a)+1))))))
110 |
111 | /*
112 | * Definitions for pointer arithmetic
113 | *
114 | * sf_idx: jump to correct vector-position in image to
115 | * split a matrix into subfields
116 | * (i,j) - requested pixel position
117 | * (m,n) - subfield index
118 | * fr - index of frame in burst
119 | * nxh,nyh - half of subfield height/width
120 | * ox, oy - offset from border
121 | * Nx,Ny - height/width of source image
122 | * shift_idx: jump to shifted pixel-position in image
123 | * (i,j) - requested pixel position
124 | * (s_x,s_y) - shift-vector
125 | * nx,ny - image height/width
126 | * mbs_idx: vector-position for MeanBiSpectrum manipulation
127 | * (i,j,m,n) - requested (u,v) position
128 | * (l1,l2,l3) - limits whithin BS is calculated
129 | * w_idx: vector-position for weight matrix manipulation
130 | * (i,j,m,n) - requested (u,v) position
131 | * (l1,l2,l3) - limits whithin BS is calculated
132 | * phs_idx: vector-position for Phase manipulation
133 | * (i,j) - requested pixel position
134 | * nx - image width
135 | * idx: jump to pixel-position in subfield image
136 | * (i,j) - requested pixel position
137 | * nx - image width
138 | * idx3d: jump to pixel-position in datacube
139 | * (i,j,k) - requested pixel position
140 | * nx - image width
141 | */
142 |
143 | // single backslash merges lines into one long line
144 | #define sf_idx(i, j, m, n, fr, nxh, nyh, ox, oy, Nx, Ny, r) \
145 | { \
146 | long tx, ty; \
147 | tx = (ox) + (m)*(nxh) + (i) + (Nx); \
148 | ty = (oy) + (n)*(nyh) + (j) + (Ny); \
149 | tx %= (Nx); \
150 | ty %= (Ny); \
151 | r = ty*(Nx) + tx + (fr)*(Nx)*(Ny); \
152 | }
153 | #define shift_idx(i, j, s_x, s_y, nx, ny, r) \
154 | { \
155 | long tx, ty; \
156 | tx = (i) + (nx) + (s_x); \
157 | ty = (j) + (ny) + (s_y); \
158 | tx = (tx)%(nx); \
159 | ty = (ty)%(ny); \
160 | r = ty*(nx) + tx; \
161 | }
162 | #define mbs_idx(i, j, m, n, l1, l2, l3, r) \
163 | { \
164 | r = (2*(((((n)+(l3))*(2*((l3)+1)) + (m)+(l3))*(2*((l2)+1)) + (j)+(l2))*(l1+1) + (i)));\
165 | }
166 | #define w_idx(i, j, m, n, l1, l2, l3, r) \
167 | { \
168 | r = (((((n)+(l3))*(2*((l3)+1)) + (m)+(l3))*(2*((l2)+1)) + (j)+(l2))*(l1+1) + (i));\
169 | }
170 | #define phs_idx(i, j, nx, r) \
171 | { \
172 | r = (2*((j)*(nx) + (i)));\
173 | }
174 | #define idx(i, j, nx, r) {r = (j)*(nx) + (i);}
175 | #define idx3d(i, j, k, nx, ny, r) {r = ((k)*(ny)+(j))*(nx) + (i);}
176 |
177 | #endif
178 |
179 |
--------------------------------------------------------------------------------
/iwlspr.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | void iwlspr(float *p1, float *p2, float *pc, float *bsc, float *wc,
66 | long *index, long bs_cnt, slaveinfo l, int maxk)
67 | {
68 | static long INIT = 0; // initialisation flag
69 | static long *d = NULL; // circle with radius l.bs_mr
70 | static float *pct = NULL; // temporary phase consistency
71 |
72 | long i, j, cnt; // loop variable
73 | long i1, i2, i3; // index variable
74 | long nx, ny, nxh, nyh; // (half of) field size
75 | long u1, u2, v1, v2; // bispectrum vectors
76 | float ct[2], ct1[2], ct2[2]; // complex temporary variable
77 | float w1; // real temporary variable
78 | float t1; // real temporary variable
79 | long c1, c2, c3, c4; // condition flags
80 |
81 | nx = l.sfsizex;
82 | ny = l.sfsizey;
83 | nxh = nx / 2;
84 | nyh = ny / 2;
85 |
86 | // set (quarter-)circle
87 | if (INIT != l.max_rad) {
88 | if (d != NULL)
89 | free(d);
90 | if (pct != NULL)
91 | free(pct);
92 | d = (long *) malloc((l.max_rad + 1) * sizeof(long));
93 | for (i = 0; i <= l.max_rad; i++) {
94 | d[i] = (long) sqrt((float) (l.max_rad * l.max_rad - i * i));
95 | }
96 | // setup temporary phase consistency
97 | pct = (float *) malloc(nx * ny * sizeof(float));
98 | INIT = l.max_rad;
99 | }
100 | // reset matrix
101 | memset(pct, 0.0, nx * ny * sizeof(float));
102 |
103 | for (cnt = 0; cnt < bs_cnt; cnt++) {
104 | // get vectors
105 | u1 = index[0 + cnt * 4];
106 | u2 = index[1 + cnt * 4];
107 | v1 = index[2 + cnt * 4];
108 | v2 = index[3 + cnt * 4];
109 |
110 | // don't go along the negative y axis with u
111 | if ((u1 == 0) && (u2 <= 0))
112 | continue;
113 |
114 | if (wc[cnt] >= l.snr) {
115 | ct[0] = bsc[2 * cnt];
116 | ct[1] = bsc[2 * cnt + 1];
117 | } else {
118 | ct[0] = 0;
119 | ct[1] = 0;
120 | }
121 | w1 = pow(wc[cnt], l.eps);
122 |
123 | // set condition flags
124 | // the first three are there to not alter the initial guesses around the origin
125 | if ((u1 * u1 + u2 * u2) <= 1)
126 | c1 = 1;
127 | else
128 | c1 = 0;
129 | if ((v1 * v1 + v2 * v2) <= 1)
130 | c2 = 1;
131 | else
132 | c2 = 0;
133 | if (((u1 + v1) * (u1 + v1) + (u2 + v2) + (u2 + v2)) <= 1)
134 | c3 = 1;
135 | else
136 | c3 = 0;
137 | // the last one is for fitting theory
138 | if ((u1 == v1) && (u2 == v2))
139 | c4 = 1;
140 | else
141 | c4 = 0;
142 | // compute indices for phases only once
143 | phs_idx(nxh - v1, nyh + v2, nx, i1); // v position
144 | phs_idx(nxh - u1, nyh + u2, nx, i2); // u position
145 | phs_idx(nxh - u1 - v1, nyh + u2 + v2, nx, i3); // u+v position
146 | // finally calculate the values
147 | if (!c4) {
148 | if (!c1) {
149 | // compute weight
150 | t1 = pc[i1 / 2] * pc[i3 / 2] * w1;
151 | // phase at u
152 | conj(&p1[i3], ct1);
153 | cmul(&p1[i1], ct1, ct2);
154 | cdiv(ct, ct2, ct1);
155 | ct2[0] = t1 * ct1[0];
156 | ct2[1] = t1 * ct1[1];
157 | cadd(&p2[i2], ct2, &p2[i2]);
158 | pct[i2 / 2] += t1;
159 | }
160 | if (!c2) {
161 | // compute weight
162 | t1 = pc[i2 / 2] * pc[i3 / 2] * w1;
163 | // phase at v
164 | conj(&p1[i3], ct1);
165 | cmul(&p1[i2], ct1, ct2);
166 | cdiv(ct, ct2, ct1);
167 | ct2[0] = t1 * ct1[0];
168 | ct2[1] = t1 * ct1[1];
169 | cadd(&p2[i1], ct2, &p2[i1]);
170 | pct[i1 / 2] += t1;
171 | }
172 | } else {
173 | // compute weight
174 | t1 = 4.0 * pc[i3 / 2] * w1;
175 | // phase at u=v
176 | conj(&p1[i3], ct1);
177 | cdiv(ct, ct1, ct1);
178 | csqr(ct1, ct2);
179 | ct2[0] *= t1;
180 | ct2[1] *= t1;
181 | cadd(&p2[i2], ct2, &p2[i2]);
182 | pct[i2 / 2] += t1;
183 | }
184 | if (!c3) {
185 | // compute weight
186 | t1 = pc[i1 / 2] * pc[i2 / 2] * w1;
187 | // phase at u+v
188 | cmul(&p1[i1], &p1[i2], ct1);
189 | cdiv(ct, ct1, ct1);
190 | conj(ct1, ct2);
191 | ct2[0] *= t1;
192 | ct2[1] *= t1;
193 | cadd(&p2[i3], ct2, &p2[i3]);
194 | pct[i3 / 2] += t1;
195 | }
196 | }
197 | // assign values to output phase p1
198 | //for (i=0; i<=l.max_rad; i++) {
199 | for (i = maxk; i <= l.max_rad; i++) {
200 | i3 = (i == 0) ? 1 : -d[i];
201 | for (j = i3; j < d[i]; j++) {
202 | phs_idx(nxh - i, nyh + j, nx, i1);
203 | phs_idx(nxh + i, nyh - j, nx, i2);
204 | /*
205 | if ((p2[i1] == 0) && (p2[i1+1] == 0)) {
206 | p1[i1] = 1.0; p1[i1+1] = 0.0;
207 | p1[i2] = 1.0; p1[i2+1] = 0.0;
208 | } else {
209 | */
210 | if ((p2[i1] != 0) && (p2[i1 + 1] != 0)) {
211 | t1 = cmod(&p2[i1]);
212 | // normalize
213 | p1[i1] = p2[i1] / t1;
214 | p1[i1 + 1] = p2[i1 + 1] / t1;
215 | pc[i1 / 2] = (pct[i1 / 2] != 0) ? t1 / pct[i1 / 2] : 0.0;
216 | // mirror
217 | conj(&p1[i1], &p1[i2]);
218 | pc[i2 / 2] = pc[i1 / 2];
219 | }
220 | }
221 | }
222 | // reset temp matrix
223 | memset(p2, 0, 2 * nx * ny * sizeof(float));
224 | }
225 |
--------------------------------------------------------------------------------
/mpi_master_rec.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 21.07.2003
46 | *
47 | * ----------------------------------------------
48 | * Main functions for the MPI control of jobs for
49 | * the KI SIP v6 Speckle Library in C
50 | * ----------------------------------------------
51 | *
52 | * This is a parallized version, implemented using MPI.
53 | * An MPI Library can be downloaded at various places,
54 | * since MPI has standardised functions, e.g.
55 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
56 | *
57 | */
58 |
59 | #include "mpifuncts.h"
60 |
61 |
62 | //---------------------------------------------------------------------------
63 | // mpi_master_rec:
64 | //---------------------------------------------------------------------------
65 | void mpi_master_rec(float *alldata, maininfo * info, int used_size, float *amp, float *phs)
66 | {
67 | // Declare variables
68 | MPI_Datatype MPI_SLAVEINF; /* Dataype for MPI communications */
69 | MPI_Status *status; /* Recv status handler */
70 | slaveinfo sl_info; /* Information structure for slaves */
71 |
72 | float *data; /* subfield data burst */
73 | int jobs, jobs_done; /* # of jobs, # of jobs done */
74 | int sfN; /* number of pixels in a subfield */
75 | int i; /* counter for loops */
76 |
77 | putslaveinf(&sl_info, info, 0);
78 |
79 | // Set Slaveinfo datatype for MPI sends and receives
80 | mpi_setslavetype(&MPI_SLAVEINF);
81 |
82 | // Initialise status variable for MPI data exchange
83 | status = (MPI_Status *) malloc(sizeof(MPI_Status));
84 |
85 | // Initialise variables
86 | jobs = (*info).subfields.nfrx * (*info).subfields.nfry;
87 | sfN = (*info).subfields.ssizex * (*info).subfields.ssizey;
88 | data = (float *) malloc(sfN * (*info).nrofframes * sizeof(float));
89 |
90 | /*************************************
91 | **** INITIALIZE SLAVES WITH WORK ****
92 | *************************************/
93 |
94 | for (i = 1; i < used_size; i++) {
95 | // divide data into subfields
96 | subfielding(alldata, i - 1, info, data);
97 | // now set the data for the slaves
98 | putslaveinf(&sl_info, info, i - 1);
99 |
100 | // Send information to the slaves
101 | MPI_Send(&sl_info, 1, MPI_SLAVEINF, i, TC, MPI_COMM_WORLD);
102 |
103 | MPI_Send(data, (*info).subfields.ssizex * (*info).subfields.ssizey *
104 | (*info).nrofframes, MPI_FLOAT, i, TC, MPI_COMM_WORLD);
105 | }
106 |
107 | /********************************************************
108 | **** CONTINUE GIVING TASKS TO SLAVES FOR COMPLETION ****
109 | ********************************************************/
110 |
111 | // set counter for jobs done
112 | jobs_done = used_size - 1;
113 | // if we are not done, send next job to slave that responds first
114 | while (jobs_done < jobs) {
115 | // receive tracked data info
116 | MPI_Recv(&sl_info, 1, MPI_SLAVEINF, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status);
117 |
118 | /**** MPI_TAG indicates whether we are at the end of the process, ****
119 | **** or just getting the mean image and tracking data ***************/
120 | if (status->MPI_TAG != GO) {
121 | // receive processed data
122 | MPI_Recv(&[sl_info.position * sfN], sfN, MPI_FLOAT,
123 | status->MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
124 | status);
125 | MPI_Recv(&phs[2 * sl_info.position * sfN], 2 * sfN, MPI_FLOAT,
126 | status->MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
127 | status);
128 |
129 |
130 | // Cut next subfield to be analyzed
131 | subfielding(alldata, jobs_done, info, data);
132 | // set the data for the slaves
133 | putslaveinf(&sl_info, info, jobs_done);
134 |
135 | // Send information to the slaves
136 | MPI_Send(&sl_info, 1, MPI_SLAVEINF, status->MPI_SOURCE, TC, MPI_COMM_WORLD);
137 |
138 | // send data to slaves
139 | MPI_Send(data, sfN * (*info).nrofframes, MPI_FLOAT,
140 | status->MPI_SOURCE, TC, MPI_COMM_WORLD);
141 |
142 | // increase jobs_done counter
143 | jobs_done += 1;
144 | }
145 | }
146 |
147 | /*********************************************************************************
148 | **** WAIT FOR THE REST OF THE SLAVES TO COMPLETE AFTER THERE IS NO MORE WORK ****
149 | *********************************************************************************/
150 |
151 | // collect the remaining data
152 | i = 1;
153 | while (i < used_size) {
154 | // receive tracked data info
155 | MPI_Recv(&sl_info, 1, MPI_SLAVEINF, MPI_ANY_SOURCE, MPI_ANY_TAG,
156 | MPI_COMM_WORLD, status);
157 |
158 | /**** MPI_TAG indicates whether we are at the end of the process, ****
159 | **** or just getting the mean image and tracking data ***************/
160 | if (status->MPI_TAG != GO) {
161 | // receive processed data
162 | MPI_Recv(&[sl_info.position * sfN], sfN, MPI_FLOAT,
163 | status->MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status);
164 | MPI_Recv(&phs[2 * sl_info.position * sfN], 2 * sfN, MPI_FLOAT,
165 | status->MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status);
166 |
167 | // send idle signal to slaves
168 | MPI_Send(&sl_info, 1, MPI_INT, status->MPI_SOURCE, NOGO, MPI_COMM_WORLD);
169 |
170 | // set counter for slaves finished off
171 | i += 1;
172 | }
173 | }
174 |
175 | free(data);
176 | free(status);
177 | MPI_Type_free(&MPI_SLAVEINF);
178 | }
179 |
--------------------------------------------------------------------------------
/mpi_mastering.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 21.07.2003
46 | *
47 | * ----------------------------------------------
48 | * Main functions for the MPI control of jobs for
49 | * the KI SIP v6 Speckle Library in C
50 | * ----------------------------------------------
51 | *
52 | * This is a parallized version, implemented using MPI.
53 | * An MPI Library can be downloaded at various places,
54 | * since MPI has standardised functions, e.g.
55 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
56 | *
57 | */
58 |
59 | #include "mpifuncts.h"
60 | #include "opts.h"
61 |
62 | //---------------------------------------------------------------------------
63 | // mpi_mastering:
64 | //---------------------------------------------------------------------------
65 | void mpi_mastering(int argc, char **argv)
66 | {
67 | // +++ Declare variables +++
68 | // MPI variables
69 | int jobs; /* # of jobs */
70 | int used_size; /* # of processors used */
71 |
72 | // data variables
73 | float *alldata = NULL; /* data variables */
74 | float *famp = NULL; /* result of calculations (amplitudes) */
75 | float *fphs = NULL; /* result of calculations (phases) */
76 | float *result = NULL; /* result of calculations (transf.) */
77 | float *rec = NULL; /* assembled reconstruction */
78 | float *flipped_recon = NULL;
79 | long sfN; /* number of pixels in a subfield */
80 | int i, j; /* counters for loops */
81 |
82 | #ifdef DEBUG
83 | time_t start, end; /* timer values */
84 | #endif
85 |
86 | maininfo info;
87 |
88 | //---------------------------------------------------------------------------
89 | // Get the vital data for processing from the GUI entries.
90 | // Set total number of jobs equal to the number of subfields
91 | // and set the number of processors used.
92 | //
93 | // Attempt to read in image data. If successful, start the
94 | // reconstruction process.
95 | //---------------------------------------------------------------------------
96 |
97 |
98 | if( getinfo(&info, argc, argv) ){
99 | alldata = malloc(info.xsize * info.ysize * info.nrofframes * sizeof(float));
100 | }
101 |
102 | if ( (alldata != NULL) && readims(info.imagefiles, &info, alldata) ) {
103 |
104 | calc_subfields(info.xsize, info.ysize, info.tc.sfs, &info);
105 |
106 | // assume maximum reconstruction radius if no command line option given
107 | if( info.tc.max_rad == DEFAULT_MAXRAD ){
108 | info.tc.max_rad = (info.subfields.ssizex / 2 - 2) ;
109 | }
110 |
111 | jobs = info.subfields.nfrx * info.subfields.nfry;
112 | sfN = info.subfields.ssizex * info.subfields.ssizey;
113 | if (jobs < proc_nr - 1){
114 | used_size = (jobs + 1);
115 | }
116 | else{
117 | used_size = proc_nr;
118 | }
119 |
120 | //---------------------------------------------------------------------------
121 | // Allocate memory shared with slaves:
122 | // alldata - the entire input time series, original data format
123 | // famp - Fourier amplitudes. Real valued, subfield times jobs
124 | // fphs - Fourier phases. Real valued, subfield times jobs
125 | // result - reconstructed image. subfield times jobs
126 | // rec - assembled reconstruction. Original image size.
127 | //---------------------------------------------------------------------------
128 | famp = (float *) malloc(jobs * sfN * sizeof(float));
129 | fphs = (float *) malloc(jobs * 2 * sfN * sizeof(float));
130 | result = (float *) malloc(jobs * sfN * sizeof(float));
131 | rec = (float *) malloc(info.xsize * info.ysize * sizeof(float));
132 | flipped_recon = malloc(info.xsize * info.ysize * sizeof(float));
133 | //---------------------------------------------------------------------------
134 | // File exists and contains enough data. Start timer. Awake the slaves.
135 | // Broadcast # of processors used and let slave decide, whether he is
136 | // needed to join the calculation.
137 | //---------------------------------------------------------------------------
138 | #ifdef DEBUG
139 | time(&start);
140 | fprintf(stderr, "\nWaking up slaves...");
141 | fflush(stdout);
142 | #endif
143 | MPI_Bcast(&used_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
144 | #ifdef DEBUG
145 | fprintf(stderr, " done.\r\n");
146 | fprintf(stderr, "Starting calculation.\r\n");
147 | #endif
148 |
149 | //---------------------------------------------------------------------------
150 | // This function distributes the tasks and manages the subfield
151 | // reconstruction process. Slave work is done when MPI_MASTER_REC
152 | // returns.
153 | //---------------------------------------------------------------------------
154 |
155 | mpi_master_rec(alldata, &info, used_size, famp, fphs);
156 |
157 | //---------------------------------------------------------------------------
158 | // Reassemble subimages with Fourier amplification (noise filter in af)
159 | //---------------------------------------------------------------------------
160 | #ifdef DEBUG
161 | fprintf(stderr, "\n\nAssembling... ");
162 | fflush(stdout);
163 | #endif
164 |
165 | for (i = 0; i < jobs; i++) {
166 |
167 | /* Combine Fourier phases and amplitudes of subimages
168 | * Calculate inverse Fourier transform to obtain reconstructed subimages
169 | */
170 | assemble(info.subfields.ssizex, info.subfields.ssizey, &famp[i * sfN],
171 | &fphs[(2 * i) * sfN], &result[i * sfN], info);
172 | }
173 |
174 | //---------------------------------------------------------------------------
175 | // Compute full field reconstruction.
176 | // End the timer.
177 | //---------------------------------------------------------------------------
178 | if( jobs != 1 ){
179 | reconstruct(result, &info, rec);
180 | }
181 | else{
182 | rec = result;
183 | }
184 |
185 | #ifdef DEBUG
186 | time(&end);
187 | fprintf(stderr, "done.\n\n");
188 | fprintf(stderr, "Master done! Used time: %.2lf seconds\r\n", difftime(end, start));
189 | #endif
190 |
191 | //---------------------------------------------------------------------------
192 | // Flip and save the results
193 | //---------------------------------------------------------------------------
194 | for(i = 0; i < info.xsize; i++){
195 | for(j = 0; j < info.ysize; j++){
196 | flipped_recon[(j * info.xsize) + i] = rec[(info.ysize - j - 1) * info.xsize + i];
197 | }
198 | }
199 |
200 | savefloat(info.savefiles, (long) info.xsize * info.ysize, info, flipped_recon);
201 |
202 | //---------------------------------------------------------------------------
203 | // Search for input data not successful. Loop to next file.
204 | //---------------------------------------------------------------------------
205 | } else {
206 | fprintf(stderr, "Read failed!\r\n");
207 | }
208 |
209 | //---------------------------------------------------------------------------
210 | // Free Memory.
211 | //---------------------------------------------------------------------------
212 |
213 | if (alldata != NULL)
214 | free(alldata);
215 | if (famp != NULL)
216 | free(famp);
217 | if (fphs != NULL)
218 | free(fphs);
219 | if (rec != NULL)
220 | free(rec);
221 | if (info.imagefiles != NULL){
222 | for(i = 0; i < info.nrofframes; i++){
223 | free(info.imagefiles[i]);
224 | }
225 | free(info.imagefiles);
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/mpi_setmoddata.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * ----------------------------------------------
39 | * Main functions for the MPI control of jobs for
40 | * the KI SIP v6 Speckle Library in C
41 | * ----------------------------------------------
42 | *
43 | * This is a parallized version, implemented using MPI.
44 | * An MPI Library can be downloaded at various places,
45 | * since MPI has standardised functions, e.g.
46 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
47 | *
48 | * created by Friedrich Woeger
49 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
50 | * last changes:
51 | *
52 | */
53 |
54 | #include "mpifuncts.h"
55 |
56 | // Define important MPI variables here
57 | int proc_id; /* Rank of processor */
58 | int proc_nr; /* Number of available processors */
59 |
60 |
61 | //---------------------------------------------------------------------------
62 | void mpi_setmoddata(int number, int rank)
63 | {
64 | proc_id = rank;
65 | proc_nr = number;
66 | }
67 |
--------------------------------------------------------------------------------
/mpi_setslavetype.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 21.07.2003
46 | *
47 | * ----------------------------------------------
48 | * Main functions for the MPI control of jobs for
49 | * the KI SIP v6 Speckle Library in C
50 | * ----------------------------------------------
51 | *
52 | * This is a parallized version, implemented using MPI.
53 | * An MPI Library can be downloaded at various places,
54 | * since MPI has standardised functions, e.g.
55 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
56 | *
57 | */
58 |
59 | #include "mpifuncts.h"
60 |
61 | #define SLAVEINFO_NUM 14
62 |
63 | //---------------------------------------------------------------------------
64 | // setslavetype:
65 | //---------------------------------------------------------------------------
66 | void mpi_setslavetype(MPI_Datatype * typ)
67 | {
68 | // Declaration of the slaveinfo MPI Type here for communication purposes
69 | int bl[SLAVEINFO_NUM] =
70 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
71 | MPI_Aint ind[SLAVEINFO_NUM];
72 | MPI_Datatype otyp[SLAVEINFO_NUM] =
73 | { MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT,
74 | MPI_INT, MPI_INT, MPI_INT,
75 | MPI_FLOAT, MPI_FLOAT, MPI_FLOAT, MPI_FLOAT,
76 | MPI_FLOAT,
77 | MPI_UB
78 | };
79 |
80 | ind[0] = 0;
81 | ind[1] = ind[0] + (MPI_Aint) sizeof(int);
82 | ind[2] = ind[1] + (MPI_Aint) sizeof(int);
83 | ind[3] = ind[2] + (MPI_Aint) sizeof(int);
84 | ind[4] = ind[3] + (MPI_Aint) sizeof(int);
85 | ind[5] = ind[4] + (MPI_Aint) sizeof(int);
86 | ind[6] = ind[5] + (MPI_Aint) sizeof(int);
87 | ind[7] = ind[6] + (MPI_Aint) sizeof(int);
88 | ind[8] = ind[7] + (MPI_Aint) sizeof(float);
89 | ind[9] = ind[8] + (MPI_Aint) sizeof(float);
90 | ind[10] = ind[9] + (MPI_Aint) sizeof(float);
91 | ind[11] = ind[10] + (MPI_Aint) sizeof(float);
92 | ind[12] = ind[11] + (MPI_Aint) sizeof(float);
93 | ind[SLAVEINFO_NUM - 1] = sizeof(slaveinfo);
94 |
95 | MPI_Type_struct(SLAVEINFO_NUM, bl, ind, otyp, typ);
96 | MPI_Type_commit(typ);
97 | }
98 |
--------------------------------------------------------------------------------
/mpi_shutdown.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 21.07.2003
46 | *
47 | * ----------------------------------------------
48 | * Main functions for the MPI control of jobs for
49 | * the KI SIP v6 Speckle Library in C
50 | * ----------------------------------------------
51 | *
52 | * This is a parallized version, implemented using MPI.
53 | * An MPI Library can be downloaded at various places,
54 | * since MPI has standardised functions, e.g.
55 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
56 | *
57 | */
58 |
59 | #include "mpifuncts.h"
60 |
61 |
62 | //---------------------------------------------------------------------------
63 | // mpi_shutdown:
64 | //---------------------------------------------------------------------------
65 | void mpi_shutdown()
66 | {
67 | int used_size = NOGO; /* # of processors used */
68 | // Broadcast shutdown signal
69 | MPI_Bcast(&used_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
70 | }
71 |
--------------------------------------------------------------------------------
/mpi_slaving.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * KI SIP Graphical User Interface
39 | * -------------------------------
40 | * The Graphical User Interface for the KI SIP v6
41 | * Speckle Library in C
42 | *
43 | * created by Friedrich Woeger
44 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg
45 | * last changes: 21.07.2003
46 | *
47 | * ----------------------------------------------
48 | * Main functions for the MPI control of jobs for
49 | * the KI SIP v6 Speckle Library in C
50 | * ----------------------------------------------
51 | *
52 | * This is a parallized version, implemented using MPI.
53 | * An MPI Library can be downloaded at various places,
54 | * since MPI has standardised functions, e.g.
55 | * Internet: http://www-unix.mcs.anl.gov/mpi/mpich
56 | *
57 | */
58 |
59 | #include "mpifuncts.h"
60 |
61 | //---------------------------------------------------------------------------
62 | // mpi_slaving:
63 | //---------------------------------------------------------------------------
64 | int mpi_slaving()
65 | {
66 | // Declare local variables
67 | MPI_Datatype MPI_SLAVEINF; /* Dataype for MPI communications */
68 | slaveinfo sl_info; /* Information structure for slaves */
69 | MPI_Status *status; /* Recv status handler */
70 | int used_size; /* # of processors used */
71 |
72 | long sfN; /* # of pixels in subfield */
73 | float *data = NULL; /* subfield data burst */
74 | float *winH = NULL; /* apodisation window for SR calc. */
75 | float *winF = NULL; /* apodisation window for phase rec. */
76 | float *mask = NULL; /* DiffLim Mask */
77 | float *pc = NULL; /* Phase Consistency */
78 |
79 | /* for reallocation: needs to be NULL */
80 | int *shifts = NULL; /* shifts for KT Cross Spectra */
81 | /* for reallocation: needs to be NULL */
82 | int maxk; /* number of shifts */
83 |
84 | // Triple correlation part
85 | long *index = NULL; /* index list for bispectrum vectors */
86 | long bs_cnt; /* # of vectors used */
87 | float *bsc = NULL; /* complex non-red/red bispectrum */
88 | float *wc = NULL; /* complex non-red/red bs weights */
89 | float *p1 = NULL; /* phase matrix for iterativ reconstr. */
90 | float *aphs = NULL; /* average of low frequencies */
91 |
92 | // General part
93 | float *phs = NULL; /* Phase of reconstructed image */
94 | float *amp = NULL; /* Amplitude of reconstructed image */
95 | int c = GO; /* helpers */
96 | long i;
97 |
98 |
99 |
100 | // set up status variable for sends and receives
101 | status = (MPI_Status *) malloc(sizeof(MPI_Status));
102 |
103 | // Set Slaveinfo datatype for MPI sends and receives
104 | mpi_setslavetype(&MPI_SLAVEINF);
105 |
106 | // Receive number of jobs ...
107 | MPI_Bcast(&used_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
108 |
109 | // ...and if used_size = NOGO, we are quitting the slave!
110 | if (used_size == NOGO) {
111 | // free memory
112 | MPI_Type_free(&MPI_SLAVEINF);
113 | free(status);
114 | // returning NOGO quits the slaves in entry.c
115 | return NOGO;
116 | }
117 | // ...and decide if I am needed
118 | if (used_size > proc_id) {
119 | // work until TAG says NOGO
120 | while (GO) {
121 | // Receive the data information
122 | MPI_Recv(&sl_info, 1, MPI_SLAVEINF, 0, MPI_ANY_TAG, MPI_COMM_WORLD, status);
123 |
124 | // Break if shutdown signal was sent
125 | if (status->MPI_TAG == NOGO)
126 | break;
127 |
128 | if (status->MPI_TAG == TC) {
129 | /* First time allocation of memory */
130 | if (c) {
131 | // find number of pixels in subfield
132 | sfN = sl_info.sfsizex * sl_info.sfsizey;
133 | // allocate memory for data
134 | data = (float *) malloc(sfN * sl_info.nrofframes * sizeof(float));
135 | winH = (float *) malloc(sfN * sizeof(float));
136 | winF = (float *) malloc(sfN * sizeof(float));
137 | pc = (float *) malloc(sfN * sizeof(float));
138 |
139 | /* Initialise hamming window, fractional hamming & mask */
140 | hanming(winH, sl_info.sfsizex, sl_info.sfsizey, 0.5);
141 | frachamming(winF, sl_info.sfsizex, sl_info.sfsizey, sl_info.limApod, 0, NULL);
142 | // mask is no longer used...
143 | mask = ellmask(sl_info.sfsizex, sl_info.sfsizey, NULL, sl_info.rad_x, sl_info.rad_y);
144 |
145 | // allocate appropriate memory
146 | index = bs_init(&bs_cnt, sl_info);
147 |
148 | bsc = (float *) malloc(2 * bs_cnt * sizeof(float));
149 | wc = (float *) malloc(bs_cnt * sizeof(float));
150 |
151 | // Allocate memory for reconstructed amplitudes & phases
152 | amp = (float *) malloc(sfN * sizeof(float));
153 | phs = (float *) malloc(2 * sfN * sizeof(float));
154 | p1 = (float *) malloc(2 * sfN * sizeof(float));
155 |
156 | // set flag so as to not allocate new memory later
157 | c = NOGO;
158 | }
159 | // initialise amps, phases & phase consistency to zero
160 | memset(bsc, 0.0, 2 * bs_cnt * sizeof(float));
161 | memset(wc, 0.0, bs_cnt * sizeof(float));
162 | memset(amp, 0.0, sfN * sizeof(float));
163 | memset(phs, 0.0, 2 * sfN * sizeof(float));
164 | memset(p1, 0.0, 2 * sfN * sizeof(float));
165 | memset(pc, 0.0, sfN * sizeof(float));
166 |
167 | // finally receive the data
168 | MPI_Recv(data, sfN * sl_info.nrofframes, MPI_FLOAT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, status);
169 |
170 | // compute mean of burst
171 | //mean(data, sl_info.sfsizex, sl_info.sfsizey, sl_info.nrofframes, temp);
172 |
173 | /* compute the position of the 'good' average phase parts
174 | 3 is an argument here because we deleted:
175 | ((int) (alpha[0] * i_rad) > 3 ?
176 | (int) (alpha[0] * i_rad) : 3), */
177 | init_shift(sl_info.sfsizex / 2, sl_info.sfsizey / 2, 3, &maxk, &shifts);
178 |
179 | // create bi-spectrum/weights in non-redundant matrix
180 | aphs = bs_ave(data, winF, sl_info, index, bs_cnt, bsc, wc, amp, maxk, shifts);
181 |
182 | // set snr-threshold
183 | bs_snrt(wc, bs_cnt, &sl_info);
184 |
185 | // phase reconstruction
186 | // init phase matrices
187 | phs_init(phs, p1, pc, sl_info, maxk, shifts, aphs);
188 |
189 | // recursive approach
190 | rpr(phs, p1, pc, index, bs_cnt, bsc, wc, sl_info);
191 |
192 | // iterative approach
193 | for (i = 0; i < sl_info.max_it; i++) {
194 | iwlspr(phs, p1, pc, bsc, wc, index, bs_cnt, sl_info, maxk);
195 | if (chkphase(sl_info, phs) < 1.0e-5)
196 | break;
197 | }
198 |
199 | // Send back info, so master knows, which subfield burst this was
200 | // MPI_TAG will indicate whether we are at the end of the process
201 | MPI_Send(&sl_info, 1, MPI_SLAVEINF, 0, NOGO, MPI_COMM_WORLD);
202 |
203 | // Send back processed data
204 | MPI_Send(amp, sfN, MPI_FLOAT, 0, NOGO, MPI_COMM_WORLD);
205 | // send back phase
206 | MPI_Send(phs, 2 * sfN, MPI_FLOAT, 0, NOGO, MPI_COMM_WORLD);
207 |
208 | // free some memory
209 | free(shifts);
210 | shifts = NULL;
211 | free(aphs);
212 | aphs = NULL;
213 | }
214 | }
215 |
216 | // free memory
217 | if (data != NULL)
218 | free(data);
219 | if (winH != NULL)
220 | free(winH);
221 | if (winF != NULL)
222 | free(winF);
223 | if (mask != NULL)
224 | free(mask);
225 | if (pc != NULL)
226 | free(pc);
227 | if (shifts != NULL)
228 | free(shifts);
229 | if (amp != NULL)
230 | free(amp);
231 | if (phs != NULL)
232 | free(phs);
233 | if (index != NULL)
234 | free(index);
235 | if (p1 != NULL)
236 | free(p1);
237 | if (bsc != NULL)
238 | free(bsc);
239 | if (wc != NULL)
240 | free(wc);
241 |
242 | free(status);
243 | MPI_Type_free(&MPI_SLAVEINF);
244 | // idle until new data or shutdown Broadcast is sent
245 | return GO;
246 | }
247 | else {
248 | // free memory
249 | free(status);
250 | MPI_Type_free(&MPI_SLAVEINF);
251 | // idle until new data or shutdown Broadcast is sent
252 | return GO;
253 | }
254 | }
255 |
--------------------------------------------------------------------------------
/mpifuncts.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /*
38 | * -------------------------------------------
39 | * Header for the KI SIP v6 MPI Functions in C
40 | * -------------------------------------------
41 | *
42 | * uses mpi.h for MPI functions
43 | * uses speckle.h for the actual calculation functions
44 | * uses visual.h for visualizing the data
45 | *
46 | */
47 |
48 | #ifndef KISIP_MPIFUNCTS_H
49 | #define KISIP_MPIFUNCTS_H
50 |
51 | #include
52 | #include
53 | #include "speckle_admin.h"
54 | #include "speckle_core.h"
55 | #include "speckle_math.h"
56 | #include "fileops.h"
57 |
58 | #ifndef GO
59 | #define GO 1
60 | #endif
61 | #ifndef NOGO
62 | #define NOGO 0
63 | #endif
64 | #ifndef KT
65 | #define KT 10
66 | #endif
67 | #ifndef TC
68 | #define TC 11
69 | #endif
70 | #ifndef NOISE
71 | #define NOISE 12
72 | #endif
73 |
74 | void mpi_setmoddata(int number, int rank);
75 | void mpi_setslavetype(MPI_Datatype * typ);
76 | void mpi_mastering(int argc, char **argv);
77 | void mpi_master_rec(float *alldata, maininfo * info, int used_size, float *amp, float *phs);
78 | void mpi_shutdown();
79 | int mpi_slaving();
80 |
81 | // These varaibles are declared here and defined in "mpi_setmoddata"
82 | extern int proc_id; /* Rank of processor */
83 | extern int proc_nr; /* Number of available processors */
84 | extern char ptmodel[]; /* Path to model */
85 |
86 | #endif /* KISIP_MPIFUNCTS_H */
87 |
--------------------------------------------------------------------------------
/opts.h:
--------------------------------------------------------------------------------
1 | #ifndef OPTS_H
2 | #define OPTS_H
3 |
4 |
5 | /* default parameter values if no option specified */
6 | #define DEFAULT_SAVEFILE "TCaverage"
7 | #define DEFAULT_XSIZE 0
8 | #define DEFAULT_YSIZE 0
9 | #define DEFAULT_HEADERSIZE 0
10 | #define DEFAULT_SFS 0.0
11 | #define DEFAULT_BSAXISLENGTH 20
12 | #define DEFAULT_BSLENGTH 20
13 | #define DEFAULT_MAXRAD -1
14 | #define DEFAULT_MAXITER 10
15 | #define DEFAULT_SNR 1.0
16 | #define DEFAULT_EXP 0.2
17 | #define DEFAULT_APODLIM 0.0
18 |
19 | /* command line options for getopt() */
20 | static struct option options[] = {
21 | { "output", required_argument, NULL, 'o' },
22 | { "xsize", required_argument, NULL, 'x' },
23 | { "ysize", required_argument, NULL, 'y' },
24 | { "headersize", required_argument, NULL, 'h' },
25 | { "subsize", required_argument, NULL, 's' },
26 | { "bs1length", required_argument, NULL, 'v' },
27 | { "bs2length", required_argument, NULL, 'w' },
28 | { "maxrad", required_argument, NULL, 'r' },
29 | { "maxiter", required_argument, NULL, 'p' },
30 | { "snr", required_argument, NULL, 'n' },
31 | { "weightexp" , required_argument, NULL, 'e' },
32 | { "apod", required_argument, NULL, 'a' }
33 | };
34 |
35 |
36 | #endif /* OPTS_H */
37 |
--------------------------------------------------------------------------------
/phs_init.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | /*
66 | * phs_init: initialise the phase matrices
67 | *
68 | * p1, p2: phases to be initialised
69 | * nx, ny: size of images
70 | */
71 |
72 | void phs_init(float *p1, float *p2, float *pc, slaveinfo l,
73 | int maxk, int *shifts, float *origin)
74 | {
75 | static int INIT = 0;
76 | static float *mask = NULL;
77 | static long N;
78 | long nx, ny;
79 | long i;
80 | long i1;
81 |
82 | nx = l.sfsizex;
83 | ny = l.sfsizey;
84 |
85 | // compute elliptic mask
86 | if ((INIT != l.max_rad) || ny != (N / nx)) {
87 | N = nx * ny;
88 | if (mask != NULL)
89 | free(mask);
90 | mask = ellmask(nx, ny, NULL, l.max_rad, l.max_rad);
91 | INIT = l.max_rad;
92 | }
93 | // set phases
94 | for (i = 0; i < maxk; i++) {
95 | phs_idx(nx / 2 + shifts[2 * i], ny / 2 + shifts[2 * i + 1], nx, i1);
96 | p1[i1] = origin[2 * i];
97 | p1[i1 + 1] = origin[2 * i + 1];
98 | p2[i1] = origin[2 * i];
99 | p2[i1 + 1] = origin[2 * i + 1];
100 | pc[i1 / 2] = 1.0;
101 | phs_idx(nx / 2 - shifts[2 * i], ny / 2 - shifts[2 * i + 1], nx, i1);
102 | p1[i1] = origin[2 * i];
103 | p1[i1 + 1] = -origin[2 * i + 1];
104 | p2[i1] = origin[2 * i];
105 | p2[i1 + 1] = -origin[2 * i + 1];
106 | pc[i1 / 2] = 1.0;
107 | }
108 |
109 | // reset phase values to decent values
110 | for (i = 0; i < N; i++) {
111 | p1[2 * i] *= mask[i];
112 | p1[2 * i + 1] *= mask[i];
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/putslaveinfo.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #include "speckle_admin.h"
57 |
58 |
59 | void putslaveinf(slaveinfo * out, maininfo * in, int i)
60 | {
61 | /* set position of subfield in whole image */
62 | (*out).position = i;
63 | /* set subfield size */
64 | (*out).sfsizex = (*in).subfields.ssizex;
65 | (*out).sfsizey = (*in).subfields.ssizey;
66 | /* set # of frames */
67 | (*out).nrofframes = (*in).nrofframes;
68 |
69 | /* set reconstr. limit (don't go too far) */
70 | (*out).rad_x = (*in).subfields.ssizex / 2 - 2;
71 | if ((*out).rad_x > (*in).subfields.ssizex / 2 - 2)
72 | (*out).rad_x = (int) (*in).subfields.ssizex / 2 - 2;
73 | (*out).rad_y = (*in).subfields.ssizey / 2 - 2;
74 | if ((*out).rad_y > (*in).subfields.ssizey / 2 - 2)
75 | (*out).rad_y = (int) (*in).subfields.ssizey / 2 - 2;
76 |
77 | /* set maximum reconstruction settings */
78 | (*out).max_rad = (*in).tc.max_rad;
79 | // *** check if this is too far
80 | if ((*out).max_rad > (*out).rad_x)
81 | (*out).max_rad = (*out).rad_x;
82 | if ((*out).max_rad > (*out).rad_y)
83 | (*out).max_rad = (*out).rad_y;
84 |
85 | // ****************************
86 | (*out).l1 = (*in).tc.l1; // hardcode
87 | // *** check if this is too far
88 | if ((*out).l1 > (*out).rad_x)
89 | (*out).l1 = (*out).rad_x;
90 | if ((*out).l1 > (*out).rad_y)
91 | (*out).l1 = (*out).rad_y;
92 |
93 | // ****************************
94 | (*out).l2 = (*in).tc.l2;
95 | // *** check if this is too far
96 | if ((*out).l2 > (*out).rad_x)
97 | (*out).l2 = (*out).rad_x;
98 | if ((*out).l2 > (*out).rad_y)
99 | (*out).l2 = (*out).rad_y;
100 |
101 | // ****************************
102 | (*out).max_it = (*in).tc.max_iterations;
103 | (*out).snr = (*in).tc.snr;
104 | (*out).eps = (*in).tc.eps;
105 | /* set phase reconstruction apodisation */
106 | (*out).limApod = (*in).tc.limApod;
107 | }
108 |
--------------------------------------------------------------------------------
/radial.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 |
62 | float *rad2im(vect * in, int nx, int ny, int *ori, float aspect)
63 | {
64 | /* static helper variables */
65 | static int INIT = 0;
66 | static float *matrix = NULL;
67 | /* helper variables */
68 | vect *w_vect;
69 | int szh[2];
70 | long int i, j;
71 |
72 | /* output variable */
73 | float *out;
74 |
75 | /* memory allocation of static helper matrix */
76 | if (INIT / nx != ny) {
77 | if (matrix != NULL) {
78 | free(matrix);
79 | matrix = NULL;
80 | }
81 | matrix = (float *) malloc(nx * ny * sizeof(float));
82 | INIT = nx * ny;
83 | }
84 | /* memory allocation for output variable */
85 | out = (float *) calloc(nx * ny, sizeof(float));
86 |
87 | if (ori == NULL) {
88 | szh[0] = nx / 2;
89 | szh[1] = ny / 2;
90 | } else {
91 | szh[0] = ori[0];
92 | szh[1] = ori[1];
93 | }
94 |
95 | /* initialise helper matrix */
96 | for (j = -szh[1]; j < szh[1]; j++) {
97 | for (i = -szh[0]; i < szh[0]; i++) {
98 | matrix[(j + szh[1]) * nx + (i + szh[0])]
99 | =
100 | (float) ((int)
101 | (sqrt(i * i + (j * aspect) * (j * aspect)) +
102 | 0.5));
103 | }
104 | }
105 |
106 | for (i = 0; i < (in->size); i++) {
107 | w_vect = w_func(matrix, "==", (float) i, nx * ny);
108 | for (j = 0; j < (w_vect->size); j++) {
109 | out[(int) (w_vect->res_vec[j])] += in->res_vec[i];
110 | }
111 | if (w_vect->size != -1) {
112 | free_vect(&w_vect);
113 | }
114 | }
115 |
116 | return (out);
117 | }
118 |
--------------------------------------------------------------------------------
/reconstruct.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #include "speckle_admin.h"
57 |
58 |
59 | void reconstruct(float *srec, maininfo * in, float *out)
60 | {
61 | long i, j;
62 | long nsf, l;
63 | long sfN, N;
64 | long p, q;
65 | float *weights;
66 | float *win;
67 |
68 | N = (*in).xsize * (*in).ysize;
69 | sfN = (*in).subfields.ssizex * (*in).subfields.ssizey;
70 | nsf = (*in).subfields.nfrx * (*in).subfields.nfry;
71 | win = malloc(sfN * sizeof(float));
72 | weights = calloc(N, sizeof(float));
73 |
74 | assmask(win, (*in).subfields.ssizex, (*in).subfields.ssizey, (*in).tc.limApod);
75 |
76 | for (l = 0; l < nsf; l++) { // total number of subfields
77 | for (j = 0; j < (*in).subfields.ssizey; j++) { // number of pixels in subfield
78 | for (i = 0; i < (*in).subfields.ssizex; i++) {
79 | sf_idx(i, j,
80 | (int) (l % (*in).subfields.nfrx),
81 | (int) (l / (*in).subfields.nfrx), 0,
82 | (int) (*in).subfields.ssizex / 2,
83 | (int) (*in).subfields.ssizey / 2,
84 | (*in).subfields.offx, (*in).subfields.offy,
85 | (*in).xsize, (*in).ysize, q);
86 | idx(i, j, (*in).subfields.ssizex, p); // jump to pixel-position in subfield image
87 | out[q] += srec[p + l * sfN] * win[p]; // add result
88 | weights[q] += win[p];
89 | }
90 | }
91 | }
92 |
93 |
94 | // divide through by weight and set border pixels to zero
95 | for (i = 0; i < N; i++) {
96 | if( weights[i] != 0 ){
97 | out[i] /= weights[i];
98 | }
99 | else{
100 | out[i] = 0.0;
101 | }
102 | }
103 |
104 | free(weights);
105 | free(win);
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/rpr.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #include "speckle_core.h"
60 |
61 |
62 | /****************************************************************************
63 | ***************TRIPLE CORRELATION PART FOR PHASE RECONSTRUCTION**************
64 | ****************************************************************************/
65 | void rpr(float *p1, float *p2, float *pc, long *index, long bs_cnt,
66 | float *bsc, float *wc, slaveinfo l)
67 | {
68 | static long INIT = 0; // Initialisation flag
69 | static long *d = NULL; // quarter circles
70 |
71 | float *bs, *w; // redundant bispectrum/weights
72 | long i, j, u, v, r, rs; // loop variables
73 | long ir; // loop variables
74 | long i1, i2, id1, id2; // index variable
75 | long l1, l2, l3, l4; // limits
76 | long l2s; // squared limits
77 | long nx, ny, nxh, nyh; // (half of) field size
78 | float t, t1, t2; // real temporary variables
79 | float ct[2], ct1[2], ct2[2], ct3[2]; // complex temporary variables
80 |
81 | nx = l.sfsizex;
82 | ny = l.sfsizey;
83 | nxh = nx / 2;
84 | nyh = ny / 2;
85 | l2s = l.l2 * l.l2;
86 |
87 | // create bi-spectrum/weights in redundant matrix
88 | bs_red(index, bs_cnt, l, bsc, wc, &bs, &w);
89 |
90 | // could use improvements later regarding matrix allocation
91 | if (INIT != l.max_rad) {
92 | if (d != NULL)
93 | free(d);
94 | d = (long *) calloc((l.max_rad + 1) * (l.max_rad + 1), sizeof(long));
95 |
96 | for (r = 0; r <= l.max_rad; r++) {
97 | rs = r * r;
98 | // set (quarter-)circle
99 | for (i = 0; i <= r; i++) {
100 | d[r * l.max_rad + i] = (long) sqrt((float) (rs - i * i));
101 | }
102 | }
103 |
104 | INIT = l.max_rad;
105 | }
106 | // begin reconstruction
107 | // - move outwards with frequency
108 | for (ir = 1; ir <= l.max_rad; ir++) {
109 | // - move in half-circles
110 | for (i = 0; i <= ir; i++) {
111 | idx(i, ir - 1, l.max_rad, id1);
112 | l1 = (i == ir) ? 0 : d[id1] + 1;
113 | idx(i, ir, l.max_rad, id2);
114 |
115 | for (j = l1; j <= d[id2]; j++) {
116 | // if this condition is true then skip
117 | if (((i == 0) && (j <= 1)) || ((j == 0) && (i <= 1)))
118 | continue;
119 | // - find all frequency values within the above half-circle
120 | l2 = ir - i - 1;
121 | for (u = -l2; u <= -i - 1; u++) {
122 | idx(abs(u), ir - 1, l.max_rad, id1);
123 | idx(abs(u - i), ir - 1, l.max_rad, id2);
124 | l3 = (-d[id1] > j - d[id2]) ? -d[id1] : j - d[id2];
125 | l4 = (d[id1] < j + d[id2]) ? d[id1] : j + d[id2];
126 | for (v = l3; v <= l4; v++) {
127 | if ((u * u + v * v) <= l2s) {
128 | mbs_idx(-u, -v, i, j, l.l1, l.l2, l.max_rad, i1);
129 | i2 = i1 / 2;
130 | t1 = w[i2];
131 | if (t1 < l.snr) {
132 | ct1[0] = 0.0;
133 | ct1[1] = 0.0;
134 | } else {
135 | ct1[0] = bs[i1];
136 | ct1[1] = -bs[i1 + 1];
137 | }
138 | mbs_idx(-u, v, i, -j, l.l1, l.l2, l.max_rad, i1);
139 | i2 = i1 / 2;
140 | t2 = w[i2];
141 | if (t2 < l.snr) {
142 | ct2[0] = 0.0;
143 | ct2[1] = 0.0;
144 | } else {
145 | ct2[0] = bs[i1];
146 | ct2[1] = -bs[i1 + 1];
147 | }
148 | } else if (((i - u) * (i - u) + (j - v) * (j - v)) <= l2s) {
149 | mbs_idx(i - u, j - v, u, v, l.l1, l.l2, l.max_rad, i1);
150 | i2 = i1 / 2;
151 | t1 = w[i2];
152 | if (t1 < l.snr) {
153 | ct1[0] = 0.0;
154 | ct1[1] = 0.0;
155 | } else {
156 | ct1[0] = bs[i1];
157 | ct1[1] = bs[i1 + 1];
158 | }
159 | mbs_idx(i - u, -j + v, u, -v, l.l1, l.l2, l.max_rad, i1);
160 | i2 = i1 / 2;
161 | t2 = w[i2];
162 | if (t2 < l.snr) {
163 | ct2[0] = 0.0;
164 | ct2[1] = 0.0;
165 | } else {
166 | ct2[0] = bs[i1];
167 | ct2[1] = bs[i1 + 1];
168 | }
169 | } else
170 | continue;
171 |
172 | phs_idx(nxh - u, nyh + v, nx, i1);
173 | phs_idx(nxh - i + u, nyh + j - v, nx, i2);
174 | cmul(&p1[i1], &p1[i2], ct3);
175 | cdiv(ct1, ct3, ct);
176 | conj(ct, ct);
177 | phs_idx(nxh - i, nyh + j, nx, i1);
178 | t = pow(t1, l.eps);
179 | p1[i1] += t * ct[0];
180 | p1[i1 + 1] += t * ct[1];
181 | pc[i1 / 2] += t;
182 | p2[i1] += t * ct[0];
183 | p2[i1 + 1] += t * ct[1];
184 |
185 | phs_idx(nxh - u, nyh - v, nx, i1);
186 | phs_idx(nxh - i + u, nyh - j + v, nx, i2);
187 | cmul(&p1[i1], &p1[i2], ct3);
188 | cdiv(ct2, ct3, ct);
189 | conj(ct, ct);
190 | phs_idx(nxh - i, nyh - j, nx, i1);
191 | t = pow(t2, l.eps);
192 | p1[i1] += t * ct[0];
193 | p1[i1 + 1] += t * ct[1];
194 | pc[i1 / 2] += t;
195 | p2[i1] += t * ct[0];
196 | p2[i1 + 1] += t * ct[1];
197 | }
198 | }
199 | l2 = (i < ir - i - 1) ? i : ir - i - 1;
200 | for (u = -l2; u <= -1; u++) {
201 | idx(abs(u), ir - 1, l.max_rad, id1);
202 | idx(abs(u - i), ir - 1, l.max_rad, id2);
203 | l3 = (-d[id1] > j - d[id2]) ? -d[id1] : j - d[id2];
204 | l4 = (d[id1] < j + d[id2]) ? d[id1] : j + d[id2];
205 | if (-u == i)
206 | l4 = (l4 < j - 1) ? l4 : j - 1;
207 | for (v = l3; v <= l4; v++) {
208 | if ((u * u + v * v) <= l2s) {
209 | mbs_idx(-u, -v, i, j, l.l1, l.l2, l.max_rad,
210 | i1);
211 | i2 = i1 / 2;
212 | t1 = w[i2];
213 | if (t1 < l.snr) {
214 | ct1[0] = 0.0;
215 | ct1[1] = 0.0;
216 | } else {
217 | ct1[0] = bs[i1];
218 | ct1[1] = -bs[i1 + 1];
219 | }
220 | mbs_idx(-u, v, i, -j, l.l1, l.l2, l.max_rad,
221 | i1);
222 | i2 = i1 / 2;
223 | t2 = w[i2];
224 | if (t2 < l.snr) {
225 | ct2[0] = 0.0;
226 | ct2[1] = 0.0;
227 | } else {
228 | ct2[0] = bs[i1];
229 | ct2[1] = -bs[i1 + 1];
230 | }
231 | }
232 | else if (((i - u) * (i - u) + (j - v) * (j - v)) <= l2s) {
233 | mbs_idx(i - u, j - v, u, v, l.l1, l.l2,
234 | l.max_rad, i1);
235 | i2 = i1 / 2;
236 | t1 = w[i2];
237 | if (t1 < l.snr) {
238 | ct1[0] = 0.0;
239 | ct1[1] = 0.0;
240 | } else {
241 | ct1[0] = bs[i1];
242 | ct1[1] = bs[i1 + 1];
243 | }
244 | mbs_idx(i - u, -j + v, u, -v, l.l1, l.l2,
245 | l.max_rad, i1);
246 | i2 = i1 / 2;
247 | t2 = w[i2];
248 | if (t2 < l.snr) {
249 | ct2[0] = 0.0;
250 | ct2[1] = 0.0;
251 | } else {
252 | ct2[0] = bs[i1];
253 | ct2[1] = bs[i1 + 1];
254 | }
255 | }
256 | else
257 | continue;
258 |
259 | phs_idx(nxh - u, nyh + v, nx, i1);
260 | phs_idx(nxh - i + u, nyh + j - v, nx, i2);
261 | cmul(&p1[i1], &p1[i2], ct3);
262 | cdiv(ct1, ct3, ct);
263 | conj(ct, ct);
264 | phs_idx(nxh - i, nyh + j, nx, i1);
265 | t = pow(t1, l.eps);
266 | p1[i1] += t * ct[0];
267 | p1[i1 + 1] += t * ct[1];
268 | pc[i1 / 2] += t;
269 | p2[i1] += t * ct[0];
270 | p2[i1 + 1] += t * ct[1];
271 |
272 | phs_idx(nxh - u, nyh - v, nx, i1);
273 | phs_idx(nxh - i + u, nyh - j + v, nx, i2);
274 | cmul(&p1[i1], &p1[i2], ct3);
275 | cdiv(ct2, ct3, ct);
276 | conj(ct, ct);
277 | phs_idx(nxh - i, nyh - j, nx, i1);
278 | t = pow(t2, l.eps);
279 | p1[i1] += t * ct[0];
280 | p1[i1 + 1] += t * ct[1];
281 | pc[i1 / 2] += t;
282 | p2[i1] += t * ct[0];
283 | p2[i1 + 1] += t * ct[1];
284 | }
285 | }
286 |
287 | l2 = (l.l1 <
288 | l.l2) ? ((l.l1 < (long) i / 2) ? l.l1 : (long) i / 2)
289 | : ((l.l2 < (long) i / 2) ? l.l2 : (long) i / 2);
290 | for (u = 0; u <= l2; u++) {
291 | idx(abs(u), ir, l.max_rad, id1);
292 | idx(abs(u - i), ir, l.max_rad, id2);
293 |
294 | l3 = (-l.l1 > -d[id1]) ?
295 | ((-l.l1 > j - d[id2]) ? -l.l1 : j - d[id2])
296 | : ((-d[id1] > j - d[id2]) ? -d[id1] : j - d[id2]);
297 |
298 | l4 = (l.l1 < d[id1]) ?
299 | ((l.l1 < j + d[id2]) ? l.l1 : j + d[id2])
300 | : ((d[id1] < j + d[id2]) ? d[id1] : j + d[id2]);
301 |
302 | if (u == 0) {
303 | l3 = 1;
304 | l4 = (l4 < 2 * j - 1) ? l4 : 2 * j - 1;
305 | }
306 |
307 | if (u == (i - u)) {
308 | l4 = (l4 < (long) j / 2) ? l4 : (long) j / 2;
309 | }
310 |
311 | for (v = l3; v <= l4; v++) {
312 | if ((u * u + v * v) > l2s)
313 | continue;
314 | mbs_idx(u, v, i - u, j - v, l.l1, l.l2, l.max_rad,
315 | i1);
316 | i2 = i1 / 2;
317 | t1 = w[i2];
318 | if (t1 < l.snr) {
319 | ct1[0] = 0.0;
320 | ct1[1] = 0.0;
321 | } else {
322 | ct1[0] = bs[i1];
323 | ct1[1] = bs[i1 + 1];
324 | }
325 | mbs_idx(u, -v, i - u, -j + v, l.l1, l.l2,
326 | l.max_rad, i1);
327 | i2 = i1 / 2;
328 | t2 = w[i2];
329 | if (t2 < l.snr) {
330 | ct2[0] = 0.0;
331 | ct2[1] = 0.0;
332 | } else {
333 | ct2[0] = bs[i1];
334 | ct2[1] = bs[i1 + 1];
335 | }
336 | phs_idx(nxh - u, nyh + v, nx, i1);
337 | phs_idx(nxh - i + u, nyh + j - v, nx, i2);
338 | cmul(&p1[i1], &p1[i2], ct3);
339 | cdiv(ct1, ct3, ct);
340 | conj(ct, ct);
341 | phs_idx(nxh - i, nyh + j, nx, i1);
342 | t = pow(t1, l.eps);
343 | p1[i1] += t * ct[0];
344 | p1[i1 + 1] += t * ct[1];
345 | pc[i1 / 2] += t;
346 | p2[i1] += t * ct[0];
347 | p2[i1 + 1] += t * ct[1];
348 |
349 | phs_idx(nxh - u, nyh - v, nx, i1);
350 | phs_idx(nxh - i + u, nyh - j + v, nx, i2);
351 | cmul(&p1[i1], &p1[i2], ct3);
352 | cdiv(ct2, ct3, ct);
353 | conj(ct, ct);
354 | phs_idx(nxh - i, nyh - j, nx, i1);
355 | t = pow(t2, l.eps);
356 | p1[i1] += t * ct[0];
357 | p1[i1 + 1] += t * ct[1];
358 | pc[i1 / 2] += t;
359 | p2[i1] += t * ct[0];
360 | p2[i1 + 1] += t * ct[1];
361 | }
362 | }
363 |
364 | phs_idx(nxh - i, nyh - j, nx, i1);
365 | t1 = cmod(&p1[i1]);
366 |
367 | if (t1 != 0) {
368 | p1[i1] /= t1;
369 | p1[i1 + 1] /= t1;
370 | } else {
371 | p1[i1] = 1.0;
372 | p1[i1 + 1] = 0.0;
373 | }
374 |
375 | phs_idx(nxh + i, nyh + j, nx, i2);
376 | p1[i2] = p1[i1];
377 | p1[i2 + 1] = -p1[i1 + 1];
378 | pc[i2 / 2] = pc[i1 / 2];
379 | p2[i2] = p2[i1];
380 | p2[i2 + 1] = -p2[i1 + 1];
381 |
382 | phs_idx(nxh - i, nyh + j, nx, i1);
383 | t1 = cmod(&p1[i1]);
384 |
385 | if (t1 != 0) {
386 | p1[i1] /= t1;
387 | p1[i1 + 1] /= t1;
388 | } else {
389 | p1[i1] = 1.0;
390 | p1[i1 + 1] = 0.0;
391 | }
392 |
393 | phs_idx(nxh + i, nyh - j, nx, i2);
394 | p1[i2] = p1[i1];
395 | p1[i2 + 1] = -p1[i1 + 1];
396 | pc[i2 / 2] = pc[i1 / 2];
397 | p2[i2] = p2[i1];
398 | p2[i2 + 1] = -p2[i1 + 1];
399 | }
400 | }
401 | }
402 |
403 | for (i = 0; i < nx * ny; i++) {
404 | t1 = cmod(&p2[2 * i]);
405 | pc[i] = ((t1 != 0) && (pc[i] != 0.0)) ? t1 / pc[i] : 0.0;
406 | }
407 |
408 | // reset temp matrix
409 | memset(p2, 0, 2 * nx * ny * sizeof(float));
410 | // free mem
411 | free(bs);
412 | free(w);
413 | }
414 |
--------------------------------------------------------------------------------
/speckle_admin.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #ifndef KISIP_SPECKLE_ADMIN_H
57 | #define KISIP_SPECKLE_ADMIN_H
58 |
59 | #include
60 | #include
61 | #include
62 |
63 | #include "inlines.h"
64 | #include "speckle_math.h"
65 |
66 | /* max string length for reading data from file */
67 | #define ZEILENLAENGE 128
68 | #define MAXLINES 20
69 | #define LL 1024
70 | #define BS 100
71 |
72 | /* Flags for calculations */
73 | #define GO 1
74 | #define NOGO 0
75 |
76 | typedef struct maininfo {
77 | /* names of image files */
78 | char **imagefiles;
79 | /* name of result file */
80 | char savefiles[ZEILENLAENGE];
81 |
82 | int headeroffset;
83 |
84 | /* data properties */
85 | int xsize, ysize; /* x/y size in px of data */
86 | int nrofframes; /* number of frames in burst */
87 |
88 | /* properties for the reconstruction */
89 | struct {
90 | int ssizex, ssizey; /* subfield size in px in x/y */
91 | int nsizex, nsizey; /* overall size reconstr. x/y */
92 | int nfrx, nfry; /* nr of subframes in x/y */
93 | int offx, offy; /* offset border in px in x/y */
94 | } subfields;
95 |
96 | /* parameters for triple correlation */
97 | struct {
98 | float sfs; /* sfs in arcsec */
99 | float lim1; /* max length of u in x-dir in %age of diff. lim. */
100 | float lim2; /* max length of u, v, u+v in %age of diff. lim. */
101 | int max_iterations; /* max number of iterations */
102 | float snr; /* SNR threshold for rec */
103 | float eps; /* weighting factor for rec */
104 | float limApod; /* Percantage of reconstr. apodisation */
105 | int max_rad;
106 | int l1, l2;
107 | } tc;
108 | } maininfo;
109 |
110 | /* IF YOU ALTER THIS, YOU MUST ADJUST MPI_SETSLAVETYPE() ACCORDINGLY OR ELSE *
111 | * YOU WILL EXPERIENCE HORRIBLY CONFOUNDING ERRORS! */
112 | typedef struct slaveinfo {
113 | int position; /* subfield position */
114 | int sfsizex, sfsizey; /* subfield size in x/y */
115 | int nrofframes; /* number of frames in burst */
116 | int max_rad; /* phase int/it radius in px */
117 | int max_it; /* max number of iterations */
118 | int l1, l2; /* Limits for bispectrum */
119 | float rad_x, rad_y; /* DiffLim Radius in x/y */
120 | float snr, eps; /* params for triple corr. */
121 | float limApod; /* %age of apod.win for phrec */
122 | } slaveinfo;
123 |
124 | int getinfo(maininfo * result, int argc, char** argv);
125 | void calc_subfields(int szx, int szy, float sfs, maininfo * result);
126 | void subfielding(float *in, int count, maininfo * info, float *out);
127 | void putslaveinf(slaveinfo * out, maininfo * in, int i);
128 | void reconstruct(float *srec, maininfo * in, float *out);
129 |
130 | #endif /* KISIP_SPECKLE_ADMIN_H */
131 |
--------------------------------------------------------------------------------
/speckle_core.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut f??r Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** core speckle routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #ifndef KISIP_SPECKLE_CORE_H
60 | #define KISIP_SPECKLE_CORE_H
61 |
62 | #include
63 | #include
64 | #include
65 | #include "inlines.h"
66 | #include "speckle_math.h"
67 | #include "speckle_admin.h"
68 |
69 | #ifndef MEMCHUNK
70 | #define MEMCHUNK 10000
71 | #endif
72 |
73 | float chkphase(slaveinfo l, float *phs);
74 |
75 | void init_shift(int nxh, int nyh, int len, int *maxk, int **shifts);
76 |
77 | void phs_init(float *p1, float *p2, float *pc, slaveinfo l, int maxk,
78 | int *shifts, float *origin);
79 | long *bs_init(long *bs_cnt, slaveinfo l);
80 | float *bs_ave(float *images, float *win, slaveinfo l, long *index,
81 | long bs_cnt, float *bsc, float *wc, float *amp, int maxk,
82 | int *shifts);
83 | void bs_snrt(float *wc, long bs_cnt, slaveinfo * l);
84 | void bs_red(long *index, long bs_cnt, slaveinfo l, float *bsc, float *wc,
85 | float **bs, float **w);
86 | void iwlspr(float *p1, float *p2, float *pc, float *bsc, float *wc,
87 | long *index, long bs_cnt, slaveinfo l, int maxk);
88 | void rpr(float *p1, float *p2, float *pc, long *index, long bs_cnt,
89 | float *bsc, float *wc, slaveinfo l);
90 |
91 | void assemble(int nx, int ny, float *amp, float *phs, float *rec, maininfo info);
92 |
93 | #endif /* KISIP_SPECKLE_CORE */
94 |
--------------------------------------------------------------------------------
/speckle_math.h:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut fuer Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fftw3 library:
44 | ** http://www.fftw.org
45 | **
46 | ** Library for fast fourier transform
47 | **
48 | ** =====================================================================
49 | **
50 | ** Author: F. Woeger
51 | ** Kiepenheuer-Institut fuer Sonnenphysik
52 | ** Freiburg, Germany
53 | **
54 | ** Written 17. 06. 2003
55 | **
56 | ** =====================================================================
57 | */
58 |
59 | #ifndef KISIP_SPECKLE_MATH_H
60 | #define KISIP_SPECKLE_MATH_H
61 |
62 | #include
63 | #include
64 | #include
65 | #include
66 | #include
67 | #include
68 | #include
69 | #include
70 | #include
71 | #include "inlines.h"
72 |
73 | typedef struct vect {
74 | long size;
75 | float *res_vec;
76 | } vect;
77 |
78 | void free_vect(vect ** v);
79 | void ctracker(float *ref, float *img, int nsx, int nsy, int nfr, float *out);
80 | void surfit(float *in, int nx, int ny, int deg, float *out);
81 | void init_matrix(int nx, int ny, int deg, gsl_matrix ** ut, gsl_matrix ** kk);
82 | vect *w_func(float *in, char *expr, float comp, int size);
83 | void mean(float *burst, int nx, int ny, int nfr, float *out);
84 | void stats(float *in, long N, float thres, double *out1, double *out2);
85 | float *rad2im(vect * in, int nx, int ny, int *ori, float aspect);
86 | void hanming(float *res, int d1, int d2, float alpha);
87 | void frachamming(float *res, int nx, int ny, float frac, int maxk, int *sh);
88 | float *ellmask(int nx, int ny, int *ori, int len_x, int len_y);
89 | void assmask(float *res, int nx, int ny, float frac);
90 |
91 | #endif /* KISIP_SPECKLE_MATH_H */
92 |
--------------------------------------------------------------------------------
/stats.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | void mean(float *in, int nx, int ny, int nfr, float *out)
62 | {
63 | // Declare helper variables
64 | long i, l;
65 | long N = nx * ny;
66 | // set resultant matrix to zero!
67 | memset(out, 0.0, N * sizeof(float));
68 |
69 | // calculate the mean image
70 | for (i = 0; i < N; i++) {
71 | for (l = 0; l < nfr; l++) {
72 | out[i] += in[i + l * N];
73 | }
74 | out[i] /= (float) nfr;
75 | }
76 | }
77 |
78 |
79 | void stats(float *in, long N, float thres, double *out1, double *out2)
80 | {
81 | /* Declare helper variable */
82 | long i, t, c = 0;
83 |
84 | if (out2 != NULL) {
85 | *out1 = 0;
86 | *out2 = 0;
87 | for (i = 0; i < N; i++) {
88 | *out1 += in[i];
89 | *out2 += in[i] * in[i];
90 | }
91 | /* calculate the mean value of image */
92 | *out1 /= N;
93 | /* calculate the variance of image */
94 | *out2 = *out2 / N - (*out1) * (*out1);
95 | } else {
96 | *out1 = 0;
97 | for (i = 0; i < N; i++) {
98 | *out1 += in[i];
99 | }
100 | /* calculate the mean value of image */
101 | *out1 /= N;
102 | }
103 | /*
104 | * if thres greater zero then compute mean only from pixels that are
105 | * greater than thres percent of overall mean
106 | */
107 | if (thres > 0) {
108 | t = thres * (*out1);
109 | *out1 = 0;
110 | for (i = 0; i < N; i++) {
111 | if (in[i] > t) {
112 | *out1 += in[i];
113 | c++;
114 | }
115 | }
116 | *out1 /= c;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/subfielding.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** speckle administration routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses: fileops routines
44 | **
45 | ** =====================================================================
46 | **
47 | ** Author: F. Woeger
48 | ** Kiepenheuer-Institut fuer Sonnenphysik
49 | ** Freiburg, Germany
50 | **
51 | ** Written 13. 10. 2003
52 | **
53 | ** =====================================================================
54 | */
55 |
56 | #include "speckle_admin.h"
57 |
58 |
59 | void subfielding(float *in, int count, maininfo * info, float *out)
60 | {
61 | int nsx, nsy; /* Subfield size in x/y */
62 | int nfrx; /* No. of subfields in x/y */
63 | int ox, oy; /* offsets in x/y */
64 | int Nx, Ny; /* Source image size in x/y */
65 | int frames; /* Nr. of frames in burst */
66 | int i, j; /* pixel index */
67 | int f; /* frame counter index */
68 | int p; /* helper index */
69 |
70 | nsx = (*info).subfields.ssizex;
71 | nsy = (*info).subfields.ssizey;
72 | nfrx = (*info).subfields.nfrx;
73 | ox = (*info).subfields.offx;
74 | oy = (*info).subfields.offy;
75 | Nx = (*info).xsize;
76 | Ny = (*info).ysize;
77 | frames = (*info).nrofframes;
78 |
79 | /* raw cutting */
80 | for (f = 0; f < frames; f++) {
81 | for (j = 0; j < nsy; j++) {
82 | for (i = 0; i < nsx; i++) {
83 | sf_idx(i, j, (int) count % nfrx, (int) count / nfrx, f,
84 | (int) nsx / 2, (int) nsy / 2, ox, oy, Nx, Ny, p);
85 | out[j * nsx + i + f * nsx * nsy] = in[p]; // p is new pixel position
86 | }
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/surfit.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | void surfit(float *in, int nx, int ny, int deg, float *out)
62 | {
63 | // static variables
64 | static long n = 0;
65 | static int nrcoeffs = 0;
66 | static gsl_vector *a, *b, *c;
67 |
68 | // helper
69 | long i;
70 | // calculation matrices
71 | gsl_matrix *ut;
72 | gsl_matrix *kk;
73 |
74 | if (n == 0) {
75 | // set variables
76 | n = nx * ny;
77 | nrcoeffs = (deg + 1) * (deg + 2) / 2;
78 | // coefficient vector
79 | a = gsl_vector_alloc(n);
80 | b = gsl_vector_alloc(n);
81 | c = gsl_vector_alloc(nrcoeffs);
82 | }
83 |
84 | if ((n != 0)
85 | && ((n / nx != ny) || (nrcoeffs != (deg + 1) * (deg + 2) / 2))) {
86 | // clear memory
87 | gsl_vector_free(a);
88 | gsl_vector_free(b);
89 | gsl_vector_free(c);
90 | // set variables
91 | n = nx * ny;
92 | nrcoeffs = (deg + 1) * (deg + 2) / 2;
93 | // coefficient vector
94 | a = gsl_vector_alloc(n);
95 | b = gsl_vector_alloc(n);
96 | c = gsl_vector_alloc(nrcoeffs);
97 | }
98 | // assign input
99 | for (i = 0; i < n; i++)
100 | gsl_vector_set(a, i, (double) in[i]);
101 |
102 | // Initialise matrix
103 | init_matrix(nx, ny, deg, &ut, &kk);
104 |
105 | // Get the fitted coefficients
106 | gsl_blas_dgemv(CblasNoTrans, 1.0, kk, a, 0.0, c);
107 | // Create fit of surface
108 | gsl_blas_dgemv(CblasTrans, 1.0, ut, c, 0.0, b);
109 |
110 | // assign output
111 | for (i = 0; i < n; i++)
112 | out[i] = (float) gsl_vector_get(b, i);
113 | }
114 |
--------------------------------------------------------------------------------
/w_func.c:
--------------------------------------------------------------------------------
1 | /* $Id$
2 | *
3 | * (C) 2003-2007, Friedrich Woeger ,
4 | * Kiepenheuer-Institut für Sonnenphysik, Freiburg (Breisgau), Germany
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are
9 | * met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | * * Neither the name of the Kiepenheuer-Institut nor the
18 | * names of its contributors may be used to endorse or promote
19 | * products derived from this software without specific prior
20 | * written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 | * POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 |
37 | /* =====================================================================
38 | **
39 | ** Supplementary speckle math routines
40 | **
41 | ** =====================================================================
42 | **
43 | ** uses fftw3 library (http://www.fftw.org)
44 | ** Library for fast fourier transform
45 | **
46 | ** =====================================================================
47 | **
48 | ** Author: F. Woeger
49 | ** Kiepenheuer-Institut fuer Sonnenphysik
50 | ** Freiburg, Germany
51 | **
52 | ** Written 17. 06. 2003
53 | **
54 | ** =====================================================================
55 | */
56 |
57 |
58 | #include "speckle_math.h"
59 |
60 |
61 | vect *w_func(float *in, char *expr, float comp, int size)
62 | {
63 | /* resultant vector */
64 | vect *out;
65 |
66 | /* helper variables */
67 | int i, count = 0;
68 |
69 | /*
70 | * Allocate memory for resultant vector
71 | */
72 | out = (vect *) malloc(sizeof(vect));
73 |
74 | /*
75 | * Allocate memory for array vector which has indices
76 | * of numbers for which the condition is fulfilled
77 | */
78 | out->res_vec = (float *) malloc(size * sizeof(float));
79 |
80 | /* Parse through possible conditions */
81 | if (!strcmp(expr, "<")) {
82 | for (i = 0; i < size; i++) {
83 | if (in[i] < comp)
84 | out->res_vec[count++] = i;
85 | }
86 | }
87 |
88 | if (!strcmp(expr, "<=") || !strcmp(expr, "=<")) {
89 | for (i = 0; i < size; i++) {
90 | if (in[i] <= comp)
91 | out->res_vec[count++] = i;
92 | }
93 | }
94 |
95 | if (!strcmp(expr, "==")) {
96 | for (i = 0; i < size; i++) {
97 | if (in[i] == comp)
98 | out->res_vec[count++] = i;
99 | }
100 | }
101 |
102 | if (!strcmp(expr, ">=") || !strcmp(expr, "=>")) {
103 | for (i = 0; i < size; i++) {
104 | if (in[i] >= comp)
105 | out->res_vec[count++] = i;
106 | }
107 | }
108 |
109 | if (!strcmp(expr, ">")) {
110 | for (i = 0; i < size; i++) {
111 | if (in[i] > comp)
112 | out->res_vec[count++] = i;
113 | }
114 | }
115 |
116 | if (!strcmp(expr, "!=")) {
117 | for (i = 0; i < size; i++) {
118 | if (in[i] != comp)
119 | out->res_vec[count++] = i;
120 | }
121 | }
122 |
123 | if (!strcmp(expr, "|<|")) {
124 | for (i = 0; i < size; i++) {
125 | if (fabs(in[i]) < comp)
126 | out->res_vec[count++] = i;
127 | }
128 | }
129 |
130 | if (!strcmp(expr, "|<=|") || !strcmp(expr, "|=<|")) {
131 | for (i = 0; i < size; i++) {
132 | if (fabs(in[i]) <= comp)
133 | out->res_vec[count++] = i;
134 | }
135 | }
136 |
137 | if (!strcmp(expr, "|==|")) {
138 | for (i = 0; i < size; i++) {
139 | if (fabs(in[i]) == comp)
140 | out->res_vec[count++] = i;
141 | }
142 | }
143 |
144 | if (!strcmp(expr, "|>=|") || !strcmp(expr, "|=>|")) {
145 | for (i = 0; i < size; i++) {
146 | if (fabs(in[i]) >= comp)
147 | out->res_vec[count++] = i;
148 | }
149 | }
150 |
151 | if (!strcmp(expr, "|>|")) {
152 | for (i = 0; i < size; i++) {
153 | if (fabs(in[i]) > comp)
154 | out->res_vec[count++] = i;
155 | }
156 | }
157 |
158 | if (!strcmp(expr, "|!=|")) {
159 | for (i = 0; i < size; i++) {
160 | if (fabs(in[i]) != comp)
161 | out->res_vec[count++] = i;
162 | }
163 | }
164 |
165 | if (count == 0) {
166 | out->size = -1;
167 | free(out->res_vec);
168 | out->res_vec = NULL;
169 | }
170 | else {
171 | out->size = count;
172 | out->res_vec =
173 | (float *) realloc(out->res_vec, count * sizeof(float));
174 | }
175 |
176 | return (out);
177 | }
178 |
--------------------------------------------------------------------------------