diff options
| -rwxr-xr-x | bin/3Drotate.py | 175 |
1 files changed, 96 insertions, 79 deletions
diff --git a/bin/3Drotate.py b/bin/3Drotate.py index 962a285..7669ffa 100755 --- a/bin/3Drotate.py +++ b/bin/3Drotate.py @@ -534,88 +534,89 @@ else: aim00 = numpy.divide(1, sx) aim02 = -numpy.divide( numpy.multiply(sx, numpy.add(di, du)), numpy.multiply(sx, focal)) - aim11= -1 / $sy" | bc` - aim12= -($sy * ($dj + $dv)) / ($sy * $focal)" | bc` - aim22= -1 / $focal" | bc` - Aim0=($aim00 0 $aim02) - Aim1=(0 $aim11 $aim12) - Aim2=(0 0 $aim22) + aim11 = numpy.divide(-1, sy) + aim12 = -numpy.divide( + numpy.multiply(sy, numpy.add(dj, dv)), numpy.multiply(sy, focal)) + aim22 = -numpy.divide(1, focal) + Aim0 = [aim00, 0, aim02] + Aim1 = [0, aim11, aim12] + Aim2 = [0, 0, aim22] -# now do successive matrix multiplies from right towards left of main equation P=A'RB + # now do successive matrix multiplies + # from right towards left of main equation P=A'RB -# convert R to T by setting T02=T12=0 and T22=-f -focalm=`echo "scale=10; - $focal" | bc` -T0=(${R0[0]} ${R0[1]} 0) -T1=(${R1[0]} ${R1[1]} 0) -T2=(${R2[0]} ${R2[1]} $focalm) + # convert R to T by setting T02=T12=0 and T22=-f + T0 = [R0[0], R0[1], 0] + T1 = [R1[0], R1[1], 0] + T2 = [R2[0], R2[1], -focal] -# multiply T x B = P -p_mat = matmul3("${T0[*]}","${T1[*]}","${T2[*]}","${B0[*]}","${B1[*]}","${B2[*]}") + # multiply T x B = P + p_mat = matmul3(T0, T1, T2, B0, B1, B2) -# multiply Aim x P = P -newmat = matmul3("${Aim0[*]}","${Aim1[*]}","${Aim2[*]}",p_mat[0],p_mat[1],p_mat[2]) + # multiply Aim x P = P + newmat = matmul3(Aim0, Aim1, Aim2, p_mat[0], p_mat[1], p_mat[2]) -# the resulting P matrix is now the perspective coefficients for the inverse transformation -P00= newmat[0][0] -P01= newmat[0][1] -P02= newmat[0][2] -P10= newmat[1][0] -P11= newmat[1][1] -P12= newmat[1][2] -P20= newmat[2][0] -P21= newmat[2][1] -P22= newmat[2][2] + # # the resulting P matrix is now + # the perspective coefficients for the inverse transformation + # P00= newmat[0][0] + # P01= newmat[0][1] + # P02= newmat[0][2] + # P10= newmat[1][0] + # P11= newmat[1][1] + # P12= newmat[1][2] + # P20= newmat[2][0] + # P21= newmat[2][1] + # P22= newmat[2][2] -# project input corners to output domain -#echo "UL" -i=0 -j=0 -u1, v1 = forwardProject(newmat, i, j) #using Aim matrix and p_mat + # project input corners to output domain + #echo "UL" + i = 0 + j = 0 + u1, v1 = forwardProject(newmat, i, j) #using Aim matrix and p_mat -i=maxwidth -j=0 -u2, v2 = forwardProject(newmat, i, j) #using Aim matrix and p_mat + i = maxwidth + j = 0 + u2, v2 = forwardProject(newmat, i, j) #using Aim matrix and p_mat -i=maxwidth -j=maxheight + i = maxwidth + j = maxheight -u3, v3 = forwardProject(newmat, i, j) #using Aim matrix and p_mat -i=0 -j=maxheight + u3, v3 = forwardProject(newmat, i, j) #using Aim matrix and p_mat + i = 0 + j = maxheight -u4, v4 = forwardProject(newmat, i, j) #using Aim matrix and p_mat + u4, v4 = forwardProject(newmat, i, j) #using Aim matrix and p_mat -# deal with adjustments for auto settings -# first get the bounding box dimensions -uArr=($u1 $u2 $u3 $u4) -vArr=($v1 $v2 $v3 $v4) -index=0 -umin=1000000 -umax=-1000000 -vmin=1000000 -vmax=-1000000 -while [ $index -lt 4 ] - do - [ `echo "${uArr[$index]} < $umin" | bc` -eq 1 ] && umin=${uArr[$index]} - [ `echo "${uArr[$index]} > $umax" | bc` -eq 1 ] && umax=${uArr[$index]} - [ `echo "${vArr[$index]} < $vmin" | bc` -eq 1 ] && vmin=${vArr[$index]} - [ `echo "${vArr[$index]} > $vmax" | bc` -eq 1 ] && vmax=${vArr[$index]} - index=`expr $index + 1` -done -delu=`echo "scale=10; $umax - $umin + 1" | bc` -delv=`echo "scale=10; $vmax - $vmin + 1" | bc` -if [ "$auto" = "c" ] - then - offsetu=`echo "scale=10; ($width - $delu) / 2" | bc` - offsetv=`echo "scale=10; ($height - $delv) / 2" | bc` - u1=`echo "scale=0; $offsetu + ($u1 - $umin)" | bc` - v1=`echo "scale=0; $offsetv + ($v1 - $vmin)" | bc` - u2=`echo "scale=0; $offsetu + ($u2 - $umin)" | bc` - v2=`echo "scale=0; $offsetv + ($v2 - $vmin)" | bc` - u3=`echo "scale=0; $offsetu + ($u3 - $umin)" | bc` - v3=`echo "scale=0; $offsetv + ($v3 - $vmin)" | bc` - u4=`echo "scale=0; $offsetu + ($u4 - $umin)" | bc` - v4=`echo "scale=0; $offsetv + ($v4 - $vmin)" | bc` + # deal with adjustments for auto settings + # first get the bounding box dimensions + uArr = [u1, u2, u3, u4] + vArr = [v1, v2, v3, v4] + umin = 1000000 + umax = -1000000 + vmin = 1000000 + vmax = -1000000 + for index in range(0, 4): + if uArr[index] < umin: + umin = uArr[index] + if uArr[index] > umax: + umax = uArr[index] + if vArr[index] < vmin: + vmin=vArr[index] + if vArr[index] > vmax: + vmax=vArr[index] + delu = numpy.add(numpy.subtract(umax, umin), 1) + delv = numpy.add(numpy.subtract(vmax, vmin), 1) + if auto == "c": + offsetu = `echo "scale = 10; ($width - $delu) / 2" | bc` + offsetv = `echo "scale = 10; ($height - $delv) / 2" | bc` + u1 = `echo "scale = 0; $offsetu + ($u1 - $umin)" | bc` + v1 = `echo "scale = 0; $offsetv + ($v1 - $vmin)" | bc` + u2 = `echo "scale = 0; $offsetu + ($u2 - $umin)" | bc` + v2 = `echo "scale = 0; $offsetv + ($v2 - $vmin)" | bc` + u3 = `echo "scale = 0; $offsetu + ($u3 - $umin)" | bc` + v3 = `echo "scale = 0; $offsetv + ($v3 - $vmin)" | bc` + u4 = `echo "scale = 0; $offsetu + ($u4 - $umin)" | bc` + v4 = `echo "scale = 0; $offsetv + ($v4 - $vmin)" | bc` elif [ "$auto" = "zc" ] then if [ `echo "$delu > $delv" | bc` -eq 1 ] @@ -628,14 +629,30 @@ elif [ "$auto" = "zc" ] offsetu=`echo "scale=10; ($width - ($delu * $height / $delv)) / 2" | bc` offsetv=0 fi - u1=`echo "scale=0; $offsetu + (($u1 - $umin) * $width / $del)" | bc` - v1=`echo "scale=0; $offsetv + (($v1 - $vmin) * $height / $del)" | bc` - u2=`echo "scale=0; $offsetu + (($u2 - $umin) * $width / $del)" | bc` - v2=`echo "scale=0; $offsetv + (($v2 - $vmin) * $height / $del)" | bc` - u3=`echo "scale=0; $offsetu + (($u3 - $umin) * $width / $del)" | bc` - v3=`echo "scale=0; $offsetv + (($v3 - $vmin) * $height / $del)" | bc` - u4=`echo "scale=0; $offsetu + (($u4 - $umin) * $width / $del)" | bc` - v4=`echo "scale=0; $offsetv + (($v4 - $vmin) * $height / $del)" | bc` + u1 = numpy.add( + offsetu, + numpy.multpily(numpy.subtract(u1, umin), numpy.divide(width, del))) + v1 = numpy.add( + offsetv, + numpy.multpily(numpy.subtract(v1, vmin), numpy.divide(height, del))) + u2 = numpy.add( + offsetu, + numpy.multpily(numpy.subtract(u2, umin), numpy.divide(width, del))) + v2 = numpy.add( + offsetv, + numpy.multpily(numpy.subtract(v2, vmin), numpy.divide(height, del))) + u3 = numpy.add( + offsetu, + numpy.multpily(numpy.subtract(u3, umin), numpy.divide(width, del))) + v3 = numpy.add( + offsetv, + numpy.multpily(numpy.subtract(v3, vmin), numpy.divide(height, del))) + u4 = numpy.add( + offsetu, + numpy.multpily(numpy.subtract(u4, umin), numpy.divide(width, del))) + v4 = numpy.add( + offsetv, + numpy.multpily(numpy.subtract(v4, vmin), numpy.divide(height, del))) fi # # now do the perspective distort |
