I have a set of microscope images that were produced in a 5x5 grid (actually 9x9 but for the purpose of this example I'm keeping it small). However, they were not taken in the same order that they appear spatially, so I want to rearrange their placement so that they appear in the right order.
The original image order looks like this, representing how the images are supposed to be laid out spatially, and which order the camera took these pics:
25 24 23 22 21
16 17 18 19 20
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
Consequently, the current list of images looks like {img1, img2, img3, img4, img5, img6 ... img25}
, but I want to create a an indexing list index = {25, 24, 23, 22, 21, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 10, 9, 8, 7, 6, 11, 12, 13, 14, 15}
. If I can create this index, it should be fairly easy to simply reorder the images in this way. To clarify: the current form of the data is a list of image files, and I want to create a new indexing list of numbers that I can use to re-index this list of images.
So, my question is: given an n*n grid, how do I create an index list that follows the above snaking pattern? So far, my code looks like this:
ReorderImages[stack_] := Block[{length, edge, startRow, firstBatch, secondBatch, indices, output}, length = Length[stack]; (*Length will always be a square of an oddnumber*) edge = Sqrt[length]; (*Edge length*) startRow = Ceiling[edge/2]; firstBatch = edge * startRow; (*The first "batch" of images taken. Here, 1-15. Not sure what to do about 16-25*) indices = {(*Stuck on how to create this part*)}; output = stack[[indices]] ]
Thanks.
ImageAssemble[]
andImageCollage[]
? $\endgroup$