{"id":17222832,"url":"https://github.com/cheind/pytorch-debayer","last_synced_at":"2025-10-17T19:14:53.604Z","repository":{"id":66175005,"uuid":"240086478","full_name":"cheind/pytorch-debayer","owner":"cheind","description":"Convolutional PyTorch debayering / demosaicing layers","archived":false,"fork":false,"pushed_at":"2022-04-08T14:46:39.000Z","size":10955,"stargazers_count":89,"open_issues_count":3,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T00:28:45.745Z","etag":null,"topics":["bayer","bayer-filter-array","convolution","debayer","demosaicing","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cheind.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-02-12T18:35:28.000Z","updated_at":"2025-04-03T14:49:04.000Z","dependencies_parsed_at":"2023-02-21T06:01:19.787Z","dependency_job_id":null,"html_url":"https://github.com/cheind/pytorch-debayer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/cheind/pytorch-debayer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpytorch-debayer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpytorch-debayer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpytorch-debayer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpytorch-debayer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheind","download_url":"https://codeload.github.com/cheind/pytorch-debayer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheind%2Fpytorch-debayer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267442460,"owners_count":24087803,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bayer","bayer-filter-array","convolution","debayer","demosaicing","pytorch"],"created_at":"2024-10-15T04:06:28.670Z","updated_at":"2025-10-17T19:14:48.545Z","avatar_url":"https://github.com/cheind.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/cheind/pytorch-debayer/actions/workflows/python-package.yml/badge.svg)](https://github.com/cheind/pytorch-debayer/actions/workflows/python-package.yml)\n\n# pytorch-debayer\n\nProvides batch GPU demosaicing of images captured by Bayer color filter array (CFA) cameras. This implementation relies on pure PyTorch functionality and thus avoids any extra build steps. This library is most useful when downstream image processing happens with PyTorch models. Additionally, uploading of Bayer images (instead of RGB) significantly reduces the occupied bandwidth.\n\n## Features\n - **Methods** Currently, the following methods are provided\n    - `debayer.Debayer2x2` uses 2x2 convolutions. Trades speed for color accuracy.\n    - `debayer.Debayer3x3` uses 3x3 convolutions. Slower but reconstruction results comparable with `OpenCV.cvtColor`.\n    - `debayer.Debayer5x5` uses 5x5 convolutions based on Malver-He-Cutler algorithm. Slower but sharper than `OpenCV.cvtColor`. Should be your default.\n    - `debayer.DebayerSplit` faster than `debayer.Debayer3x3` but decreased image quality.    \n - **Precision** Each method supports `float32` or `float16` precision. \n\n## Usage\nUsage is straight forward\n\n```python\nimport torch\nfrom debayer import Debayer5x5\n\nf = Debayer5x5().cuda()\n\nbayer = ...         # a Bx1xHxW, [0..1], torch.float32 RGGB-Bayer tensor\nwith torch.no_grad():\n    rgb = f(bayer)  # a Bx3xHxW, torch.float32 tensor of RGB images\n```\n\nsee [this example](debayer/apps/example.py) for elaborate code.\n\n## Install\nLibrary, apps and development tools\n```\npip install git+https://github.com/cheind/pytorch-debayer#egg=pytorch-debayer[full]\n```\n\nJust the library core requirements\n```\npip install git+https://github.com/cheind/pytorch-debayer\n```\n\n## Bayer Layouts\nBayer filter arrays may come in different layouts. **pytorch-debayer** distinguishes these layouts by looking at the upper-left 2x2 pixel block. For example\n```\nRGrg...\nGBgb...\nrgrg...\n```\ndefines the `Layout.RGGB` which is also the default. In total four layouts are supported\n```python\nfrom debayer import Layout\n\nLayout.RGGB\nLayout.GRBG\nLayout.GBRG\nLayout.BGGR\n```\n\nand you can set the layout as follows\n\n```python\nfrom debayer import Debayer5x5, Layout\n\nf = Debayer5x5(layout=Layout.BGGR).cuda()\n```\n\n## Evaluation\n\n### PSNR values\nThe PSNR (Peak-Signal-Noise-Ratio) values (dB, higher is better) for each channel (R, G, B) and PSNR of the whole image (RGB) across 2 Datasets (Kodak, McMaster) and for each algorithm. See [Metrics.md](./Metrics.md) for additional details.\n\n| Database   | Method       |     R (dB)|     G (dB)|     B (dB)|   PSNR (dB)|\n|------------|--------------|-------|-------|-------|--------|\n| Kodak      | Debayer2x2   | 26.64 | 28.18 | 26.98 |  27.27 |\n|       | Debayer3x3   | 28.18 | 32.66 | 28.86 |  29.90 |\n|       | Debayer5x5   | 33.84 | 38.05 | 33.53 |  35.14 |\n|       | DebayerSplit | 26.64 | 32.66 | 26.98 |  28.76 |\n|       | OpenCV       | 28.15 | 31.25 | 28.62 |  29.34 |\n| McMaster   | Debayer2x2   | 28.47 | 30.32 | 28.63 |  29.14 |\n|    | Debayer3x3   | 31.68 | 35.40 | 31.25 |  32.78 |\n|    | Debayer5x5   | 34.04 | 37.62 | 33.02 |  34.89 |\n|    | DebayerSplit | 28.47 | 35.40 | 28.63 |  30.83 |\n|    | OpenCV       | 31.64 | 35.22 | 31.22 |  32.69 |\n\n\n### Runtimes\nPerformance comparison on a 5 megapixel [test image](etc/test.bmp) using a batch size of 10. \nTimings are in milliseconds per given megapixels. See [Benchmarks.md](./Benchmarks.md) for additional details.\n\nMethod | Device | Elapsed [msec/5.1mpix] | Mode |\n|:----:|:------:|:-------:|:----:|\n| Debayer2x2 | GeForce GTX 1080 Ti | 0.617 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer3x3 | GeForce GTX 1080 Ti | 3.298 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer5x5 | GeForce GTX 1080 Ti | 5.842 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer2x2 | GeForce GTX 1080 Ti | 0.563 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| Debayer3x3 | GeForce GTX 1080 Ti | 2.927 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| Debayer5x5 | GeForce GTX 1080 Ti | 4.044 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| Debayer2x2 | NVIDIA GeForce RTX 3090 | 0.231 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer3x3 | NVIDIA GeForce RTX 3090 | 1.052 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer5x5 | NVIDIA GeForce RTX 3090 | 1.610 | batch=10,time_upload=False,prec=torch.float32,torchscript=False |\n| Debayer2x2 | NVIDIA GeForce RTX 3090 | 0.174 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| Debayer3x3 | NVIDIA GeForce RTX 3090 | 0.854 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| Debayer5x5 | NVIDIA GeForce RTX 3090 | 1.589 | batch=10,time_upload=False,prec=torch.float16,torchscript=False |\n| OpenCV 4.5.3 | Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz | 2.205 | batch=10,time_upload=False,opencv-threads=4,transparent-api=False |\n| OpenCV 4.5.3 | Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz | 2.206 | batch=10,time_upload=False,opencv-threads=4,transparent-api=True |\n| OpenCV 4.5.3 | Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz | 1.937 | batch=10,time_upload=False,opencv-threads=12,transparent-api=False |\n| OpenCV 4.5.3 | Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz | 1.925 | batch=10,time_upload=False,opencv-threads=12,transparent-api=True |\n\n\n### Subjective Results\n\nHere are some subjective image demosaicing results using the following [test image](etc/test.bmp) image. \n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"60%\" src=\"etc/readme/input.png\" /\u003e\n\u003c/div\u003e\n\nThe following highlights algorithmic differences on various smaller regions for improved pixel visibility. From left to right \n```\nOpenCV, Debayer2x2, Debayer3x3, DebayerSplit, Debayer5x5\n```\n\nClick images to enlarge.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"100%\" src=\"etc/readme/test-mosaic-l1429-r1659-b1889-t1725.png\" /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"100%\" src=\"etc/readme/test-mosaic-l1779-r1998-b1145-t949.png\" /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"100%\" src=\"etc/readme/test-mosaic-l620-r872-b1430-t1233.png\" /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"100%\" src=\"etc/readme/test-mosaic-l588-r817-b1178-t981.png\" /\u003e\n\u003c/div\u003e\n\nCreated using\n```\npython -m debayer.apps.compare etc\\test.bmp\n# Then select a region and check `tmp`/\n```\n\n## Limitations\n\nCurrently **pytorch-debayer** requires\n - the image to have an even number of rows and columns\n - `debayer.DebayerSplit` requires a Bayer filter layout of `Layout.RGGB`, all others support varying layouts (since v1.3.0).\n\n## References \nThe following reference are mostly for comparison metrics and not algorithms. See the individual module documentation for algorithmic references.\n\n- Wang, Shuyu, et al. \"A Compact High-Quality Image Demosaicking Neural Network for Edge-Computing Devices.\" Sensors 21.9 (2021): 3265.\n\n- Losson, Olivier, Ludovic Macaire, and Yanqin Yang. \"Comparison of color demosaicing methods.\" Advances in Imaging and electron Physics. Vol. 162. Elsevier, 2010. 173-265.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheind%2Fpytorch-debayer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheind%2Fpytorch-debayer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheind%2Fpytorch-debayer/lists"}