stereobase.py

Created by andy-modla

Created on June 17, 2019

1.8 KB

For 3D photography, calculate the stereo base for dual left and right cameras or sequential left and right eye photos from a single camera. The calculated base (mm) gives the most comfortable viewing experience for the stereo photo. Use different formulas for normal, close-up, or macro photography. Reference: http://nzphoto.tripod.com/stereo/3dtake/fbercowitz.htm


## 3D Photography: Stereo base calculation
# For dual camera stereo configuration 
# or single camera sequential L/R base separation
# Assumes 35mm equivalent lens focal length 
# P parallax for standard 35mm film - 36mm x 24 mm
#   P = 1.2 for 1/30 of 36mm width, 3.33% deviation
#   Assumes 3.33% is maximum deviation for comfortable viewing
#  This is the standard 1/30 rule.
# F lens focal length mm
# N near subject distance mm
# L background distance mm
# B stero base mm, the cameras interaxial distance

# Reference: http://nzphoto.tripod.com/stereo/3dtake/fbercowitz.htm

# Bercovitz formula for dual camera separation
def base(F, N, L, P=1.2):
  B=P*((L*N)/(L-N))*(1/F-(L+N)/(2*L*N))
  return B

# same as base()
def b(F, N, L, P=1.2):
  B=P/(L-N)*(L*N/F-(L+N)/2)
  return B

def near(F, B, L, P=1.2):
  t=B/P
  N = (L*(t + 0.5))/(t+L/F-0.5)
  return N
  
def far(F, B, N, P=1.2):
  t=B/P
  L = N*(t-0.5)/(t-N/F+0.5)
  return L

def focal(B, N, L, P=1.2):
  F = (L*N)/(B*(L-N)/P + (L+N)/2)
  return F
  
# Davis modification of Bercovitz formula for close-up photography
# assumes background is close to the subject
def base_closeup(F, N, L, P=1.2):
    if L<2*N:
        L = 2*N
    B=P*((L*N)/(L-N))*(1/F-(L+N)/(2*L*N))
    return B

# Wattie modification of Bercovitz formula for correct roundness
# for macro photography
# V is viewing distance mm typically 600mm for 15 inch diagonal notebook
# I is Interocular distance mm, average 63mm
def base_macro(F, N, L, V, I=63, P=1.2):
  B=P*((L*N)/(L-N))*(1/F-(L+N)/(2*L*N))
  W = N*I/V
  if W < B:
    return W
  else:
    return B

def base_meindre(F, N, L, P=1.2):
  B = (P/F)*((L*N)/(L-N))
  return B

def near_meindre(F, B, L, P=1.2):
  t = F*B/P
  N = (t*L)/(t + L)
  return N

# shortcut for close-up
def bc(F, N, L, P=1.2):
  return base_closeup(F, N, L)