Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function name as as input of another function?

Tags:

python

I an image processing enginner, and am using Python as a prototyping language.

Most of the time, as I get thousands of images, named "imagen.jpg", n being the increment.

So the main structure of my program may be seen as :

def main_IP(imgRoot, stop_ncrement):
  name = update_the_increment(imgRoot, stop_increment)
  img = load_the_image(name)
  out_img = process_image(img)
  displays_images(img, out_img)
  return out_img

As you can see it, from one application to another, the only change would be the process_image function. Is there a way so that the process_image can be inserted as an input?

I would get a generic function, prototyped as : main_IP(imgRoot, stop_increment, process_image)

Thanks ! Julien

like image 722
jlengrand Avatar asked Apr 10 '26 04:04

jlengrand


1 Answers

Functions can be passed around in python just like a string or any other object can.

def processImage(...):
    pass

def main_IP(imgRoot, stop_ncrement, process_image):
    name = update_the_increment(imgRoot, stop_increment)
    img = load_the_image(name)
    out_img = process_image(img)
    displays_images(img, out_img)
    return out_img

main_IP('./', 100, processImage)
like image 71
Bill Lynch Avatar answered Apr 11 '26 17:04

Bill Lynch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!