Friday, September 30, 2011

Rotate a picture using gnuplot

Last time I promised rotating a picture using gnuplot will be talked. Today I come to realize my promise.Let us look at the script at first.
#Utility:Convert a rgb colorized image to a gray one
##call "rotate.gnuplot" angle inputfile outputfile
##angle: the angle to be rotated
##inputfile: input filename (without ".png")
##outputfile: outputfilename (without ".png")
angle=$0    #angle to be rotated
angle=angle*pi/180    #change degrees to radians
inputfile="$1.png"    #input file
outputfile="$2.png"    #ouput file
set size ratio -1
# Set the scales so that the unit has the same length
#on both the x and y axes
set lmargin 0    #nO margin
set rmargin 0
set tmargin 0
set bmargin 0
unset tics    #no tics and border line
unset border
#plot and get the size of the rotated picture
plot inputfile binary filetype=png rotate=angle w rgbima notitle
set xrange [xmin:xmax]    #set x and y range
set yrange [ymin:ymax]
set term png truecolor size (xmax-xmin),(ymax-ymin)    #set the terminal
set output outputfile
plot inputfile binary filetype=png rotate=angle w rgbima notitle
The script first plot the plot the rotated picture on screen. This plot has two functions, determining the size of the output picture and letting the user have view at the rotated picture. Save the script as "rotate.gnuplot", and then it can be called like this:
gnuplot> call "rotate.gnuplot" 30 input output
At last is one of our finished work.

Input picture file (initial file download from here)

Picture rotated by 30 degree using our script

1 comment:

  1. This is just what I was looking for, thank you.


Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.