Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch Background Removal
#11
(04-18-2019, 08:10 PM)Ofnuts Wrote: Removing a background is still a relatively labor-intensive process in the general case. You can automate it quite a bit if you take the photographs with that in mind: good lighting, contrasting and uniform background as a minimum. But in the pictures above, even a human has trouble distinguishing the mannequin from the background.

Otherwise you can offshore the work to sweat shops in Asia, the rates aren't that high and these folks are likely more trained than you, and this can be less expensive than hiring a trained photographer locally to redo the shorts properly.

PS: with that link above, it looks like I'm spamming my own forum Smile
[Image: smile.png]
Hi Ofnuts,  
I want to submit a question;  but I can't find any submit new question button.   I know this is cheating by contacting you here off the subject - but what else could I do?
Reply
#12
Hi Ofnots,

Thanks for your help but I feel I am far away from getting this done without your coding help.
I am unable to translate all what is obvious for you pythonwise :-)

> I cannot find simple ways to export in png the file
> for some reason the script does not appear in the console


Could you please correct this code, knowing that the purpose is to deal with 400 photos and I would like their name to be the same in another file.

PS: my business is very small so I need to use to the max GNU solutions and their generous community;

Thanks again,

Chris

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

#     Erase a complex and non even background

#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

import os,sys,math,time
from gimpfu import *


def eraseBackground2(image,layer):
   image.undo_group_start()
   gimp.context_push()
   try:
        # 1. Duplicate the layer
        DuplicateLayer = pdb.gimp_layer_copy(layer, add_alpha)
                
        # 1.1 increase contrast and tweak the brightness so that everything you want to remove is white.
        pdb.gimp_brightness_contrast(drawable, 10, 110)
        
        # 2. apply color-to-alpha and remove the white
        pdb.plug_in_colortoalpha(image, drawable, 255)
    
        # 3. alpha-select the result
        
        gimp_select_item()

        # 4. add a layer mask to the initial image, using the selection to initialize the mask
        pdb.gimp_image_add_layer_mask(image, layer-1, mask)
    
        # 5. delete the copy
        pdb.gimp_layer_delete(DuplicateLayer)
        
       # 6. save in png  
             
???

   gimp.context_pop()
   image.undo_group_end()


### Registration
whoiam='\n'+os.path.abspath(sys.argv[0])
author='Chris'
copyrightYear='2019'
desc='Erase a complex and non even background'
moredesc='\nWand-select (roughly) the background before use'
register(
   'ofn-erase-background',
   desc+moredesc+whoiam,desc,
   author,author,copyrightYear,
   'Erase uneven background',
   'RGB*',
   [
       (PF_IMAGE, 'image', 'Input image', None),
       (PF_DRAWABLE, 'drawable', 'Input drawable', None),
   ],
   [],
   eraseUnevenBackground2,
   menu='<Image>/Layer'
)

main()
Reply
#13
(04-23-2019, 06:17 AM)Terry50 Wrote: I want to submit a question;  but I can't find any submit new question button.   I know this is cheating by contacting you here off the subject - but what else could I do?

In a Forum page (here your are in a thread, not a forum), there is a big Post thread button.
Reply
#14
(04-23-2019, 09:10 AM)ct197475 Wrote: PS: my business is very small so I need to use to the max GNU solutions and their generous community;

You are mistaking me for a free script writing service. I write scripts if:
  • I learn something in the process
  • I have some use for it
  • It can benefit a wide audience
None of this seems to apply here.

The Open Source movement works based on mutual benefit. A "generous community" doesn't mean that they do the work and you get the money.
Reply
#15
Code:
gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import batch;batch.eraseBackground('C:/Users/chris/Desktop/CHRIS/MABONNEAMIE/Site/Catalogue/00 Images Produits/00 Images Shooting Originale png')" -b "pdb.gimp_quit(1)


Apprently this piece of code returns an error too but I just changed the name of the script; would you have also any clue?

Thanks a lot,

Chris


Attached Files Thumbnail(s)
   
Reply


Forum Jump: