(self, image)
| 1735 | FUNCTION = "load_image" |
| 1736 | |
| 1737 | def load_image(self, image): |
| 1738 | image_path = folder_paths.get_annotated_filepath(image) |
| 1739 | |
| 1740 | dtype = comfy.model_management.intermediate_dtype() |
| 1741 | device = comfy.model_management.intermediate_device() |
| 1742 | |
| 1743 | components = InputImpl.VideoFromFile(image_path).get_components() |
| 1744 | if components.images.shape[0] > 0: |
| 1745 | return (components.images.to(device=device, dtype=dtype), (1.0 - components.alpha[..., -1]).to(device=device, dtype=dtype) if components.alpha is not None else torch.zeros((components.images.shape[0], 64, 64), dtype=dtype, device=device)) |
| 1746 | |
| 1747 | # This code is left here to handle animated webp which pyav does not support loading |
| 1748 | img = node_helpers.pillow(Image.open, image_path) |
| 1749 | |
| 1750 | output_images = [] |
| 1751 | output_masks = [] |
| 1752 | w, h = None, None |
| 1753 | |
| 1754 | for i in ImageSequence.Iterator(img): |
| 1755 | i = node_helpers.pillow(ImageOps.exif_transpose, i) |
| 1756 | |
| 1757 | image = i.convert("RGB") |
| 1758 | |
| 1759 | if len(output_images) == 0: |
| 1760 | w = image.size[0] |
| 1761 | h = image.size[1] |
| 1762 | |
| 1763 | if image.size[0] != w or image.size[1] != h: |
| 1764 | continue |
| 1765 | |
| 1766 | image = np.array(image).astype(np.float32) / 255.0 |
| 1767 | image = torch.from_numpy(image)[None,] |
| 1768 | if 'A' in i.getbands(): |
| 1769 | mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0 |
| 1770 | mask = 1. - torch.from_numpy(mask) |
| 1771 | else: |
| 1772 | mask = torch.zeros((64, 64), dtype=torch.float32, device="cpu") |
| 1773 | output_images.append(image.to(dtype=dtype)) |
| 1774 | output_masks.append(mask.unsqueeze(0).to(dtype=dtype)) |
| 1775 | |
| 1776 | output_image = torch.cat(output_images, dim=0) |
| 1777 | output_mask = torch.cat(output_masks, dim=0) |
| 1778 | |
| 1779 | return (output_image.to(device=device, dtype=dtype), output_mask.to(device=device, dtype=dtype)) |
| 1780 | |
| 1781 | @classmethod |
| 1782 | def IS_CHANGED(s, image): |
no test coverage detected