Trim by alpha #105
-
|
I'm using chroma key to cut out pieces of clothing from their white background and I'd like to get rid of that transparent whitespace. Trim seems to be color based, but really I'd like to simply trim based on the alpha channel only. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Hey Benjamin, thanks for the issue. Should be very possible and I'll work on a case Image.split_alpha(image) do
{_image_without_alpha, alpha} when !is_nil(alpha) ->
# Find the trim area of the alpha band
{:ok, {left, top, width, height}} = Vix.Vips.Operation.find_trim(alpha, background: [0, 0, 0], tolerance: 10.0)
# Crop the original image based upon the trim
Image.crop(image, left, top, width, height)
_other ->
{:error, "Image has no alpha band"}
endYou might need to do some tuning on the |
Beta Was this translation helpful? Give feedback.
-
|
I've pushed a commit that adds the option Your feedback very much appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
I've published image version 0.37.0 with the new |
Beta Was this translation helpful? Give feedback.
I've pushed a commit that adds the option
background: :alphato theImage.trim/2function. I've added a simple test case which suggests it's working as expected. If can try it by configuringimagefrom{:image, github: "elixir-image/image"}. I'll release it when you confirm its operating as expected.Your feedback very much appreciated.