mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
parent
810f0cb2e8
commit
b60e9e3134
@ -3,14 +3,20 @@
|
||||
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: url: "https://linux.cn/article-15762-1.html"
|
||||
|
||||
使用此 Linux 命令从图像中删除背景
|
||||
使用 Linux 命令从图像中删除背景
|
||||
======
|
||||
|
||||
你有一张很棒的自己的照片,并想将其用于你的社交媒体资料,但背景让人分心。另一张图片为你的个人资料图片提供了完美的背景。你如何将两者结合起来? 一些智能手机应用可以进行这种照片处理,但价格太贵或充斥着广告软件。而且它们不是开源的。[Rembg][1] 将迎接挑战!
|
||||
![][0]
|
||||
|
||||
> Python 的力量使 Linux 上的图像编辑变得简单。
|
||||
|
||||
你有一张很棒的自己的照片,并想将其用于你的社交媒体资料,但背景让人分心。而另一张图片为你的个人资料图片提供了完美的背景。你如何将两者结合起来?一些智能手机应用可以进行这种照片处理,但价格太贵或充斥着广告软件。而且它们不是开源的。
|
||||
|
||||
[Rembg][1] 正适合于此。
|
||||
|
||||
Rembg 是用 Python 编写的,因此请在你的计算机上安装 Python 3。大多数 Linux 发行版默认包含 Python 3。你可以使用这个简单的命令检查你的版本:
|
||||
|
||||
@ -22,7 +28,7 @@ Rembg 至少需要 Python 3.7 且不高于 Python 3.11。就我而言,我安
|
||||
|
||||
### 在 Linux 上安装 Rembg
|
||||
|
||||
我在我的 Linux 笔记本电脑上创建了一个名为 PythonCoding 的目录,然后创建了一个 Python 虚拟环境:
|
||||
我在我的 Linux 笔记本电脑上创建了一个名为 `PythonCoding` 的目录,然后创建了一个 Python 虚拟环境:
|
||||
|
||||
```
|
||||
$ python3 -m venv /home/don/PythonCoding
|
||||
@ -30,7 +36,6 @@ $ python3 -m venv /home/don/PythonCoding
|
||||
|
||||
接下来,我使用 `pip` 安装 `rembg`:
|
||||
|
||||
|
||||
```
|
||||
$ python3 -m pip install rembg
|
||||
```
|
||||
@ -47,9 +52,9 @@ $ python3 -m pip install rembg
|
||||
$ rembg i dgw_ato.jpeg dgw_noback.jpg
|
||||
```
|
||||
|
||||
第一次运行 `rembg` 时,它会下载一个开源[模式识别模型][3]。这可能超过 100 MB,并且 `rembg` 将它保存到 `~/.u2net/u2net.onnx` 的用户目录中。该模型是 U-2-Net 并使用 Apache 2.0 许可证。有关模式识别模型的更多信息(包括如何训练你自己的模型),请阅读 Rembg 文档。
|
||||
第一次运行 `rembg` 时,它会下载一个开源 [模式识别模型][3]。这可能超过 100 MB,并且 `rembg` 将它保存到 `~/.u2net/u2net.onnx` 的用户目录中。该模型是 U-2-Net,并使用 Apache 2.0 许可证。有关模式识别模型的更多信息(包括如何训练你自己的模型),请阅读 Rembg 文档。
|
||||
|
||||
它在大约十秒钟内创建了我没有背景的新照片。我有一个带有 16 GB RAM 的 Ryzen 7。你的体验可能因硬件而异。
|
||||
它在大约十秒钟内创建了我没有背景的新照片。我有一个带有 16 GB 内存的 Ryzen 7。你的体验可能因硬件而异。
|
||||
|
||||
![A processed image of Don Watkins, with the background removed by Rembg.][4]
|
||||
|
||||
@ -61,7 +66,7 @@ $ rembg i dgw_ato.jpeg dgw_noback.jpg
|
||||
|
||||
接下来,我想给图片添加一个新的背景。有不同的方法可以做到这一点。例如,你可以使用 [ImageMagick][6] 组合图像,但获得正确的帧大小可能很复杂。最简单的方法是使用 GIMP 或 [Krita][7]。
|
||||
|
||||
我使用 GIMP。首先,打开新创建的图像(在我的例子中是 `ato_image.jpg`)。现在转到**文件**菜单并选择**打开为图层**。为背景选择不同的图像。此图像作为现有照片的叠加层打开。
|
||||
我使用 GIMP。首先,打开新创建的图像(在我的例子中是 `ato_image.jpg`)。现在转到 “<ruby>文件<rt>File</rt></ruby>” 菜单并选择 “<ruby>打开为图层<rt>Open as layers</rt></ruby>”。选择不同的背景图像。此图像作为现有照片的叠加层打开。
|
||||
|
||||
我想将新背景移到我的肖像下方。在 GIMP 窗口的右侧有两个缩略图,每个图像层一个。背景层在上面。我将背景层拖到肖像图像下方,结果如下:
|
||||
|
||||
@ -85,6 +90,8 @@ $ rembg --help
|
||||
|
||||
Rembg 使用 [MIT][9] 许可证发布。下次你需要从图像中删除背景时试试看。
|
||||
|
||||
*(题图:MJ/blur background image lens in high resolution, very detailed, 8k)*
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/23/4/image-editing-linux-python
|
||||
@ -92,7 +99,7 @@ via: https://opensource.com/article/23/4/image-editing-linux-python
|
||||
作者:[Don Watkins][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@ -106,4 +113,5 @@ via: https://opensource.com/article/23/4/image-editing-linux-python
|
||||
[6]: https://opensource.com/article/17/8/imagemagick
|
||||
[7]: https://opensource.com/article/21/12/open-source-photo-editing-krita
|
||||
[8]: https://opensource.com/sites/default/files/2023-03/don-watkins-at-the-beach.webp
|
||||
[9]: https://github.com/danielgatis/rembg/blob/main/LICENSE.txt
|
||||
[9]: https://github.com/danielgatis/rembg/blob/main/LICENSE.txt
|
||||
[0]: https://img.linux.net.cn/data/attachment/album/202304/27/225433ed1xkzdfz7iuwfyo.jpg
|
Loading…
Reference in New Issue
Block a user