Adding a dimension to your photos


Have you ever wanted to transform a run-of-the-mill photograph into a complete 3D scene automagically like Jack Black does in this mildly-NSFW 35MiB 2min clip from Enemy of the State?

Well too bad -- it’s just not possible to ascertain details that are hidden from the camera’s view!

You can get pretty close, though, with some software I discovered via an article in the Linux Journal.

The software is called Discrete Geometry Viewer (DGV) and I’ll illustrate the salient feature with this photo I took of a cylindrical epoxy bottle:

GDV uses the Visualization Toolkit (VTK) to display what are called “surface plots”. I wanted to record a simple screencast of myself rotating a surface plot by hand but I couldn’t convince VTK to do “live” previews. As a workaround I whipped up this shell script which rotates the surface plot in small increments, taking screenshots along the way:

# simulate multiple click-and-drag mouse events along predetermined

# coordinates. after each of these click-and-drag events, take a screenshot
# with imagemagick's "import" utility.

# you should generate coordinates at which to click with...
#  (while :; do xdotool getmouselocation | \
#   awk '{print substr($1,3) " " substr($2,3)}'; done) | uniq
# ... and save them to the file at COORDS_PATH

# you can assemble the screenshots into a movie with...
#  ffmpeg -r 30 -b 300k -i %05d.jpg -b 1157kb out.mp4

COORDS_PATH=~/prog/sh/screenshot_rect_while_dragging.dat
SHOTS_DIR=/media/humid_data/tmp/shots
# head -n1 ${COORDS_PATH} | read PREV_X PREV_Y
# PUZZLE: why doesnt the above work? instead we'll use...
PREV_X=343; PREV_Y=135
I=1
mkdir ${SHOTS_DIR}
while read CUR_X CUR_Y
do
  echo moving to ${CUR_X} ${CUR_Y} as step ${I}
  # move to pos
  # greets to fellow RIT alum jordan sissel, xdotool's author
  xdotool mousemove ${PREV_X} ${PREV_Y}
  # mouse down
  xdotool mousedown 1
  # move to pos
  xdotool mousemove ${CUR_X} ${CUR_Y}
  # mouse up
  xdotool mouseup 1
  # give the app some time to finish rendering
  sleep .3s
  # take screenshot
  import -crop 640x480+38+130 -window root -quality 100 \
  ${SHOTS_DIR}/$(printf "%05d" ${I}).jpg

  I=$((I+1))
  PREV_X=${CUR_X}
  PREV_Y=${CUR_Y}
done < ${COORDS_PATH}

Next I assembled the screenshots into a video with Openshot, a young but very stable and featureful nonlinear video editor. Here’s the result:

For some more image-processing fanciness, see this slick video demo of the “structural editing” tools planned for Photoshop CS5. There’s interesting discussion (incl. some NSFW comments) at this proggit thread. For instructions on feeding “heightmaps” to a 3D printer, see these¬†instructions.


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!