Use custom header image on child page

I have created a theme for wordpress in which each page can be customized with a different header image.

By default you set a custom image for the whole site, but depending on customization you can end up with various header image. Each content type can have a custom image, and each page can be set with a custom one.

In my header.php page this is what I have :

Then in my function.php page :

}

Now I just realized that I didn’t plan well enough for child page, as I would like for their parent page image to be displayed.

Pages are using $customheadimg to display their own header image.