/usr/include/vigra/fftw3.hxx is in libvigraimpex-dev 1.10.0+dfsg-11ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 | /************************************************************************/
/* */
/* Copyright 1998-2004 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_FFTW3_HXX
#define VIGRA_FFTW3_HXX
#include <cmath>
#include <functional>
#include <complex>
#include "stdimage.hxx"
#include "copyimage.hxx"
#include "transformimage.hxx"
#include "combineimages.hxx"
#include "numerictraits.hxx"
#include "imagecontainer.hxx"
#include <fftw3.h>
namespace vigra {
typedef double fftw_real;
template <class T>
struct FFTWReal;
template <>
struct FFTWReal<fftw_complex>
{
typedef double type;
};
template <>
struct FFTWReal<fftwf_complex>
{
typedef float type;
};
template <>
struct FFTWReal<fftwl_complex>
{
typedef long double type;
};
template <class T>
struct FFTWReal2Complex;
template <>
struct FFTWReal2Complex<double>
{
typedef fftw_complex type;
typedef fftw_plan plan_type;
};
template <>
struct FFTWReal2Complex<float>
{
typedef fftwf_complex type;
typedef fftwf_plan plan_type;
};
template <>
struct FFTWReal2Complex<long double>
{
typedef fftwl_complex type;
typedef fftwl_plan plan_type;
};
/********************************************************/
/* */
/* FFTWComplex */
/* */
/********************************************************/
/** \brief Wrapper class for the FFTW complex types '<TT>fftw_complex</TT>'.
This class encapsulates the low-level complex number types provided by the
<a href="http://www.fftw.org/">FFTW Fast Fourier Transform</a> library (i.e.
'<TT>fftw_complex</TT>', '<TT>fftwf_complex</TT>', '<TT>fftwl_complex</TT>').
In particular, it provides constructors, member functions and
\ref FFTWComplexOperators "arithmetic operators" that make FFTW complex numbers
compatible with <tt>std::complex</tt>. In addition, the class defines
transformations to polar coordinates and \ref FFTWComplexAccessors "accessors".
FFTWComplex implements the concepts \ref AlgebraicField and
\ref DivisionAlgebra. The standard image types <tt>FFTWRealImage</tt>
and <tt>FFTWComplexImage</tt> are defined.
<b>See also:</b>
<ul>
<li> \ref FFTWComplexTraits
<li> \ref FFTWComplexOperators
<li> \ref FFTWComplexAccessors
</ul>
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWComplex
{
public:
/** The wrapped complex type
*/
typedef typename FFTWReal2Complex<Real>::type complex_type;
/** The complex' component type, as defined in '<TT>fftw3.h</TT>'
*/
typedef Real value_type;
/** reference type (result of operator[])
*/
typedef value_type & reference;
/** const reference type (result of operator[] const)
*/
typedef value_type const & const_reference;
/** iterator type (result of begin() )
*/
typedef value_type * iterator;
/** const iterator type (result of begin() const)
*/
typedef value_type const * const_iterator;
/** The norm type (result of magnitude())
*/
typedef value_type NormType;
/** The squared norm type (result of squaredMagnitde())
*/
typedef value_type SquaredNormType;
/** Construct from real and imaginary part.
Default: 0.
*/
FFTWComplex(value_type const & re = 0.0, value_type const & im = 0.0)
{
data_[0] = re;
data_[1] = im;
}
/** Copy constructor.
*/
FFTWComplex(FFTWComplex const & o)
{
data_[0] = o.data_[0];
data_[1] = o.data_[1];
}
/** Copy constructor.
*/
template <class U>
FFTWComplex(FFTWComplex<U> const & o)
{
data_[0] = (Real)o.real();
data_[1] = (Real)o.imag();
}
/** Construct from plain <TT>fftw_complex</TT>.
*/
FFTWComplex(fftw_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
}
/** Construct from plain <TT>fftwf_complex</TT>.
*/
FFTWComplex(fftwf_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
}
/** Construct from plain <TT>fftwl_complex</TT>.
*/
FFTWComplex(fftwl_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
}
/** Construct from std::complex.
*/
template <class T>
FFTWComplex(std::complex<T> const & o)
{
data_[0] = (Real)o.real();
data_[1] = (Real)o.imag();
}
/** Construct from TinyVector.
*/
template <class T>
FFTWComplex(TinyVector<T, 2> const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
}
/** Assignment.
*/
FFTWComplex& operator=(FFTWComplex const & o)
{
data_[0] = o.data_[0];
data_[1] = o.data_[1];
return *this;
}
/** Assignment.
*/
template <class U>
FFTWComplex& operator=(FFTWComplex<U> const & o)
{
data_[0] = (Real)o.real();
data_[1] = (Real)o.imag();
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(fftw_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(fftwf_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(fftwl_complex const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(double o)
{
data_[0] = (Real)o;
data_[1] = 0.0;
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(float o)
{
data_[0] = (Real)o;
data_[1] = 0.0;
return *this;
}
/** Assignment.
*/
FFTWComplex& operator=(long double o)
{
data_[0] = (Real)o;
data_[1] = 0.0;
return *this;
}
/** Assignment.
*/
template <class T>
FFTWComplex& operator=(TinyVector<T, 2> const & o)
{
data_[0] = (Real)o[0];
data_[1] = (Real)o[1];
return *this;
}
/** Assignment.
*/
template <class T>
FFTWComplex& operator=(std::complex<T> const & o)
{
data_[0] = (Real)o.real();
data_[1] = (Real)o.imag();
return *this;
}
reference re()
{ return data_[0]; }
const_reference re() const
{ return data_[0]; }
reference real()
{ return data_[0]; }
const_reference real() const
{ return data_[0]; }
reference im()
{ return data_[1]; }
const_reference im() const
{ return data_[1]; }
reference imag()
{ return data_[1]; }
const_reference imag() const
{ return data_[1]; }
/** Unary negation.
*/
FFTWComplex operator-() const
{ return FFTWComplex(-data_[0], -data_[1]); }
/** Squared magnitude x*conj(x)
*/
SquaredNormType squaredMagnitude() const
{ return data_[0]*data_[0]+data_[1]*data_[1]; }
/** Magnitude (length of radius vector).
*/
NormType magnitude() const
{ return VIGRA_CSTD::sqrt(squaredMagnitude()); }
/** Phase angle.
*/
value_type phase() const
{ return VIGRA_CSTD::atan2(data_[1], data_[0]); }
/** Access components as if number were a vector.
*/
reference operator[](int i)
{ return data_[i]; }
/** Read components as if number were a vector.
*/
const_reference operator[](int i) const
{ return data_[i]; }
/** Length of complex number (always 2).
*/
int size() const
{ return 2; }
iterator begin()
{ return data_; }
iterator end()
{ return data_ + 2; }
const_iterator begin() const
{ return data_; }
const_iterator end() const
{ return data_ + 2; }
private:
complex_type data_;
};
/********************************************************/
/* */
/* FFTWComplexTraits */
/* */
/********************************************************/
/** \page FFTWComplexTraits Numeric and Promote Traits of FFTWComplex
The numeric and promote traits for fftw_complex and FFTWComplex follow
the general specifications for \ref NumericPromotionTraits and
\ref AlgebraicField. They are explicitly specialized for the types
involved:
\code
template<>
struct NumericTraits<fftw_complex>
{
typedef fftw_complex Promote;
typedef fftw_complex RealPromote;
typedef fftw_complex ComplexPromote;
typedef fftw_real ValueType;
typedef VigraFalseType isIntegral;
typedef VigraFalseType isScalar;
typedef VigraFalseType isOrdered;
typedef VigraTrueType isComplex;
// etc.
};
template<class Real>
struct NumericTraits<FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Promote;
typedef FFTWComplex<Real> RealPromote;
typedef FFTWComplex<Real> ComplexPromote;
typedef Real ValueType;
typedef VigraFalseType isIntegral;
typedef VigraFalseType isScalar;
typedef VigraFalseType isOrdered;
typedef VigraTrueType isComplex;
// etc.
};
template<>
struct NormTraits<fftw_complex>
{
typedef fftw_complex Type;
typedef fftw_real SquaredNormType;
typedef fftw_real NormType;
};
template<class Real>
struct NormTraits<FFTWComplex>
{
typedef FFTWComplex Type;
typedef fftw_real SquaredNormType;
typedef fftw_real NormType;
};
template <>
struct PromoteTraits<fftw_complex, fftw_complex>
{
typedef fftw_complex Promote;
};
template <>
struct PromoteTraits<fftw_complex, double>
{
typedef fftw_complex Promote;
};
template <>
struct PromoteTraits<double, fftw_complex>
{
typedef fftw_complex Promote;
};
template <class Real>
struct PromoteTraits<FFTWComplex<Real>, FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Promote;
};
template <class Real>
struct PromoteTraits<FFTWComplex<Real>, double>
{
typedef FFTWComplex<Real> Promote;
};
template <class Real>
struct PromoteTraits<double, FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Promote;
};
\endcode
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template<>
struct NumericTraits<fftw_complex>
{
typedef fftw_complex Type;
typedef fftw_complex Promote;
typedef fftw_complex RealPromote;
typedef fftw_complex ComplexPromote;
typedef fftw_real ValueType;
typedef VigraFalseType isIntegral;
typedef VigraFalseType isScalar;
typedef NumericTraits<fftw_real>::isSigned isSigned;
typedef VigraFalseType isOrdered;
typedef VigraTrueType isComplex;
static FFTWComplex<> zero() { return FFTWComplex<>(0.0, 0.0); }
static FFTWComplex<> one() { return FFTWComplex<>(1.0, 0.0); }
static FFTWComplex<> nonZero() { return one(); }
static const Promote & toPromote(const Type & v) { return v; }
static const RealPromote & toRealPromote(const Type & v) { return v; }
static const Type & fromPromote(const Promote & v) { return v; }
static const Type & fromRealPromote(const RealPromote & v) { return v; }
};
template<class Real>
struct NumericTraits<FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Type;
typedef FFTWComplex<Real> Promote;
typedef FFTWComplex<Real> RealPromote;
typedef FFTWComplex<Real> ComplexPromote;
typedef typename Type::value_type ValueType;
typedef VigraFalseType isIntegral;
typedef VigraFalseType isScalar;
typedef typename NumericTraits<ValueType>::isSigned isSigned;
typedef VigraFalseType isOrdered;
typedef VigraTrueType isComplex;
static Type zero() { return Type(0.0, 0.0); }
static Type one() { return Type(1.0, 0.0); }
static Type nonZero() { return one(); }
static const Promote & toPromote(const Type & v) { return v; }
static const RealPromote & toRealPromote(const Type & v) { return v; }
static const Type & fromPromote(const Promote & v) { return v; }
static const Type & fromRealPromote(const RealPromote & v) { return v; }
};
template<>
struct NormTraits<fftw_complex>
{
typedef fftw_complex Type;
typedef fftw_real SquaredNormType;
typedef fftw_real NormType;
};
template<class Real>
struct NormTraits<FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Type;
typedef typename Type::SquaredNormType SquaredNormType;
typedef typename Type::NormType NormType;
};
template <>
struct PromoteTraits<fftw_complex, fftw_complex>
{
typedef fftw_complex Promote;
};
template <>
struct PromoteTraits<fftw_complex, double>
{
typedef fftw_complex Promote;
};
template <>
struct PromoteTraits<double, fftw_complex>
{
typedef fftw_complex Promote;
};
template <class Real>
struct PromoteTraits<FFTWComplex<Real>, FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Promote;
};
template <class Real>
struct PromoteTraits<FFTWComplex<Real>, double>
{
typedef FFTWComplex<Real> Promote;
};
template <class Real>
struct PromoteTraits<double, FFTWComplex<Real> >
{
typedef FFTWComplex<Real> Promote;
};
template<class T>
struct CanSkipInitialization<std::complex<T> >
{
typedef typename CanSkipInitialization<T>::type type;
static const bool value = type::asBool;
};
template<class Real>
struct CanSkipInitialization<FFTWComplex<Real> >
{
typedef typename CanSkipInitialization<Real>::type type;
static const bool value = type::asBool;
};
namespace multi_math {
template <class ARG>
struct MultiMathOperand;
template <class Real>
struct MultiMathOperand<FFTWComplex<Real> >
{
typedef MultiMathOperand<FFTWComplex<Real> > AllowOverload;
typedef FFTWComplex<Real> result_type;
static const int ndim = 0;
MultiMathOperand(FFTWComplex<Real> const & v)
: v_(v)
{}
template <class SHAPE>
bool checkShape(SHAPE const &) const
{
return true;
}
template <class SHAPE>
FFTWComplex<Real> const & operator[](SHAPE const &) const
{
return v_;
}
void inc(unsigned int /*LEVEL*/) const
{}
void reset(unsigned int /*LEVEL*/) const
{}
FFTWComplex<Real> const & operator*() const
{
return v_;
}
FFTWComplex<Real> v_;
};
} // namespace multi_math
template<class Ty>
class FFTWAllocator
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef Ty *pointer;
typedef const Ty *const_pointer;
typedef Ty& reference;
typedef const Ty& const_reference;
typedef Ty value_type;
pointer address(reference val) const
{ return &val; }
const_pointer address(const_reference val) const
{ return &val; }
template<class Other>
struct rebind
{
typedef FFTWAllocator<Other> other;
};
FFTWAllocator() throw()
{}
template<class Other>
FFTWAllocator(const FFTWAllocator<Other>& right) throw()
{}
template<class Other>
FFTWAllocator& operator=(const FFTWAllocator<Other>& right)
{
return *this;
}
pointer allocate(size_type count, void * = 0)
{
return (pointer)fftw_malloc(count * sizeof(Ty));
}
void deallocate(pointer ptr, size_type count)
{
fftw_free(ptr);
}
void construct(pointer ptr, const Ty& val)
{
new(ptr) Ty(val);
}
void destroy(pointer ptr)
{
ptr->~Ty();
}
size_type max_size() const throw()
{
return NumericTraits<std::ptrdiff_t>::max() / sizeof(Ty);
}
};
} // namespace vigra
namespace std {
template<class Real>
class allocator<vigra::FFTWComplex<Real> >
{
public:
typedef vigra::FFTWComplex<Real> value_type;
typedef size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef value_type *pointer;
typedef const value_type *const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
pointer address(reference val) const
{ return &val; }
const_pointer address(const_reference val) const
{ return &val; }
template<class Other>
struct rebind
{
typedef allocator<Other> other;
};
allocator() throw()
{}
template<class Other>
allocator(const allocator<Other>& right) throw()
{}
template<class Other>
allocator& operator=(const allocator<Other>& right)
{
return *this;
}
pointer allocate(size_type count, void * = 0)
{
return (pointer)fftw_malloc(count * sizeof(value_type));
}
void deallocate(pointer ptr, size_type /*count*/)
{
fftw_free(ptr);
}
void construct(pointer ptr, const value_type& val)
{
new(ptr) value_type(val);
}
void destroy(pointer ptr)
{
ptr->~value_type();
}
size_type max_size() const throw()
{
return vigra::NumericTraits<std::ptrdiff_t>::max() / sizeof(value_type);
}
};
} // namespace std
namespace vigra {
/********************************************************/
/* */
/* FFTWComplex Operations */
/* */
/********************************************************/
/** \addtogroup FFTWComplexOperators Functions for FFTWComplex
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
These functions fulfill the requirements of an Algebraic Field.
Return types are determined according to \ref FFTWComplexTraits.
Namespace: vigra
<p>
*/
//@{
/// equal
template <class R>
inline bool operator ==(FFTWComplex<R> const &a, const FFTWComplex<R> &b) {
return a.re() == b.re() && a.im() == b.im();
}
template <class R>
inline bool operator ==(FFTWComplex<R> const &a, double b) {
return a.re() == b && a.im() == 0.0;
}
template <class R>
inline bool operator ==(double a, const FFTWComplex<R> &b) {
return a == b.re() && 0.0 == b.im();
}
/// not equal
template <class R>
inline bool operator !=(FFTWComplex<R> const &a, const FFTWComplex<R> &b) {
return a.re() != b.re() || a.im() != b.im();
}
/// not equal
template <class R>
inline bool operator !=(FFTWComplex<R> const &a, double b) {
return a.re() != b || a.im() != 0.0;
}
/// not equal
template <class R>
inline bool operator !=(double a, const FFTWComplex<R> &b) {
return a != b.re() || 0.0 != b.im();
}
/// add-assignment
template <class R>
inline FFTWComplex<R> & operator +=(FFTWComplex<R> &a, const FFTWComplex<R> &b) {
a.re() += b.re();
a.im() += b.im();
return a;
}
/// subtract-assignment
template <class R>
inline FFTWComplex<R> & operator -=(FFTWComplex<R> &a, const FFTWComplex<R> &b) {
a.re() -= b.re();
a.im() -= b.im();
return a;
}
/// multiply-assignment
template <class R>
inline FFTWComplex<R> & operator *=(FFTWComplex<R> &a, const FFTWComplex<R> &b) {
typename FFTWComplex<R>::value_type t = a.re()*b.re()-a.im()*b.im();
a.im() = a.re()*b.im()+a.im()*b.re();
a.re() = t;
return a;
}
/// divide-assignment
template <class R>
inline FFTWComplex<R> & operator /=(FFTWComplex<R> &a, const FFTWComplex<R> &b) {
typename FFTWComplex<R>::value_type sm = b.squaredMagnitude();
typename FFTWComplex<R>::value_type t = (a.re()*b.re()+a.im()*b.im())/sm;
a.im() = (b.re()*a.im()-a.re()*b.im())/sm;
a.re() = t;
return a;
}
/// add-assignment with scalar double
template <class R>
inline FFTWComplex<R> & operator +=(FFTWComplex<R> &a, double b) {
a.re() += (R)b;
return a;
}
/// subtract-assignment with scalar double
template <class R>
inline FFTWComplex<R> & operator -=(FFTWComplex<R> &a, double b) {
a.re() -= (R)b;
return a;
}
/// multiply-assignment with scalar double
template <class R>
inline FFTWComplex<R> & operator *=(FFTWComplex<R> &a, double b) {
a.re() *= (R)b;
a.im() *= (R)b;
return a;
}
/// divide-assignment with scalar double
template <class R>
inline FFTWComplex<R> & operator /=(FFTWComplex<R> &a, double b) {
a.re() /= (R)b;
a.im() /= (R)b;
return a;
}
/// addition
template <class R>
inline FFTWComplex<R> operator +(FFTWComplex<R> a, const FFTWComplex<R> &b) {
a += b;
return a;
}
/// right addition with scalar double
template <class R>
inline FFTWComplex<R> operator +(FFTWComplex<R> a, double b) {
a += b;
return a;
}
/// left addition with scalar double
template <class R>
inline FFTWComplex<R> operator +(double a, FFTWComplex<R> b) {
b += a;
return b;
}
/// subtraction
template <class R>
inline FFTWComplex<R> operator -(FFTWComplex<R> a, const FFTWComplex<R> &b) {
a -= b;
return a;
}
/// right subtraction with scalar double
template <class R>
inline FFTWComplex<R> operator -(FFTWComplex<R> a, double b) {
a -= b;
return a;
}
/// left subtraction with scalar double
template <class R>
inline FFTWComplex<R> operator -(double a, FFTWComplex<R> const & b) {
return (-b) += a;
}
/// multiplication
template <class R>
inline FFTWComplex<R> operator *(FFTWComplex<R> a, const FFTWComplex<R> &b) {
a *= b;
return a;
}
/// right multiplication with scalar double
template <class R>
inline FFTWComplex<R> operator *(FFTWComplex<R> a, double b) {
a *= b;
return a;
}
/// left multiplication with scalar double
template <class R>
inline FFTWComplex<R> operator *(double a, FFTWComplex<R> b) {
b *= a;
return b;
}
/// division
template <class R>
inline FFTWComplex<R> operator /(FFTWComplex<R> a, const FFTWComplex<R> &b) {
a /= b;
return a;
}
/// right division with scalar double
template <class R>
inline FFTWComplex<R> operator /(FFTWComplex<R> a, double b) {
a /= b;
return a;
}
using VIGRA_CSTD::abs;
/// absolute value (= magnitude)
template <class R>
inline typename FFTWComplex<R>::NormType abs(const FFTWComplex<R> &a)
{
return a.magnitude();
}
/// pahse
template <class R>
inline R arg(const FFTWComplex<R> &a)
{
return a.phase();
}
/// real part
template <class R>
inline R real(const FFTWComplex<R> &a)
{
return a.real();
}
/// imaginary part
template <class R>
inline R imag(const FFTWComplex<R> &a)
{
return a.imag();
}
/// complex conjugate
template <class R>
inline FFTWComplex<R> conj(const FFTWComplex<R> &a)
{
return FFTWComplex<R>(a.re(), -a.im());
}
/// norm (= magnitude)
template <class R>
inline typename FFTWComplex<R>::NormType norm(const FFTWComplex<R> &a)
{
return a.magnitude();
}
/// squared norm (= squared magnitude)
template <class R>
inline typename FFTWComplex<R>::SquaredNormType squaredNorm(const FFTWComplex<R> &a)
{
return a.squaredMagnitude();
}
#define VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(fct) \
template <class R> \
inline FFTWComplex<R> fct(const FFTWComplex<R> &a) \
{ \
return std::fct(reinterpret_cast<std::complex<R> const &>(a)); \
}
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(cos)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(cosh)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(exp)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(log)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(log10)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(sin)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(sinh)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(sqrt)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(tan)
VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION(tanh)
#undef VIGRA_DEFINE_FFTW_COMPLEX_FUNCTION
template <class R>
inline FFTWComplex<R> pow(const FFTWComplex<R> &a, int e)
{
return std::pow(reinterpret_cast<std::complex<R> const &>(a), e);
}
template <class R>
inline FFTWComplex<R> pow(const FFTWComplex<R> &a, R const & e)
{
return std::pow(reinterpret_cast<std::complex<R> const &>(a), e);
}
template <class R>
inline FFTWComplex<R> pow(const FFTWComplex<R> &a, const FFTWComplex<R> & e)
{
return std::pow(reinterpret_cast<std::complex<R> const &>(a),
reinterpret_cast<std::complex<R> const &>(e));
}
template <class R>
inline FFTWComplex<R> pow(R const & a, const FFTWComplex<R> &e)
{
return std::pow(a, reinterpret_cast<std::complex<R> const &>(e));
}
//@}
} // namespace vigra
namespace std {
template <class Real>
ostream & operator<<(ostream & s, vigra::FFTWComplex<Real> const & v)
{
s << std::complex<Real>(v.re(), v.im());
return s;
}
} // namespace std
namespace vigra {
/** \addtogroup StandardImageTypes
*/
//@{
/********************************************************/
/* */
/* FFTWRealImage */
/* */
/********************************************************/
/** Float (<tt>fftw_real</tt>) image.
The type <tt>fftw_real</tt> is defined as <tt>double</tt> (in FFTW 2 it used to be
either <tt>float</tt> or <tt>double</tt>, as specified during compilation of FFTW).
FFTWRealImage uses \ref vigra::BasicImageIterator and \ref vigra::StandardAccessor and
their const counterparts to access the data.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
typedef BasicImage<fftw_real> FFTWRealImage;
/********************************************************/
/* */
/* FFTWComplexImage */
/* */
/********************************************************/
template<class R>
struct IteratorTraits<
BasicImageIterator<FFTWComplex<R>, FFTWComplex<R> **> >
{
typedef FFTWComplex<R> Type;
typedef BasicImageIterator<Type, Type **> Iterator;
typedef Iterator iterator;
typedef BasicImageIterator<Type, Type **> mutable_iterator;
typedef ConstBasicImageIterator<Type, Type **> const_iterator;
typedef typename iterator::iterator_category iterator_category;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference reference;
typedef typename iterator::index_reference index_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::row_iterator row_iterator;
typedef typename iterator::column_iterator column_iterator;
typedef VectorAccessor<Type> default_accessor;
typedef VectorAccessor<Type> DefaultAccessor;
typedef VigraTrueType hasConstantStrides;
};
template<class R>
struct IteratorTraits<
ConstBasicImageIterator<FFTWComplex<R>, FFTWComplex<R> **> >
{
typedef FFTWComplex<R> Type;
typedef ConstBasicImageIterator<Type, Type **> Iterator;
typedef Iterator iterator;
typedef BasicImageIterator<Type, Type **> mutable_iterator;
typedef ConstBasicImageIterator<Type, Type **> const_iterator;
typedef typename iterator::iterator_category iterator_category;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference reference;
typedef typename iterator::index_reference index_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::row_iterator row_iterator;
typedef typename iterator::column_iterator column_iterator;
typedef VectorAccessor<Type> default_accessor;
typedef VectorAccessor<Type> DefaultAccessor;
typedef VigraTrueType hasConstantStrides;
};
/** Complex (FFTWComplex) image.
It uses \ref vigra::BasicImageIterator and \ref vigra::StandardAccessor and
their const counterparts to access the data.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
typedef BasicImage<FFTWComplex<> > FFTWComplexImage;
//@}
/********************************************************/
/* */
/* FFTWComplex-Accessors */
/* */
/********************************************************/
/** \addtogroup DataAccessors
*/
//@{
/** \defgroup FFTWComplexAccessors Accessors for FFTWComplex
Encapsulate access to pixels of type FFTWComplex
*/
//@{
/** Encapsulate access to the the real part of a complex number.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWRealAccessor
{
public:
/// The accessor's value type.
typedef Real value_type;
/// Read real part at iterator position.
template <class ITERATOR>
value_type operator()(ITERATOR const & i) const {
return (*i).re();
}
/// Read real part at offset from iterator position.
template <class ITERATOR, class DIFFERENCE>
value_type operator()(ITERATOR const & i, DIFFERENCE d) const {
return i[d].re();
}
/// Write real part at iterator position from a scalar.
template <class ITERATOR>
void set(value_type const & v, ITERATOR const & i) const {
(*i).re()= v;
}
/// Write real part at offset from iterator position from a scalar.
template <class ITERATOR, class DIFFERENCE>
void set(value_type const & v, ITERATOR const & i, DIFFERENCE d) const {
i[d].re()= v;
}
/// Write real part at iterator position into a scalar.
template <class R, class ITERATOR>
void set(FFTWComplex<R> const & v, ITERATOR const & i) const {
*i = v.re();
}
/// Write real part at offset from iterator position into a scalar.
template <class R, class ITERATOR, class DIFFERENCE>
void set(FFTWComplex<R> const & v, ITERATOR const & i, DIFFERENCE d) const {
i[d] = v.re();
}
};
/** Encapsulate access to the the imaginary part of a complex number.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWImaginaryAccessor
{
public:
/// The accessor's value type.
typedef Real value_type;
/// Read imaginary part at iterator position.
template <class ITERATOR>
value_type operator()(ITERATOR const & i) const {
return (*i).im();
}
/// Read imaginary part at offset from iterator position.
template <class ITERATOR, class DIFFERENCE>
value_type operator()(ITERATOR const & i, DIFFERENCE d) const {
return i[d].im();
}
/// Write imaginary part at iterator position from a scalar.
template <class ITERATOR>
void set(value_type const & v, ITERATOR const & i) const {
(*i).im()= v;
}
/// Write imaginary part at offset from iterator position from a scalar.
template <class ITERATOR, class DIFFERENCE>
void set(value_type const & v, ITERATOR const & i, DIFFERENCE d) const {
i[d].im()= v;
}
/// Write imaginary part at iterator position into a scalar.
template <class R, class ITERATOR>
void set(FFTWComplex<R> const & v, ITERATOR const & i) const {
*i = v.im();
}
/// Write imaginary part at offset from iterator position into a scalar.
template <class R, class ITERATOR, class DIFFERENCE>
void set(FFTWComplex<R> const & v, ITERATOR const & i, DIFFERENCE d) const {
i[d] = v.im();
}
};
/** Write a real number into a complex one. The imaginary part is set
to 0.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWWriteRealAccessor
: public FFTWRealAccessor<Real>
{
public:
/// The accessor's value type.
typedef Real value_type;
/** Write real number at iterator position. Set imaginary part
to 0.
*/
template <class ITERATOR>
void set(value_type const & v, ITERATOR const & i) const {
(*i).re()= v;
(*i).im()= 0;
}
/** Write real number at offset from iterator position. Set imaginary part
to 0.
*/
template <class ITERATOR, class DIFFERENCE>
void set(value_type const & v, ITERATOR const & i, DIFFERENCE d) const {
i[d].re()= v;
i[d].im()= 0;
}
};
/** Calculate squared magnitude of complex number on the fly.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWSquaredMagnitudeAccessor
{
public:
/// The accessor's value type.
typedef Real value_type;
/// Read squared magnitude at iterator position.
template <class ITERATOR>
value_type operator()(ITERATOR const & i) const {
return (*i).squaredMagnitude();
}
/// Read squared magnitude at offset from iterator position.
template <class ITERATOR, class DIFFERENCE>
value_type operator()(ITERATOR const & i, DIFFERENCE d) const {
return (i[d]).squaredMagnitude();
}
};
/** Calculate magnitude of complex number on the fly.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWMagnitudeAccessor
{
public:
/// The accessor's value type.
typedef Real value_type;
/// Read magnitude at iterator position.
template <class ITERATOR>
value_type operator()(ITERATOR const & i) const {
return (*i).magnitude();
}
/// Read magnitude at offset from iterator position.
template <class ITERATOR, class DIFFERENCE>
value_type operator()(ITERATOR const & i, DIFFERENCE d) const {
return (i[d]).magnitude();
}
};
/** Calculate phase of complex number on the fly.
<b>\#include</b> \<vigra/fftw3.hxx\> (for FFTW 3) or<br>
<b>\#include</b> \<vigra/fftw.hxx\> (for deprecated FFTW 2)<br>
Namespace: vigra
*/
template <class Real = double>
class FFTWPhaseAccessor
{
public:
/// The accessor's value type.
typedef Real value_type;
/// Read phase at iterator position.
template <class ITERATOR>
value_type operator()(ITERATOR const & i) const {
return (*i).phase();
}
/// Read phase at offset from iterator position.
template <class ITERATOR, class DIFFERENCE>
value_type operator()(ITERATOR const & i, DIFFERENCE d) const {
return (i[d]).phase();
}
};
//@}
//@}
/********************************************************/
/* */
/* Fourier Transform */
/* */
/********************************************************/
/* \addtogroup FourierTransform Fast Fourier Transform
This documentation describes the VIGRA interface to FFTW version 3. The interface
to the old FFTW version 2 (file "vigra/fftw.hxx") is deprecated.
VIGRA uses the <a href="http://www.fftw.org/">FFTW Fast Fourier
Transform</a> package to perform Fourier transformations. VIGRA
provides a wrapper for FFTW's complex number type (FFTWComplex),
but FFTW's functions are used verbatim. If the image is stored as
a FFTWComplexImage, the simplest call to an FFT function is like this:
\code
vigra::FFTWComplexImage spatial(width,height), fourier(width,height);
... // fill image with data
// create a plan with estimated performance optimization
fftw_plan forwardPlan = fftw_plan_dft_2d(height, width,
(fftw_complex *)spatial.begin(), (fftw_complex *)fourier.begin(),
FFTW_FORWARD, FFTW_ESTIMATE );
// calculate FFT (this can be repeated as often as needed,
// with fresh data written into the source array)
fftw_execute(forwardPlan);
// release the plan memory
fftw_destroy_plan(forwardPlan);
// likewise for the inverse transform
fftw_plan backwardPlan = fftw_plan_dft_2d(height, width,
(fftw_complex *)fourier.begin(), (fftw_complex *)spatial.begin(),
FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(backwardPlan);
fftw_destroy_plan(backwardPlan);
// do not forget to normalize the result according to the image size
transformImage(srcImageRange(spatial), destImage(spatial),
std::bind1st(std::multiplies<FFTWComplex>(), 1.0 / width / height));
\endcode
Note that in the creation of a plan, the height must be given
first. Note also that <TT>spatial.begin()</TT> may only be passed
to <TT>fftw_plan_dft_2d</TT> if the transform shall be applied to the
entire image. When you want to restrict operation to an ROI, you
can create a copy of the ROI in an image of appropriate size, or
you may use the Guru interface to FFTW.
More information on using FFTW can be found <a href="http://www.fftw.org/doc/">here</a>.
FFTW produces fourier images that have the DC component (the
origin of the Fourier space) in the upper left corner. Often, one
wants the origin in the center of the image, so that frequencies
always increase towards the border of the image. This can be
achieved by calling \ref moveDCToCenter(). The inverse
transformation is done by \ref moveDCToUpperLeft().
<b>\#include</b> \<vigra/fftw3.hxx\><br>
Namespace: vigra
*/
/** \addtogroup FourierTransform Fast Fourier Transform
VIGRA provides a powerful C++ API for the popular <a href="http://www.fftw.org/">FFTW library</a>
for fast Fourier transforms. There are two versions of the API: an older one based on image
iterators (and therefore restricted to 2D) and a new one based on \ref MultiArrayView that
works for arbitrary dimensions. In addition, the functions \ref convolveFFT() and
\ref applyFourierFilter() provide an easy-to-use interface for FFT-based convolution,
a major application of Fourier transforms.
*/
//@{
/********************************************************/
/* */
/* moveDCToCenter */
/* */
/********************************************************/
/** \brief Rearrange the quadrants of a Fourier image so that the origin is
in the image center.
FFTW produces fourier images where the DC component (origin of
fourier space) is located in the upper left corner of the
image. The quadrants are placed like this (using a 4x4 image for
example):
\code
DC 4 3 3
4 4 3 3
1 1 2 2
1 1 2 2
\endcode
After applying the function, the quadrants are at their usual places:
\code
2 2 1 1
2 2 1 1
3 3 DC 4
3 3 4 4
\endcode
This transformation can be reversed by \ref moveDCToUpperLeft().
Note that the 2D versions of this transformation must not be executed in place - input
and output images must be different. In contrast, the nD version (with MultiArrayView
argument) always works in-place.
<b> Declarations:</b>
use MultiArrayView (this works in-place, with arbitrary dimension N):
\code
namespace vigra {
template <unsigned int N, class T, class Stride>
void moveDCToCenter(MultiArrayView<N, T, Stride> a);
}
\endcode
pass iterators explicitly (2D only, not in-place):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToCenter(SrcImageIterator src_upperleft,
SrcImageIterator src_lowerright, SrcAccessor sa,
DestImageIterator dest_upperleft, DestAccessor da);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories (2D only, not in-place):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToCenter(
triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<DestImageIterator, DestAccessor> dest);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<vigra/fftw3.hxx\> (for 2D variants) <br>
<b>\#include</b> \<vigra/multi_fft.hxx\> (for nD variants) <br>
Namespace: vigra
\code
vigra::FFTWComplexImage spatial(width,height), fourier(width,height);
... // fill image with data
// create a plan with estimated performance optimization
fftw_plan forwardPlan = fftw_plan_dft_2d(height, width,
(fftw_complex *)spatial.begin(), (fftw_complex *)fourier.begin(),
FFTW_FORWARD, FFTW_ESTIMATE );
// calculate FFT
fftw_execute(forwardPlan);
vigra::FFTWComplexImage rearrangedFourier(width, height);
moveDCToCenter(srcImageRange(fourier), destImage(rearrangedFourier));
// delete the plan
fftw_destroy_plan(forwardPlan);
\endcode
*/
doxygen_overloaded_function(template <...> void moveDCToCenter)
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToCenter(SrcImageIterator src_upperleft,
SrcImageIterator src_lowerright, SrcAccessor sa,
DestImageIterator dest_upperleft, DestAccessor da)
{
int w = int(src_lowerright.x - src_upperleft.x);
int h = int(src_lowerright.y - src_upperleft.y);
int w1 = w/2;
int h1 = h/2;
int w2 = (w+1)/2;
int h2 = (h+1)/2;
// 2. Quadrant zum 4.
copyImage(srcIterRange(src_upperleft,
src_upperleft + Diff2D(w2, h2), sa),
destIter (dest_upperleft + Diff2D(w1, h1), da));
// 4. Quadrant zum 2.
copyImage(srcIterRange(src_upperleft + Diff2D(w2, h2),
src_lowerright, sa),
destIter (dest_upperleft, da));
// 1. Quadrant zum 3.
copyImage(srcIterRange(src_upperleft + Diff2D(w2, 0),
src_upperleft + Diff2D(w, h2), sa),
destIter (dest_upperleft + Diff2D(0, h1), da));
// 3. Quadrant zum 1.
copyImage(srcIterRange(src_upperleft + Diff2D(0, h2),
src_upperleft + Diff2D(w2, h), sa),
destIter (dest_upperleft + Diff2D(w1, 0), da));
}
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
inline void moveDCToCenter(
triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<DestImageIterator, DestAccessor> dest)
{
moveDCToCenter(src.first, src.second, src.third,
dest.first, dest.second);
}
/********************************************************/
/* */
/* moveDCToUpperLeft */
/* */
/********************************************************/
/** \brief Rearrange the quadrants of a Fourier image so that the origin is
in the image's upper left.
This function is the inversion of \ref moveDCToCenter(). See there
for a detailed description and usage examples.
<b> Declarations:</b>
use MultiArrayView (this works in-place, with arbitrary dimension N):
\code
namespace vigra {
template <unsigned int N, class T, class Stride>
void moveDCToUpperLeft(MultiArrayView<N, T, Stride> a);
}
\endcode
pass iterators explicitly (2D only, not in-place):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToUpperLeft(SrcImageIterator src_upperleft,
SrcImageIterator src_lowerright, SrcAccessor sa,
DestImageIterator dest_upperleft, DestAccessor da);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories (2D only, not in-place):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToUpperLeft(
triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<DestImageIterator, DestAccessor> dest);
}
\endcode
*/
doxygen_overloaded_function(template <...> void moveDCToUpperLeft)
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
void moveDCToUpperLeft(SrcImageIterator src_upperleft,
SrcImageIterator src_lowerright, SrcAccessor sa,
DestImageIterator dest_upperleft, DestAccessor da)
{
int w = int(src_lowerright.x - src_upperleft.x);
int h = int(src_lowerright.y - src_upperleft.y);
int w2 = w/2;
int h2 = h/2;
int w1 = (w+1)/2;
int h1 = (h+1)/2;
// 2. Quadrant zum 4.
copyImage(srcIterRange(src_upperleft,
src_upperleft + Diff2D(w2, h2), sa),
destIter (dest_upperleft + Diff2D(w1, h1), da));
// 4. Quadrant zum 2.
copyImage(srcIterRange(src_upperleft + Diff2D(w2, h2),
src_lowerright, sa),
destIter (dest_upperleft, da));
// 1. Quadrant zum 3.
copyImage(srcIterRange(src_upperleft + Diff2D(w2, 0),
src_upperleft + Diff2D(w, h2), sa),
destIter (dest_upperleft + Diff2D(0, h1), da));
// 3. Quadrant zum 1.
copyImage(srcIterRange(src_upperleft + Diff2D(0, h2),
src_upperleft + Diff2D(w2, h), sa),
destIter (dest_upperleft + Diff2D(w1, 0), da));
}
template <class SrcImageIterator, class SrcAccessor,
class DestImageIterator, class DestAccessor>
inline void moveDCToUpperLeft(
triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<DestImageIterator, DestAccessor> dest)
{
moveDCToUpperLeft(src.first, src.second, src.third,
dest.first, dest.second);
}
namespace detail {
template <class T>
void
fourierTransformImpl(FFTWComplexImage::const_traverser sul,
FFTWComplexImage::const_traverser slr, FFTWComplexImage::ConstAccessor src,
FFTWComplexImage::traverser dul, FFTWComplexImage::Accessor dest, T sign)
{
int w = int(slr.x - sul.x);
int h = int(slr.y - sul.y);
FFTWComplexImage sworkImage, dworkImage;
fftw_complex * srcPtr = (fftw_complex *)(&*sul);
fftw_complex * destPtr = (fftw_complex *)(&*dul);
// test for right memory layout (fftw expects a 2*width*height floats array)
if (h > 1 && &(*(sul + Diff2D(w, 0))) != &(*(sul + Diff2D(0, 1))))
{
sworkImage.resize(w, h);
copyImage(srcIterRange(sul, slr, src), destImage(sworkImage));
srcPtr = (fftw_complex *)(&(*sworkImage.upperLeft()));
}
if (h > 1 && &(*(dul + Diff2D(w, 0))) != &(*(dul + Diff2D(0, 1))))
{
dworkImage.resize(w, h);
destPtr = (fftw_complex *)(&(*dworkImage.upperLeft()));
}
fftw_plan plan = fftw_plan_dft_2d(h, w, srcPtr, destPtr, sign, FFTW_ESTIMATE );
fftw_execute(plan);
fftw_destroy_plan(plan);
if (h > 1 && &(*(dul + Diff2D(w, 0))) != &(*(dul + Diff2D(0, 1))))
{
copyImage(srcImageRange(dworkImage), destIter(dul, dest));
}
}
} // namespace detail
/********************************************************/
/* */
/* fourierTransform */
/* */
/********************************************************/
/** \brief Compute forward and inverse Fourier transforms.
The array referring to the spatial domain (i.e. the input in a forward transform,
and the output in an inverse transform) may be scalar or complex. The array representing
the frequency domain (i.e. output for forward transform, input for inverse transform)
must always be complex.
The new implementations (those using MultiArrayView arguments) perform a normalized transform,
whereas the old ones (using 2D iterators or argument objects) perform an un-normalized
transform (i.e. the result of the inverse transform is scaled by the number of pixels).
In general, input and output arrays must have the same shape, with the exception of the
special <a href="http://www.fftw.org/doc/Multi_002dDimensional-DFTs-of-Real-Data.html">R2C
and C2R modes</a> defined by FFTW.
The R2C transform reduces the redundancy in the Fourier representation of a real-valued signal:
Since the Fourier representation of a real signal is symmetric, about half of the Fourier coefficients
can simply be dropped. By convention, this reduction is applied to the first (innermost) dimension,
such that <tt>fourier.shape(0) == spatial.shape(0)/2 + 1</tt> holds. The correct frequency domain
shape can be conveniently computed by means of the function \ref fftwCorrespondingShapeR2C().
Note that your program must always link against <tt>libfftw3</tt>. If you want to compute Fourier
transforms for <tt>float</tt> or <tt>long double</tt> arrays, you must <i>additionally</i> link against <tt>libfftw3f</tt> and <tt>libfftw3l</tt> respectively. (Old-style functions only support <tt>double</tt>).
The Fourier transform functions internally create <a href="http://www.fftw.org/doc/Using-Plans.html">FFTW plans</a>
which control the algorithm details. The plans are creates with the flag <tt>FFTW_ESTIMATE</tt>, i.e.
optimal settings are guessed or read from saved "wisdom" files. If you need more control over planning,
you can use the class \ref FFTWPlan.
<b> Declarations:</b>
use complex-valued MultiArrayView arguments (this works for arbitrary dimension N):
\code
namespace vigra {
template <unsigned int N, class Real, class C1, class C2>
void
fourierTransform(MultiArrayView<N, FFTWComplex<Real>, C1> in,
MultiArrayView<N, FFTWComplex<Real>, C2> out);
template <unsigned int N, class Real, class C1, class C2>
void
fourierTransformInverse(MultiArrayView<N, FFTWComplex<Real>, C1> in,
MultiArrayView<N, FFTWComplex<Real>, C2> out);
}
\endcode
use real-valued MultiArrayView in the spatial domain, complex-valued MultiArrayView
in the frequency domain (this works for arbitrary dimension N, and also supports
the R2C and C2R transform, depending on the array shape in the frequency domain):
\code
namespace vigra {
template <unsigned int N, class Real, class C1, class C2>
void
fourierTransform(MultiArrayView<N, Real, C1> in,
MultiArrayView<N, FFTWComplex<Real>, C2> out);
template <unsigned int N, class Real, class C1, class C2>
void
fourierTransformInverse(MultiArrayView<N, FFTWComplex<Real>, C1> in,
MultiArrayView<N, Real, C2> out);
}
\endcode
pass iterators explicitly (2D only, double only):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor>
void fourierTransform(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor src,
FFTWComplexImage::traverser destUpperLeft, FFTWComplexImage::Accessor dest);
void
fourierTransformInverse(FFTWComplexImage::const_traverser sul,
FFTWComplexImage::const_traverser slr, FFTWComplexImage::ConstAccessor src,
FFTWComplexImage::traverser dul, FFTWComplexImage::Accessor dest)
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories (2D only, double only):
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor>
void fourierTransform(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<FFTWComplexImage::traverser, FFTWComplexImage::Accessor> dest);
void
fourierTransformInverse(triple<FFTWComplexImage::const_traverser,
FFTWComplexImage::const_traverser, FFTWComplexImage::ConstAccessor> src,
pair<FFTWComplexImage::traverser, FFTWComplexImage::Accessor> dest);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<vigra/fftw3.hxx\> (old-style 2D variants)<br>
<b>\#include</b> \<vigra/multi_fft.hxx\> (new-style nD variants)<br>
Namespace: vigra
old-style example (using FFTWComplexImage):
\code
// compute complex Fourier transform of a real image, old-style implementation
vigra::DImage src(w, h);
vigra::FFTWComplexImage fourier(w, h);
fourierTransform(srcImageRange(src), destImage(fourier));
// compute inverse Fourier transform
// note that both source and destination image must be of type vigra::FFTWComplexImage
vigra::FFTWComplexImage inverseFourier(w, h);
fourierTransformInverse(srcImageRange(fourier), destImage(inverseFourier));
\endcode
new-style examples (using MultiArray):
\code
// compute Fourier transform of a real array, using the R2C algorithm
MultiArray<2, double> src(Shape2(w, h));
MultiArray<2, FFTWComplex<double> > fourier(fftwCorrespondingShapeR2C(src.shape()));
fourierTransform(src, fourier);
// compute inverse Fourier transform, using the C2R algorithm
MultiArray<2, double> dest(src.shape());
fourierTransformInverse(fourier, dest);
\endcode
\code
// compute Fourier transform of a real array with standard algorithm
MultiArray<2, double> src(Shape2(w, h));
MultiArray<2, FFTWComplex<double> > fourier(src.shape());
fourierTransform(src, fourier);
// compute inverse Fourier transform, using the C2R algorithm
MultiArray<2, double> dest(src.shape());
fourierTransformInverse(fourier, dest);
\endcode
Complex input arrays are handled in the same way.
*/
doxygen_overloaded_function(template <...> void fourierTransform)
inline void
fourierTransform(FFTWComplexImage::const_traverser sul,
FFTWComplexImage::const_traverser slr, FFTWComplexImage::ConstAccessor src,
FFTWComplexImage::traverser dul, FFTWComplexImage::Accessor dest)
{
detail::fourierTransformImpl(sul, slr, src, dul, dest, FFTW_FORWARD);
}
template <class SrcImageIterator, class SrcAccessor>
void fourierTransform(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
FFTWComplexImage::traverser destUpperLeft, FFTWComplexImage::Accessor da)
{
// copy real input images into a complex one...
int w= srcLowerRight.x - srcUpperLeft.x;
int h= srcLowerRight.y - srcUpperLeft.y;
FFTWComplexImage workImage(w, h);
copyImage(srcIterRange(srcUpperLeft, srcLowerRight, sa),
destImage(workImage, FFTWWriteRealAccessor<>()));
// ...and call the complex -> complex version of the algorithm
FFTWComplexImage const & cworkImage = workImage;
fourierTransform(cworkImage.upperLeft(), cworkImage.lowerRight(), cworkImage.accessor(),
destUpperLeft, da);
}
template <class SrcImageIterator, class SrcAccessor>
inline
void fourierTransform(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<FFTWComplexImage::traverser, FFTWComplexImage::Accessor> dest)
{
fourierTransform(src.first, src.second, src.third, dest.first, dest.second);
}
/** \brief Compute inverse Fourier transforms.
See \ref fourierTransform() for details.
*/
doxygen_overloaded_function(template <...> void fourierTransformInverse)
inline void
fourierTransformInverse(FFTWComplexImage::const_traverser sul,
FFTWComplexImage::const_traverser slr, FFTWComplexImage::ConstAccessor src,
FFTWComplexImage::traverser dul, FFTWComplexImage::Accessor dest)
{
detail::fourierTransformImpl(sul, slr, src, dul, dest, FFTW_BACKWARD);
}
template <class DestImageIterator, class DestAccessor>
void fourierTransformInverse(FFTWComplexImage::const_traverser sul,
FFTWComplexImage::const_traverser slr, FFTWComplexImage::ConstAccessor src,
DestImageIterator dul, DestAccessor dest)
{
int w = slr.x - sul.x;
int h = slr.y - sul.y;
FFTWComplexImage workImage(w, h);
fourierTransformInverse(sul, slr, src, workImage.upperLeft(), workImage.accessor());
copyImage(srcImageRange(workImage), destIter(dul, dest));
}
template <class DestImageIterator, class DestAccessor>
inline void
fourierTransformInverse(triple<FFTWComplexImage::const_traverser,
FFTWComplexImage::const_traverser, FFTWComplexImage::ConstAccessor> src,
pair<DestImageIterator, DestAccessor> dest)
{
fourierTransformInverse(src.first, src.second, src.third, dest.first, dest.second);
}
/********************************************************/
/* */
/* applyFourierFilter */
/* */
/********************************************************/
/** \brief Apply a filter (defined in the frequency domain) to an image.
After transferring the image into the frequency domain, it is
multiplied pixel-wise with the filter and transformed back. The
result is put into the given destination image which must have the right size.
The result will be normalized to compensate for the two FFTs.
If the destination image is scalar, only the real part of the result image is
retained. In this case, you are responsible for choosing a filter image
which ensures a zero imaginary part of the result (e.g. use a real, even symmetric
filter image, or a purely imaginary, odd symmetric one).
The DC entry of the filter must be in the upper left, which is the
position where FFTW expects it (see \ref moveDCToUpperLeft()).
See also \ref convolveFFT() for corresponding functionality on the basis of the
\ref MultiArrayView interface.
<b> Declarations:</b>
pass 2D array views:
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
void applyFourierFilter(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
FilterImageIterator filterUpperLeft, FilterAccessor fa,
DestImageIterator destUpperLeft, DestAccessor da);
}
\endcode
pass \ref ImageIterators and \ref DataAccessors :
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
void applyFourierFilter(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
FilterImageIterator filterUpperLeft, FilterAccessor fa,
DestImageIterator destUpperLeft, DestAccessor da);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor,
class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
void applyFourierFilter(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<FilterImageIterator, FilterAccessor> filter,
pair<DestImageIterator, DestAccessor> dest);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<vigra/fftw3.hxx\><br>
Namespace: vigra
\code
// create a Gaussian filter in Fourier space
vigra::FImage gaussFilter(w, h), filter(w, h);
for(int y=0; y<h; ++y)
for(int x=0; x<w; ++x)
{
xx = float(x - w / 2) / w;
yy = float(y - h / 2) / h;
gaussFilter(x,y) = std::exp(-(xx*xx + yy*yy) / 2.0 * scale);
}
// applyFourierFilter() expects the filter's DC in the upper left
moveDCToUpperLeft(srcImageRange(gaussFilter), destImage(filter));
vigra::FFTWComplexImage result(w, h);
vigra::applyFourierFilter(srcImageRange(image), srcImage(filter), result);
\endcode
For inspection of the result, \ref FFTWMagnitudeAccessor might be
useful. If you want to apply the same filter repeatedly, it may be more
efficient to use the FFTW functions directly with FFTW plans optimized
for good performance.
*/
doxygen_overloaded_function(template <...> void applyFourierFilter)
template <class SrcImageIterator, class SrcAccessor,
class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
void applyFourierFilter(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
FilterImageIterator filterUpperLeft, FilterAccessor fa,
DestImageIterator destUpperLeft, DestAccessor da)
{
// copy real input images into a complex one...
int w = int(srcLowerRight.x - srcUpperLeft.x);
int h = int(srcLowerRight.y - srcUpperLeft.y);
FFTWComplexImage workImage(w, h);
copyImage(srcIterRange(srcUpperLeft, srcLowerRight, sa),
destImage(workImage, FFTWWriteRealAccessor<>()));
// ...and call the impl
FFTWComplexImage const & cworkImage = workImage;
applyFourierFilterImpl(cworkImage.upperLeft(), cworkImage.lowerRight(), cworkImage.accessor(),
filterUpperLeft, fa,
destUpperLeft, da);
}
template <class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
inline
void applyFourierFilter(
FFTWComplexImage::const_traverser srcUpperLeft,
FFTWComplexImage::const_traverser srcLowerRight,
FFTWComplexImage::ConstAccessor sa,
FilterImageIterator filterUpperLeft, FilterAccessor fa,
DestImageIterator destUpperLeft, DestAccessor da)
{
int w = srcLowerRight.x - srcUpperLeft.x;
int h = srcLowerRight.y - srcUpperLeft.y;
// test for right memory layout (fftw expects a 2*width*height floats array)
if (&(*(srcUpperLeft + Diff2D(w, 0))) == &(*(srcUpperLeft + Diff2D(0, 1))))
applyFourierFilterImpl(srcUpperLeft, srcLowerRight, sa,
filterUpperLeft, fa,
destUpperLeft, da);
else
{
FFTWComplexImage workImage(w, h);
copyImage(srcIterRange(srcUpperLeft, srcLowerRight, sa),
destImage(workImage));
FFTWComplexImage const & cworkImage = workImage;
applyFourierFilterImpl(cworkImage.upperLeft(), cworkImage.lowerRight(), cworkImage.accessor(),
filterUpperLeft, fa,
destUpperLeft, da);
}
}
template <class SrcImageIterator, class SrcAccessor,
class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
inline
void applyFourierFilter(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
pair<FilterImageIterator, FilterAccessor> filter,
pair<DestImageIterator, DestAccessor> dest)
{
applyFourierFilter(src.first, src.second, src.third,
filter.first, filter.second,
dest.first, dest.second);
}
template <class FilterImageIterator, class FilterAccessor,
class DestImageIterator, class DestAccessor>
void applyFourierFilterImpl(
FFTWComplexImage::const_traverser srcUpperLeft,
FFTWComplexImage::const_traverser srcLowerRight,
FFTWComplexImage::ConstAccessor,
FilterImageIterator filterUpperLeft, FilterAccessor fa,
DestImageIterator destUpperLeft, DestAccessor da)
{
int w = int(srcLowerRight.x - srcUpperLeft.x);
int h = int(srcLowerRight.y - srcUpperLeft.y);
FFTWComplexImage complexResultImg(srcLowerRight - srcUpperLeft);
// FFT from srcImage to complexResultImg
fftw_plan forwardPlan=
fftw_plan_dft_2d(h, w, (fftw_complex *)&(*srcUpperLeft),
(fftw_complex *)complexResultImg.begin(),
FFTW_FORWARD, FFTW_ESTIMATE );
fftw_execute(forwardPlan);
fftw_destroy_plan(forwardPlan);
// convolve in freq. domain (in complexResultImg)
combineTwoImages(srcImageRange(complexResultImg), srcIter(filterUpperLeft, fa),
destImage(complexResultImg), std::multiplies<FFTWComplex<> >());
// FFT back into spatial domain (inplace in complexResultImg)
fftw_plan backwardPlan=
fftw_plan_dft_2d(h, w, (fftw_complex *)complexResultImg.begin(),
(fftw_complex *)complexResultImg.begin(),
FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(backwardPlan);
fftw_destroy_plan(backwardPlan);
typedef typename
NumericTraits<typename DestAccessor::value_type>::isScalar
isScalarResult;
// normalization (after FFTs), maybe stripping imaginary part
applyFourierFilterImplNormalization(complexResultImg, destUpperLeft, da,
isScalarResult());
}
template <class DestImageIterator, class DestAccessor>
void applyFourierFilterImplNormalization(FFTWComplexImage const &srcImage,
DestImageIterator destUpperLeft,
DestAccessor da,
VigraFalseType)
{
double normFactor= 1.0/(srcImage.width() * srcImage.height());
for(int y=0; y<srcImage.height(); y++, destUpperLeft.y++)
{
DestImageIterator dIt= destUpperLeft;
for(int x= 0; x< srcImage.width(); x++, dIt.x++)
{
da.setComponent(srcImage(x, y).re()*normFactor, dIt, 0);
da.setComponent(srcImage(x, y).im()*normFactor, dIt, 1);
}
}
}
inline
void applyFourierFilterImplNormalization(FFTWComplexImage const & srcImage,
FFTWComplexImage::traverser destUpperLeft,
FFTWComplexImage::Accessor da,
VigraFalseType)
{
transformImage(srcImageRange(srcImage), destIter(destUpperLeft, da),
linearIntensityTransform<FFTWComplex<> >(1.0/(srcImage.width() * srcImage.height())));
}
template <class DestImageIterator, class DestAccessor>
void applyFourierFilterImplNormalization(FFTWComplexImage const & srcImage,
DestImageIterator destUpperLeft,
DestAccessor da,
VigraTrueType)
{
double normFactor= 1.0/(srcImage.width() * srcImage.height());
for(int y=0; y<srcImage.height(); y++, destUpperLeft.y++)
{
DestImageIterator dIt= destUpperLeft;
for(int x= 0; x< srcImage.width(); x++, dIt.x++)
da.set(srcImage(x, y).re()*normFactor, dIt);
}
}
/**********************************************************/
/* */
/* applyFourierFilterFamily */
/* */
/**********************************************************/
/** \brief Apply an array of filters (defined in the frequency domain) to an image.
This provides the same functionality as \ref applyFourierFilter(),
but applying several filters at once allows to avoid
repeated Fourier transforms of the source image.
Filters and result images must be stored in \ref vigra::ImageArray data
structures. In contrast to \ref applyFourierFilter(), this function adjusts
the size of the result images and the the length of the array.
<b> Declarations:</b>
pass 2D array views:
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor, class FilterType>
void applyFourierFilterFamily(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
const ImageArray<FilterType> &filters,
ImageArray<FFTWComplexImage> &results)
}
\endcode
pass \ref ImageIterators and \ref DataAccessors :
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor, class FilterType>
void applyFourierFilterFamily(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
const ImageArray<FilterType> &filters,
ImageArray<FFTWComplexImage> &results)
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcImageIterator, class SrcAccessor, class FilterType>
void applyFourierFilterFamily(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
const ImageArray<FilterType> &filters,
ImageArray<FFTWComplexImage> &results)
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<vigra/fftw3.hxx\><br>
Namespace: vigra
\code
// assuming the presence of a real-valued image named "image" to
// be filtered in this example
vigra::ImageArray<vigra::FImage> filters(16, image.size());
for (int i=0; i<filters.size(); i++)
// create some meaningful filters here
createMyFilterOfScale(i, destImage(filters[i]));
vigra::ImageArray<vigra::FFTWComplexImage> results();
vigra::applyFourierFilterFamily(srcImageRange(image), filters, results);
\endcode
*/
doxygen_overloaded_function(template <...> void applyFourierFilterFamily)
template <class SrcImageIterator, class SrcAccessor,
class FilterType, class DestImage>
inline
void applyFourierFilterFamily(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
const ImageArray<FilterType> &filters,
ImageArray<DestImage> &results)
{
applyFourierFilterFamily(src.first, src.second, src.third,
filters, results);
}
template <class SrcImageIterator, class SrcAccessor,
class FilterType, class DestImage>
void applyFourierFilterFamily(SrcImageIterator srcUpperLeft,
SrcImageIterator srcLowerRight, SrcAccessor sa,
const ImageArray<FilterType> &filters,
ImageArray<DestImage> &results)
{
int w = int(srcLowerRight.x - srcUpperLeft.x);
int h = int(srcLowerRight.y - srcUpperLeft.y);
FFTWComplexImage workImage(w, h);
copyImage(srcIterRange(srcUpperLeft, srcLowerRight, sa),
destImage(workImage, FFTWWriteRealAccessor<>()));
FFTWComplexImage const & cworkImage = workImage;
applyFourierFilterFamilyImpl(cworkImage.upperLeft(), cworkImage.lowerRight(), cworkImage.accessor(),
filters, results);
}
template <class FilterType, class DestImage>
inline
void applyFourierFilterFamily(
FFTWComplexImage::const_traverser srcUpperLeft,
FFTWComplexImage::const_traverser srcLowerRight,
FFTWComplexImage::ConstAccessor sa,
const ImageArray<FilterType> &filters,
ImageArray<DestImage> &results)
{
int w= srcLowerRight.x - srcUpperLeft.x;
// test for right memory layout (fftw expects a 2*width*height floats array)
if (&(*(srcUpperLeft + Diff2D(w, 0))) == &(*(srcUpperLeft + Diff2D(0, 1))))
applyFourierFilterFamilyImpl(srcUpperLeft, srcLowerRight, sa,
filters, results);
else
{
int h = srcLowerRight.y - srcUpperLeft.y;
FFTWComplexImage workImage(w, h);
copyImage(srcIterRange(srcUpperLeft, srcLowerRight, sa),
destImage(workImage));
FFTWComplexImage const & cworkImage = workImage;
applyFourierFilterFamilyImpl(cworkImage.upperLeft(), cworkImage.lowerRight(), cworkImage.accessor(),
filters, results);
}
}
template <class FilterType, class DestImage>
void applyFourierFilterFamilyImpl(
FFTWComplexImage::const_traverser srcUpperLeft,
FFTWComplexImage::const_traverser srcLowerRight,
FFTWComplexImage::ConstAccessor sa,
const ImageArray<FilterType> &filters,
ImageArray<DestImage> &results)
{
// FIXME: sa is not used
// (maybe check if StandardAccessor, else copy?)
// make sure the filter images have the right dimensions
vigra_precondition((srcLowerRight - srcUpperLeft) == filters.imageSize(),
"applyFourierFilterFamily called with src image size != filters.imageSize()!");
// make sure the result image array has the right dimensions
results.resize(filters.size());
results.resizeImages(filters.imageSize());
// FFT from srcImage to freqImage
int w = int(srcLowerRight.x - srcUpperLeft.x);
int h = int(srcLowerRight.y - srcUpperLeft.y);
FFTWComplexImage freqImage(w, h);
FFTWComplexImage result(w, h);
fftw_plan forwardPlan=
fftw_plan_dft_2d(h, w, (fftw_complex *)&(*srcUpperLeft),
(fftw_complex *)freqImage.begin(),
FFTW_FORWARD, FFTW_ESTIMATE );
fftw_execute(forwardPlan);
fftw_destroy_plan(forwardPlan);
fftw_plan backwardPlan=
fftw_plan_dft_2d(h, w, (fftw_complex *)result.begin(),
(fftw_complex *)result.begin(),
FFTW_BACKWARD, FFTW_ESTIMATE );
typedef typename
NumericTraits<typename DestImage::Accessor::value_type>::isScalar
isScalarResult;
// convolve with filters in freq. domain
for (unsigned int i= 0; i < filters.size(); i++)
{
combineTwoImages(srcImageRange(freqImage), srcImage(filters[i]),
destImage(result), std::multiplies<FFTWComplex<> >());
// FFT back into spatial domain (inplace in destImage)
fftw_execute(backwardPlan);
// normalization (after FFTs), maybe stripping imaginary part
applyFourierFilterImplNormalization(result,
results[i].upperLeft(), results[i].accessor(),
isScalarResult());
}
fftw_destroy_plan(backwardPlan);
}
/********************************************************/
/* */
/* fourierTransformReal */
/* */
/********************************************************/
/** \brief Real Fourier transforms for even and odd boundary conditions
(aka. cosine and sine transforms).
If the image is real and has even symmetry, its Fourier transform
is also real and has even symmetry. The Fourier transform of a real image with odd
symmetry is imaginary and has odd symmetry. In either case, only about a quarter
of the pixels need to be stored because the rest can be calculated from the symmetry
properties. This is especially useful, if the original image is implicitly assumed
to have reflective or anti-reflective boundary conditions. Then the "negative"
pixel locations are defined as
\code
even (reflective boundary conditions): f[-x] = f[x] (x = 1,...,N-1)
odd (anti-reflective boundary conditions): f[-1] = 0
f[-x] = -f[x-2] (x = 2,...,N-1)
\endcode
end similar at the other boundary (see the FFTW documentation for details).
This has the advantage that more efficient Fourier transforms that use only
real numbers can be implemented. These are also known as cosine and sine transforms
respectively.
If you use the odd transform it is important to note that in the Fourier domain,
the DC component is always zero and is therefore dropped from the data structure.
This means that index 0 in an odd symmetric Fourier domain image refers to
the <i>first</i> harmonic. This is especially important if an image is first
cosine transformed (even symmetry), then in the Fourier domain multiplied
with an odd symmetric filter (e.g. a first derivative) and finally transformed
back to the spatial domain with a sine transform (odd symmetric). For this to work
properly the image must be shifted left or up by one pixel (depending on whether
the x- or y-axis is odd symmetric) before the inverse transform can be applied.
(see example below).
The real Fourier transform functions are named <tt>fourierTransformReal??</tt>
where the questions marks stand for either <tt>E</tt> or <tt>O</tt> indicating
whether the x- and y-axis is to be transformed using even or odd symmetry.
The same functions can be used for both the forward and inverse transforms,
only the normalization changes. For signal processing, the following
normalization factors are most appropriate:
\code
forward inverse
------------------------------------------------------------
X even, Y even 1.0 4.0 * (w-1) * (h-1)
X even, Y odd -1.0 -4.0 * (w-1) * (h+1)
X odd, Y even -1.0 -4.0 * (w+1) * (h-1)
X odd, Y odd 1.0 4.0 * (w+1) * (h+1)
\endcode
where <tt>w</tt> and <tt>h</tt> denote the image width and height.
<b> Declarations:</b>
pass 2D array views:
\code
namespace vigra {
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void
fourierTransformRealEE(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm);
fourierTransformRealEO, fourierTransformRealOE, fourierTransformRealOO likewise
}
\endcode
pass \ref ImageIterators and \ref DataAccessors :
\code
namespace vigra {
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void
fourierTransformRealEE(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm);
fourierTransformRealEO, fourierTransformRealOE, fourierTransformRealOO likewise
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void
fourierTransformRealEE(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm);
fourierTransformRealEO, fourierTransformRealOE, fourierTransformRealOO likewise
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<vigra/fftw3.hxx\><br>
Namespace: vigra
\code
vigra::FImage spatial(width,height), fourier(width,height);
... // fill image with data
// forward cosine transform == reflective boundary conditions
fourierTransformRealEE(srcImageRange(spatial), destImage(fourier), (fftw_real)1.0);
// multiply with a first derivative of Gaussian in x-direction
for(int y = 0; y < height; ++y)
{
for(int x = 1; x < width; ++x)
{
double dx = x * M_PI / (width - 1);
double dy = y * M_PI / (height - 1);
fourier(x-1, y) = fourier(x, y) * dx * std::exp(-(dx*dx + dy*dy) * scale*scale / 2.0);
}
fourier(width-1, y) = 0.0;
}
// inverse transform -- odd symmetry in x-direction, even in y,
// due to symmetry of the filter
fourierTransformRealOE(srcImageRange(fourier), destImage(spatial),
(fftw_real)-4.0 * (width+1) * (height-1));
\endcode
*/
doxygen_overloaded_function(template <...> void fourierTransformReal)
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEE(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm)
{
fourierTransformRealEE(src.first, src.second, src.third,
dest.first, dest.second, norm);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEE(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_REDFT00, FFTW_REDFT00);
}
template <class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEE(
FFTWRealImage::const_traverser sul,
FFTWRealImage::const_traverser slr,
FFTWRealImage::Accessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
// test for right memory layout (fftw expects a width*height fftw_real array)
if (&(*(sul + Diff2D(w, 0))) == &(*(sul + Diff2D(0, 1))))
fourierTransformRealImpl(sul, slr, dul, dest,
norm, FFTW_REDFT00, FFTW_REDFT00);
else
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_REDFT00, FFTW_REDFT00);
}
/********************************************************************/
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOE(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm)
{
fourierTransformRealOE(src.first, src.second, src.third,
dest.first, dest.second, norm);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOE(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_RODFT00, FFTW_REDFT00);
}
template <class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOE(
FFTWRealImage::const_traverser sul,
FFTWRealImage::const_traverser slr,
FFTWRealImage::Accessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
// test for right memory layout (fftw expects a width*height fftw_real array)
if (&(*(sul + Diff2D(w, 0))) == &(*(sul + Diff2D(0, 1))))
fourierTransformRealImpl(sul, slr, dul, dest,
norm, FFTW_RODFT00, FFTW_REDFT00);
else
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_RODFT00, FFTW_REDFT00);
}
/********************************************************************/
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEO(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm)
{
fourierTransformRealEO(src.first, src.second, src.third,
dest.first, dest.second, norm);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEO(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_REDFT00, FFTW_RODFT00);
}
template <class DestTraverser, class DestAccessor>
inline void
fourierTransformRealEO(
FFTWRealImage::const_traverser sul,
FFTWRealImage::const_traverser slr,
FFTWRealImage::Accessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
// test for right memory layout (fftw expects a width*height fftw_real array)
if (&(*(sul + Diff2D(w, 0))) == &(*(sul + Diff2D(0, 1))))
fourierTransformRealImpl(sul, slr, dul, dest,
norm, FFTW_REDFT00, FFTW_RODFT00);
else
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_REDFT00, FFTW_RODFT00);
}
/********************************************************************/
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOO(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm)
{
fourierTransformRealOO(src.first, src.second, src.third,
dest.first, dest.second, norm);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOO(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_RODFT00, FFTW_RODFT00);
}
template <class DestTraverser, class DestAccessor>
inline void
fourierTransformRealOO(
FFTWRealImage::const_traverser sul,
FFTWRealImage::const_traverser slr,
FFTWRealImage::Accessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
// test for right memory layout (fftw expects a width*height fftw_real array)
if (&(*(sul + Diff2D(w, 0))) == &(*(sul + Diff2D(0, 1))))
fourierTransformRealImpl(sul, slr, dul, dest,
norm, FFTW_RODFT00, FFTW_RODFT00);
else
fourierTransformRealWorkImageImpl(sul, slr, src, dul, dest,
norm, FFTW_RODFT00, FFTW_RODFT00);
}
/*******************************************************************/
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void
fourierTransformRealWorkImageImpl(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest,
fftw_real norm, fftw_r2r_kind kindx, fftw_r2r_kind kindy)
{
FFTWRealImage workImage(slr - sul);
copyImage(srcIterRange(sul, slr, src), destImage(workImage));
FFTWRealImage const & cworkImage = workImage;
fourierTransformRealImpl(cworkImage.upperLeft(), cworkImage.lowerRight(),
dul, dest, norm, kindx, kindy);
}
template <class DestTraverser, class DestAccessor>
void
fourierTransformRealImpl(
FFTWRealImage::const_traverser sul,
FFTWRealImage::const_traverser slr,
DestTraverser dul, DestAccessor dest,
fftw_real norm, fftw_r2r_kind kindx, fftw_r2r_kind kindy)
{
int w = slr.x - sul.x;
int h = slr.y - sul.y;
BasicImage<fftw_real> res(w, h);
fftw_plan plan = fftw_plan_r2r_2d(h, w,
(fftw_real *)&(*sul), (fftw_real *)res.begin(),
kindy, kindx, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
if(norm != 1.0)
transformImage(srcImageRange(res), destIter(dul, dest),
std::bind1st(std::multiplies<fftw_real>(), 1.0 / norm));
else
copyImage(srcImageRange(res), destIter(dul, dest));
}
//@}
} // namespace vigra
#endif // VIGRA_FFTW3_HXX
|