PixelArtDetectorConverter will upscale the image if the input image is smaller than the resize sizes.

Added img2img worfklow
This commit is contained in:
Dimitar Tonev
2023-08-13 12:45:11 +02:00
parent a26af21eaf
commit 7ae1411010
7 changed files with 35 additions and 6 deletions
+9 -4
View File
@@ -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,]
+26 -2
View File
@@ -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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 915 KiB