segment-anything icon indicating copy to clipboard operation
segment-anything copied to clipboard

Can SAM be used to segment grayscale image?

Open jimmylihui opened this issue 1 year ago • 5 comments

Can SAM be used to segment grayscale image with only one channel?

jimmylihui avatar Dec 09 '23 10:12 jimmylihui

And is it possible to define how many component you want to segment?

jimmylihui avatar Dec 09 '23 12:12 jimmylihui

Can SAM be used to segment grayscale image with only one channel?

As-is, the model requires input images with 3 channels (RGB or BGR). So you'd need to convert the image to have 3 channels (e.g. by duplicating the single channel 3 times for R, G and B) before passing it into the model. This can be done using photo editing software, or in code, you can use opencv:

image_3ch = cv2.cvtColor(image_1ch, cv2.COLOR_GRAY2RGB)

And is it possible to define how many component you want to segment?

If you're just using the SAM predictor directly, then the number of independent prompts determines the number of segmentations. If you use the automatic mask generation script, then you can't control it directly, though you can influence the results by adjusting the parameters, like points-per-side or min-mask-region-area

heyoeyo avatar Dec 09 '23 16:12 heyoeyo

And is it possible to define how many component you want to segment?

If you mean something like "one prompt to X outputs", and you want to customize the number X,

the only way is to initiate a new model and train it end2end.

math-yyj avatar Dec 10 '23 14:12 math-yyj

I mean customize the number of masks

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年12月10日(星期天) 晚上10:21 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [facebookresearch/segment-anything] Can SAM be used to segment grayscale image? (Issue #642)

And is it possible to define how many component you want to segment?

If you mean something like "one prompt to X outputs", and you want to customize the number X,

the only way is to initiate a new model and train it end2end.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jimmylihui avatar Dec 10 '23 14:12 jimmylihui

I mean customize the number of masks ------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年12月10日(星期天) 晚上10:21 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [facebookresearch/segment-anything] Can SAM be used to segment grayscale image? (Issue #642) And is it possible to define how many component you want to segment? If you mean something like "one prompt to X outputs", and you want to customize the number X, the only way is to initiate a new model and train it end2end. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

then you may refer to mask2former series' work, something like "max output masks/tokens" in its configs.

math-yyj avatar Dec 10 '23 17:12 math-yyj