Prepare sqrt (N )/sqrt(N) square image from N tiles

How can we make square image from given N tiles that is perfect square . Say N=36
each tile is 3 * H * W dimensions

N=25
Ng=5
for i in range(N//Ng):
            imgs_tmp=[imgs[i*Ng+j] for j in range(Ng) if i*Ng+j <= len(imgs)]
          
            combine_tensor_list.append(torch.cat(imgs_tmp,0))
        
    
    img=torch.cat(combine_tensor_list,0).view(3,Ng*imgs[0].size(1),Ng*imgs[0].size(2))

I am using above logic but gives a very weird image. dsnt looks to be right one wrt to view of single tile image.

1 Like

@Jaideep_Valani Could you please elaborate the question a little bit more ?

i have got 16 small rgb patches of a big image…
I want to combine them into 4/4 square grid to make a single sq size image out of that

Your problems seems interesting, just trying to solve it.
One question, does your rgb patches come in this format (N, 3, h,w) ?

assuming your stack is 16x3xhxw this will give you an image in HxWx3:

import einops
einops.rearrange(stack, '(b1 b2) c h w -> (b1 h) (b2 w) c', b1=4)

thanku what are arguements b1,b2
suppose i have 16 image tiles i need 4*4 image from this ,what would be b1,b2

thanku what are arguements b1,b2
suppose i have 16 image tiles i need 4*4 image from this ,what would be b1,b2

b1=4, b2=4 (but you can specify only one, second will be guessed since 16 / 4 = 4)