{"id":22698175,"url":"https://github.com/yash-10/galmask","last_synced_at":"2026-03-05T21:05:49.140Z","repository":{"id":37370191,"uuid":"482832399","full_name":"Yash-10/galmask","owner":"Yash-10","description":"Unsupervised galaxy masking to remove background source detections","archived":false,"fork":false,"pushed_at":"2024-01-08T13:59:51.000Z","size":6861,"stargazers_count":9,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-26T21:46:58.574Z","etag":null,"topics":["galaxy-morphology","image-processing"],"latest_commit_sha":null,"homepage":"https://galmask.readthedocs.io/en/latest/","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/Yash-10.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}},"created_at":"2022-04-18T12:07:12.000Z","updated_at":"2025-01-06T07:49:45.000Z","dependencies_parsed_at":"2024-01-08T15:34:31.753Z","dependency_job_id":null,"html_url":"https://github.com/Yash-10/galmask","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yash-10%2Fgalmask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yash-10%2Fgalmask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yash-10%2Fgalmask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yash-10%2Fgalmask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yash-10","download_url":"https://codeload.github.com/Yash-10/galmask/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665756,"owners_count":21142123,"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":["galaxy-morphology","image-processing"],"created_at":"2024-12-10T05:18:30.907Z","updated_at":"2026-03-05T21:05:49.089Z","avatar_url":"https://github.com/Yash-10.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# galmask\n\n[![DOI](https://zenodo.org/badge/482832399.svg)](https://zenodo.org/badge/latestdoi/482832399)\n[![PyPI version](https://badge.fury.io/py/galmask.svg)](https://badge.fury.io/py/galmask)\n[![Read the Docs](https://readthedocs.org/projects/galmask/badge/?version=latest)](https://galmask.readthedocs.io/en/latest/)\n\n**galmask** is an open-source package written in Python that provides a simple way to remove unwanted background source detections from galaxy images.\nIt builds on top of `astropy` and `photutils` astronomical Python libraries and the `opencv` and `skimage` image processing libraries.\n\nThe main requirements of `galmask` are:\n- `astropy` for handling FITS I/O and general-purpose astronomical routines.\n- `photutils` for photometry purposes and deblending detected sources.\n- `opencv-python` for connected-component analysis.\n- `skimage` for general image processing functionalities.\n\n# Installation\n\n## Via `pip`\n\n`galmask` can be installed from PyPI via `pip` by running::\n\n```\npip install galmask\n```\n\n## Alternative method\n\n`galmask` can also be installed by cloning the repository and doing a pip install in the project directory::\n\n```\ngit clone https://github.com/Yash-10/galmask\ncd galmask\npip install\n```\n\nIt would be beneficial to create a python virtual environment and install the package within it, to prevent\nmanipulating your global dependency versions.\n\n# Quick example\n\n```python\nfrom astropy.io import fits\nfrom astropy.visualization import AsinhStretch, ImageNormalize, ZScaleInterval, LogStretch\n\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\n\n# Import galmask\nfrom galmask.galmask import galmask\n\ndef axes_colorbar(ax):\n    divider = make_axes_locatable(ax)\n    cax = divider.append_axes('bottom', size='5%', pad=0.3)\n    return cax\n\nfilepath = 'example/gal1_G.fits'\nimage = fits.getdata(filepath)\nnpixels, nlevels, nsigma, contrast, min_distance, num_peaks, num_peaks_per_label, connectivity, remove_local_max = 5, 32, 2., 0.15, 1, 10, 3, 4, True  # Parameters for galmask\nseg_image = None  # No segmentation map example\n\norig_segmap = fits.getdata('example/gal_seg1.fits')\n\ngalmasked, galsegmap = galmask(\n    image, npixels, nlevels, nsigma, contrast, min_distance, num_peaks, num_peaks_per_label,\n    connectivity=4, kernel=fits.getdata('kernel.fits'), seg_image=seg_image, mode=\"1\",\n    remove_local_max=True, deblend=True\n)\n\n# Plotting result.\nfig, ax = plt.subplots(1, 4, figsize=(24, 6))\n\n# For keeping original and final images on same scale.\nvmin = min(image.min(), galmasked.min())\nvmax = max(image.max(), galmasked.max())\n\n# fig.suptitle(filepath)\nnorm1 = ImageNormalize(image, vmin=vmin, vmax=vmax, interval=ZScaleInterval(), stretch=LogStretch())\nim0 = ax[0].imshow(image, norm=norm1, origin='lower', cmap='gray')\nax[0].set_title(\"Original image\")\ncax0 = axes_colorbar(ax[0])\nfig.colorbar(im0, cax=cax0, orientation='horizontal')\n\nim1 = ax[1].imshow(orig_segmap, origin='lower')\nax[1].set_title(\"Original segmentation map (photutils)\")\ncax1 = axes_colorbar(ax[1])\nfig.colorbar(im1, cax=cax1, orientation='horizontal')\n\nim2 = ax[2].imshow(galsegmap, origin='lower', cmap='gray')\nax[2].set_title(\"Final segmentation map (galmask)\")\ncax2 = axes_colorbar(ax[2])\nfig.colorbar(im2, cax=cax2, orientation='horizontal')\n\nnorm2 = ImageNormalize(galmasked, vmin=vmin, vmax=vmax, interval=ZScaleInterval(), stretch=LogStretch())\nim3 = ax[3].imshow(galmasked, norm=norm2, origin='lower', cmap='gray')\nax[3].set_title(\"Final image (galmask)\")\ncax3 = axes_colorbar(ax[3])\nfig.colorbar(im3, cax=cax3, orientation='horizontal')\n\nplt.show()\n```\n\nOutput:\n\n![galmask_example](https://github.com/Yash-10/galmask/blob/main/example/galmask_example1.png)\n\n\u003e **_NOTE:_**  `orig_segmap` is the original segmentation map - it is not returned by galmask. It is an intermediate result calculated inside galmask (if a pre-calculated segmentation map is not input). Here the original segmentation map was stored in a FITS file for demonstration purposes. So if you pass `seg_image=None` (as done in the above example) and would like to create such four-column plots, you would need to edit the source code of `galmask.py` to save the internally calculated segmentation map in a FITS file.\n\n# Documentation\n\nThe documentation is generated using the [Sphinx](https://www.sphinx-doc.org/) documentation tool and hosted by [Read the Docs](https://readthedocs.org/).\nYou can find the API reference and also some empirical tips to use galmask in the [documentation](https://galmask.readthedocs.io/en/latest/).\n\n# Tests\n\nFor running the tests, you would need to install [pytest](https://docs.pytest.org/). You can navigate to the `tests/` directory and run:\n\n```\npytest \u003cname_of_file\u003e\n```\n\n# Contribute\n\nContributions are welcome! Currently, there seem to be a few inefficient ways of handling things within galmask, and we would like you to contribute and improve the package!\n\nPlease let us know of any bugs/issues by opening an issue in the [issue tracker](https://github.com/Yash-10/galmask/issues).\n\n# Citing\n\nIf you use `galmask` in your research, please consider citing the paper associated with this package:\n\n```bibtex\n@article{Gondhalekar_2022,\n    doi = {10.3847/2515-5172/ac780b},\n    url = {https://dx.doi.org/10.3847/2515-5172/ac780b},\n    year = {2022},\n    month = {jun},\n    publisher = {The American Astronomical Society},\n    volume = {6},\n    number = {6},\n    pages = {128},\n    author = {Yash Gondhalekar and Rafael S. de Souza and Ana L. Chies-Santos},\n    title = {galmask: A Python Package for Unsupervised Galaxy Masking},\n    journal = {Research Notes of the AAS},\n    abstract = {Galaxy morphological classification is a fundamental aspect of galaxy formation and evolution studies. Various machine learning tools have been developed for automated pipeline analysis of large-scale surveys, enabling a fast search for objects of interest. However, crowded regions in the image may pose a challenge as they can lead to bias in the learning algorithm. In this Research Note, we present galmask, an open-source package for unsupervised galaxy masking to isolate the central object of interest in the image. galmask is written in Python and can be installed from PyPI via the pip command.}\n}\n```\n\n\n# License and copyright\n\ngalmask is licensed under the [MIT License](LICENSE).\n\nCopyright (c) 2022 Yash Gondhalekar\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyash-10%2Fgalmask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyash-10%2Fgalmask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyash-10%2Fgalmask/lists"}