It is currently Sat Jul 06, 2024 5:57 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 50 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Sep 11, 2023 9:17 am  (#41) 
Offline
GimpChat Member

Joined: Nov 19, 2019
Posts: 207
Thanks Tas_mania

I got stuck here though

Quote:
$ mkdir ~/.conda/envs/orion/lib/python3.8/opencv_python-3.4.11.dist-info
mkdir: cannot create directory ‘/home/myPC/.conda/envs/orion/lib/python3.8/opencv_python-3.4.11.dist-info’: No such file or directory


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Sep 11, 2023 9:32 am  (#42) 
Offline
GimpChat Member

Joined: Nov 19, 2019
Posts: 207
I installed Open CV using

sudo apt install python3-opencv -y


but still getting an error

Quote:
rembg i /home/myPC/12.png /home/myPC/haa.png
Traceback (most recent call last):
File "/home/myPC/.local/bin/rembg", line 8, in <module>
sys.exit(main())
File "/home/myPC/.local/lib/python3.10/site-packages/rembg/cli.py", line 33, in main
_main() # type: ignore
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1257, in invoke
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 700, in make_context
self.parse_args(ctx, args)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1048, in parse_args
value, args = param.handle_parse_result(ctx, opts, args)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1623, in handle_parse_result
value = self.full_process_value(ctx, value)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1965, in full_process_value
return Parameter.full_process_value(self, ctx, value)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1592, in full_process_value
value = self.get_default(ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1917, in get_default
return Parameter.get_default(self, ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1534, in get_default
return self.type_cast_value(ctx, rv)
File "/home/myPC/.local/lib/python3.10/site-packages/click/core.py", line 1561, in type_cast_value
return self.type(value or (), self, ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/types.py", line 46, in __call__
return self.convert(value, param, ctx)
File "/home/myPC/.local/lib/python3.10/site-packages/click/types.py", line 681, in convert
raise TypeError(
TypeError: It would appear that nargs is set to conflict with the composite type arity.


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Sep 11, 2023 9:42 am  (#43) 
Offline
GimpChat Member

Joined: Nov 19, 2019
Posts: 207
Solved using this trick. Commented out a few lines in i_command.py

https://github.com/danielgatis/rembg/is ... 1621412245


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Thu Nov 16, 2023 11:42 am  (#44) 
Offline
GimpChat Member

Joined: Nov 19, 2019
Posts: 207
A different PC, installing on Windows 10. Added rembg, the GPU version + CLI, added the correct path and placed the plugin in plugins folder. Nothing under PythonFU. Restarted the computer, still nothing. Do we need to use some special command to start GIMP in Windows 10 to get the bg remove options? Thanks

Using 2.10.24


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Thu Nov 16, 2023 12:00 pm  (#45) 
Offline
GimpChat Member

Joined: Nov 19, 2019
Posts: 207
Found a solution. It is not working when added under program files. So added under AppData path. Now fine :)


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Nov 27, 2023 12:37 pm  (#46) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1457
This plugin will soon have a Linux only GEGL counterpart that calls REMBG or any bash string from the users system in GEGL.

viewtopic.php?f=9&t=20652

On my machine for it to work I will have to
1.open the GEGL plugin.
2. type in a given import/export file name
3.insert the string
source ~/Applications/mc/etc/profile.d/conda.sh && conda activate base && rembg -p


Then REMBG will be inside GEGL due to it being a bash string. Though I must note Gimp will be frozen until REMBG loads, Stay tuned!


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Nov 27, 2023 1:36 pm  (#47) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
@contrast_ that sounds really cool. :coolthup

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Fri Dec 01, 2023 2:57 pm  (#48) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1457
outdated post


Last edited by contrast_ on Thu Dec 28, 2023 8:52 pm, edited 1 time in total.

Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Dec 05, 2023 2:11 am  (#49) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1457
REMBG now runs in GEGL and you guys can see it here.

viewtopic.php?f=9&t=20652&start=10


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Thu Dec 28, 2023 3:53 am  (#50) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1457
JamesH was the one who wrote the flatpak-spawn stuff but I edited it and got it working on the latest release of REMBG from late 2023. Please replace contrast with your username


#!/usr/bin/env python
# -*- coding: utf-8 -*-

# James Huang <elastic192@gmail.com>
# https://elastic192.blogspot.com/

from gimpfu import *
import os, sys, string, tempfile
import platform

def python_fu_RemoveBG(image, drawable, asMask, AlphaMatting, aeValue):
   removeTmpFile = True
   osName = platform.system()
   exportSep = str(os.sep)
   tdir = "/home/contrast/rembggimp"
   #tdir = "./"
   print(tdir)
   jpgFile = "%s%ssubjectR.jpg" % (tdir, exportSep)
   pngFile = "%s%ssubjectR.png" % (tdir, exportSep)
   x1 = 0
   y1 = 0
   option = ""

   image.undo_group_start()
   curLayer = pdb.gimp_image_get_active_layer(image)

   if pdb.gimp_selection_is_empty(image):
      pdb.file_jpeg_save(image, drawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0)
   else:
      pdb.gimp_edit_copy(drawable)
      non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
      tmpImage = gimp.Image(x2-x1, y2-y1, 0)
      tmpDrawable = gimp.Layer(tmpImage, "Temp", tmpImage.width, tmpImage.height, RGB_IMAGE, 100, NORMAL_MODE)
      pdb.gimp_image_add_layer(tmpImage, tmpDrawable, 0)
      pat = pdb.gimp_context_get_pattern()
      pdb.gimp_context_set_pattern("Leopard")
      pdb.gimp_drawable_fill(tmpDrawable, 4)
      pdb.gimp_context_set_pattern(pat)
      pdb.gimp_floating_sel_anchor(pdb.gimp_edit_paste(tmpDrawable,TRUE))
      pdb.file_jpeg_save(tmpImage, tmpDrawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0)
      pdb.gimp_image_delete(tmpImage)
   
   aiExe = "/home/contrast/.local/bin/rembg"
   if AlphaMatting:
      option = "-a -ae %d" % (aeValue)
   cmd = "flatpak-spawn --host %s i %s %s" % (aiExe, jpgFile, pngFile)
   os.system(cmd)

   file_exists = os.path.exists(pngFile)
   if file_exists:
      newlayer = pdb.gimp_file_load_layer(image, pngFile)
         image.add_layer(newlayer, -1)
         pdb.gimp_layer_set_offsets(newlayer, x1, y1)
         if asMask:
            pdb.gimp_image_select_item(image, CHANNEL_OP_REPLACE, newlayer)
            image.remove_layer(newlayer)
         copyLayer = pdb.gimp_layer_copy(curLayer, TRUE)
         image.add_layer(copyLayer, -1)
         mask=copyLayer.create_mask(ADD_SELECTION_MASK)
         copyLayer.add_mask(mask)
         pdb.gimp_selection_none(image)

      image.undo_group_end()
      gimp.displays_flush()

   if removeTmpFile:
      if osName == "Windows":
         del_command = "del \"%s%ssubjectR.*\"" % (tdir, exportSep)
      else:
         del_command = "sleep 0.6 && rm %s%ssubjectR.*" % (tdir, exportSep)
      os.system(del_command)

register(
    "python_fu_RemoveBG",
    "AI移除影像背景, AI Remove image background",
    "AI移除影像背景, AI Remove image background",
    "JamesH, <elastic192@gmail.com>",
    "JamesH, https://elastic192.blogspot.com",
    "2022/6/4",
    "<Image>/REMBG/AI移除影像背景(AI Remove background) ...",
    "RGB*",
    [
       (PF_TOGGLE, "asMask", ("當作圖層遮罩(as Mask)"), False),
       (PF_TOGGLE, "AlphaMatting", ("alpha matting"), False),
       (PF_SPINNER,"aeValue", ("ALPHA_MATTING_ERODE_SIZE"), 10, (10,100,1))
    ],
    [],
    python_fu_RemoveBG,
    domain=("gimp20-python", gimp.locale_directory))

main()


Top
Post new topic Reply to topic  [ 50 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) REMBG - an open source offline usable background removal AI

12

No new posts Attachment(s) Use of Fuzzy Select tool to remove white background from black text

2

No new posts Attachment(s) Remove Stain from Image

5

No new posts Attachment(s) Remove white background but keep white inner

6

No new posts How is the background removed from this image?

2



* Login  



Powered by phpBB3 © phpBB Group