You need to train your mind in order to control it. This is not easy, and it requires a lot of practice as any physical exercise.
A good trick is, when that image/though comes to your mind, you realize and you think "let's move to a different thing" and think in whatever else you want. You can also say it (if you are on your own). Also, you can have a list of nice things to think about it like: what am I going to do this weekend? or what do I want for dinner? and so on.
A similar one is set a time in the day to think about that. For example, set 10 minutes in the night to think about it, say at 9.30pm. Then, when this comes to your mind, you think "this is not the time to think about it" and keep postponing it till 9.30pm and you can think about it 10 minutes. Then, reduce the time that you are going to spend thinking about it: from 10 minutes to 8, then 6, 4... when you arrive to the 2 minutes, probably your mind will be trained enough to chose the option of stopping thinking about it.
A good way to learn how to control your mind is meditation. Again, this is not easy and it requires practice. Meditation can sound like something empty that is just going to help you to fall sleep if you practice but, actually, the goal is to learn how to control your mind and meditation will help you to be focus in one single thing during a period of time. If you are able to achieve this, you will be controlling your mind and you will be able to apply that lesson to the rest of the aspects in your life. This is an article that explains a bit how to meditate but there are several resources available in Internet that you can try and see which one is better for you, bearing in mind that what you want to achieve is cleaning your mind and to do so, you are going to practice this exercise about focusing :)