LaTex2Web logo

Documents Live, a web authoring and publishing system

If you see this, something is wrong

Table of contents

First published on Saturday, Jan 11, 2025 and last modified on Sunday, May 10, 2026

Linear Algebra in the Euclidean Plane Final Assessment

Fabienne Chaplais Mathedu

Keywords: shear, fast rotation

1 Introduction

2 Horizontal and vertical shears

3 Three shears for a rotation

\[ A=\begin{bmatrix}1+\alpha\beta&\alpha(2+\alpha\beta)\\ \beta&1+\alpha\beta \end{bmatrix} \]

4 Bonus: Script to rotate an image by \( \pi/2\) , directly and as the result of three shears

import imageio as iio
from matplotlib.pyplot import *
from numpy import *
# Read 'lena_gray.gif'
lena0=iio.imread('lena_gray.gif')
# Extract the first layer of the image, in gray
lena=lena0[:,:,0]
# Visualize in figure 1 the image as a matrix 512x512 pixels
imshow(lena,cmap='gray')
# Direct rotation of pi/2
R=array([[0,-1],[1,0]])
lena_rotated=zeros([512,512])
for i in arange(-255,256):
 for j in arange(-255,256):
 V=array([i,j])@R 
 lena_rotated[256+i,256+j]=lena[256+V[0],256+V[1]]
		
# Visualize in figure 2 the rotated image as a 512x512 matrix
figure()
imshow(lena_rotated,cmap='gray')
		
# margins of 256 pixels at each side
lena1=zeros([1024,1024])
lena1[256:768,256:768]=lena
		
# First horizontal shear
HS=array([[1,-1],[0,1]])
lena1_sheared=zeros([1024,1024])
for i in arange(-255,255):
	for j in arange(-255+i,255+i):
	 U=array([i,j])@HS
		lena1_sheared[512+i,512+j]=lena1[512+U[0],512+U[1]]
	 
# Visualize in figure 3 the sheared image as a 1024x1024 marix
figure()
imshow(lena1_sheared,cmap='gray')
		
# margins of 512 pixels at each side
lena2=zeros([2048,2048])
lena2[512:1536,512:1536]=lena1_sheared
		
# Vertical shear
VS=array([[1,0],[1,1]])
lena2_sheared=zeros([2048,2048])
for j in arange(-511,511):
		for i in arange(-255-j,255-j):
			W=array([i,j])@VS
		 lena2_sheared[1024+i,1024+j]=lena2[1024+W[0],1024+W[1]]
# crop to 1024 over 1024 pixels
lena2_sheared=lena2_sheared[512:1536,512:1536]

# Visualize in figure 4 the double sheared image as a 1024x1024 marix
figure()
imshow(lena2_sheared,cmap='gray')

# margins of 512 pixels at each side
lena3=zeros([2048,2048])
lena3[512:1536,512:1536]=lena2_sheared

# Second horiaontal shear
lena3=zeros([2048,2048])
lena3[512:1536,512:1536]=lena2_sheared
lena3_rotated=zeros([2048,2048])
for i in arange(-511,511):
 for j in arange(-511+i,511+i):
 U=array([i,j])@HS
 lena3_rotated[1024+i,1024+j]=lena3[1024+U[0],1024+U[1]]

# Crop to 512 over 512 pixels
lena3_rotated=lena3_rotated[768:1280,768:1280]

# Visualize in figure 5 the rotated image obtained by 3 shears as a 512x512 
matrix
figure()
imshow(lena3_rotated,cmap='gray')

5 Conclusion