Need help for Creating Terrain using an Image

This is my code for creating a terrain using a black and white image

using System.Collections;
using UnityEngine;

public class ImageTerrain : MonoBehaviour {
    public Texture2D heightMapTexture;
    public float maxHeight = 7.5f; // Maximum height to map to

    void Start()
    {
        //GenerateTerrain();
        int width = heightMapTexture.width;
        int height = heightMapTexture.height;

        Terrain terrain = GetComponent<Terrain>();
        TerrainData terrainData = terrain.terrainData;

        float[,] heights = new float[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                heights[x, y] = 0f;
            }
        }
        terrainData.SetHeights(0, 0, heights);

        StartCoroutine(GenerateTerrain());

    }

    IEnumerator GenerateTerrain()
    {
        int width = heightMapTexture.width;
        int height = heightMapTexture.height;

        Terrain terrain = GetComponent<Terrain>();
        TerrainData terrainData = terrain.terrainData;

        float[,] heights = new float[width, height];
        Color[] pixels = heightMapTexture.GetPixels();

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Color pixel = pixels[y * width + x];
                float grayscaleValue = pixel.grayscale; 
                float heightValue = grayscaleValue * maxHeight;
                heights[x, y] = heightValue;
                string hex = ColorUtility.ToHtmlStringRGB(pixel);
                Debug.Log($"HEX: {hex}, height: {heightValue}, Greyscale: {grayscaleValue}");
            }
            yield return new WaitForSeconds(0.05f);
            terrainData.SetHeights(0, 0, heights);
        }

        //terrainData.SetHeights(0, 0, heights);
    }

}

What I want to do is, get the greyscale value and multiply it with a number and set appropriate height to that point in the map.
maptest 3
This is image with just three colors, #FFFFFF, #000000 & #555555
image
Here below is my Terrain details
image
This is below the cube I added in the scene just to check the terrain.


I am stuck at this from the morning…
I don’t understand why the grey patch is getting the height of 7.5 as well when the Debug.Log is showing actually 2.5 height for it…

Is there any solution to this?