Blur parts of an Image [on hold]

How to blur parts of an image according to pixel values in a given range. Basically I’ve the corresponding marked image portions as foreground and background, and I want to blur the background using python.

I am basically trying to achieve conversion of normal image to a portrait mode image(as in IphoneX or Pixel)

Blur parts of an Image [on hold]