Save a batch of images (based on SaveImage source code in nodes.py)
Copy
Ask AI
for (batch_number, image) in enumerate(images): i = 255. * image.cpu().numpy() img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) filepath = # some path that takes the batch number into account img.save(filepath)
# We want [B,H,W,C] with C = 1if len(mask.shape)==2: # we have [H,W], so insert B and C as dimension 1 mask = mask[None,:,:,None]elif len(mask.shape)==3 and mask.shape[2]==1: # we have [H,W,C] mask = mask[None,:,:,:]elif len(mask.shape)==3: # we have [B,H,W] mask = mask[:,:,:,None]
When used for tasks like inpainting or segmentation, the MASK’s values will eventually be rounded to the nearest integer so that they are binary — 0 indicating regions to be ignored and 1 indicating regions to be targeted. However, this doesn’t happen until the MASK is passed to those nodes. This flexibility allows you to use MASKs as you would in digital photography contexts as a transparency layer:
Copy
Ask AI
# Invert mask back to original transparency layermask = 1.0 - mask# Unsqueeze the `C` (channels) dimensionmask = mask.unsqueeze(-1)# Concatenate ("cat") along the `C` dimensionrgba_image = torch.cat((rgb_image, mask), dim=-1)
Here’s an example of creating a noise object which mixes the noise from two sources. This could be used to create slight noise variations by varying weight2.