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
#Author:数声风笛离亭晚，我想潇湘君想秦！
#Email：qinjieli@gmail.com
#Usage:
##call "rotate.gnuplot" angle inputfile outputfile
#parameters:
##angle: the angle to be rotated
##inputfile: input filename (without ".png")
##outputfile: outputfilename (without ".png")
reset
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
xmax=GPVAL_DATA_X_MAX
xmin=GPVAL_DATA_X_MIN
ymin=GPVAL_DATA_Y_MIN
ymax=GPVAL_DATA_Y_MAX
set xrange [xmin:xmax] #set x and y range
set yrange [ymin:ymax]
set term png truecolor size (xmaxxmin),(ymaxymin) #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 
This is just what I was looking for, thank you.
ReplyDelete