From 4125cdedd18f6f0763b0dfdde2a37b34ccfc9323 Mon Sep 17 00:00:00 2001 From: Gsurus Date: Tue, 18 Apr 2023 10:57:30 -0400 Subject: [PATCH] Fixed an issue where the image had too many channels and failed to be loaded by PIL. --- scripts/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/app.py b/scripts/app.py index 8ce66da..f560a80 100644 --- a/scripts/app.py +++ b/scripts/app.py @@ -121,7 +121,13 @@ def run(self, p, only_save_background_free_pictures, do_not_auto_save, custom_ba # Separate the background from the foreground nmask, nimg = rmbg_fn(np.array(proc.images[i])) - # Convert the image back to a format that can be saved + # Check the number of channels in the nimg array, select only the first 3 or 4 channels + num_channels = nimg.shape[2] + if num_channels > 4: + nimg = nimg[:, :, :4] + + # Ensure the data type is uint8 and convert the image back to a format that can be saved + nimg = nimg.astype(np.uint8) img = im.fromarray(nimg) # If only_save_background_free_pictures is true, check if the image has a background