Move each image to its most referenced folder

I don’t know what plugin or script could achieve this. Most referenced? I think the image can be anywhere. The important thing is the markdown file containing the reference.

If you are bothered by the fact the images are dumped together in the root folder, you can set a folder below each folder with a name like attachments, assets, resources, media, images, etc.
See in my case:

There was also a similar thread in the past: