{"id":24442163,"url":"https://github.com/techut30/hyperspectral-image-band-selection-using-gwo","last_synced_at":"2026-04-28T09:02:05.786Z","repository":{"id":261064357,"uuid":"882757991","full_name":"techut30/Hyperspectral-Image-Band-Selection-using-GWO","owner":"techut30","description":"Hyperspectral band selection using Gray Wolf Optimization with KNN \u0026 Random Forest.","archived":false,"fork":false,"pushed_at":"2024-11-23T17:21:15.000Z","size":6201,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T21:47:20.761Z","etag":null,"topics":["composite-images","dimensionality-reduction","feature-selection","gwo-optimization-algorithm","hyperspectral-image-selection","knn-classification","parameter-tuning","random-forest-classifier"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techut30.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-11-03T17:24:05.000Z","updated_at":"2024-11-23T17:21:18.000Z","dependencies_parsed_at":"2025-01-20T21:45:47.869Z","dependency_job_id":"dfa70ff5-669e-4469-ad7c-24813cc9f17a","html_url":"https://github.com/techut30/Hyperspectral-Image-Band-Selection-using-GWO","commit_stats":null,"previous_names":["techut30/hyperspectral-image-band-selection-using-gwo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techut30%2FHyperspectral-Image-Band-Selection-using-GWO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techut30%2FHyperspectral-Image-Band-Selection-using-GWO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techut30%2FHyperspectral-Image-Band-Selection-using-GWO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techut30%2FHyperspectral-Image-Band-Selection-using-GWO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techut30","download_url":"https://codeload.github.com/techut30/Hyperspectral-Image-Band-Selection-using-GWO/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243510923,"owners_count":20302469,"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":["composite-images","dimensionality-reduction","feature-selection","gwo-optimization-algorithm","hyperspectral-image-selection","knn-classification","parameter-tuning","random-forest-classifier"],"created_at":"2025-01-20T21:45:32.599Z","updated_at":"2025-12-28T10:11:37.572Z","avatar_url":"https://github.com/techut30.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hyperspectral-Image-Band-Selection-using-GWO\n\n# Band Selection for Hyperspectral Image Analysis using Gray Wolf Optimization\n\nThis repository contains Python code for selecting the optimal bands from hyperspectral images using the **Gray Wolf Optimization (GWO)** algorithm. The GWO algorithm helps select the most informative spectral bands, enhancing the classification accuracy of hyperspectral images. Two methods are implemented for classification: **K-Nearest Neighbors (KNN)** and **Random Forest** classifiers.\n\n## Overview\n\nThe repository includes two main files:\n- `GWO_KNN.py`: Uses a K-Nearest Neighbors (KNN) classifier for band selection.\n- `GWO_RandomForest.py`: Alternative approach that uses a Random Forest classifier for band selection.\n\nBoth files utilize Gray Wolf Optimization to identify the optimal subset of spectral bands for classification.\n\n## Requirements\n\n- Python 3.x\n- NumPy\n- Scikit-Learn\n- Scipy\n- Matplotlib\n- `GrayWolfOpt` (Gray Wolf Optimization algorithm, should be implemented or imported)\n- `CompositeImages` and `ImagePlots` (modules for visualization)\n\n## Files\n\n### `GWO_KNN.py`\n\nThis file performs band selection using the GWO algorithm and classifies using the **K-Nearest Neighbors** classifier.\n\n1. **Objective Function**: Defines the objective function for GWO. The function minimizes the classification error rate based on selected spectral bands.\n2. **Dataset Loading**: Loads the hyperspectral dataset (`Indian_pines_corrected.mat` for data and `Indian_pines_gt.mat` for labels).\n3. **Optimization**: The GWO algorithm optimizes the selected bands to minimize the error rate.\n4. **Visualization**: Selected bands are visualized as a composite image.\n\n#### Usage\n```python\npython GWO_KNN.py\n\n```\n\n### `GWO_RandomForest.py`\n\nAn alternative approach where band selection is performed using the **Random Forest classifier** instead of KNN. This script is structured similarly to main.py, with the following differences:\n\n1. **Classifier**: Uses RandomForestClassifier with 100 estimators to evaluate the fitness of the selected bands.\n2. **Parameters**: Adjusted parameters for GWO, including a higher number of bands and wolves.\n3. **Visualization**: Visualizes the selected bands as a composite image.\n\n### Usage\n\n```python\npython GWO_RandomForest.py\n```\n\n## Code Explanation \n\n### Objective Function for Band Selection\n\nThe objective function in both scripts takes in a set of selected bands, trains a classifier (KNN or Random Forest), and returns the error rate based on classification accuracy. The goal is to minimize this error rate, which represents the fitness score for GWO.\n\n### DataSet Loading \n\nThe dataset used is the Indian Pines hyperspectral dataset. The data is reshaped to (pixels, bands) format, and unlabeled pixels (background) are removed for accurate band selection.\n\n\n### Gray Wolf Optimization \n\nThe GWO algorithm optimizes the band selection process. The algorithm is configured with:\n\n**dim**: Number of bands to select.\n\n**lb and ub**: Lower and upper bounds for band indices.\n\n**num_wolves and max_iter**: Parameters defining the number of wolves and iterations.\n\n### Timer\n\nA timer function displays the elapsed time for the optimization process.\n\n\n## Example Outputs\n\nUpon running each script, the output includes:\n\n**Best Bands Selected**: The optimal subset of bands for classification.\n\n**Best Score (Error Rate)**: The minimized classification error achieved.\n\n**Composite Image**: A visualization of the selected bands.\n\n## References \n\n1. Gray Wolf Optimizer: Inspired by the social hierarchy and hunting strategy of gray wolves.\n2. Indian Pines Dataset: Commonly used hyperspectral dataset for classification tasks.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechut30%2Fhyperspectral-image-band-selection-using-gwo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechut30%2Fhyperspectral-image-band-selection-using-gwo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechut30%2Fhyperspectral-image-band-selection-using-gwo/lists"}