segment-anything
segment-anything copied to clipboard
How to save only segmented object as original colored in jpg or png format ?
I have extracted the segmented object from the input image by first creating bounding box around the detected object using YOLOv8 and passed the bounding box and input image to SAM model. Now, I want to save original colored segmented object in jpg or png format. If possible please provide code for this work.
Hey, did you find the solution?
Nope, I am also still searching for the solution. But I have found out one another way to do it. When you are getting the segmentation mask from SAM output, you try to create binary mask of it and then remove that part only from the original image. Lastly, create an RGBA image and combine with the previous output. So, this way you can get an segment part with all the other things are made transparent.
Remember that the size of the final output will increase, so for that you can use yolo to detect only the segment object first and then crop the image based on bounding box you get from yolo and then pass the cropped image to SAM and follow the above process.
But in the demo UI they are showing cut outs at left side, so there must be code for that
Yeah it is possible but I didn't find that code from its official repo.
Yeah it is possible but I didn't find that code from its official repo.
Hello, maybe this repository can solve your problem: https://github.com/Nomination-NRB/SAM-webui
Save white mask, Save color mask, Save origin image of mask
Nope, I am also still searching for the solution. But I have found out one another way to do it. When you are getting the segmentation mask from SAM output, you try to create binary mask of it and then remove that part only from the original image. Lastly, create an RGBA image and combine with the previous output. So, this way you can get an segment part with all the other things are made transparent.
Remember that the size of the final output will increase, so for that you can use yolo to detect only the segment object first and then crop the image based on bounding box you get from yolo and then pass the cropped image to SAM and follow the above process.
How did you create the binary mask from the mask image outputted from SAM?
Nope, I am also still searching for the solution. But I have found out one another way to do it. When you are getting the segmentation mask from SAM output, you try to create binary mask of it and then remove that part only from the original image. Lastly, create an RGBA image and combine with the previous output. So, this way you can get an segment part with all the other things are made transparent. Remember that the size of the final output will increase, so for that you can use yolo to detect only the segment object first and then crop the image based on bounding box you get from yolo and then pass the cropped image to SAM and follow the above process.
How did you create the binary mask from the mask image outputted from SAM?
I also want to know
I added a file here which will extract out individual pieces of segmented items and displays them. Instead of displaying, you can save "item" from cmd-11. https://github.com/abhishek0093/segment-anything/blob/main/notebooks/Get_individual_transparent_items.ipynb