I also tried to improve speed by switching to MyRGB := ieTemp.IEBitmap.Pixels[X, Y];
But this also does not make any difference.
I used function Proc.GetDominantColor but the color returned by it and that calculated by my code are different. And the color returned by Proc.GetDominantColor does not match visually when we look at the image and the color returned by this function. But on the contrary the color calculated by my code matches visually with the image.