#!/usr/bin/env python # coding: utf-8 # In[1]: import os import dask import dask_image.imread import matplotlib.pyplot as plt import imageio # In[2]: # Set up figure defaults # plt.rc('image', cmap='gray', interpolation='nearest') # Display all images in b&w and with 'nearest' interpolation plt.rcParams['figure.figsize'] = (16, 9) # Size up figures a bit plt.rcParams['figure.dpi'] = 300 # Increase dpi # In[3]: Images = dask_image.imread.imread(os.path.join('img', '*.jpg')) # In[4]: Images # In[5]: Images.shape # In[6]: # 'Roll' the array so that autumn is in the middle of the array and not at the start # Roll along the image axis, otherwise we roll the RGB channels :) Images = dask.array.roll(Images, shift=len(Images)//2, axis=0) # In[7]: # Show every xth image x = 5 for c, img in enumerate(Images[::x]): plt.subplot(1,len(Images[::x]), c+1) plt.imshow(img) plt.title(range(len(Images))[::x][c]) plt.axis('off') plt.show() # In[8]: # Show first x images for c, img in enumerate(Images[:x]): plt.subplot(1,len(Images[:x]), c+1) plt.imshow(img) plt.title(range(len(Images))[:x][c]) plt.axis('off') plt.show() # In[9]: Images.shape[1] / len(Images) # In[10]: Images.shape[2] / len(Images) # In[11]: TimeSlice = dask.array.zeros_like(Images[0]) # In[12]: # Debug # stepwidth = int(round((Images.shape[2] / len(Images)))) # for c, image in enumerate(Images): # print(c * stepwidth + 1, c * stepwidth + stepwidth) # In[13]: # Make a vertical timeslice stepwidth = int(round(Images.shape[2] / len(Images))) TimeSlice_Vertical = dask.array.zeros_like(Images[0]) for c, image in enumerate(Images): TimeSlice_Vertical[:,c * stepwidth + 1:c * stepwidth + stepwidth] = image[:,c * stepwidth + 1:c * stepwidth + stepwidth] # plt.subplot(121) # plt.imshow(TimeSlice_Vertical) # plt.axis('off') # plt.title(c) # plt.subplot(122) # plt.imshow(image) # plt.fill_betweenx(range(image.shape[0]), # c * stepwidth, # c * stepwidth + stepwidth, # alpha=0.5) # plt.axis('off') # plt.show() # In[14]: plt.imshow(TimeSlice_Vertical) plt.axis('off') plt.show() # In[15]: imageio.imwrite('innenhof.vertical.jpg', TimeSlice_Vertical) # In[16]: # Debug # stepheight = int(round(Images.shape[1] / len(Images))) # for c, image in enumerate(Images): # print(c * stepheight + 1, c * stepheight + stepheight) # In[18]: # Make a horizontal timeslice TimeSlice_Horizontal = dask.array.zeros_like(Images[0]) stepheight = int(round(Images.shape[1] / len(Images))) for c, image in enumerate(Images): TimeSlice_Horizontal[c * stepheight + 1: c * stepheight + stepheight] = image[c * stepheight + 1: c * stepheight + stepheight] # plt.subplot(121) # plt.imshow(TimeSlice_Horizontal) # plt.axis('off') # plt.title(c) # plt.subplot(122) # plt.imshow(image) # plt.fill_between(range(image.shape[1]), # c * stepheight, # c * stepheight + stepheight, # alpha=0.5) # plt.axis('off') # plt.show() # In[19]: plt.imshow(TimeSlice_Horizontal) plt.axis('off') plt.show() # In[20]: imageio.imwrite('innenhof.horizontal.jpg', TimeSlice_Horizontal) # In[ ]: