Question: Part 2) Affine Transformation: For the second part, you are implementing a function to apply an affine transformation to the input image. Such transformation is

Part 2) Affine Transformation:

For the second part, you are implementing a function to apply an affine transformation to the input image. Such transformation is described using a 2x3 transform matrix (M) that map pixels at input image to different coordinates in output image. Affine transformations have this property that they map parallel lines in input image to parallel lines in output image. Examples of affine transformations include: translation, rotation, reflection and scale.

The following algorithm demonstrates applying affine transformation to an input image. In this algorithm x and y represents current pixel coordinates -- x being the column index and y being the row index. Top-left pixel has coordinates of (0, 0).

for each input image pixel at x,y coordinate:

x0= Moox + Mo1 y + M02

y0= M1ox + M11 y + M12

output(x,y) = input(x0, y0) if cols >xo0 and rows> y00 otherwise 0

Although image pixel are bytes, matrix elements are integers. Heres some examples of affine transformations:

############################################################### # Text Section .text # Utility function to print byte arrays #a0: array #a1: length print_array: li $t1, 0 move $t2, $a0 print: lb $a0, ($t2) andi $a0, $a0, 0xff li $v0, 1 syscall li $v0, 4 la $a0, space syscall addi $t2, $t2, 1 addi $t1, $t1, 1 blt $t1, $a1, print jr $ra ######################################################################################## #a0 = input array #a1 = output array #a2 = matrix #s3 = input dim #s4 = test str #s5 = expected array # Test transform function ######################################################################################## test_p2: # save ra addi $sp, $sp, -4 sw $ra, 0($sp)

addi $sp, $sp, -4 sw $a0, 0($sp) addi $sp, $sp, -4 sw $a1, 0($sp) addi $sp, $sp, -4 sw $a2, 0($sp) addi $sp, $sp, -4 sw $a3, 0($sp) addi $sp, $sp, -4 sw $s4, 0($sp) addi $sp, $sp, -4 sw $s5, 0($sp)

#a0: input buffer address #a1: output buffer address #a2: transform matrix address #a3: image dimension (Image will be square sized, i.e. total size = a3*a3) jal transform

lw $s5, 0($sp) addi $sp, $sp, 4 lw $s4, 0($sp) addi $sp, $sp, 4 lw $s3, 0($sp) addi $sp, $sp, 4 lw $s2, 0($sp) addi $sp, $sp, 4 lw $s1, 0($sp) addi $sp, $sp, 4 lw $s0, 0($sp) addi $sp, $sp, 4

# s5: exp arraay # s4: input string # s3: input dimenstion # s2: matrix # s1: user out # s0: inputd

mul $s3, $s3, $s3

move $a0, $s4 syscall la $a0, i_str syscall move $a0, $s0 move $a1, $s3 jal print_array li $v0, 4 la $a0, new_line syscall

la $a0, po_str syscall move $a0, $s1 move $a1, $s3 jal print_array li $v0, 4 la $a0, new_line syscall la $a0, eo_str syscall move $a0, $s5 move $a1, $s3 jal print_array li $v0, 4 la $a0, new_line syscall syscall

# restore ra lw $ra, 0($sp) addi $sp, $sp, 4

jr $ra

############################################################### # PART 2 (Matrix Transform) #a0: input buffer address #a1: output buffer address #a2: transform matrix address #a3: image dimension (Image will be square sized, i.e., number of pixels = a3*a3) ############################################################### transform: ############################### Part 2: your code begins here ##

############################### Part 2: your code ends here ## jr $ra ###############################################################

###############################################################

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!