lib/tracksperanto/uv_coordinates.rb in tracksperanto-2.12.0 vs lib/tracksperanto/uv_coordinates.rb in tracksperanto-3.0.0

- old
+ new

@@ -1,23 +1,25 @@ # -*- encoding : utf-8 -*- -# Syntheyes and some other apps use a relative UV coordinate sustem. For Syntheyes, zero is at the -# optical center of the image, and goes positive right and up. Since Tracksperanto works in absolute -# pixels we need to convert to and fro. +# For Syntheyes, zero is at the +# optical center of the image, and goes positive right and up. The corners get the [-1..1] coordinates +# respectively. Since Tracksperanto works in absolute pixels we need to convert to and from these cords. +# Note that Syntheyes actually assumes the center of the first pixel to be at -1,1 so a small +# adjustment is necessary to maintain subpixel accuracy. module Tracksperanto::UVCoordinates - # UV coords used by Syntheyes and it's lens distortion algos. + # Convert absoilute X and Y values off the BL corner into Syntheyes UV coordinates def absolute_to_uv(abs_x, abs_y, w, h) [convert_to_uv(abs_x, w), convert_to_uv(abs_y, h) * -1] end - def convert_to_uv(absolute_value, absolute_side) - x = (absolute_value / absolute_side.to_f) - 0.5 - # .2 to -.3, y is reversed and coords are double - x * 2 + # Convert absoilute pixel value off the BL corner into Syntheyes UV coordinate + def convert_to_uv(abs_value, absolute_side) + uv_value = (((abs_value.to_f - 0.5) / (absolute_side.to_f - 1)) - 0.5) * 2.0 end - - def convert_from_uv(absolute_side, uv_value) - # First, start from zero (-.1 becomes .4) - value_off_corner = (uv_value.to_f / 2) + 0.5 - absolute_side * value_off_corner + + # Convert Syntheyes UV value into absoilute pixel value off the BL corner + def convert_from_uv(uv_value, absolute_side) + # Account for the fact that Syntheyes assumes the + # pixel values to be at the center of the pixel + abs_value = (((uv_value.to_f / 2.0) + 0.5) * (absolute_side.to_f - 1)) + 0.5 end end