{"id":18076801,"url":"https://github.com/utkarsh-deshmukh/spatially-varying-blur-detection-python","last_synced_at":"2025-08-20T18:35:36.167Z","repository":{"id":43779314,"uuid":"369339462","full_name":"Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python","owner":"Utkarsh-Deshmukh","description":"python implementation of the paper \"Spatially-Varying Blur Detection Based on Multiscale Fused and Sorted Transform Coefficients of Gradient Magnitudes\" - cvpr 2017","archived":false,"fork":false,"pushed_at":"2023-01-27T20:41:12.000Z","size":119,"stargazers_count":163,"open_issues_count":0,"forks_count":23,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T12:05:58.923Z","etag":null,"topics":["blur","blur-detection","blur-detector","computer-vision","cvpr2017","image-processing","image-quality","image-quality-assessment","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Utkarsh-Deshmukh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-20T21:13:42.000Z","updated_at":"2025-03-27T10:05:29.000Z","dependencies_parsed_at":"2023-02-15T12:31:15.952Z","dependency_job_id":null,"html_url":"https://github.com/Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Utkarsh-Deshmukh%2FSpatially-Varying-Blur-Detection-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Utkarsh-Deshmukh%2FSpatially-Varying-Blur-Detection-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Utkarsh-Deshmukh%2FSpatially-Varying-Blur-Detection-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Utkarsh-Deshmukh%2FSpatially-Varying-Blur-Detection-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Utkarsh-Deshmukh","download_url":"https://codeload.github.com/Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694877,"owners_count":20980733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blur","blur-detection","blur-detector","computer-vision","cvpr2017","image-processing","image-quality","image-quality-assessment","python"],"created_at":"2024-10-31T11:11:11.913Z","updated_at":"2025-04-07T17:12:11.905Z","avatar_url":"https://github.com/Utkarsh-Deshmukh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Efficient-Spatially-Varying-Blur-Detection-python\npython implementation of the paper \"***Spatially-Varying Blur Detection Based on Multiscale Fused and Sorted Transform Coefficients of Gradient Magnitudes\" - cvpr 2017***\n\n***NOTE: This project outputs regions in an image which are sharp and blurry. In order to perform \"OUT-OF-FOCUS\" blur estimation, please refer to this repo: https://github.com/Utkarsh-Deshmukh/Blurry-Image-Detector***\n\n# Brief Theory:\n- The repo is a python implementation of the paper which can be found here\n[link to the paper](https://arxiv.org/pdf/1703.07478.pdf)\n- The discrete cosine transform is used to convert the image from spatial domain to frequency domain.\n- The DCT coefficients are divided into 'low', 'medium' and 'high' frequency bands, out of which only the high frequencies are used.\n- At a particular location, the high frequency DCT coefficients are extracted at various resolutions. All these selected coefficients are combined together and sorted to form the `multiscale-fused and sorted high-frequency transform coefficients`\n- these coefficients show a visual difference for blurry vs sharp patches in the image (refer to fig 2 in the paper)\n- each of these coefficients results in the generation of a \"filtered layer\" for the image. The first layer is the smallest DCT high frequency coefficient while the last layer is the highest DCT high frequency coefficient at various scales. (refer to secion 2.1 in the paper)\n- The union of a subset of these layers is selected. This is then sent through a max pooling to retain the highest activation from the set of layers\n- This resultant map is then sent for post processing which involves computing the local entropy and smoothing this local entropy map using a edge retaining smoothing filter such as `Domain transform recursive edge-preserving filter`. A guided filter can also be used here.\n- The *Domain transform recursive edge-preserving filter* was proposed in 2011 and can be found here:\n[link to the paper](https://www.inf.ufrgs.br/~eslgastal/DomainTransform/Gastal_Oliveira_SIGGRAPH2011_Domain_Transform.pdf)\n\n# Installation and Running an example:\n## method 1 - use the library:\n`pip install blur_detector`\n\n```\nimport blur_detector\nimport cv2\nif __name__ == '__main__':\n    img = cv2.imread('image_name', 0)\n    blur_map = blur_detector.detectBlur(img, downsampling_factor=4, num_scales=4, scale_start=2, num_iterations_RF_filter=3)\n\n    cv2.imshow('ori_img', img)\n    cv2.imshow('blur_map', blur_map)\n    cv2.waitKey(0)\n```\n--------------------------------------------------------------------------------------------------------------\n# Results\n--------------------------------------------------------------------------------------------------------------\n### Detecting Depth of field:\n![image](https://user-images.githubusercontent.com/13918778/119441249-aa3dc780-bcda-11eb-911b-432266dfa92c.png)\n--------------------------------------------------------------------------------------------------------------\n ### Detecting various types of blurs:\n![image](https://user-images.githubusercontent.com/13918778/119441726-74e5a980-bcdb-11eb-8d55-55b3e2c5f7be.png)\n![image](https://user-images.githubusercontent.com/13918778/119441933-cee66f00-bcdb-11eb-907e-776ed1f47054.png)\n![image](https://user-images.githubusercontent.com/13918778/119442075-09e8a280-bcdc-11eb-826a-cf8277f3c7cc.png)\n--------------------------------------------------------------------------------------------------------------\n# Algorithm overview:\n![image](https://user-images.githubusercontent.com/13918778/119443637-c7749500-bcde-11eb-9b71-c16210e39910.png)\n--------------------------------------------------------------------------------------------------------------\n# Development/Testing Environment \nThis repository uses `poetry` as a package manager\n\n```\nMake sure your python version is \u003e= 3.7\npython --version\n\n# Install poetry if you don't have it\npython -m pip install poetry\n\n# Install dependencies in a virtual environment\npoetry install \n(This will install all locked dependencies from poetry.lock file)\n\n# Activate virtual environment\npoetry shell (Now you have a virtual environment with all dependencies)\nAlternatively, to avoid creating a new shell, you can manually activate the virtual environment by running `source {path_to_venv}/bin/activate`\nTo get the path to your virtual environment run `poetry env info --path`. You can also combine these into a nice one-liner, `source $(poetry env info --path)/bin/activate`. To deactivate this virtual environment simply use `deactivate`.\n\n# Using poetry run\nTo run your script simply use poetry run python your_script.py. This will automatically run your script in above created shell   \n\n# Specifying dependencies\nIf you want to add dependencies to this project, you can specify them in the `tool.poetry.dependencies` section.\n\nFor example;\n\n[tool.poetry.dependencies]\npendulum = \"^1.4\"\n\nAs you can see, it takes a mapping of package names and version constraints.\nPoetry uses this information to search for the right set of files in package \"repositories\" that you register in the tool.poetry.repositories section, or on PyPI by default. \nAlso, instead of modifying the pyproject.toml file by hand, you can use the add command.\n\npoetry add pendulum\n\nIt will automatically find a suitable version constraint and install the package and subdependencies.\n\n```\n--------------------------------------------------------------------------------------------------------\n\n# Publish to Pypi\nBefore you can actually publish your library, you will need to package it.\n\n```\npoetry build\n```\n\nThis command will package your library in two different formats: `sdist` which is the source format, and `wheel` which is a `compiled` package.\nOnce that is done you are ready to publish your library.\n\nPoetry will publish to PyPI by default. Anything that is published to PyPI is available automatically through Poetry.\n\nTo share `blur_detection` library with the Python community, we would publish on PyPI as well. Doing so is really easy.\n\n```\npoetry publish\n```\n\nThis will package and publish the library to PyPI, at the condition that you are a registered user and you have configured your credentials properly.\n\n---------------------------------------------------------------------------------------------------\n\n# Acknowledgements\nThis algorithm is based on the paper: `Spatially-Varying Blur Detection Based on Multiscale Fused and SortedTransform Coefficients of Gradient Magnitudes`\nThe paper can be found here: https://arxiv.org/pdf/1703.07478.pdf\n\nThe author would like to thank Dr. Alireza Golestaneh (This code is a python implementation of his work. His original work is an Matlab and can be found here: https://github.com/isalirezag/HiFST)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarsh-deshmukh%2Fspatially-varying-blur-detection-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futkarsh-deshmukh%2Fspatially-varying-blur-detection-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarsh-deshmukh%2Fspatially-varying-blur-detection-python/lists"}