code: def localcorr(self, size=2):
          
  
          from thunder.images.readers import fromarray, fromrdd
          from numpy import corrcoef, concatenate
  
          nimages = self.shape[0]
  
          # spatially average the original image set over the specified neighborhood
          blurred = self.uniform_filter(size)
  
          # union the averaged images with the originals to create an
          # Images object containing 2N images (where N is the original number of images),
          # ordered such that the first N images are the averaged ones.
          if self.mode == 'spark':
              combined = self.values.concatenate(blurred.values)
              combined_images = fromrdd(combined.tordd())
          else:
              combined = concatenate((self.values, blurred.values), axis=0)
              combined_images = fromarray(combined)
  
          # correlate the first N (averaged) records with the last N (original) records
          series = combined_images.toseries()
          corr = series.map(lambda x: corrcoef(x[:nimages], x[nimages:])[0, 1])
  
          return corr.toarray()
docs: Correlate every pixel in an image sequence to the average of its local neighborhood.
  
          This algorithm computes, for every pixel, the correlation coefficient
          between the sequence of values for that pixel, and the average of all pixels
          in a local neighborhood. It does this by blurring the image(s) with a uniform filter,
          and then correlates the original sequence with the blurred sequence.
  
          Parameters
          ----------
          size : int or tuple, optional, default = 2
              Size of the filter in pixels. If a scalar, will use the same filter size
              along each dimension.