In reality, highly accurate estimations are specific to the individual, but there are some basic properties to start with. So, we'll start laying at least a foundation now.
A paper from the Journal of Applied Physiology has looked at how energy expenditure is affected by the slope (grade) while walking (and running). You can read the full study with the link provided. Basically, they put people on a treadmill at different gradients and measure how much oxygen they are consuming. From that, they find an equation relating the relative work performed at a given grade relative to the work performed while walking on flat ground.
Concept: Oxygen Consumed ~ Work ~ Calories Burned
Given this relationship, if one know's how much work and oxygen they are consuming at any velocity and grade, one can estimate how many calories they are burning. The figure below (from the paper) shows how the relative work changes as a function of incline for both walking and running. The values of Cw are not intuitive, but how the numbers change relative to a 0 gradient may be. Given a certain velocity, positive grades increase energy expenditure, while slightly negative grades decrease expenditure. At about -10% grade, expenditure increases as the grade gets more negative.
Minetti et al 2002
So how well does this translate to outdoor hiking? There are plenty of other variables to consider such as terrain & altitude, but I think this will do a decent job estimating energy expenditure while going uphill. Downhill? I'm not as confident. I think the terrain will play a big part in make actual expenditure higher outdoors while hiking down steep trails.
You'll notice an equation deriving the energy relative to the treadmill grade:
With this equation, we can estimate the instantaneous energy expenditure at any given grade. If we have GPS data with information about the steepness as a function of distance along the trail, we can integrate and estimate the expenditure for the entire hike. Or more simply, use the average grade and distance values.
With this info, we will determine how many equivalent flat miles of walking the hike was worth. For example, I may estimate a hike up Mt Baldy (4 mile uphill, ~ 4000 ft gain) to be about the same as walking 12 flat miles (not in terms of time, but calories burned).
If we have a known quantity of energy expenditure and bodyweight for a given hike, we can make generalized estimates for other hikes and other bodyweights. For right now, the basic assumption is that calories burned is linearly related to bodyweight. So, a person weighing 100 lbs will burn 1/2 as many calories as someone weighing 200 lbs.
As I have measured my own caloric expenditure using indirect calorimetry, I use that as a basis to start with. The assumption of linear relationship between weight and calories burned will probably be improved, but we will start with that.
Also, I incorporated estimates for backpack weight, and a terrain "scaling" factor. The backpack weight inclusion will need improvement as it seems that there is a non-linear relationship between pack weight and calories burned.
So, here is the first version! Also place as a tab at the top.