Renaming files from spiral to snake matrix

Any suggestion on how to rename images captured using spiral scan to snake?

Yes, @dgrosen that is an interesting problem. First you need to do it in a program that can understand the original filenames so that it knows what to rename. I personally would use Matlab as I know my way round it better than Python, but simple renaming could be done in a batch file.
If you have many scans that are the same size and shape, then just a look-up table would work and a batch file would be the easiest way to do it. You know exactly what the files are called, and you know exactly what the files need to be called, so it is just a list of rename commands. You would need the files to be more than just the number at some point in the process, otherwise it all gets very confusing.

1 Like

Hi @dgrosen

My smart stack / background detect mix up was embarrassing enough that it inspired me to finally make this work! It’s not formatted nicely and I’m sure @r.w.bowman will have a much cleaner way for me to share / use it, but for now this is something you can try

If you download that file to your computer, save it in the folder with all the images, then run it, it should

  • Find all images in that folder

  • Check the images look like a spiral scan (should be a square number of images)

  • Show you a preview of how each image is being renamed


    so in this example, the first image (0) in the spiral scan would be renamed to 24. The 42nd image in the spiral scan was in the top left, and so would be renamed to 0

  • ask whether or not you’re happy with this. I’ve only tested it on windows with the scans / extensions I’ve used, so this might be an important check!

  • if you type “yes”, it then makes a new folder in that image folder called “snake rename”, and copies the images in there with their new names. imageJ can then tile them as if it was a snake scan

Like I say, just put this together and it works for me, but Mac / someone else’s computer / different scans might not work, but it might be a good temporary thing until we make something nicer. Eventually I’m imagining an option to run a spiral scan in the software, but save the images to the Pi already named as if they were from a snake scan

Please let us know what you think and if you run into any trouble. Can also change it so you don’t need to save it in the folder each time, just type in the path in the terminal when you run it, so let me know if that’s easier for you

1 Like