Hands On - Part I
1. Register in Adessowiki platform
2. Create your own Adessowiki Page
This page should contain your name, institution and other personal information. You can use this homepage as template: HomePage Template.
3. Code execution
Articles written on Adessowiki can embed programming code that will be executed on the server when the page is rendered, incorporating the results as figures, texts and tables on the document.
The enclosed code, for example, reads an image, processes it and shows the resulting image.
1 from ia636 import * 2 3 # reads an image 4 f = adread('lenina.pgm') 5 6 # set parameters 7 theta = pi/6 # set rotation parameter 8 scale = [1,1] # set scale parameter 9 t = [0,0] # set translation parameter 10 11 # create the transformation matrix 12 Ts = [[scale,0,0], 13 [0,scale,0], 14 [0, 0 ,1]] #Scale 15 16 Trot = [[cos(theta),-sin(theta),0], 17 [sin(theta),cos(theta) ,0], 18 [0 ,0 ,1]] #Rotation 19 20 Tx = [[1,0,t], 21 [0,1,t], 22 [0,0,1 ]] #Translation 23 24 # execute the affine transformation 25 g = iaffine(f,dot(Tx,dot(Ts,Trot))) 26 27 # image visualization 28 adshow(f,"Original image") 29 adshow(g,"Affine transformation Result")
Task I: let´s get started
- The code show is an example of using iaffine function. This function is implemented on ia636 toolbox, an open source library. This program executes affine transformations according to the input parameter:
- Rotation: theta
- Scale: scale
- Translation: t.
Your task is to change the parameter in order to get different resulting images. First of all, create a link to the first hands-on on your page. Then, copy and paste the code shown below and execute:
- A rotation;
- A vertical translation;
- A horizontal translation;
- A scale procedure to zoom in;
- A scale procedure to zoom out;
- A cascade procedure comprising rotation, translation and scale operations;
Task II: getting hard (optional)
1 import dicom 2 from ia636 import * 3 from math import * 4 5 # reads an image 6 f = iaread('lenina.pgm') 7 8 # set parameters 9 theta = pi/4 # set rotation parameter 10 scale = [0.5,0.5] # set scale parameter 11 t = [60,60] # set translation parameter 12 13 # create the transformation matrix 14 Ts = [[scale,0,0], [0,scale,0], [0,0,1]] #Scale 15 Trot = [[cos(theta),-sin(theta),0], [sin(theta),cos(theta),0], [0,0,1]] #Rotation 16 Tx = [[1,0,t], [0,1,t], [0,0,1]] #Translation 17 18 19 # image visualization 20 adshow(f,"Original image") 21 22 # iaffine transform 23 g = iaffine(f,dot(Tx,dot(Ts,Trot))) 24 adshow(g,"Affine transformation Result")
The code executes a cascade operation on the input image. Unfortunally, the result image is not the expected one. We lost relevant information that will be necessary for other operation. Note that affine transformation results depends on the order in which the operations are been executed. Your task is to solve this problem by doing some modifications in the program code.
- Change the order in which the operations are done
- Change the parameters
Task III: For Jedi Masters (optional)
In this task, you are invited to explore the functions of ia636 toolbox. You should first use the code fragment of the samples shown before to:
- generate a python code on AdessoWiki and
- read a image file
Then, use your image processing knowledge and make an interesting demonstration. We suggest those interesting options: