Create a Unity Script to crop Image (Texture2D) to the smallest bounding box that removes all white space

Job ID: 33053504

Budget: $12 – $30 SGD

I want a Unity script that, when given a Texture2D as input, can crop the Texture2D to only retain the smallest box whereby all the image still remains. This means to crop out any area whereby it is white space and not relevant to the image.

For the image, there will only be two colors - black and white, with the black indicating the image and the white area indicating empty space that can be cropped out.

In the attached files, I show a drawing of a house (in black) and I want the script to crop the image to only retain the image within the red dotted lines.
Related categories: C# Programming Unity 3D