changed the entire code for setting the transparency. Now we first read a FG image and for the positions where FG is not zero, we put the value of flow as the transparency value.