Batch Background Removal - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +--- Thread: Batch Background Removal (/Thread-Batch-Background-Removal) Pages:
1
2
|
Batch Background Removal - ct197475 - 04-18-2019 Hi There, After having scanned despairately the net to find a simple solution (and found out this place from http://gimp-tools.sourceforge.net/index.shtml and previously https://sourceforge.net/projects/gimp-tools/) I am asking help for this problem I have: a solution to remove the background of 300 dresses. Here are the specs - in jpg - the background is not evenly white unfortunaltely I did not find any script doing it even roughly on the net (did I miss something after 4h of search ???) I have implemented Bimp but am blocked by not being able in Bimp to create a alpha channel from a jpg photo. ➤ Has anybody the procedure on Bimp ? ➤ or a beautiful script? Thanks for your help ! Chris RE: Batch Background Removal - Ritergeek - 04-18-2019 If I understand right, you need to add an alpha channel to these images. Have you tried right-clicking your base image and adding an alpha channel? JPG images did not load with an alpha channel until 2.10.10, which released a few days ago. Now you can set GIMP to automatically add an alpha channel to jpg images. The switch is in Preferences>Image Import & Export >Import Policies. RE: Batch Background Removal - Ofnuts - 04-18-2019 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 RE: Batch Background Removal - Ritergeek - 04-19-2019 (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. Spam away Ofnuts, if that's what it is. Many of us are new enough not to know of your rich treasure trove. RE: Batch Background Removal - ct197475 - 04-19-2019 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. Thanks a lot Ofnuts for your swift answer proving Gimp is a real alternative; yes I believe in automation;-) and I want to be autonomous on this matter if possible; I have discovered that the "alfa to color" function with Threshold and Opacity set to 50% create a realy good job even in complicated background! ➤ I am missing the code though to batch process it as the Bimp in Gimp does not offer to deal with those functionality. Would you have such a code that I could adapt to the file where I have 500 pictures to handle ? Very best, Chris (04-18-2019, 01:36 PM)Ritergeek Wrote: If I understand right, you need to add an alpha channel to these images. Have you tried right-clicking your base image and adding an alpha channel? JPG images did not load with an alpha channel until 2.10.10, which released a few days ago. Now you can set GIMP to automatically add an alpha channel to jpg images. The switch is in Preferences>Image Import & Export >Import Policies. Thanks Ritergeek for your answer! As I did not know it I made a Bimp on it;-) took ages ;-) I have discovered that the "alfa to color" function with Threshold and Opacity set to 50% create a realy good job even in complicated background! ➤ I am missing the code though to batch process it as the Bimp in Gimp does not offer to deal with those functionality. Would you have such a code that I could adapt to the file where I have 500 pictures to handle ? Very best, Chris RE: Batch Background Removal - Ofnuts - 04-19-2019 (04-19-2019, 07:05 AM)ct197475 Wrote: Thanks a lot Ofnuts for your swift answer proving Gimp is a real alternative; https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560 RE: Batch Background Removal - ct197475 - 04-19-2019 (04-19-2019, 09:24 AM)Ofnuts Wrote:(04-19-2019, 07:05 AM)ct197475 Wrote: Thanks a lot Ofnuts for your swift answer proving Gimp is a real alternative; Thanks Ofnuts for this resource but where can I find the command that creates the action of getting color tonalphaband then setting Opacity and Transparency thresold ? Sorry my knowledge is poor in gimp and Puthon RE: Batch Background Removal - Ofnuts - 04-19-2019 (04-19-2019, 01:49 PM)ct197475 Wrote:(04-19-2019, 09:24 AM)Ofnuts Wrote:(04-19-2019, 07:05 AM)ct197475 Wrote: Thanks a lot Ofnuts for your swift answer proving Gimp is a real alternative; Filters>Python-fu>Console, and hit the Browse button. It's all there, use the search bar. The old Color-to-alpha (the one you can use via Python-fu) has no Transparency/Opacity thresholds, but I don't think it matters much in your case. In a script, I would: * duplicate the layer, * increase contrast and tweak the brightness so that everything you want to remove is white. * apply color-color-alpha and remove the white * alpha-select the result (IIRC, gimp_select_item() the layer) * add a layer mask to the initial image, using the selection to initialize the mask * delete the copy RE: Batch Background Removal - ct197475 - 04-22-2019 (04-19-2019, 02:12 PM)Ofnuts Wrote:(04-19-2019, 01:49 PM)ct197475 Wrote:(04-19-2019, 09:24 AM)Ofnuts Wrote: https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560 Hi Ofnuts, I am really struggling here !-) I think I need your kind expertise. I have found this great piece of code you did formerly; we could start from that to code what you defined here above? * duplicate the layer, * increase contrast and tweak the brightness so that everything you want to remove is white. * apply color-color-alpha and remove the white * alpha-select the result (IIRC, gimp_select_item() the layer) * add a layer mask to the initial image, using the selection to initialize the mask * delete the copy So can you please check the amended code? Code: #!/usr/bin/env python If I am right the code to batch process with the name of my batch file would be? 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) Chris RE: Batch Background Removal - Ofnuts - 04-22-2019 Given the question marks, you haven't really understood how my procedure works. The fundamental idea is that your source image hasn't enough contrast to do a useful color-erase. But we can; 1) make a copy of that layer and increase the contrast on it so that the background becomes white 2) color-erase the background on that over-contrasted copy. We now have a cut-out, over-contrasted image and the initial image. We wan to transfer the transparency of the over-contrasted image to the initial image, so 3) create a selection from the opacity of the cut-out image (in the UI, that's Alpha to selection, but in a script, that's gimp_select_item(layer)) 4) use the selection to create a layer mask for the initial image Then we are done, we just need to 5) erase the over-contrasted image, that has served its purpose. 6) export the image to file (in a format that supports transparency, so PNG or WEBP). As to your code: 1) please remove any reference to me, that's your code... 2) no need to fetch the active drawable since this is exactly what is passed to you as the layer argument. 3) when you duplicate the layer, the function returns a reference to the copy, keep it safely, it will be useful later 4) brightness-contrast needs two plain numbers, you use brightness and contrast variables out of the blue... |