瀏覽代碼

Merge pull request #432 from Flippchen/doc

Documentation for sam model
Daniel Gatis 2 年之前
父節點
當前提交
91379e8d78
共有 2 個文件被更改,包括 73 次插入2 次删除
  1. 2 2
      README.md
  2. 71 0
      USAGE.md

+ 2 - 2
README.md

@@ -249,7 +249,7 @@ for file in Path('path/to/folder').glob('*.png'):
             output = remove(input, session=session)
             o.write(output)
 ```
-
+To see a full list of examples on how to use rembg, go to the [examples](USAGE.md) page.
 ## Usage as a docker
 
 Just replace the `rembg` command for `docker run danielgatis/rembg`.
@@ -272,7 +272,7 @@ The available models are:
 -   u2net_cloth_seg ([download](https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net_cloth_seg.onnx), [source](https://github.com/levindabhi/cloth-segmentation)): A pre-trained model for Cloths Parsing from human portrait. Here clothes are parsed into 3 category: Upper body, Lower body and Full body.
 -   silueta ([download](https://github.com/danielgatis/rembg/releases/download/v0.0.0/silueta.onnx), [source](https://github.com/xuebinqin/U-2-Net/issues/295)): Same as u2net but the size is reduced to 43Mb.
 -   isnet-general-use ([download](https://github.com/danielgatis/rembg/releases/download/v0.0.0/isnet-general-use.onnx), [source](https://github.com/xuebinqin/DIS)): A new pre-trained model for general use cases.
--   sam ([encoder](https://github.com/danielgatis/rembg/releases/download/v0.0.0/vit_b-encoder-quant.onnx), [decoder](https://github.com/danielgatis/rembg/releases/download/v0.0.0/vit_b-decoder-quant.onnx), [source](https://github.com/facebookresearch/segment-anything)): The Segment Anything Model (SAM).
+-   sam ([download encoder](https://github.com/danielgatis/rembg/releases/download/v0.0.0/vit_b-encoder-quant.onnx), [download decoder](https://github.com/danielgatis/rembg/releases/download/v0.0.0/vit_b-decoder-quant.onnx), [source](https://github.com/facebookresearch/segment-anything)): A pre-trained model for any use cases.
 
 ### Some differences between the models result
 

+ 71 - 0
USAGE.md

@@ -0,0 +1,71 @@
+# How to use the remove function
+
+## Load the Image
+```python
+from PIL import Image
+from rembg import new_session, remove
+
+input_path = 'input.png'
+output_path = 'output.png'
+
+input = Image.open(input_path)
+```
+## Removing the background
+
+### Without additional arguments
+This defaults to the `u2net` model.
+```python
+output = remove(input)
+output.save(output_path)
+```
+
+### With a specific model
+You can use the `new_session` function to create a session with a specific model.
+```python
+model_name = "isnet-general-use"
+session = new_session(model_name)
+output = session.remove(input, session=session)
+```
+
+### With alpha metting
+Alpha metting is a post processing step that can be used to improve the quality of the output.
+```python
+output = remove(input, alpha_matting=True, alpha_matting_foreground_threshold=270,alpha_matting_background_threshold=20, alpha_matting_erode_size=11)
+```
+
+### Only mask
+If you only want the mask, you can use the `only_mask` argument.
+```python
+output = remove(input, only_mask=True)
+```
+
+### With post processing
+You can use the `post_process_mask` argument to post process the mask to get better results.
+```python
+output = remove(input, post_process_mask=True)
+```
+
+### Replacing the background color
+You can use the `bgcolor` argument to replace the background color.
+```python
+output = remove(input, bgcolor=(255, 255, 255))
+```
+
+### Using input points
+You can use the `input_point` and `input_label` argument to specify the points that should be used for the masks. This only works with the `sam` model.
+```python
+import numpy as np
+# Define the points and labels
+# The points are defined as [y, x]
+input_point = np.array([[400, 350], [700, 400], [200, 400]])
+input_label = np.array([1, 1, 2])
+
+image = remove(image,session=session, input_point=input_point, input_label=input_label)
+```
+
+## Save the image
+```python
+output.save(output_path)
+```
+
+