def montage2d(arr_in, fill='mean', rescale_intensity=False, grid_shape=None):
 assert (arr_in.ndim == 3)
 (n_images, height, width) = arr_in.shape
 arr_in = arr_in.copy()
 if rescale_intensity:
  for i in range(n_images):
   arr_in[i] = exposure.rescale_intensity(arr_in[i])
 if grid_shape:
  (alpha_y, alpha_x) = grid_shape
 else:
  alpha_y = alpha_x = int(np.ceil(np.sqrt(n_images)))
 if (fill == 'mean'):
  fill = arr_in.mean()
 n_missing = int(((alpha_y * alpha_x) - n_images))
 missing = (np.ones((n_missing, height, width), dtype=arr_in.dtype) * fill)
 arr_out = np.vstack((arr_in, missing))
 arr_out = arr_out.reshape(alpha_y, alpha_x, height, width)
 arr_out = arr_out.swapaxes(1, 2)
 arr_out = arr_out.reshape((alpha_y * height), (alpha_x * width))
 return arr_out

def montage2d ( arr_in , fill = 'mean' , rescale_intensity = False , grid_shape = None ) : assert ( arr_in . ndim == 3 ) ( n_images , height , width ) = arr_in . shape arr_in = arr_in . copy ( ) if rescale_intensity : for i in range ( n_images ) : arr_in [ i ] = exposure . rescale_intensity ( arr_in [ i ] ) if grid_shape : ( alpha_y , alpha_x ) = grid_shape else : alpha_y = alpha_x = int ( np . ceil ( np . sqrt ( n_images ) ) ) if ( fill == 'mean' ) : fill = arr_in . mean ( ) n_missing = int ( ( ( alpha_y * alpha_x ) - n_images ) ) missing = ( np . ones ( ( n_missing , height , width ) , dtype = arr_in . dtype ) * fill ) arr_out = np . vstack ( ( arr_in , missing ) ) arr_out = arr_out . reshape ( alpha_y , alpha_x , height , width ) arr_out = arr_out . swapaxes ( 1 , 2 ) arr_out = arr_out . reshape ( ( alpha_y * height ) , ( alpha_x * width ) ) return arr_out
create a 2-dimensional montage from a 3-dimensional input array representing an ensemble of equally shaped 2-dimensional images .