Did you want those sinful imaginations?
If images were merely presented to your imagination, but they disgusted you and you would rather they not be there, they could be placed there by the devil.
You might have experienced only a temptation, and not a sin.
The devil, being a pure spirit (as opposed to body and soul, like a human being), is master of the physical universe. He understands science, physics, and other earthly sciences implicitly.
He can only do things in the physical realm -- such as try to stimulate your emotions or passions, present things to your imagination (which is part of the physical realm -- even dogs dream, for instance)
What the devil CAN'T do is make you choose evil, or sin. He can't touch
A) your intellect, or
B) your free will.
Those are the faculties of your soul.
Matthew