ZhengPeng7 / BiRefNet

[CAAI AIR'24] Bilateral Reference for High-Resolution Dichotomous Image Segmentation
https://www.birefnet.top
MIT License
1.1k stars 85 forks source link

How to find the edge better? #97

Closed duxuan11 closed 1 hour ago

duxuan11 commented 5 days ago

For the first image I used birefnet to get the good result, now I want to get the edge of the mask, but I find that cv2.findContours does not get good results. How to find the edge better? image image

contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

ZhengPeng7 commented 5 days ago

Personally, I suggest you use two methods to remove the noise contours:

  1. morphology operation.
  2. remove contours with smaller areas.
duxuan11 commented 14 hours ago

Thank you for your advice, I was wondering if there was a way to outline the target edges more accurately (morphological manipulation is necessary) and how to filter out the blurred pixels. Fine-tuning my data set will make the results more accurate?

ZhengPeng7 commented 12 hours ago

Sure. If you have similar data used for training, model will definitely get more familiar with those cases and perform better there.

duxuan11 commented 10 hours ago

I'm sorry to bother you, I understand my needs, I need a high-precision segmentation algorithm, so I want to convert the cutout algorithm to a segmentation algorithm, alpha can only take 0 or 1. So, do you have any good suggestions?

ZhengPeng7 commented 2 hours ago

How did you use BiRefNet to obtain your results above? If you directly use it, there might be some gaps between the training and your data, such as resolution, data domain, object class, etc. So, I suggest you do some fine-tuning (for <200 samples) or training from scratch (if you have >200 samples) according to the settings of your original (cell?) data.

duxuan11 commented 1 hour ago

I directly used it to obtain the cell segmentation mask, and found a few improvement on the edge by reducing blur radius(This parameter is used to perform blur fusion to estimate foreground and background images). I think it will be useful to train the model on my dataset and adjust the value of predicted_alpha_array during inference.