Visit ComfyUI Online for ready-to-use ComfyUI environment
Specialized node for extracting character images from composite sheets, maintaining aspect ratio and resizing for various applications.
The CharacterSheetCropper is a specialized node designed to process character sheets by extracting individual character images from a larger composite image. This node is particularly useful for artists and developers working with sprite sheets or character sheets, where multiple character images are arranged in a grid format. The primary function of the CharacterSheetCropper is to identify and isolate each character or object within the sheet using contour detection on a provided mask. It then crops these characters, ensuring that each extracted image maintains its original aspect ratio while being resized to a specified target height. This process is essential for creating uniform character images that can be used in various applications, such as game development or animation. The node handles various edge cases, such as zero-sized arrays or degenerate bounding boxes, ensuring robust performance even with imperfect input data.
The image parameter is a tensor representing the character sheet from which individual characters will be extracted. This input is crucial as it provides the visual data that the node processes to isolate and crop each character. The image should be in a format compatible with PyTorch tensors, typically with dimensions corresponding to height, width, and color channels.
The mask parameter is a tensor that acts as a guide for the node to identify the contours of each character within the sheet. It is a binary or grayscale image where the presence of a character is marked by non-zero values. The mask helps the node determine the boundaries of each character, ensuring accurate cropping. Like the image parameter, the mask should be formatted as a PyTorch tensor.
The min_size parameter specifies the minimum width and height, in pixels, that a character must have to be considered for cropping. This parameter helps filter out noise or very small objects that are not relevant, ensuring that only significant characters are processed. The default value is 64 pixels, but it can be adjusted based on the specific requirements of the character sheet being processed.
The target_height parameter defines the height, in pixels, to which each cropped character image will be resized. This resizing maintains the original aspect ratio of the character, ensuring that the width is adjusted proportionally. The default target height is 3072 pixels, which can be modified to suit different output size requirements.
The all_cropped_images output is a list of tensors, each representing a cropped character image extracted from the original sheet. These images are processed to maintain their aspect ratio and are resized to the specified target height. This output is essential for users who need individual character images for further use in projects such as game development or animation.
mask accurately represents the contours of the characters in the image to achieve precise cropping results.min_size parameter to filter out unwanted small objects or noise, focusing only on significant characters.target_height according to the desired output size for your project, keeping in mind that the aspect ratio will be preserved.mask to ensure it correctly outlines the characters. Verify that the min_size is not set too high, which might exclude valid characters.{contour_idx} in item {i}. Skipping this character.mask for accuracy and completeness. Ensure that the contours are correctly defined and that the mask aligns with the characters in the image.{i} has unexpected shape {mask_np_raw.shape}. Skipping this item.mask is formatted correctly as a PyTorch tensor and matches the dimensions of the image. Adjust the mask preparation process if necessary.{char_w}, h={char_h}) for contour {contour_idx} in item {i}. Skipping this character.mask to ensure it accurately represents the character boundaries. Adjust the contour detection parameters if needed to improve accuracy.RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.