[
  {
    "path": ".gitignore",
    "content": "*.asv"
  },
  {
    "path": "LICENSE.md",
    "content": "#LICENSE\nBy exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this license (\"License\"). To the extent this License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.\n\n##Section 1 – Definitions.\na.\t**Adapted Material** means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. \n\nb.\t**Adapter's License** means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this License.\n\nc.\t**Copyright and Similar Rights** means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.\n\nd.\t**Effective Technological Measures** means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.\n\ne.\t**Exceptions and Limitations** means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.\n\nf.\t**Licensed Material** means the software code and associated literature to which the Licensor applied this License.\n\ng.\t**Licensed Rights** means the rights granted to You subject to the terms and conditions of this License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.\n\nh.\t**Licensor** means, jointly and severally: \n\n  1.\tCarmel Haifa University Economic Corporation Ltd., of Haifa, Israel, its successors or assigns; and\n\t\n  2.\tRamot at Tel Aviv University Ltd., of Tel Aviv, Israel, its successors or assigns.\n  \ni.\tNon Commercial means intended solely for research purposes and not intended for or directed towards commercial advantage or monetary compensation. For purposes of this License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is Non Commercial provided there is no payment of monetary compensation in connection with the exchange.\n\nj.\tShare means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.\n\nk.\tSui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.\n\nl.\tYou means the individual or entity exercising the Licensed Rights under this License. Your has a corresponding meaning.\n\n##Section 2 – Scope.\n\na. **License grant.**\n\n  1.\tSubject to the terms and conditions of this License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:\n\n    A.\treproduce and Share the Licensed Material, in whole or in part, for Non Commercial purposes only; and\n\n    B.\tproduce, reproduce, and Share Adapted Material for Non Commercial purposes only.\n  2.\t*Exceptions and Limitations*. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this License does not apply, and You do not need to comply with its terms and conditions.\n  3.\t*Term*. The term of this License is specified in Section 6(a).\n  4.\t*Media and formats; technical modifications allowed*. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.\n  5.\t*Downstream recipients*.\n    A.\t*Offer from the Licensor – Licensed Material*. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this License.\n    B.\t*Additional offer from the Licensor – Adapted Material*. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.\n    C.\t*No downstream restrictions*. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.\n  6.\t*No endorsement*. Nothing in this License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).\n  \nb.\tOther rights.\n\n  1.\tMoral rights, such as the right of integrity, are not licensed under this License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.\n  2.\tPatent and trademark rights are not licensed under this License.\n  3.\tTo the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for Non Commercial purposes.\n\n##Section 3 – License Conditions.\nYour exercise of the Licensed Rights is expressly made subject to the following conditions.\n\na.\t**Attribution**.\n\n  1.\tIf You Share the Licensed Material (including in modified form), You must:\n  \n    A.\tretain the following if it is supplied by the Licensor with the Licensed Material:\n\n      i.\tidentification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor;\n\n      ii.\ta copyright notice;\n\n      iii.\ta notice that refers to this License;\n\n      iv.\ta notice that refers to the disclaimer of warranties;\n\n      v.\ta URI or hyperlink to the Licensed Material to the extent reasonably practicable;\n\n    B.\tindicate if You modified the Licensed Material and retain an indication of any previous modifications; and\n\n    C.\tindicate the Licensed Material is licensed under this License, and include the text of, or the URI or hyperlink to, this License.\n\n  2.\tYou may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.\n\n  3.\tIf requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.\n  \nb.\t**Share Alike**.\n\nIn addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.\n\n  1.\tThe Adapter’s License You apply must have the same conditions as this License.\n  2.\tYou must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.\n  3.\tYou may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.\n  \n##Section 4 – Sui Generis Database Rights.\nWhere the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:\n\na.\tfor the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for Non Commercial purposes only;\n\nb.\tif You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and\n\nc.\tYou must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.\nFor the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this License where the Licensed Rights include other Copyright and Similar Rights.\n\n##Section 5 – Disclaimer of Warranties and Limitation of Liability.\na.\t**Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.**\n\nb.\t**To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.**\n\nc.\tThe disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.\n\n##Section 6 – Term and Termination.\na.\tThis License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this License, then Your rights under this License terminate automatically.\n\nb.\tWhere Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:\n\n  1.\tautomatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or\n  2.\tupon express reinstatement by the Licensor.\n  \nFor the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this License.\n\nc.\tFor the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this License.\n\nd.\tSections 1, 5, 6, 7, and 8 survive termination of this License.\n\n##Section 7 – Other Terms and Conditions.\na.\tThe Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.\n\nb.\tAny arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this License.\n\n##Section 8 – Interpretation.\na.\tFor the avoidance of doubt, this License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this License.\n\nb.\tTo the extent possible, if any provision of this License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this License without affecting the enforceability of the remaining terms and conditions.\n\nc.\tNo term or condition of this License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.\n\nd.\tNothing in this License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.\n\n"
  },
  {
    "path": "README.md",
    "content": "# Non-Local Image Dehazing\n\n<img height=\"285px\" width=\"200px\" align=\"right\" src=\"http://www.eng.tau.ac.il/~berman/images/cityscape_half.jpg\">\n\nThis is the source code implementing the non-local single image dehazing algorithm described in the papers:\n\n[Non-Local Image Dehazing. Berman, D. and Treibitz, T. and Avidan S., CVPR2016](https://www.eng.tau.ac.il/~berman/NonLocalDehazing/NonLocalDehazing_CVPR2016.pdf)\n\n[Air-light Estimation using Haze-Lines. Berman, D. and Treibitz, T. and Avidan S., ICCP2017](https://www.eng.tau.ac.il/~berman/NonLocalDehazing/AirlightEstimation_ICCP2017.pdf)\n\nIf you use this code, please cite the appropriate paper.\n\n#### bibtex\n\n>    @inproceedings{NonLocalImageDehazing,    \n>      title={Non-Local Image Dehazing},    \n>      author={Berman, D. and Treibitz, T. and Avidan, S.},    \n>      booktitle={IEEE Conf. CVPR},    \n>      year={2016},\n>    }\n>\n>    @inproceedings{AirlightEstimation,    \n>      title={Air-light Estimation Using Haze-Lines},    \n>      author={Berman, D. and Treibitz, T. and Avidan, S.},    \n>      booktitle={IEEE Conf. ICCP},    \n>      year={2017},\n>    }\n\n\n\n\n## Getting Started\n\n### System Requirements:\nThe code requires MATLAB, and was tested on windows.\n\n### Demo\n1. Change MATLAB's directory to the folder the code was extracted to.\n2. Run the file demo_non_local_dehazing.m in order to see the algorithm's\nperfomance on the attached images.\n\n### Dehazing other images\nEach image in the demo is accompanied by a text file containing parameters. These value were taken from the [result pages of the paper: \"Dehazing using Color-Lines\"](http://www.cs.huji.ac.il/~raananf/projects/dehaze_cl/results/).\n\nThe gamma value is required since the image formation model applies to the linear images, where each pixel's value is directly related to the number of photons received at that location on the sensor. \nA non-linear tone-mapping is applied in camera and most of the images we see are not linear. The gamma value approximates the inverse mapping of the pixels' values to linear.\n\nDespite that, **for new images, I recommend trying gamma=1 first** (this is the default). It often works even though it is not physically accurate.\n\n\n## Authors\nDana Berman, *danamena@post.tau.ac.il*\n\n\n## License\n \nThe software code of the non-local image dehazing algorithm is provided for non-commercial use under the attached [LICENSE.md](LICENSE.md)\n"
  },
  {
    "path": "TR1000.txt",
    "content": "   -0.9425   -0.2041   -0.2648\n    0.5224    0.7539    0.3985\n    0.5528    0.0429   -0.8322\n    0.6499    0.0243   -0.7596\n    0.6986    0.1199   -0.7054\n   -0.0303    0.9929   -0.1151\n    0.8482    0.0839   -0.5230\n    0.9526    0.0586   -0.2985\n   -0.2253   -0.1544   -0.9620\n    0.9065    0.0667   -0.4168\n    0.9313   -0.0364   -0.3625\n    0.9274    0.2528   -0.2755\n    0.9601    0.1575   -0.2311\n    0.9827    0.0588   -0.1759\n    0.4552    0.2145    0.8641\n    0.0245    0.6354    0.7718\n    0.9838    0.1794    0.0003\n    0.9944    0.0840    0.0637\n    0.1522    0.2044   -0.9670\n    0.9784    0.1048    0.1784\n    0.1846    0.8742   -0.4490\n    0.9353    0.0254    0.3528\n    0.8863    0.0396    0.4613\n   -0.4683    0.2315    0.8527\n    0.8514   -0.0566    0.5215\n    0.8241    0.0513    0.5642\n    0.7803   -0.0439    0.6238\n    0.0253   -0.0740    0.9969\n    0.6571    0.0871    0.7487\n    0.5676    0.1304    0.8129\n    0.4011    0.0242    0.9157\n   -0.1442    0.9656    0.2165\n    0.3730   -0.9271   -0.0358\n    0.3781    0.2043   -0.9030\n    0.5067    0.1507   -0.8489\n    0.6084    0.1352   -0.7820\n    0.6523    0.2322   -0.7215\n    0.7786    0.1026   -0.6190\n    0.7782    0.4864   -0.3974\n    0.8083    0.1983   -0.5544\n    0.8251    0.2929   -0.4831\n    0.9227    0.1605   -0.3506\n   -0.1930   -0.2652   -0.9447\n    0.2991   -0.7068   -0.6410\n    0.9420    0.2887   -0.1714\n    0.9597    0.2731   -0.0659\n    0.9245    0.3775   -0.0524\n    0.9124    0.4034    0.0693\n    0.8871    0.4228    0.1851\n    0.9539    0.2970    0.0444\n    0.9485    0.2208    0.2270\n    0.9358    0.3163    0.1556\n    0.9052    0.3318    0.2656\n    0.9110    0.2363    0.3379\n    0.8596    0.2498    0.4457\n    0.8511    0.1507    0.5028\n    0.5268   -0.1617   -0.8345\n    0.4062   -0.8690   -0.2825\n    0.7849    0.1609    0.5984\n    0.6297    0.2089    0.7482\n   -0.4992   -0.5457    0.6731\n    0.4784    0.1069    0.8716\n    0.3721    0.1418    0.9173\n    0.2940    0.0590    0.9540\n    0.1776    0.0098   -0.9841\n    0.4599    0.2507   -0.8518\n    0.5606    0.2450   -0.7910\n    0.8616    0.3439    0.3733\n    0.5910    0.3426   -0.7303\n    0.6792    0.3292   -0.6559\n    0.6980    0.4219   -0.5786\n    0.7573    0.3130   -0.5732\n    0.7092    0.5082   -0.4887\n    0.8347    0.3809   -0.3977\n    0.8390    0.4548   -0.2988\n    0.7755    0.5572   -0.2970\n    0.8357    0.5103   -0.2028\n    0.8797    0.4629   -0.1087\n    0.7105    0.5858   -0.3899\n    0.8213    0.5628   -0.0929\n    0.8731    0.4875    0.0001\n    0.8536    0.5093    0.1093\n    0.8232    0.5241    0.2183\n    0.7814    0.5319    0.3263\n    0.8495    0.4357    0.2975\n   -0.2468    0.1027    0.9636\n    0.7977    0.4449    0.4071\n    0.1627   -0.2310    0.9593\n    0.7389    0.3623    0.5681\n    0.7948    0.2599    0.5484\n    0.6632    0.3722    0.6494\n    0.5757    0.4340    0.6929\n    0.5132    0.3740    0.7725\n    0.5376    0.2555    0.8036\n    0.3492    0.2587    0.9006\n    0.2158   -0.0260    0.9761\n    0.2310    0.1126   -0.9664\n    0.2889    0.3200   -0.9023\n    0.3872    0.3360   -0.8586\n    0.4929    0.3498   -0.7966\n    0.6143    0.4353   -0.6581\n    0.4626    0.6167   -0.6369\n   -0.6389    0.0488   -0.7677\n    0.6308    0.5228   -0.5734\n    0.8405   -0.5070    0.1908\n    0.6358    0.6762   -0.3721\n    0.7049    0.6511   -0.2813\n    0.2048   -0.4480    0.8703\n    0.7686    0.6112   -0.1887\n    0.6725    0.7383   -0.0519\n    0.7523    0.6547   -0.0744\n    0.8087    0.5879    0.0188\n    0.7329    0.6792    0.0388\n    0.7873   -0.6015    0.1353\n    0.5690    0.7715    0.2847\n   -0.1491   -0.2403    0.9592\n    0.7501    0.6177    0.2361\n   -0.7850    0.5957    0.1702\n    0.6162    0.6969    0.3670\n    0.7255    0.5343    0.4339\n    0.6520    0.6136    0.4454\n    0.7248    0.4607    0.5123\n    0.6498    0.4717    0.5960\n    0.4806    0.4880    0.7286\n   -0.6173    0.7753    0.1334\n    0.4338    0.3253    0.8403\n    0.2405    0.2983    0.9237\n    0.2661    0.1811    0.9468\n    0.2703    0.2162   -0.9382\n    0.4466    0.8881    0.1087\n    0.3099    0.4290   -0.8485\n    0.3354    0.5265   -0.7812\n    0.4417    0.5321   -0.7223\n   -0.7669   -0.1000   -0.6339\n    0.5554    0.6141   -0.5607\n   -0.7876    0.4996   -0.3608\n    0.5594    0.6906   -0.4585\n    0.6260    0.7356   -0.2588\n    0.7031    0.6952    0.1496\n    0.4621   -0.1997    0.8640\n    0.5381    0.8103   -0.2322\n    0.6084    0.7806   -0.1430\n    0.5820    0.8127   -0.0279\n    0.6463    0.7606    0.0617\n    0.5501    0.8307    0.0855\n    0.5624   -0.2132    0.7989\n    0.6640    0.7017    0.2585\n    0.7224   -0.6868    0.0807\n   -0.0298    0.3762   -0.9261\n    0.5645    0.6711    0.4806\n    0.4687    0.7228    0.5077\n    0.6256    0.5636    0.5394\n    0.5548    0.5351    0.6371\n   -0.4648    0.8330    0.3002\n    0.4522    0.5876    0.6709\n    0.3754    0.5376    0.7550\n    0.4077    0.4334    0.8037\n    0.0966    0.4429    0.8914\n   -0.0566   -0.9558    0.2885\n    0.1077    0.0948   -0.9897\n    0.2017    0.4148   -0.8873\n    0.5197    0.4436   -0.7302\n    0.2489    0.6064   -0.7552\n    0.2711    0.6883   -0.6729\n    0.3592    0.6144   -0.7025\n    0.3791    0.6935   -0.6126\n    0.2903    0.7607   -0.5805\n    0.3883    0.7669   -0.5109\n    0.3818    0.8329   -0.4007\n    0.3598    0.8862   -0.2918\n    0.4628    0.8271   -0.3188\n   -0.1835    0.3060    0.9342\n    0.4391    0.8744   -0.2065\n    0.5134    0.8500   -0.1180\n    0.4820    0.8762   -0.0044\n    0.4840   -0.3078    0.8191\n    0.1280    0.3348    0.9335\n    0.5120    0.8358    0.1982\n    0.4699    0.8258    0.3118\n    0.3654    0.8692    0.3332\n    0.4230    0.8014    0.4230\n    0.5220    0.6279    0.5773\n    0.3662    0.7653    0.5294\n    0.2580    0.7980    0.5447\n    0.3434    0.6325    0.6943\n    0.4017   -0.7699    0.4959\n    0.2640    0.5758    0.7738\n    0.2969    0.4765    0.8275\n    0.2130    0.4087    0.8875\n    0.1571    0.2192    0.9630\n    0.0338    0.1872   -0.9817\n    0.1778    0.3110   -0.9336\n    0.6041   -0.7333   -0.3119\n    0.1352    0.5942   -0.7929\n   -0.5395   -0.4109   -0.7349\n    0.1568    0.6791   -0.7171\n    0.1087   -0.6415   -0.7594\n    0.1768    0.7534   -0.6333\n    0.0925   -0.5496   -0.8303\n    0.2947    0.8282   -0.4767\n   -0.7825    0.1475   -0.6049\n    0.2749    0.8865   -0.3722\n    0.7211   -0.3034   -0.6228\n    0.3303    0.9261   -0.1825\n    0.3376    0.9323    0.1298\n    0.2606    0.9647    0.0375\n    0.4078    0.8857    0.2218\n    0.2982    0.9237    0.2406\n   -0.2396    0.4107   -0.8797\n    0.8711    0.1783   -0.4575\n    0.2562    0.9013    0.3492\n    0.2108    0.8654    0.4546\n    0.3189    0.8386    0.4417\n    0.1450    0.8198    0.5540\n    0.7000   -0.5315    0.4770\n    0.3049    0.7191    0.6244\n    0.2295    0.6664    0.7094\n    0.1898    0.7478    0.6362\n    0.1472    0.6066    0.7813\n    0.0623    0.5436    0.8370\n    0.0763    0.1349    0.9879\n    0.0624    0.2954   -0.9533\n    0.0871    0.4001   -0.9123\n    0.3691   -0.8047   -0.4650\n   -0.0480    0.7293   -0.6825\n   -0.6396    0.7299    0.2411\n    0.0646    0.7522   -0.6557\n    0.8438   -0.4136   -0.3420\n    0.0872    0.8233   -0.5609\n    0.0781    0.8946   -0.4400\n    0.1588    0.9243   -0.3471\n    0.0424    0.9421   -0.3328\n    0.1262    0.9618   -0.2430\n    0.2466    0.9318   -0.2665\n    0.2133    0.9639   -0.1597\n    0.0913    0.9865   -0.1361\n    0.2965    0.9523   -0.0727\n   -0.0677    0.9977   -0.0047\n    0.1780    0.9827   -0.0517\n    0.7488    0.0605    0.6601\n    0.2231    0.9636    0.1471\n    0.1033    0.9811    0.1636\n    0.1427    0.9218    0.3604\n    0.0997    0.8810    0.4625\n    0.0641    0.9612    0.2682\n    0.0694    0.7668    0.6382\n   -0.0169    0.7166    0.6972\n    0.1103    0.6919    0.7135\n   -0.0998    0.6557    0.7484\n   -0.0584    0.5691    0.8202\n   -0.0211    0.4718    0.8815\n    0.0124    0.3659    0.9306\n    0.0450    0.2541    0.9661\n   -0.0551    0.2675   -0.9620\n   -0.0040    0.4795   -0.8775\n   -0.0673    0.6417   -0.7640\n   -0.6821    0.7297    0.0471\n   -0.1518    0.7000   -0.6979\n   -0.0348    0.8001   -0.5989\n    0.6401   -0.2910   -0.7110\n   -0.1488    0.7913   -0.5930\n   -0.1151    0.8558   -0.5043\n   -0.0421    0.9104   -0.4115\n   -0.1567    0.9040   -0.3978\n   -0.1948    0.9369   -0.2904\n   -0.1145    0.9729   -0.2008\n   -0.1515    0.9843   -0.0910\n   -0.4692    0.0630   -0.8808\n    0.4747    0.6953   -0.5396\n   -0.1885    0.9819    0.0205\n   -0.1057    0.9887    0.1060\n    0.0169    0.9965    0.0814\n   -0.1837    0.9266    0.3282\n   -0.0634    0.9527    0.2971\n   -0.1039    0.9096    0.4023\n   -0.0142    0.8852    0.4651\n    0.0264    0.8309    0.5557\n   -0.1031    0.8475    0.5207\n    0.2068   -0.6779   -0.7054\n   -0.0618    0.7868    0.6141\n   -0.1801    0.5848    0.7909\n   -0.1393    0.4940    0.8583\n   -0.8438   -0.4630    0.2714\n   -0.0364    0.1688    0.9850\n   -0.1683    0.2374   -0.9567\n   -0.1216    0.4501   -0.8847\n   -0.0947    0.5487   -0.8306\n   -0.1829    0.6088   -0.7720\n   -0.2701    0.6536   -0.7070\n   -0.2340    0.7372   -0.6338\n   -0.2850    0.7855   -0.5493\n   -0.2225    0.8469   -0.4830\n   -0.3395    0.8249   -0.4521\n   -0.2707    0.8862   -0.3760\n   -0.3087    0.9128   -0.2675\n   -0.2318    0.9559   -0.1801\n   -0.3451    0.9257   -0.1548\n    0.7136    0.2696    0.6466\n   -0.2687    0.9609   -0.0675\n   -0.3047    0.9513    0.0460\n   -0.4148    0.9067    0.0758\n   -0.2251    0.9653    0.1326\n   -0.2586    0.9338    0.2473\n   -0.3581    0.8912    0.2785\n   -0.1636   -0.1226    0.9789\n   -0.1991    0.8678    0.4554\n   -0.2778    0.8831    0.3781\n    0.4746    0.7669   -0.4320\n   -0.2832    0.8148    0.5058\n   -0.1437    0.7314    0.6667\n    0.9489    0.1232    0.2906\n   -0.2233    0.6642    0.7134\n    0.9079   -0.0710    0.4131\n   -0.1030    0.3920    0.9142\n   -0.2626    0.2148    0.9407\n   -0.0787    0.1501   -0.9855\n   -0.1468    0.3464   -0.9265\n   -0.2126    0.5126   -0.8319\n   -0.3017    0.5626   -0.7697\n    0.7844    0.6069    0.1284\n   -0.9995    0.0320    0.0087\n   -0.3459    0.7023   -0.6222\n   -0.4518    0.6594   -0.6009\n   -0.3995    0.7489   -0.5287\n   -0.6044    0.6423   -0.4713\n   -0.3851    0.8548   -0.3480\n   -0.4935    0.8081   -0.3216\n   -0.5209    0.8268   -0.2124\n   -0.4186    0.8759   -0.2399\n   -0.4534    0.8824   -0.1258\n   -0.3813    0.9236   -0.0401\n    0.8824    0.2712   -0.3845\n   -0.4876    0.8730   -0.0091\n   -0.5171    0.8490    0.1084\n   -0.3372    0.9276    0.1607\n   -0.0030    0.8608   -0.5089\n   -0.4804    0.7781    0.4048\n   -0.3848    0.7901    0.4771\n   -0.3625    0.7348    0.5733\n   -0.9911   -0.0428    0.1264\n   -0.2609    0.7375    0.6229\n   -0.8758    0.0725    0.4772\n   -0.3400    0.6627    0.6673\n   -0.2590    0.5067    0.8223\n   -0.2188    0.4123    0.8844\n   -0.4272    0.0449    0.9030\n   -0.1884    0.1246   -0.9742\n   -0.2628    0.3033   -0.9159\n   -0.3299    0.4643   -0.8220\n   -0.4140    0.5157   -0.7501\n   -0.5188    0.4615   -0.7196\n   -0.4888    0.5637   -0.6658\n   -0.5520    0.6068   -0.5719\n   -0.5055    0.7006   -0.5036\n   -0.5509    0.7323   -0.4002\n   -0.5957    0.7486   -0.2910\n   -0.6453    0.6707   -0.3657\n   -0.8289   -0.0099    0.5594\n   -0.6927    0.6750   -0.2543\n   -0.6143    0.7677   -0.1827\n   -0.7910    0.5591   -0.2484\n   -0.5542    0.8269   -0.0952\n   -0.5859    0.8100    0.0240\n   -0.4533   -0.0577   -0.8895\n    0.6376    0.6041   -0.4781\n   -0.7078    0.6893    0.1545\n   -0.5447    0.8099    0.2176\n   -0.5635    0.7597    0.3244\n   -0.6487    0.6762    0.3492\n   -0.4726    0.7186    0.5102\n   -0.5540    0.6387    0.5340\n   -0.3829    0.6125   -0.6916\n   -0.4975    0.4979    0.7104\n   -0.4209    0.5839    0.6942\n   -0.3816    0.5073    0.7727\n   -0.3364    0.4241    0.8408\n   -0.2959    0.3258    0.8979\n    0.1060    0.0120    0.9943\n   -0.2818    0.1905   -0.9404\n    0.7198   -0.5001   -0.4814\n   -0.3544    0.3592   -0.8634\n   -0.4612    0.3020   -0.8343\n   -0.1872    0.7990    0.5714\n    0.0066    0.9744   -0.2246\n   -0.5881    0.5058   -0.6311\n   -0.6458    0.5454   -0.5344\n   -0.7332    0.4808   -0.4809\n   -0.6967    0.5739   -0.4305\n   -0.6806    0.4421   -0.5843\n   -0.7701    0.6184   -0.1565\n   -0.7310    0.5983   -0.3281\n   -0.6972    0.7015   -0.1480\n   -0.8101    0.5847   -0.0434\n   -0.7372    0.6743   -0.0438\n   -0.3344   -0.1017   -0.9369\n   -0.7666    0.6391    0.0624\n   -0.7412   -0.5639   -0.3643\n   -0.7217    0.6405    0.2625\n   -0.7238    0.5834    0.3684\n   -0.9242    0.3810   -0.0272\n   -0.6450    0.6148    0.4538\n   -0.6281    0.5486    0.5519\n    0.2056   -0.0969   -0.9738\n    0.6931    0.7010   -0.1678\n   -0.5647    0.4003    0.7217\n   -0.4563    0.4197    0.7846\n   -0.4489    0.7844   -0.4280\n   -0.4093    0.3354    0.8485\n   -0.1534    0.1925    0.9692\n    0.9774    0.1726   -0.1217\n   -0.3738    0.2477   -0.8938\n   -0.5558    0.2381   -0.7965\n   -0.4485    0.6571    0.6059\n   -0.5422    0.3535   -0.7623\n   -0.6160    0.4004   -0.6784\n   -0.7147    0.2203   -0.6638\n   -0.7610    0.3699   -0.5329\n   -0.8039    0.4078   -0.4329\n   -0.8970    0.2891   -0.3343\n   -0.9045    0.3564   -0.2344\n   -0.8549    0.3924   -0.3395\n   -0.2367   -0.5384   -0.8088\n   -0.8956    0.4231   -0.1376\n    0.4088    0.9077   -0.0944\n   -0.8734    0.4859   -0.0326\n   -0.8937    0.4420    0.0773\n   -0.8359    0.5446    0.0684\n   -0.9010    0.3919    0.1862\n   -0.8491    0.4971    0.1785\n   -0.8404    0.3770    0.3894\n   -0.7924    0.5433    0.2773\n   -0.8509    0.4406    0.2861\n   -0.7880    0.4832    0.3816\n   -0.7722    0.4150    0.4811\n   -0.7451    0.3405    0.5736\n   -0.6923    0.4484    0.5653\n   -0.6191    0.2914    0.7292\n    0.7103    0.1674    0.6838\n    0.2117   -0.8454    0.4905\n    0.3399   -0.8830    0.3237\n   -0.0055    0.0495    0.9988\n   -0.1348    0.0302   -0.9904\n   -0.2808    0.0672   -0.9574\n   -0.4711    0.1843   -0.8626\n   -0.6328    0.2882   -0.7187\n   -0.6413    0.1710   -0.7480\n   -0.7022    0.3322   -0.6297\n   -0.7815    0.2631   -0.5657\n    0.1412    0.9884    0.0565\n   -0.8376    0.3025   -0.4548\n   -0.8880    0.2086   -0.4098\n   -0.2688   -0.9286    0.2560\n   -0.9349    0.1658   -0.3137\n   -0.9410    0.3133   -0.1283\n   -0.9628    0.2694   -0.0203\n   -0.1435   -0.4813   -0.8647\n   -0.9390    0.3339    0.0824\n   -0.9716    0.2199    0.0875\n   -0.9058    0.0963   -0.4125\n   -0.9403    0.2819    0.1905\n   -0.8970    0.3316    0.2922\n   -0.7140    0.5188    0.4702\n   -0.8804    0.2655    0.3930\n   -0.8184    0.3052    0.4868\n   -0.8528    0.1904    0.4863\n   -0.7856    0.2265    0.5757\n   -0.7483   -0.2219   -0.6251\n   -0.6596    0.1761    0.7307\n   -0.5678    0.2059    0.7970\n   -0.4902    0.1264    0.8624\n   -0.3696    0.2330    0.8995\n   -0.6277   -0.7784    0.0020\n    0.0688   -0.9925   -0.1015\n   -0.3692    0.0059   -0.9293\n   -0.5520   -0.0031   -0.8338\n   -0.7153    0.0994   -0.6917\n    0.0547    0.9981   -0.0277\n   -0.7807    0.0274   -0.6243\n   -0.8422    0.1859   -0.5060\n   -0.8438    0.0767   -0.5312\n   -0.9700   -0.1392    0.1994\n    0.0243    0.9292    0.3687\n    0.3428    0.1021   -0.9338\n   -0.9698    0.1217   -0.2112\n   -0.9796    0.0023   -0.2008\n   -0.9726    0.1985   -0.1212\n   -0.9426    0.2438   -0.2284\n   -0.9881    0.1531   -0.0128\n   -0.9906    0.0993    0.0943\n   -0.9668    0.1671    0.1932\n   -0.9525    0.0954    0.2891\n    0.1838    0.9493    0.2551\n   -0.0779    0.9482   -0.3079\n   -0.9266    0.0310    0.3748\n   -0.8141    0.1087    0.5705\n   -0.7419    0.1432    0.6551\n   -0.6837    0.0592    0.7274\n   -0.5944    0.0936    0.7987\n   -0.5288    0.0106    0.8487\n    0.1947    0.8177   -0.5418\n   -0.1203    0.0842    0.9892\n   -0.2392   -0.0348   -0.9703\n   -0.5331   -0.1214   -0.8373\n   -0.6274   -0.0729   -0.7752\n   -0.7094   -0.0238   -0.7044\n   -0.2971   -0.8401    0.4539\n   -0.6603    0.3729    0.6519\n   -0.8314   -0.0490   -0.5535\n   -0.8868   -0.0000   -0.4622\n   -0.8782   -0.1168   -0.4637\n    0.2250    0.5151   -0.8271\n   -0.9284   -0.0423   -0.3691\n   -0.9590   -0.0857   -0.2702\n   -0.9849   -0.1664   -0.0485\n   -0.9949   -0.0415   -0.0921\n   -0.9967   -0.0784    0.0190\n    0.9727    0.2020    0.1144\n   -0.9371   -0.1745    0.3022\n   -0.9805    0.0459    0.1910\n   -0.9204   -0.2783    0.2745\n   -0.9306   -0.0793    0.3573\n   -0.9648   -0.0392    0.2600\n   -0.8851   -0.0446    0.4633\n   -0.8366   -0.1300    0.5322\n   -0.7741   -0.0963    0.6257\n   -0.7063   -0.1805    0.6845\n   -0.7017   -0.0616    0.7098\n   -0.6282   -0.1448    0.7645\n   -0.6198   -0.0262    0.7843\n   -0.3585    0.1286    0.9247\n   -0.3286    0.0095    0.9444\n    0.8513   -0.5228   -0.0450\n   -0.4221   -0.1687   -0.8907\n   -0.5033   -0.2328   -0.8322\n   -0.6043   -0.1916   -0.7734\n   -0.6916   -0.1479   -0.7070\n   -0.6676   -0.2657   -0.6955\n   -0.8182   -0.1718   -0.5486\n   -0.7756   -0.6312    0.0074\n   -0.6004    0.4779    0.6413\n   -0.8319   -0.3501   -0.4305\n   -0.3776    0.8432    0.3827\n   -0.8932   -0.2817   -0.3505\n   -0.9782   -0.1271   -0.1639\n   -0.9244   -0.3568   -0.1348\n   -0.9602   -0.2740   -0.0540\n   -0.9615   -0.2691    0.0556\n   -0.9266   -0.3759   -0.0130\n   -0.9027   -0.3726    0.2154\n    0.2015   -0.9477   -0.2474\n    0.1105   -0.9386   -0.3268\n   -0.8668   -0.3693    0.3352\n   -0.8844   -0.2638    0.3851\n   -0.8896   -0.1607    0.4275\n   -0.8336   -0.2439    0.4956\n    0.5379   -0.1063    0.8363\n   -0.7747   -0.2142    0.5950\n   -0.7018   -0.2963    0.6478\n   -0.6280   -0.2618    0.7329\n   -0.4426   -0.0642    0.8944\n    0.6113    0.7722    0.1734\n   -0.1982    0.0016    0.9802\n   -0.1339   -0.0907   -0.9868\n   -0.3793    0.1278   -0.9164\n   -0.1804   -0.8800    0.4394\n   -0.5759   -0.3033   -0.7592\n    0.7352    0.2167   -0.6424\n   -0.6361   -0.3771   -0.6732\n   -0.7958   -0.2903   -0.5314\n   -0.7210   -0.3377   -0.6051\n   -0.9307    0.2172    0.2944\n   -0.7612   -0.4045   -0.5069\n   -0.8583   -0.3969   -0.3252\n   -0.9143   -0.3224   -0.2452\n   -0.8131   -0.5043   -0.2908\n   -0.8751   -0.4339   -0.2143\n   -0.8841   -0.4579   -0.0937\n   -0.8714   -0.4668    0.1507\n   -0.3026    0.5880    0.7501\n   -0.7077   -0.7044   -0.0539\n   -0.3130   -0.2184   -0.9243\n   -0.8266   -0.5567    0.0824\n   -0.7736   -0.5440    0.3250\n   -0.8018   -0.4522    0.3907\n   -0.6672   -0.5077    0.5451\n   -0.8229   -0.3505    0.4473\n   -0.7503   -0.4324    0.5001\n   -0.7666   -0.3271    0.5525\n   -0.6882   -0.4058    0.6014\n   -0.6170   -0.3734    0.6928\n   -0.5370   -0.3379    0.7730\n   -0.5454   -0.2249    0.8074\n   -0.3614   -0.1311    0.9231\n    0.1862    0.0975    0.9777\n    0.8099   -0.5151   -0.2805\n   -0.2807   -0.3295   -0.9015\n   -0.4734   -0.3426   -0.8115\n   -0.3602   -0.3954   -0.8449\n   -0.4335   -0.4484   -0.7816\n   -0.5851   -0.4816   -0.6524\n   -0.6810   -0.4477   -0.5795\n   -0.6209   -0.5448   -0.5637\n   -0.7157   -0.5108   -0.4762\n   -0.7912   -0.4614   -0.4015\n   -0.6655   -0.6451   -0.3753\n   -0.7621   -0.5995   -0.2445\n   -0.8287   -0.5328   -0.1714\n   -0.7750   -0.6207   -0.1193\n   -0.8350   -0.5484   -0.0452\n   -0.8828   -0.4686    0.0328\n   -0.7045   -0.7067    0.0651\n   -0.8401    0.5232   -0.1429\n   -0.8082   -0.5522    0.2048\n   -0.7595   -0.6360    0.1368\n   -0.7332   -0.6300    0.2561\n   -0.7251   -0.5308    0.4387\n   -0.6918   -0.6209    0.3687\n   -0.6386   -0.6019    0.4795\n    0.1816    0.5116    0.8398\n   -0.5742   -0.5752    0.5825\n   -0.5987   -0.4782    0.6425\n   -0.4409    0.8767    0.1926\n   -0.4493   -0.2979    0.8423\n   -0.3440   -0.3610    0.8668\n   -0.4554   -0.1837    0.8711\n    0.7060    0.6205    0.3414\n   -0.6464    0.7605   -0.0609\n   -0.4609   -0.8136    0.3545\n   -0.3483   -0.5175   -0.7816\n   -0.4801   -0.5154   -0.7098\n    0.3855   -0.7280   -0.5670\n   -0.4433   -0.6686   -0.5970\n   -0.5190   -0.5817   -0.6263\n   -0.5484   -0.6422   -0.5355\n   -0.5706   -0.6948   -0.4377\n   -0.5131   -0.8117   -0.2790\n   -0.5910   -0.7350   -0.3325\n   -0.6851   -0.6748   -0.2745\n   -0.6104   -0.7600   -0.2233\n   -0.6443   -0.7063    0.2932\n   -0.7009   -0.6934   -0.1673\n   -0.5393   -0.8408   -0.0467\n   -0.6223   -0.7738    0.1186\n   -0.5425   -0.8367    0.0749\n    0.7420   -0.5628    0.3643\n   -0.6775   -0.7108    0.1891\n   -0.5568   -0.7671    0.3186\n   -0.5666    0.7014    0.4324\n   -0.8503    0.4630   -0.2501\n   -0.5432   -0.6640    0.5138\n   -0.4163   -0.5091    0.7533\n   -0.3917   -0.6049    0.6933\n   -0.3268   -0.4665    0.8219\n   -0.2322   -0.4163    0.8791\n   -0.3562   -0.2496    0.9005\n   -0.2583   -0.1983    0.9455\n   -0.0369   -0.0324   -0.9988\n   -0.1693   -0.3769   -0.9106\n   -0.2599   -0.4420   -0.8585\n   -0.4085   -0.5972   -0.6903\n   -0.3053   -0.6128   -0.7289\n   -0.3658   -0.7533   -0.5466\n   -0.9087    0.1493    0.3898\n   -0.4702   -0.7288   -0.4977\n   -0.3903   -0.8069   -0.4434\n    0.7702   -0.5864    0.2510\n   -0.4928   -0.7773   -0.3912\n   -0.4120   -0.8481   -0.3331\n   -0.5297   -0.8322   -0.1641\n   -0.4403    0.4121   -0.7977\n   -0.4436   -0.8906   -0.1009\n   -0.5405   -0.1069    0.8345\n   -0.4518   -0.8919    0.0188\n   -0.4301   -0.8760   -0.2182\n   -0.4708   -0.8469    0.2473\n   -0.3706   -0.9051    0.2085\n   -0.3700   -0.8702    0.3252\n   -0.5663   -0.7973    0.2086\n   -0.5071   -0.7436    0.4359\n    0.7099   -0.6764    0.1961\n   -0.4382   -0.7243    0.5323\n   -0.4713   -0.6390    0.6079\n   -0.3625   -0.6928    0.6234\n   -0.2775   -0.6581    0.6999\n   -0.3046   -0.5659    0.7661\n   -0.2131   -0.5183    0.8282\n   -0.2473   -0.3094    0.9182\n   -0.0222    0.9815    0.1900\n   -0.0758   -0.3089   -0.9481\n    0.5416    0.5314   -0.6514\n   -0.9916    0.0770   -0.1040\n   -0.1140   -0.5796   -0.8069\n   -0.1952   -0.6296   -0.7520\n   -0.2553   -0.7698   -0.5850\n    0.1120    0.5000   -0.8588\n   -0.1665   -0.8309   -0.5310\n   -0.2817   -0.8264   -0.4875\n   -0.2164   -0.9231   -0.3178\n   -0.3056   -0.8724   -0.3815\n   -0.3258   -0.9064   -0.2689\n   -0.1397   -0.9814   -0.1314\n   -0.3417   -0.9274   -0.1519\n    0.3688   -0.9256    0.0851\n   -0.3534   -0.9349   -0.0320\n   -0.7076    0.2605    0.6568\n   -0.2484   -0.9649   -0.0853\n   -0.2651   -0.9531    0.1462\n   -0.3643   -0.9269    0.0900\n   -0.2692   -0.8925    0.3620\n   -0.3948   -0.2837   -0.8738\n   -0.9503    0.0483   -0.3074\n   -0.3290   -0.7715    0.5445\n   -0.2137   -0.8165    0.5362\n   -0.2461   -0.7419    0.6237\n    0.9062    0.1385    0.3996\n   -0.1889   -0.6144    0.7661\n   -0.0981   -0.5588    0.8235\n   -0.1183   -0.4584    0.8808\n   -0.1353   -0.3521    0.9261\n    0.0475   -0.3508   -0.9352\n   -0.0508   -0.4132   -0.9092\n   -0.0245   -0.5115   -0.8589\n   -0.9516   -0.2559    0.1704\n   -0.1051   -0.6875   -0.7185\n   -0.2257   -0.7038   -0.6736\n   -0.1380   -0.7662   -0.6276\n   -0.0767   -0.8832   -0.4627\n    0.0175   -0.9175   -0.3974\n   -0.1933   -0.8830   -0.4278\n   -0.1029   -0.9276   -0.3592\n   -0.0098   -0.9567   -0.2909\n   -0.0292   -0.9840   -0.1756\n    0.8777   -0.0262   -0.4785\n   -0.2347   -0.9507   -0.2029\n   -0.1501   -0.9886   -0.0139\n    0.1662   -0.8336   -0.5267\n   -0.0405   -0.9975   -0.0578\n   -0.0508   -0.9834    0.1740\n    0.0519   -0.9679    0.2459\n   -0.1557   -0.9826    0.1017\n    0.0371   -0.9317    0.3613\n   -0.0723   -0.9124    0.4028\n    0.0139   -0.8808    0.4734\n   -0.0967   -0.8531    0.5127\n   -0.0126   -0.8151    0.5792\n   -0.1289   -0.7833    0.6082\n   -0.0434   -0.7389    0.6724\n   -0.0726   -0.6528    0.7541\n    0.0163   -0.5916    0.8061\n   -0.0223   -0.3890    0.9209\n   -0.0388   -0.2781    0.9598\n   -0.0018   -0.1375   -0.9905\n   -0.0077   -0.6069   -0.7947\n    0.0061   -0.6891   -0.7246\n   -0.0237   -0.7624   -0.6466\n   -0.0498   -0.8280   -0.5586\n    0.0725   -0.8041   -0.5900\n    0.0220    0.5772   -0.8163\n   -0.1002   -0.1994   -0.9748\n    0.0457   -0.8667   -0.4967\n    0.1397   -0.8925   -0.4288\n    0.2301   -0.9080   -0.3500\n    0.0824   -0.9724   -0.2184\n    0.1784   -0.9732   -0.1449\n    0.0652   -0.9978    0.0141\n   -0.1635   -0.9306    0.3275\n    0.1691   -0.9823    0.0811\n    0.0590   -0.9898    0.1300\n    0.1603   -0.9671    0.1976\n   -0.8609   -0.2341   -0.4517\n    0.1467   -0.9377    0.3149\n    0.1258   -0.8945    0.4290\n   -0.5201    0.3190    0.7923\n    0.0987   -0.8378    0.5370\n    0.1813   -0.7840    0.5937\n    0.0708   -0.7659    0.6390\n    0.1533   -0.7060    0.6914\n    0.0418   -0.6832    0.7290\n   -0.0040   -0.4935    0.8697\n    0.1100   -0.5226    0.8455\n   -0.0854   -0.0362    0.9957\n   -0.9573   -0.2404   -0.1603\n    0.0732   -0.4517   -0.8892\n    0.1894   -0.4854   -0.8535\n    0.2057   -0.5827   -0.7862\n    0.1020   -0.7311   -0.6746\n    0.1950   -0.7634   -0.6158\n    0.2848   -0.7876   -0.5464\n    0.9667   -0.2206    0.1300\n    0.2556   -0.8537   -0.4537\n    0.3069   -0.9196   -0.2455\n   -0.4356   -0.4065    0.8032\n   -0.9165   -0.1621   -0.3658\n    0.2811   -0.9530   -0.1128\n    0.2758   -0.9611    0.0160\n   -0.9243   -0.3671    0.1047\n    0.1762   -0.9838   -0.0338\n    0.2670   -0.9536    0.1392\n    0.2534   -0.9316    0.2604\n    0.3572   -0.9113    0.2049\n    0.2336   -0.2057   -0.9503\n   -0.0703    0.2818    0.9569\n    0.2356   -0.8949    0.3791\n    0.3205   -0.8390    0.4397\n    0.2950   -0.7839    0.5463\n    0.6090    0.3156    0.7276\n    0.2617   -0.7197    0.6431\n    0.2373   -0.6364    0.7340\n    0.3336   -0.5625    0.7565\n    0.1285   -0.6175    0.7760\n    0.0913   -0.4211    0.9024\n   -0.9823   -0.1656    0.0874\n    0.1409   -0.2755   -0.9509\n    0.1674   -0.3825   -0.9087\n    0.2825   -0.4170   -0.8639\n    0.3002   -0.5178   -0.8011\n    0.3053   -0.6157   -0.7264\n    0.4160    0.4393   -0.7962\n    0.3978   -0.6410   -0.6564\n    0.4836   -0.6581   -0.5771\n    0.3357   -0.8673   -0.3675\n    0.4483   -0.8108   -0.3764\n    0.3766   -0.9131   -0.1564\n    0.5231   -0.8049   -0.2802\n    0.4717   -0.8599   -0.1952\n    0.4709   -0.8785   -0.0807\n    0.5626   -0.8263   -0.0268\n    0.4680   -0.8831    0.0342\n   -0.2701   -0.0820    0.9593\n    0.6463   -0.7581   -0.0868\n    0.4592   -0.8755    0.1505\n    0.9705    0.0071    0.2409\n    0.4429   -0.8560    0.2666\n    0.4218   -0.8223    0.3820\n    0.6836   -0.0874   -0.7246\n    0.5943   -0.7131    0.3719\n    0.4158    0.6789    0.6051\n    0.4723   -0.6849    0.5548\n    0.3433   -0.6455    0.6823\n    0.4402   -0.6000    0.6679\n   -0.4640   -0.8747    0.1404\n    0.2225   -0.5455    0.8080\n    0.1846   -0.3431    0.9210\n    0.0725   -0.3126    0.9471\n    0.1134   -0.1624   -0.9802\n    0.2599   -0.3125   -0.9137\n    0.3893   -0.4438   -0.8072\n    0.3995   -0.5460   -0.7364\n    0.4907   -0.5678   -0.6610\n    0.5750   -0.5816   -0.5754\n    0.5633   -0.6654   -0.4898\n    0.4649   -0.7401   -0.4860\n    0.6381   -0.6607   -0.3954\n    0.5379   -0.7421   -0.4001\n    0.6284   -0.7501   -0.2060\n   -0.0006    0.0683   -0.9977\n    0.5603   -0.8152   -0.1468\n    0.7129   -0.6832   -0.1581\n    0.7250   -0.6877   -0.0371\n    0.5569   -0.8256    0.0907\n    0.6465   -0.7623    0.0301\n   -0.6025   -0.6878    0.4049\n    0.6377   -0.7564    0.1456\n    0.5437   -0.8134    0.2069\n    0.5226   -0.7896    0.3217\n    0.6883   -0.6565    0.3087\n    0.4963   -0.7508    0.4358\n    0.5605   -0.6724    0.4834\n    0.6172   -0.5855    0.5256\n    0.5299   -0.5994    0.5999\n    0.4262   -0.5026    0.7521\n    0.3171   -0.4712    0.8230\n    0.2960   -0.3699    0.8806\n    0.3254    0.3706    0.8700\n    0.2734   -0.2613    0.9257\n    0.0227   -0.2456   -0.9691\n    0.3466   -0.2298   -0.9094\n    0.3707   -0.3385   -0.8648\n    0.4852   -0.4675   -0.7389\n    0.5656   -0.3816   -0.7310\n    0.5722   -0.4854   -0.6611\n    0.6507   -0.4961   -0.5748\n   -0.6469   -0.5997   -0.4710\n    0.6536   -0.5861   -0.4788\n    0.7227   -0.5897   -0.3604\n    0.6922   -0.6657   -0.2786\n    0.5536    0.7568   -0.3475\n    0.7668   -0.6005   -0.2270\n   -0.3374   -0.6887   -0.6418\n    0.7870   -0.6081   -0.1043\n    0.7939   -0.6078    0.0170\n    0.8520   -0.5182    0.0741\n   -0.0560   -0.1604    0.9855\n    0.6203   -0.7401    0.2597\n   -0.5210   -0.4451    0.7283\n   -0.3986   -0.8014    0.4459\n   -0.6233   -0.7740   -0.1118\n    0.6569   -0.6272    0.4184\n    0.6161   -0.5079    0.6020\n    0.8124   -0.0097   -0.5830\n    0.8995   -0.3259   -0.2910\n    0.5899   -0.4194    0.6900\n    0.4033   -0.3977    0.8241\n    0.3820   -0.2891    0.8778\n    0.3559   -0.1772    0.9176\n    0.0528   -0.1969    0.9790\n    0.3185   -0.1174   -0.9406\n    0.4526   -0.2528   -0.8551\n    0.4730   -0.3616   -0.8034\n    0.7257   -0.4040   -0.5570\n    0.5507   -0.2732   -0.7887\n    0.6498   -0.3962   -0.6487\n   -0.5597    0.1185   -0.8202\n    0.8513   -0.2198   -0.4765\n    0.5208   -0.5129    0.6824\n    0.7924   -0.4048   -0.4563\n    0.0445    0.6696   -0.7414\n    0.7757   -0.4992   -0.3861\n    0.8755   -0.4266   -0.2268\n   -0.1600   -0.7031    0.6929\n    0.8962   -0.4305   -0.1073\n    0.8379   -0.5206   -0.1639\n    0.9033   -0.4288    0.0128\n    0.3760   -0.7087    0.5969\n    0.8979   -0.4199    0.1319\n    0.8503   -0.3829    0.3610\n    0.8178   -0.4883    0.3046\n    0.5998    0.0042    0.8001\n    0.7826   -0.4640    0.4151\n    0.7314   -0.4393    0.5217\n    0.7479   -0.3310    0.5753\n    0.6734   -0.4159    0.6112\n    0.6680   -0.3180    0.6728\n    0.5797   -0.3178    0.7503\n    0.4998   -0.4132    0.7612\n   -0.5288    0.5726    0.6265\n    0.4338   -0.0891    0.8966\n    0.2458   -0.1465    0.9582\n    0.0798   -0.0428   -0.9959\n    0.4256   -0.1407   -0.8939\n    0.9894   -0.1356   -0.0516\n    0.3743    0.9271    0.0177\n    0.6213   -0.1816   -0.7622\n    0.7071   -0.1975   -0.6790\n    0.7839   -0.2094   -0.5845\n    0.7935   -0.3097   -0.5239\n    0.8974   -0.1292   -0.4220\n    0.9054   -0.2280   -0.3581\n    0.8548   -0.3171   -0.4108\n    0.9433   -0.2341   -0.2352\n    0.9269   -0.3341   -0.1711\n    0.9649   -0.2374   -0.1122\n    0.8805   -0.4041    0.2479\n    0.9725   -0.2328    0.0104\n    0.9411   -0.3345   -0.0494\n    0.9899   -0.1241    0.0687\n    0.9419   -0.3281    0.0716\n    0.4439    0.0755   -0.8929\n    0.9302   -0.3143    0.1898\n   -0.2588   -0.9654    0.0323\n    0.9053   -0.2956    0.3051\n    0.8057   -0.3593    0.4710\n    0.8132   -0.2509    0.5251\n    0.7396   -0.2305    0.6324\n    0.7213   -0.1275    0.6807\n    0.6542   -0.2159    0.7249\n   -0.7617    0.0246    0.6475\n    0.5081    0.0016    0.8613\n    0.9005    0.3921   -0.1881\n    0.2894   -0.0006   -0.9572\n    0.3935   -0.0238   -0.9190\n    0.4940   -0.0464   -0.8682\n    0.5929   -0.0697   -0.8023\n    0.7363    0.0076   -0.6766\n    0.7649   -0.1030   -0.6358\n    0.8366   -0.1180   -0.5349\n    0.7713    0.4042   -0.4916\n    0.8043    0.3558    0.4760\n   -0.1240   -0.9609   -0.2477\n    0.9440   -0.1359   -0.3007\n    0.9701   -0.0408   -0.2393\n    0.9747   -0.1385   -0.1756\n    0.9928   -0.0379   -0.1140\n    0.9996   -0.0261    0.0061\n    0.9957    0.0727   -0.0575\n   -0.1601   -0.9633    0.2154\n    0.9919   -0.0126    0.1261\n    0.9762   -0.1091    0.1874\n    0.9473   -0.2038    0.2472\n    0.9144   -0.1837    0.3607\n    0.9491   -0.0894    0.3019\n    0.8665   -0.2742    0.4171\n    0.8670   -0.1637    0.4707\n    0.8020   -0.1479    0.5787\n    0.8877    0.3550   -0.2931\n    0.6933   -0.0221    0.7203\n    0.6313   -0.1092    0.7678\n   -0.0455   -0.9973    0.0585\n    0.3250   -0.0616    0.9437\n    0.1355   -0.1114    0.9845"
  },
  {
    "path": "adjust.m",
    "content": "function adj = adjust(img,percen)\n%Contrast stretch utility function. Clip percen percentages of the pixels,\n%while avoiding a drastic change to the white-balance.\n% \n% This is a utility function used by the non-local image dehazing algorithm\n% described in the paper:\n% Non-Local Image Dehazing. Berman, D. and Treibitz, T. and Avidan S., CVPR2016,\n% which can be found at:\n% www.eng.tau.ac.il/~berman/NonLocalDehazing/NonLocalDehazing_CVPR2016.pdf\n% If you use this code, please cite our paper.\n% \n% The software code of the Non-Local Image Dehazing algorithm is provided\n% under the attached LICENSE.md\n\nif ~exist('percen','var') || isempty(percen), percen=[0.01 0.99]; end;\n\n% linear contrast stretch to [0,1], identical on all colors\nminn=min(img(:));\nimg=img-minn;\nimg=img./max(img(:));\n\n% limit the change magnitude so the WB would not be drastically changed\ncontrast_limit = stretchlim(img,percen);\nval = 0.2;\ncontrast_limit(2,:) = max(contrast_limit(2,:), 0.2);\ncontrast_limit(2,:) = val*contrast_limit(2,:) + (1-val)*max(contrast_limit(2,:), mean(contrast_limit(2,:)));\ncontrast_limit(1,:) = val*contrast_limit(1,:) + (1-val)*min(contrast_limit(1,:), mean(contrast_limit(1,:)));\nadj=imadjust(img,contrast_limit,[],1);\n"
  },
  {
    "path": "demo_non_local_dehazing.m",
    "content": "% This is a demo script demonstrating the non-local image dehazing algorithm\n% described in the paper:\n% Non-Local Image Dehazing. Berman, D. and Treibitz, T. and Avidan S., CVPR2016,\n% which can be found at:\n% www.eng.tau.ac.il/~berman/NonLocalDehazing/NonLocalDehazing_CVPR2016.pdf\n% If you use this code, please cite our paper.\n% \n% Please read the instructions on README.md in order to use this code.\n%\n% Author: Dana Berman, 2016. \n% \n% The software code of the Non-Local Image Dehazing algorithm is provided\n% under the attached LICENSE.md\n\n\n% Choose image to use, four example image are supplied with the code in the\n% sub-folder \"images\":\nimage_name = 'pumpkins'; % 'train'; % 'cityscape'; % 'forest'; % \nimg_hazy = imread(['images/',image_name,'_input.png']);\n\n% Load the gamma from the param file. \n% These values were given by Ra'anan Fattal, along with each image:\n% http://www.cs.huji.ac.il/~raananf/projects/dehaze_cl/results/\nfid = fopen(['images/',image_name,'_params.txt'],'r');\n[C] = textscan(fid,'%s %f');\nfclose(fid);\ngamma = C{2}(1);\n\n% Estimate air-light using our method described in:\n% Air-light Estimation using Haze-Lines. Berman, D. and Treibitz, T. and \n% Avidan S., ICCP 2017\nA = reshape(estimate_airlight(im2double(img_hazy).^(gamma)),1,1,3);\n\n% Dehaze the image\t\n[img_dehazed, trans_refined] = non_local_dehazing(img_hazy, A, gamma );\n\n% Display results\nfigure('Position',[50,50, size(img_hazy,2)*3 , size(img_hazy,1)]);\nsubplot(1,3,1); imshow(img_hazy);    title('Hazy input')\nsubplot(1,3,2); imshow(img_dehazed); title('De-hazed output')\nsubplot(1,3,3); imshow(trans_refined); colormap('jet'); title('Transmission')\n"
  },
  {
    "path": "estimate_airlight.m",
    "content": "function [ Aout ] = estimate_airlight( img, Amin, Amax, N, spacing, K, thres )\n%Estimate airlight of an image, using a 3*2D Hough transform, where each\n%point votes for a given location using a fixed set of angles.\n%\n%   This is an implementation of our paper:\n%   Dana Berman, Tali Treibitz, Shai Avidan,\n%   \"Air-light Estimation using Haze-Lines\", ICCP 2017\n%   \n%   Input arguments:\n%   img - input image (mandatory)\n%   Amin (Amax) - minimal (maximal) value if the air-light. Optional\n%               Can be used to reduce the search space and save time\n%               Either a scalar (identical for all color channels) or a 3\n%               value vector (different range for each color channel)\n%   N - number of colors clusters to use (the image is converted to an\n%       indexed image of at most N different cluster). Optional\n%   spacing - air-light candidates' resolution, 1/M in the paper. Optional\n%   K - angular resolution. Optional\n%   thres - cone resolution, optional, default recommended\n\n\n%% Verify input params, set defaults when necessary (same as published results)\nif ~exist('thres','var') || isempty(thres), thres = 0.01 ; end;\nif ~exist('spacing','var') || isempty(spacing), spacing = 0.02 ; end; %1/M in the paper\nif ~exist('n_colors','var') || isempty(N), N = 1000 ; end; %number of colors clusters\nif ~exist('K','var') || isempty(K), K = 40 ; end; %number of angles\n\n% Define search range for the air-light. The search range is different for each \n% color channel. These values were used in all of our experiments.\nif ~exist('Amin','var') || isempty(Amin), Amin = [0,0.05,0.1]; end;\nif ~exist('Amax','var') || isempty(Amax), Amax = 1; end;\n\n% Air-light search range, accept a scalar if identical for all color channels\nif isscalar(Amin), Amin = repmat(Amin,1,3); end \nif isscalar(Amax), Amax = repmat(Amax,1,3); end\n\n%% Convert input image to an indexed image\n[img_ind, points] = rgb2ind(img, N);\n[h,w,~] = size(img);\n% Remove empty clusters\nidx_in_use = unique(img_ind(:));\nidx_to_remove = setdiff(0:(size(points,1)-1),idx_in_use);\npoints(idx_to_remove+1,:) = [];\nimg_ind_sequential = zeros(h,w);\nfor kk = 1:length(idx_in_use)\n    img_ind_sequential(img_ind==idx_in_use(kk)) = kk;\nend\n% Now the min value of img_ind_sequential is 1 rather then 0, and the indices\n% correspond to points\n\n% Count the occurences if each index - this is the clusters' weight\n[points_weight,~] = histcounts(img_ind_sequential(:),size(points,1));\npoints_weight = points_weight./(h*w);\nif ~ismatrix(points), points = reshape(points,[],3); end % verify dim\n\n%% Define arrays of candidate air-light values and angles\nangle_list = reshape(linspace(0, pi, K),[],1);\n% Use angle_list(1:end-1) since angle_list(end)==pi, which is the same line\n% in 2D as since angle_list(1)==0\ndirections_all = [sin(angle_list(1:end-1)) , cos(angle_list(1:end-1)) ];\n\n% Air-light candidates in each color channel\nArangeR = Amin(1):spacing:Amax(1);\nArangeG = Amin(2):spacing:Amax(2);\nArangeB = Amin(3):spacing:Amax(3);\n\n%% Estimate air-light in each pair of color channels\n% Estimate RG\nAall = generate_Avals(ArangeR, ArangeG);\n[~, AvoteRG] = vote_2D(points(:,1:2), points_weight, directions_all, Aall, thres );\n% Estimate GB\nAall = generate_Avals(ArangeG, ArangeB);\n[~, AvoteGB] = vote_2D(points(:,2:3), points_weight, directions_all, Aall, thres );\n% Estimate RB\nAall = generate_Avals(ArangeR, ArangeB);\n[~, AvoteRB] = vote_2D(points(:,[1,3]), points_weight, directions_all, Aall, thres);\n\n%% Find most probable airlight from marginal probabilities (2D arrays)\n% Normalize (otherwise the numbers are quite large)\nmax_val = max( [max(AvoteRB(:)) , max(AvoteRG(:)) , max(AvoteGB(:)) ]);\nAvoteRG2 = AvoteRG./max_val;\nAvoteGB2 = AvoteGB./max_val;\nAvoteRB2 = AvoteRB./max_val;\n% Generate 3D volumes from 3 different 2D arrays\nA11 = repmat( reshape(AvoteRG2, length(ArangeG),length(ArangeR))', 1,1,length(ArangeB));\ntmp = reshape(AvoteRB2, length(ArangeB),length(ArangeR))';\nA22 = repmat(reshape(tmp, length(ArangeR),1,length(ArangeB)) , 1,length(ArangeG),1);\ntmp2 = reshape(AvoteGB2, length(ArangeB),length(ArangeG))';\nA33 = repmat(reshape(tmp2, 1, length(ArangeG),length(ArangeB)) , length(ArangeR),1,1);\nAvoteAll = A11.*A22.*A33;\n[~, idx] = max(AvoteAll(:));\n[idx_r,idx_g,idx_b] = ind2sub([length(ArangeR),length(ArangeG),length(ArangeB)],idx);\nAout = [ArangeR(idx_r), ArangeG(idx_g), ArangeB(idx_b)];\n\n\nend % function estimate_airlight_2D\n\n%% Sub functions\n\nfunction Aall = generate_Avals(Avals1, Avals2)\n%Generate a list of air-light candidates of 2-channels, using two lists of\n%values in a single channel each\n%Aall's length is length(Avals1)*length(Avals2)\nAvals1 = reshape(Avals1,[],1);\nAvals2 = reshape(Avals2,[],1);\nA1 = kron(Avals1, ones(length(Avals2),1));\nA2 = kron(ones(length(Avals1),1), Avals2);\nAall = [A1, A2];\nend % function generate_Avals\n\nfunction [Aout, Avote2] = vote_2D(points, points_weight, directions_all, Aall, thres)\nn_directions = size(directions_all,1);\naccumulator_votes_idx = false(size(Aall,1), size(points,1), n_directions);\nfor i_point = 1:size(points,1)\n    for i_direction = 1:n_directions\n\t\t % save time and ignore irelevant points from the get-go\n        idx_to_use = find( (Aall(:, 1) > points(i_point, 1)) & (Aall(:, 2) > points(i_point, 2)));\n        if isempty(idx_to_use), continue; end\n\t\t\n        % calculate distance between all A options and the line defined by\n        % i_point and i_direction. If the distance is smaller than a thres,\n        % increase the cell in accumulator\n        dist1 = sqrt(sum([Aall(idx_to_use, 1)-points(i_point, 1), Aall(idx_to_use, 2)-points(i_point, 2)].^2,2));\n        %dist1 = dist1 - min(dist1);\n        dist1 = dist1./sqrt(2) + 1;\n        \n        dist =  -points(i_point, 1)*directions_all(i_direction,2) + ...\n            points(i_point, 2)*directions_all(i_direction,1) + ...\n            Aall(idx_to_use, 1)*directions_all(i_direction,2) - ...\n            Aall(idx_to_use, 2)*directions_all(i_direction,1);\n        idx = abs(dist)<2*thres.*dist1;\n        if ~any(idx), continue; end\n\n        idx_full = idx_to_use(idx);\n        accumulator_votes_idx(idx_full, i_point,i_direction) = true;\n    end\nend\n% use only haze-lined that are supported by 2 points or more\naccumulator_votes_idx2 = (sum(uint8(accumulator_votes_idx),2))>=2; \naccumulator_votes_idx = bsxfun(@and, accumulator_votes_idx ,accumulator_votes_idx2);\naccumulator_unique = zeros(size(Aall,1),1);\nfor iA = 1:size(Aall,1)\n    idx_to_use = find(Aall(iA, 1) > points(:, 1) & (Aall(iA, 2) > points(:, 2)));\n    points_dist = sqrt((Aall(iA,1) - points(idx_to_use,1)).^2+(Aall(iA,2) - points(idx_to_use,2)).^2);\n    points_weight_dist = points_weight(idx_to_use).*(5.*exp(-reshape(points_dist,1,[]))+1); \n    accumulator_unique(iA) = sum(points_weight_dist(any(accumulator_votes_idx(iA,idx_to_use,:),3)));\nend\n[~, Aestimate_idx] = max(accumulator_unique);\nAout = Aall(Aestimate_idx,:);\nAvote2 = accumulator_unique; \n\nend % function vote_2D\n"
  },
  {
    "path": "images/cityscape_params.txt",
    "content": "﻿gamma 1.6\nA1 0.81\nA2 0.81\nA3 0.82"
  },
  {
    "path": "images/forest_params.txt",
    "content": "﻿gamma 1\nA1 0.805\nA2 0.817\nA3 0.83"
  },
  {
    "path": "images/pumpkins_params.txt",
    "content": "﻿gamma 1\nA1 0.72\nA2 0.785\nA3 0.81"
  },
  {
    "path": "images/train_params.txt",
    "content": "﻿gamma 1.5\nA1 0.53\nA2 0.53\nA3 0.53"
  },
  {
    "path": "non_local_dehazing.m",
    "content": "function [img_dehazed, transmission] = non_local_dehazing(img_hazy, air_light, gamma)\n%The core implementation of \"Non-Local Image Dehazing\", CVPR 2016\n% \n% The details of the algorithm are described in our paper: \n% Non-Local Image Dehazing. Berman, D. and Treibitz, T. and Avidan S., CVPR2016,\n% which can be found at:\n% www.eng.tau.ac.il/~berman/NonLocalDehazing/NonLocalDehazing_CVPR2016.pdf\n% If you use this code, please cite the paper.\n%\n%   Input arguments:\n%   ----------------\n%\timg_hazy     - A hazy image in the range [0,255], type: uint8\n%\tair_light    - As estimated by prior methods, normalized to the range [0,1]\n%\tgamma        - Radiometric correction. If empty, 1 is assumed\n%\n%   Output arguments:\n%   ----------------\n%   img_dehazed  - The restored radiance of the scene (uint8)\n%   transmission - Transmission map of the scene, in the range [0,1]\n%\n% Author: Dana Berman, 2016. \n%\n% The software code of the Non-Local Image Dehazing algorithm is provided\n% under the attached LICENSE.md\n\n\n%% Validate input\n[h,w,n_colors] = size(img_hazy);\nif (n_colors ~= 3) % input verification\n    error(['Non-Local Dehazing reuires an RGB image, while input ',...\n        'has only ',num2str(n_colors),' dimensions']);\nend\n\nif ~exist('air_light','var') || isempty(air_light) || (numel(air_light)~=3)\n    error('Dehazing on sphere requires an RGB airlight');\nend\n\nif ~exist('gamma','var') || isempty(gamma), gamma = 1; end\n\nimg_hazy = im2double(img_hazy);\nimg_hazy_corrected = img_hazy.^gamma; % radiometric correction\n\n\n%% Find Haze-lines\n% Translate the coordinate system to be air_light-centric (Eq. (3))\ndist_from_airlight = double(zeros(h,w,n_colors));\nfor color_idx=1:n_colors\n    dist_from_airlight(:,:,color_idx) = img_hazy_corrected(:,:,color_idx) - air_light(:,:,color_idx);\nend\n\n% Calculate radius (Eq. (5))\nradius = sqrt( dist_from_airlight(:,:,1).^2 + dist_from_airlight(:,:,2).^2 +dist_from_airlight(:,:,3).^2 );\n\n% Cluster the pixels to haze-lines\n% Use a KD-tree impementation for fast clustering according to their angles\ndist_unit_radius = reshape(dist_from_airlight,[h*w,n_colors]);\ndist_norm = sqrt(sum(dist_unit_radius.^2,2));\ndist_unit_radius = bsxfun(@rdivide, dist_unit_radius, dist_norm);\nn_points = 1000;\n% load pre-calculated uniform tesselation of the unit-sphere\nfid = fopen(['TR',num2str(n_points),'.txt']);\npoints = cell2mat(textscan(fid,'%f %f %f')) ;\nfclose(fid);\nmdl = KDTreeSearcher(points);\nind = knnsearch(mdl, dist_unit_radius);\n\n\n%% Estimating Initial Transmission\n\n% Estimate radius as the maximal radius in each haze-line (Eq. (11))\nK = accumarray(ind,radius(:),[n_points,1],@max);\nradius_new = reshape( K(ind), h, w);\n    \n% Estimate transmission as radii ratio (Eq. (12))\ntransmission_estimation = radius./radius_new;\n\n% Limit the transmission to the range [trans_min, 1] for numerical stability\ntrans_min = 0.1;\ntransmission_estimation = min(max(transmission_estimation, trans_min),1);\n\n\n%% Regularization\n\n% Apply lower bound from the image (Eqs. (13-14))\ntrans_lower_bound = 1 - min(bsxfun(@rdivide,img_hazy_corrected,reshape(air_light,1,1,3)) ,[],3);\ntransmission_estimation = max(transmission_estimation, trans_lower_bound);\n \n% Solve optimization problem (Eq. (15))\n% find bin counts for reliability - small bins (#pixels<50) do not comply with \n% the model assumptions and should be disregarded\nbin_count       = accumarray(ind,1,[n_points,1]);\nbin_count_map   = reshape(bin_count(ind),h,w);\nbin_eval_fun    = @(x) min(1, x/50);\n\n% Calculate std - this is the data-term weight of Eq. (15)\nK_std = accumarray(ind,radius(:),[n_points,1],@std);\nradius_std = reshape( K_std(ind), h, w);\nradius_eval_fun = @(r) min(1, 3*max(0.001, r-0.1));\nradius_reliability = radius_eval_fun(radius_std./max(radius_std(:)));\ndata_term_weight   = bin_eval_fun(bin_count_map).*radius_reliability;\nlambda = 0.1;\ntransmission = wls_optimization(transmission_estimation, data_term_weight, img_hazy, lambda);\n\n\n%% Dehazing\n% (Eq. (16))\nimg_dehazed = zeros(h,w,n_colors);\nleave_haze = 1.06; % leave a bit of haze for a natural look (set to 1 to reduce all haze)\nfor color_idx = 1:3\n    img_dehazed(:,:,color_idx) = ( img_hazy_corrected(:,:,color_idx) - ...\n        (1-leave_haze.*transmission).*air_light(color_idx) )./ max(transmission,trans_min);\nend\n\n% Limit each pixel value to the range [0, 1] (avoid numerical problems)\nimg_dehazed(img_dehazed>1) = 1;\nimg_dehazed(img_dehazed<0) = 0;\nimg_dehazed = img_dehazed.^(1/gamma); % radiometric correction\n\n% For display, we perform a global linear contrast stretch on the output, \n% clipping 0.5% of the pixel values both in the shadows and in the highlights \nadj_percent = [0.005, 0.995];\nimg_dehazed = adjust(img_dehazed,adj_percent);\n\nimg_dehazed = im2uint8(img_dehazed);\n\nend % function non_local_dehazing\n"
  },
  {
    "path": "wls_optimization.m",
    "content": "function out = wls_optimization(in, data_weight, guidance, lambda)\n%Weighted Least Squares optimization solver.\n% Given an input image IN, we seek a new image OUT, which, on the one hand,\n% is as close as possible to IN, and, at the same time, is as smooth as\n% possible everywhere, except across significant gradients in the hazy image.\n%\n%  Input arguments:\n%  ----------------\n%  in             - Input image (2-D, double, N-by-M matrix).   \n%  data_weight    - High values indicate it is accurate, small values\n%                   indicate it's not.\n%  guidance       - Source image for the affinity matrix. Same dimensions\n%                   as the input image IN. Default: log(IN)\n%  lambda         - Balances between the data term and the smoothness\n%                   term. Increasing lambda will produce smoother images.\n%                   Default value is 0.05 \n%\n% This function is based on the implementation of the WLS Filer by Farbman,\n% Fattal, Lischinski and Szeliski, \"Edge-Preserving Decompositions for \n% Multi-Scale Tone and Detail Manipulation\", ACM Transactions on Graphics, 2008\n% The original function can be downloaded from: \n% http://www.cs.huji.ac.il/~danix/epd/wlsFilter.m\n\n\nsmall_num = 0.00001;\n\nif ~exist('lambda','var') || isempty(lambda), lambda = 0.05; end\n\n[h,w,~] = size(guidance);\nk = h*w;\nguidance = rgb2gray(guidance);\n\n% Compute affinities between adjacent pixels based on gradients of guidance\ndy = diff(guidance, 1, 1);\ndy = -lambda./(sum(abs(dy).^2,3) + small_num);\ndy = padarray(dy, [1 0], 'post');\ndy = dy(:);\n\ndx = diff(guidance, 1, 2); \ndx = -lambda./(sum(abs(dx).^2,3) + small_num);\ndx = padarray(dx, [0 1], 'post');\ndx = dx(:);\n\n\n% Construct a five-point spatially inhomogeneous Laplacian matrix\nB = [dx, dy];\nd = [-h,-1];\ntmp = spdiags(B,d,k,k);\n\nea = dx;\nwe = padarray(dx, h, 'pre'); we = we(1:end-h);\nso = dy;\nno = padarray(dy, 1, 'pre'); no = no(1:end-1);\n\nD = -(ea+we+so+no);\nAsmoothness = tmp + tmp' + spdiags(D, 0, k, k);\n\n% Normalize data weight\ndata_weight = data_weight - min(data_weight(:)) ;\ndata_weight = 1.*data_weight./(max(data_weight(:))+small_num);\n\n% Make sure we have a boundary condition for the top line:\n% It will be the minimum of the transmission in each column\n% With reliability 0.8\nreliability_mask = data_weight(1,:) < 0.6; % find missing boundary condition\nin_row1 = min( in,[], 1);\ndata_weight(1,reliability_mask) = 0.8;\nin(1,reliability_mask) = in_row1(reliability_mask);\n\nAdata = spdiags(data_weight(:), 0, k, k);\n\nA = Adata + Asmoothness;\nb = Adata*in(:);\n\n% Solve\n% out = lsqnonneg(A,b);\nout = A\\b;\nout = reshape(out, h, w);\n"
  }
]