Upgrade status: still ongoing: WIMS. Please alert the webmaster about any anomalies.
<< WebHome


Lorentz_image.sh

packages needed

  • exiv2
  • imagemagick

#!/bin/bash

##    Lorentz_image - transform an image file 
## 
##    Copyright (C) 2013-2018 B. Roukema 
## 
##    This program is free software; you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation; either version 3, or (at your option)
##    any later version.
## 
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
## 
##    You should have received a copy of the GNU General Public License
##    along with this program; if not, write to the Free Software Foundation,
##    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
## 
##    See also http://www.gnu.org/licenses/gpl.html

## Version 2018-04-24.0

if [[ ($# -eq 0) || ($# -ge 5) ]]; then
    echo "Usage: Lorentz_image.sh image [rapidity [Lorentz [outimage]]]"
    echo "If present, Lorentz must be either 1 (Lorentz) or 0 (rotation)."
    ##echo "e.g. Lorentz_image.sh IMAGE_FILENAME 1.0 1 new.png"
    exit 0
fi

LANG=C
IMAGE=$1

## hardwired min/maximum PHI to avoid overstretching memory
MAXPHI=1.5
MINPHI=-1.5


if [[ $# -ge 2 ]]; then
    PHI=$2
    # convert from French/Polish decimal comma
    if [[ $(echo ${PHI}|grep ",") ]]; then 
        NEWPHI=$(echo ${PHI}|sed -e 's/,/\./')
        PHI=${NEWPHI}
    fi
    # make sure |PHI| is not too big
    PHI=$(echo ${PHI} | awk -v maxphi=${MAXPHI} -v minphi=${MINPHI} '{print ($1 > maxphi)? maxphi : (($1 < minphi)? minphi : $1)}')
else
    PHI=1.0
fi

if [[ $# -eq 3 ]]; then
    DO_LORENTZ=$3
else
    # default
    DO_LORENTZ="1"
fi

if [[ $# -eq 4 ]]; then
    OUTIMAGE=$4
else
    OUTIMAGE="-"
fi

XSIZE=$(exiv2 ${IMAGE} 2>/dev/null |grep "Image size" |awk '{print $4}')
YSIZE=$(exiv2 ${IMAGE} 2>/dev/null |grep "Image size" |awk '{print $6}')

if [[ "${DO_LORENTZ}" -eq "1" ]]; then
# cosh(phi)
    CPHI=$(echo ${PHI}|awk '{print 0.5*(exp($1)+exp(-$1))}')
# -sinh(phi)
    SPHI1=$(echo ${PHI}|awk '{print -0.5*(exp($1)-exp(-$1))}')
    SPHI2="${SPHI1}"
else
# cos(phi)
    CPHI=$(echo ${PHI}|awk '{print cos($1)}')
# +-sin(phi)
    SPHI1=$(echo ${PHI}|awk '{print -sin($1)}')
    SPHI2=$(echo ${SPHI1}|awk '{print (-1*$1)}')
fi
    
## test
#echo ${IMAGE} ${PHI} ${CPHI} ${SPHI} ${OUTIMAGE} && exit 0

convert ${IMAGE} -matte -virtual-pixel Transparent \
    +distort AffineProjection ${CPHI},${SPHI1},${SPHI2},${CPHI},0,0 \
    +repage ${OUTIMAGE}

examples

With -0.8 < \phi < 0.8, the Lorentz transformation gives:
bicycle world sheet La Joconde (Mona Lisa)
bike_Lorentz.gif Joconde_Lorentz.gif

-- BoudRoukema - 31 Mar 2016
I Attachment Action Size Date Who Comment
Joconde_Lorentz.gifgif Joconde_Lorentz.gif manage 1 MB 31 Mar 2016 - 11:38 BoudRoukema La Joconde (Mona Lisa) - Lorentz transform movie
bike_Lorentz.gifgif bike_Lorentz.gif manage 113 K 31 Mar 2016 - 11:37 BoudRoukema  
Topic revision: r2 - 24 Apr 2018, BoudRoukema
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback