Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node to remove border/frame with constant color #2794

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

RunDevelopment
Copy link
Member

Someone asked for this on discord, and I thought this would be a useful feature.

image

This node has a few useful features:

  • It automatically detects the frame/border color.
  • It allows the user to select which non-frame/border section of the image they want.
  • It allows the user to add a padding around the selected section.

The select options have the following effects:
image

The node is also quite useful for cropping images with a constant background color:

image

@joeyballentine
Copy link
Member

Is the "crop to content" node still needed after this?

@RunDevelopment
Copy link
Member Author

Yes. While the 2 nodes are very similar, they define the "content of the image" differently. Crop to Content only looks at the alpha channel to determine whether a pixel is part of the content of the image. Crop Border looks at the average error of the pixel color to a background color.

This actually the only difference between the 2 nodes. Otherwise, Crop Border is a super set of Crop to Content. I even combined the 2 nodes into Crop to Content while working on this PR, but then discarded it, because the node became too complex. I think new users would have a hard time using this node when the equivalent filters in Gimp and other programs are so much simpler.

image

@joeyballentine
Copy link
Member

I feel like you don't even have to have separate tabs for them.... "transparent" is just a bg color

@RunDevelopment
Copy link
Member Author

I feel like you don't even have to have separate tabs for them.... "transparent" is just a bg color

That would be a breaking change.

Right now, Crop To content only considers the alpha channel. Suppose we set an opacity threshold of 50%. Then any pixels with alpha >50% will be considered content, regardless of their RGB values.

However, if we use "transparent" as the border, we'll have to also set its RGB values. So let's say we set the border color to transparent black (RGBA=0,0,0,0), then the absdiff to pixels of transparent white would be ΔRGBA=(1,1,1,0). Despite being fully transparent, this pixel would be considered "content" with a tolerance of 50% due to the large absdiff.

As I said, these 2 nodes define the "content of the image" differently. However, we could change how Crop Border defines it to be compatible with Crop to Content. But I can't think of a useful distance function for that.

And even if we find such a distance function, it would still be a breaking change, because the Crop Border node automatically determines the background/border color. So it even if we have the right distance function for transparent colors, there's no guarantee that the node will pick a transparent color as the background/border color.

Copy link
Member

@joeyballentine joeyballentine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind then 👍

@joeyballentine joeyballentine merged commit 5e404e9 into chaiNNer-org:main Apr 16, 2024
14 checks passed
@RunDevelopment RunDevelopment deleted the remove-frame branch April 16, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants