Skip to content

SAM application in remote sensing images object-based classification for UGIS course

License

Notifications You must be signed in to change notification settings

JeasunLok/SAM-UGIS-Homework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAM application in remote sensing images object-based classification for UGIS course

The homework of UGIS course: to develop a software (including algorithm and GUI) equipped with SAM to do segmentation and classification for remote sensing images.


Geography Information Science Grade 2020, School of Geography and Planning, Sun Yat-Sen Univeristy.

June 14, 2023


Introduction

This is a software that can use SAM or multiscale segmentation to sement remote sensing images, then classify the images with input samples based on the segmenation and check the accuracy. The software is entirely written by Python, and the GUI is written by Python package tkinter.


Features

  • Easy installation and visualized GUI
  • Two segmentation algorithms and three classification algorithms
  • All results can be seen in GUI

Installation

Install the requirement

git clone https://github.com/JeasunLok/SAM-UGIS-Homework.git && cd SAM-UGIS-Homework
conda create -n SAM-UGIS-Homework python=3.9
conda activate SAM-UGIS-Homework
pip install -r requirements.txt
pip install torch==1.13.1+cu117 -f https://download.pytorch.org/whl/torch_stable.html

Run the GUI in main to complete your task

python main.py

Download the pth parameters file of sam_vit_b in: Parameters file of sam_vit_b Then place it under folder asset.
Or you can modify the code and switch the backbone to sam_vit_l or sam_vit_h in src/sam_segmentation.py


How to use it

The GUI is shown below: GUI

  1. Segmentation
    Two file paths are need: click "选择路径" for ""输入图像文件" and ""输出分割文件"""输入图像文件" is the original image you want to do segmentation and the output segmentation file is ""输出分割文件", then select the segmentation algorithm in "选择分割算法". All these files are tif file. Two selections "SAM分割" and ""多尺度分割" can be selected. The former uses SAM to do segmentation and the latter uses quickshift algorithm to do segmentation. When using ""多尺度分割", two parmaters ""核大小" and ""最大距离" are needed, which represent the scale of the segmentation. When doing segmentation, you should select the device GPU or CPU in "选择运算设备".
    "SAM分割" uses segment-anything model and ""多尺度分割" uses quickshift algorithm.

  1. Classification
    After completing the segmentation or you have the segmentation result of original image, you can enter two paths: click "选择路径" for ""输入样本文件" and ""输出分类文件"""输入样本文件" is the training and testing samples of the classfier, and the output classification file is ""输出分割文件" Then select the classification algorithm in "选择分类算法", "决策树" is decision tree algorithm, "支持向量机" is support vector machine algorithm and "随机森林" is random forest algorithm. It should be noticed that the samples file is shp point file and the output classification file is tif file. The train ratio ranged from 0 to 1 should be entered in "训练集比例", and the classification accuracies (i.e. Overall accuracy (OA) and kappa coefficient (Kappa)) are shown in GUI immediately.

  1. Image visualization
    The "图片" button can check the original image, segmentation result and classification result of the task: Image
  • "初始图片" button shows the original image.
  • "分割结果" button shows the segmentation result.
  • "分类结果" button shows the classification result.

Source

We provide 3 example images and samples in folder images for users to use and test our software and the video of how to use the software in Chinese is released at video of how to use the software.


License

The software is licensed under the Apache 2.0 license.


Acknowledgement

This software is made possible by the following open source projects. Credit goes to the developers of these projects: segment-geospatial
segment-anything

About

SAM application in remote sensing images object-based classification for UGIS course

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages