How to set canvas image to a Texture2D created in a script at runtime?

I’m making a game with a map that only needs part of it shown at any time, so I have code that crops it to return a new Texture2D. This is done in its own static C# class.
I have got this far but actually setting a canvas to have this cropped image is proving impossible for me.

All tutorials show dragging and dropping sprite assets into the image component but none show how to do this in code.

Here is the property to set a texture to a sprite in code: https://docs.unity3d.com/ScriptReference/UI.Image-sprite.html
To assign “sprite” to an Image first you need to create the sprite and assign your cropped Texture2D to it probably using this method: Unity - Scripting API: Sprite.Create