Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch Background Removal
#10
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...
Reply


Messages In This Thread
Batch Background Removal - by ct197475 - 04-18-2019, 11:51 AM
RE: Batch Background Removal - by Ritergeek - 04-18-2019, 01:36 PM
RE: Batch Background Removal - by Ofnuts - 04-18-2019, 08:10 PM
RE: Batch Background Removal - by Ritergeek - 04-19-2019, 12:37 AM
RE: Batch Background Removal - by ct197475 - 04-19-2019, 07:05 AM
RE: Batch Background Removal - by Ofnuts - 04-19-2019, 09:24 AM
RE: Batch Background Removal - by ct197475 - 04-19-2019, 01:49 PM
RE: Batch Background Removal - by Ofnuts - 04-19-2019, 02:12 PM
RE: Batch Background Removal - by ct197475 - 04-22-2019, 01:01 PM
RE: Batch Background Removal - by Terry50 - 04-23-2019, 06:17 AM
RE: Batch Background Removal - by Ofnuts - 04-23-2019, 09:19 AM
RE: Batch Background Removal - by Ofnuts - 04-22-2019, 07:55 PM
RE: Batch Background Removal - by ct197475 - 04-23-2019, 09:10 AM
RE: Batch Background Removal - by Ofnuts - 04-23-2019, 09:46 AM
RE: Batch Background Removal - by ct197475 - 04-23-2019, 09:49 AM

Forum Jump: