How can I get the correct color value of a Texture2D in a compute shader?,

I would like to get the red, green and blue color values of a specific pixel in a compute shader. But unfortunately the values I get are always lower than the correct value unless it is 0 or 1.

To test this I have created a shader that writes a certain color in a pixel:

fixed4 frag() : SV_Target
{
    return _Color;
}

And read the value in the compute shader:

RWStructuredBuffer<float3> _Color;
Texture2D<float4> _Source;
//...
if (dispatchThreadId.x == 990 & dispatchThreadId.y == 1038)
{
    float3 color = _Source[dispatchThreadId].rgb;
    _Color.x = color.r;
}

The compute shader is called in OnRenderImage:

private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
    int kernel = m_ComputeShader.FindKernel("KCompute");
    m_ComputeShader.SetBuffer(kernel, "_Color", m_Buffer);
    m_ComputeShader.SetTexture(kernel, "_Source", source);
    m_ComputeShader.Dispatch(kernel, Mathf.CeilToInt(source.width / 16f), Mathf.CeilToInt(source.height / 16f), 1);
}

Unfortunately the written and the read values are not equals. If I write for example a 0.5 in the shader, I get a 0.2 in the compute shader. Only if a 0 or a 1 is written, it is the same in the compute shader.

I am pretty sure that the writing is correct, as I exported the Texture as png in the OnRenderImage and validated the pixel color of the png in Gimp.

Do you have any ideas how I can get the correct values?
Does it perhaps have something to do with the sRGB?

Have you tried using the linear=true option when you create the texture?

I wrote a compute shader that returns the count of pixels that have little red

.compute

#pragma kernel CSMain
#pragma kernel CSInit
RWStructuredBuffer<int> ResultBuffer;
Texture2D<float4> InputImage;
[numthreads(1, 1, 1)]
void CSInit(uint3 id : SV_DispatchThreadID)
{
	ResultBuffer[0] = 0;
}
//an awsnser writen by rex for full code in my github 


[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
	// found at https://answers.unity.com/questions/1745566/how-can-i-get-the-correct-color-value-of-a-texture.html from https://github.com/fenderrex/dyson-sphere
	uint4 col = InputImage[id.xy];
	if ((col.r< 0.4))
	{
		InterlockedAdd(ResultBuffer[0], 1);
	}
}

.cs

cBuffer = new ComputeBuffer(1, sizeof(int));
analysisResult = new int[1];//a awnser writen by rex for full code in my github https://answers.unity.com/questions/1745566/how-can-i-get-the-correct-color-value-of-a-texture.html
cShader.SetBuffer(kernalMain, "ResultBuffer", cBuffer);
cShader.SetBuffer(kernalInit, "ResultBuffer", cBuffer);
  
cShader.Dispatch(kernalInit, 1, 1, 1);
cShader.Dispatch(kernalMain, rt.width / 8, rt.height / 8, 1);
  
cBuffer.GetData(analysisResult);
  
cBuffer.Release();
cBuffer = null;

the fix is to remove the sRGB check on the texture if this is an asset texture, because marking it as sRGB makes it convert to linear color space