facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.63k stars 5.63k forks source link

How to change the colour of the mask #183

Closed stupworker closed 1 year ago

stupworker commented 1 year ago

Here is my outcome. image I want to get a white and black jpg, what can i do? Thanks!!!!

JordanMakesMaps commented 1 year ago

The mask doesn't have a color. You're using something like matplotlib which is providing the default yellow (1) and purple (0) cmap. The mask is only a single binary channel, with 1 being where something is. If you want black and white, just do this:

mask[mask == 1] =255
plt.imsave(arr=mask, fname="mask.jpg")
stupworker commented 1 year ago

The mask doesn't have a color. You're using something like matplotlib which is providing the default yellow (1) and purple (0) cmap. The mask is only a single binary channel, with 1 being where something is. If you want black and white, just do this:

mask[mask == 1] =255
plt.imsave(arr=mask, fname="mask.jpg")

Excuse me, where should i put the code in? I put them after function save_mask_data(output_dir, masks, boxes_filt, pred_phrases) in grounded_sam_demo.py, but it does not work...

Nomination-NRB commented 1 year ago

The mask doesn't have a color. You're using something like matplotlib which is providing the default yellow (1) and purple (0) cmap. The mask is only a single binary channel, with 1 being where something is. If you want black and white, just do this:

mask[mask == 1] =255
plt.imsave(arr=mask, fname="mask.jpg")

Excuse me, where should i put the code in? I put them after function save_mask_data(output_dir, masks, boxes_filt, pred_phrases) in grounded_sam_demo.py, but it does not work...

You can use this repo: https://github.com/Nomination-NRB/SAM-webui