diff --git a/PixelArtDetector.py b/PixelArtDetector.py index e7c27b2..c0d05cd 100644 --- a/PixelArtDetector.py +++ b/PixelArtDetector.py @@ -162,6 +162,11 @@ class PixelArtDetectorConverter(): results = list() for image in images: pilImage = Image.fromarray(np.clip(255. * image.cpu().numpy(), 0, 255).astype(np.uint8)).convert("RGB") + resizeBefore = pilImage.width < resize_w and pilImage.height < resize_h + + # resize if image needs upscale + if resizeBefore and resize_w >= 128 and resize_h >= 128: + pilImage = pilImage.resize((resize_w, resize_h), resample=Image.Resampling.NEAREST) # Start timer start = round(time.time()*1000) @@ -175,11 +180,11 @@ class PixelArtDetectorConverter(): PILOutput = pixelate(pilImage, grid_pixelate_grid_size, transformPalette(palette, "tuple")) print(f"### {self.CGREEN}[PixelArtDetectorConverter]{self.CEND} Image converted in {self.CYELLOW}{round(time.time()*1000)-start}{self.CEND} milliseconds") - - # resize - if not isGrid and resize_w >= 128 and resize_h >= 128: - PILOutput = PILOutput.resize((resize_w, resize_h), resample=Image.Resampling.NEAREST) + # resize if image needs downscale + if not resizeBefore and not isGrid and resize_w >= 128 and resize_h >= 128: + PILOutput = PILOutput.resize((resize_w, resize_h), resample=Image.Resampling.NEAREST) + # Convert to torch.Tensor PILOutput = np.array(PILOutput).astype(np.float32) / 255.0 PILOutput = torch.from_numpy(PILOutput)[None,] diff --git a/README.md b/README.md index 13b6c7c..9bf477f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ComfyUI PixelArt Detector v1.1 +# ComfyUI PixelArt Detector v1.2 Generate, downscale, change palletes and restore pixel art images with SDXL. ![](./examples/Image_00135_.webp) ![](./examples/Image_00157_.webp) ![](./examples/Image_00162_.webp) ![](./examples/Image_00165_.webp) ![](./examples/Image_00166_.webp) @@ -9,7 +9,9 @@ Generate, downscale, change palletes and restore pixel art images with SDXL. Save a picture as Webp (+optional JPEG) file in Comfy + Workflow loading. -**Update**: changed the default workflow.json to use the default "Save Image" node. workflow_webp.json will be using the webp node. +**Update 1.2**: PixelArtDetectorConverter will upscale the image if the input image is smaller than the resize sizes. + +**Update 1.1**: changed the default workflow.json to use the default "Save Image" node. workflow_webp.json will be using the webp node. > [!IMPORTANT] > If you have an older version of the nodes, delete the node and add it again. Location of the nodes: "Image/PixelArt". I've added some example workflow in the workflow.json. The example images might have outdated workflows with older node versions embedded inside. @@ -62,6 +64,8 @@ Set the resize inputs to 0 to disable upscaling in the "Save" node. Reduce palettes or completely exchange palettes on your images. +##text2image + **Positive prompt**: pixelart, {your scene}, pixel-art. low-res, blocky, pixel art style, 8-bit graphics, sharp details, less colors, early computer game art **Negative prompt**: sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic, high-resolution, photo-realistic @@ -70,6 +74,26 @@ Reduce palettes or completely exchange palettes on your images. ![](./examples/community/PixelArt_00004_.webp) ![](./examples/community/ImageConverted_00006_.webp) ![](./examples/community/ImageConverted_00005_.webp) +##image2image + +on a pixel drawing converting to a pixel asset for finetuning: + +Input: +![](./examples/pixil-frame-0.png) + +Output: +![](./examples/PixelArt_00065_.webp) +![](./examples/PixelArt_00058_.jpg) +![](./examples/PixelArt_00071_.webp) + +Workflow WEBP (drag & drop): +![](./img2img_webp.png) + +Feel free to experiment! + +Other image2image examples: +https://github.com/dimtoneff/ComfyUI-PixelArt-Detector/issues/2 + ### Extra info about the "PixelArt Detector (+Save)" Node: There is a compression slider and a lossy/lossless option for webp. The compression slider is a bit misleading. diff --git a/examples/PixelArt_00058_.jpg b/examples/PixelArt_00058_.jpg new file mode 100644 index 0000000..8263d43 Binary files /dev/null and b/examples/PixelArt_00058_.jpg differ diff --git a/examples/PixelArt_00065_.webp b/examples/PixelArt_00065_.webp new file mode 100644 index 0000000..41565d8 Binary files /dev/null and b/examples/PixelArt_00065_.webp differ diff --git a/examples/PixelArt_00071_.webp b/examples/PixelArt_00071_.webp new file mode 100644 index 0000000..fd414b8 Binary files /dev/null and b/examples/PixelArt_00071_.webp differ diff --git a/examples/pixil-frame-0.png b/examples/pixil-frame-0.png new file mode 100644 index 0000000..0cdd8ef Binary files /dev/null and b/examples/pixil-frame-0.png differ diff --git a/img2img_webp.png b/img2img_webp.png new file mode 100644 index 0000000..0846d6c Binary files /dev/null and b/img2img_webp.png differ