Make output image equal to the displayed image.
Add comments to clarify code.
Make sure output image takes the gradient image when it is displayed.