Different color while saving the image as texture2D

I’m using BSR GAN from Model Zoo git

Using the below code to load the model and giving input as texture to the model in a Couroutine

  yield return null;
        _runtimeModel = ModelLoader.Load(modelAsset);
        yield return null;
        _worker = WorkerFactory.CreateWorker(BackendType.CPU, _runtimeModel, true);
        _tensor = TextureConverter.ToTensor(tex, width: tex.width / 2, height: tex.height / 2, 3);
        _worker.Execute(_tensor);
        Debug.LogError("_worker Executed");
        yield return null;
        _peekOutput = _worker.PeekOutput() as TensorFloat;
        _peekOutput.MakeReadable();

The below is for showing the output in the screen and saving that as a image using a plugin

RenderTexture rt;
 rt=  TextureConverter.ToTexture(_peekOutput, width: tex.width, height: tex.height);
        rawImage.texture = rt;
 NativeGallery.SaveImageToGallery(rt.toTexture2D(), "Converted",
             "Converted_" + DateTime.Now.ToLongTimeString());

        _peekOutput?.Dispose();
        _tensor?.Dispose();
        _worker?.Dispose();

Expected Behaviour :
The saving texture should have the same color as output
Actual Behaviour :
Converted Texture2D output is dark (maybe be more vivid) than output render texture

Extension Method :

 public static Texture2D toTexture2D(this RenderTexture rTex)
    {
        Texture2D tex = new Texture2D(rTex.width, rTex.height,GraphicsFormat.R32G32B32A32_SFloat,0);
        var old_rt = RenderTexture.active;
        RenderTexture.active = rTex;

        tex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0);
        tex.Apply();

        RenderTexture.active = old_rt;
        return tex;
    }

Tried Replacing GraphicsFormat.R32G32B32A32_SFloat to TextureFormat.RGB24 but same results.
Kindly help me to save the texture as same as output

Suggested idea
Should have a API to convert the tensor output as texture2d

Most likely a gamma issue.
Use this and check if you need to pow(color, 1.0/2.2) or pow(color, 2.2) should fix your issues

        static Color[] GetRenderTextureColors(RenderTexture rt)
        {
            RenderTexture.active = rt;

            var tex = new Texture2D(rt.width, rt.height);
            tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

            return tex.GetPixels();
        }

Hi @alexandreribard_unity , thank you for your support, but I don’t know how to save it as a image in local storage. can you help on this?

if I read the pixels without setting the texture format, it is full black

Be sure to use GraphicsFormat.R32G32B32A32_SFloat
If you cannot solve it, could you share the model we’ll investigate

Model Link

Hi,

There seems to be no output difference between Sentis and ONNX Runtime, so the problem is not related to the model’s inference. Did you manage to overcome the issue?