AlbughdadiM / satellite-sam-dashboard

This app integrates the Segment Anything Model (SAM) with Sentinel-2 data. The app is built using Dash Plotly and dash leaflet. It allows segmenting satellite images using the two ways provided by SAM: automatic mask generator and prompt segmentation (using points and bounding boxes).
MIT License
27 stars 5 forks source link

Buildings Instance Segmentation Support #6

Open sharoseali opened 2 days ago

sharoseali commented 2 days ago

HI @AlbughdadiM I have opened another issue as the topic is different.

I've opened another issue since the topics are different.

Previously, I worked on SAM Geo, where we can segment buildings. In that context, SAM can easily detect buildings without requiring explicit foreground inputs. However, in this case, the output is quite different. After applying Zoom and drawing the ROI, the result is a single polygon. I also tried using the SAM L and SAM H models.

image

Do I need to adjust any specific settings in the code? Also tiff imagery appearance is quite bright as compared to QGIS appearance. like this :

image

AlbughdadiM commented 1 day ago

Hi @sharoseali From what I can see, it looks like you defined a bounding box for the ROI with support points inside it. As mentioned in the README file, points are not supported as standalone prompts, so the points you added are considered to belong for the same object, which explains the rectangular mask. Try either automatic segmentation as explained in the repo, or define a bounding box for each building inside the ROI. Then if needed, you can add prompt points inside the bounding box of each object defining the foreground and background. Regarding the image, could you provide more info on the source of this image? Make sure that the image is scaled between 0 and 255 to be correctly overlayed on the map. Also, this is required by SAM.

sharoseali commented 1 day ago

hi @AlbughdadiM Well I have tried to apply automatic segmentation again carefully. But getting the same results. It draws one big polygon on the area. Also, I tried Foreground and background pixels but got the same output. Here is the tiff file link.

For image scaling, I don't think so we have any implementation code that extracts tile from ROI and rescales it.

AlbughdadiM commented 1 day ago

hi @sharoseali There are two concerns regarding the image:

I cropped part of the image and performed automatic and prompt segmentation as you can see in the following screenshots

Screenshot 2024-11-12 at 12 55 06 Screenshot 2024-11-12 at 12 56 09 Screenshot 2024-11-12 at 12 56 45
sharoseali commented 1 day ago

I see did you update the code also in sam utils? OR I have used dashboard wrongly ?

AlbughdadiM commented 1 day ago

only minor changes to handle data types when creating the PNG but this doesn't affect the segmentation as the GeoTiff image is directly used for that

sharoseali commented 1 day ago
  • The fourth band will be probably treated as alpha band. So this should be removed.

  • The size of the image is very large and it requires a lot of resources

I have checked same Tiff image using Sam Geo library. It has given very good results without cropping or changing tiff to PNG. I also created GeoJSON and map on QGIS. Its working correctly for the whole image. Normally it loose accuracy if we give very huge tile to it.

May be need some more operations to handle all size imagery in your implementation. Will try to compare the codes.

AlbughdadiM commented 1 day ago
  • The fourth band will be probably treated as alpha band. So this should be removed.

  • The size of the image is very large and it requires a lot of resources

I have checked same Tiff image using Sam Geo library. It has given very good results without cropping or changing tiff to PNG. I also created GeoJSON and map on QGIS. Its working correctly for the whole image. Normally it loose accuracy if we give very huge tile to it.

May be need some more operations to handle all size imagery in your implementation. Will try to compare the codes.

The PNG is only to overlay on the map but not used for segmentation.