Skip to content

Instantly share code, notes, and snippets.

@prateekiiest
Last active March 21, 2019 13:10
Show Gist options
  • Save prateekiiest/993d1a1cd0a8a25ce8675c56bc534689 to your computer and use it in GitHub Desktop.
Save prateekiiest/993d1a1cd0a8a25ce8675c56bc534689 to your computer and use it in GitHub Desktop.
A rough pseudo-code work-out of OCCULT-2 Algorithm

Background Suppression

def backgd_sup(image_data,  zmin, qmed =None):
  
  """
  Parameters:
  
  image_data : numpy.ndarray (map data)
  qmed : Set by user (range [1,2.5])
        if None : set qmed = 1
        
  return : numpy.ndarray 
  
  """
  
  zmed = np.median(image_data)
  low_intensity = np.argwhere(image_data < zmin)
     
  image_data[low_intensity[:,0], low_intensity[:,1]] = zmed
  
  return image_data
  

High Pass and Low Pass Filter

will depend on which scipy filtering module we will be using . For the time being I use smooth

def filter(image_data, nsm1, nsm2):
  
  """
  Parameters:
      
       image_data : Processed image <numpy.ndarray> (map.data)
       nsm1 : low pass filter constant <int> or <float>
       nsm2 : high pass filter constant <int> or <float>
    
       return : numpy.ndarray 
  """
  if(nsm1>=nsm2):
    print("nsm1 should be less than nsm2")
   
 low_pass = scipy.smooth(image_data, nsm1)
 high_pass = scipy.smooth(image_data, nsm2) # will depend on which scipy filtering module we will be using [](http://scipy-cookbook.readthedocs.io/items/SignalSmooth.html)
 
 result_image = low_pass - high_pass
 
 return result_image

Initialization of Loop Structures (Find Loop)

def find_loop(image_data):
  """
  image_data : Processed image <numpy.ndarray> (map.data)
  
  returns array of the position of individual loops  <numpy.array>
  """
  while(max(image_data) != 0):  # until the entire image is zeroed out
      pixel_pos = np.argwhere(image_data == image_data.max())
      image_data, loop_coords = trace_loop(image_data, pixel_pos) # new data with the traced loop being zeroed out
      
return loop_coords # the array of the position of individual loops

Loop Tracing (trace_loop)

def trace_loop(image_data, pix):
  """
  image_data : Processed image <numpy.ndarray> (map.data)
  pix : loop start position [X,Y] <np.array>
  
  returns loop_coordinates  <numpy.array>
  """
  # implement the algorithm as described in the paper
  
  return s # loop_coordinates range(1,ns)

Loop Subtraction

def subtract_loop(image_data,pix):
  """
  image_data : Processed image <numpy.ndarray> (map.data)
  pix : loop start position [X,Y] <np.array>
  
  returns :  <numpy.ndarray>
  """
  w = (nsm2/2 -1) #nsm2 from filter function
  s = trace_loop(image_data,pix)
  for i in range(1,len(s)):
    image_data[pix[0]+i+w][pix[1]+i+w] = 0 # setting to 0
    image_data[pix[0]+i-w][pix[1]+i-w] = 0 # setting to 0
    
    
  return image_data


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment