Skip to content

image perspective transformation around 3d axis (rotation)

Notifications You must be signed in to change notification settings

TheRincon/askew

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ASKEW: Perspective transform along specified axes

This is a rewrite of the original repo

Why a clone and not a fork? I think the original repo is great, and it is a really cool project that I use all the time. That being said, it has too many comments, requires manual changing of parameters every time, and does not support python3. I added proportional rotation for all three axes, and an option to make a gif from the tool, if imagemagick is installed. This was a fairly small change of course, but I also plan to add more image resizing based on the change in perspective (with the original you must calculate the ideal height and width yourself and pass it into the program as an awkward tuple argument).

I would try to fork and make a PR, but it does not look like it is supported currently.

Finally, I added the option to make a GIF with a flag if imagemagick is installed.

Original Author

Hou-Ning Hu / @eborboihuc

Prerequisites

Contrary to what it says on the original repo

This version is made for:

  • Python3 with numpy
  • OpenCV
  • Imagemagick* if you wish to make a GIF

Unlike the previous version, it should be able to run on any unix system with Python3, and does not require a specific version of OpenCV.

Usage

python3 askew.py [-i image_path] [-o outout] [--mode] [--theta] [--phi] [--gamma] [--length] [--width] [--dx] [--dy] [--dz] [-j gif]

Example of rotating an image along yz-axis from 0 to 360 degree with a 5 pixel shift in +X direction and making a GIF:

python3 askew.py -i images/example.jpg -o output --mode multi --phi 360 --gamma 360 -j --bg '#665151'

Single image:

python3 askew.py -i images/example.jpg --mode single  --theta 120 --gamma 120  --dz 10

Animation

Gif rotating along YZ axes and translate 5 pixel along X axis

Single frame rotated 120 degrees along the XZ axes

Parameters:

it = ImageTransformer(img_path, height=height, width=width)
it.rotate_along_axis(theta=0, phi=0, gamma=0, dx=0, dy=0, dz=0):
  • image_path : the path of image that you want rotated
  • output : name of the output image/gif
  • height : the height of output image, default is original size.
  • width : the width of output image, default is original size.
  • theta : the rotation around the x axis
  • phi : the rotation around the y axis
  • gamma : the rotation around the z axis (basically a 2D rotation)
  • dx : translation along the x axis
  • dy : translation along the y axis
  • dz : translation along the z axis (distance to the image)

Calculate max height and width

In order to calculate max height and width, as far as I know, we must pre-calculate each degree rotation and

Acknowledgments

Code ported and modified from jepson and stackoverflow. Thanks for their excellent work!

About

image perspective transformation around 3d axis (rotation)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages