Cut out black background from white and black image

I’ve recently been trying to think of a way of cutting an object from a transparent background. The best explanation to what I want to do is using pictures. Picture before:


And after:

256872-after.png


As you may have noticed, I have uploaded black’n’white images, because I have an access to the transparency channel. My approach would be to get the coordinates of the first white pixel within the image and the extents of the box. Then accordingly cut the fragment out. How would I go about doing it? Is this effect possible to achieve using Unreal’s materials? If not, is there a way to do it elsewhere inside Unreal or maybe even using any kind of software that could be shipped with the project?
Thanks in advance for any tips!

Also, if I could find the median point of the opaque part of image, I could scale it to match my preferences, but the problem is I don’t know how to get the coords of this point

Take a look at this: UE4 - Advanced Mask Texture Optimisation Tutorial - YouTube and its download in the description.

Nice stuff, though I am actually interested in finding the exact positions of the bounding pixels procedurally, as I don’t have them hard-coded. I think I found a way to do so using CPP/Blueprints. When I’m ready I’ll post an answer if anybody wants it