Trim transparent pixel out of an image in COP

   243   2   2
User Avatar
Member
212 posts
Joined: June 2023
Offline
I'm trying to remove transparent pixels around an image. For example, say I have an 5x5 image like this:

OOOOO
OXOXO
OXXOO
OOOOO
OOOOO

(O = transparent pixel. X = opaque pixel)

I'd like to get this 3x2 output:

XOX
XXO
In other words, I'd like to trim out as many as transparent pixels around, while keeping opaque pixels untouched.

But I can't figure out how to do this. COPVOP seems to work pixel by pixel, but in this case I need to get position of the topmost/bottommost/leftmost/rightmost opaque pixels first. How to do this in COP?
Edited by kodra - April 20, 2024 04:27:13
User Avatar
Member
1010 posts
Joined: April 2017
Offline
hmmm...

My method would be to apply the original image onto a grid. Each primitive representing the pixel with the opacity value. From there, you could use some vex to get what resolution you need to fit the opaque section and forward those info into a COPs network.

Sorry for being super vague but I don't have the time to go into details...
User Avatar
Member
160 posts
Joined: Feb. 2016
Offline
There is a iautocrop [www.sidefx.com] command line tool you could try. I've not used it, so might not work as you want.
I would suggest trying something like
iautocrop -f -p "A" example.exr cropped.exr
Edited by AslakKS - April 24, 2024 11:45:19
  • Quick Links