Unit1 lecture recording November 16th

angelaob (1190 points)
2 4 7
asked Nov 23, 2021 in Course info by angelaob (1,190 points)
I'm watching the lecture recording from last Tuesday and I noticed that the recording stopped during the 10 min break around 1 pm and didn't continue. I was wondering if that was the actual end of the lecture or there is a missing part that hasn't been uploaded.

2 Answers

Best answer
Luigi Pizza (6120 points)
11 20 65
answered Nov 23, 2021 by Luigi Pizza (6,120 points)
selected Nov 24, 2021 by angelaob

This is all the notes I have taken during class:

# how can i append some text at the beginning of a file?

if 1:
    with open(r'.\filehandler\test33-Open.txt', 'r') as fh:
        l = fh.readlines()
    l.insert(0, '****')
    l.insert(len(l)//2 , '++')
    with open(r'.\filehandler\test33-Open.txt', 'w') as fh:

    Best Case Scenario:
        - Depth: log2(n) (Depth == (imagine the recursion fuction as a tree), the height of the tree)
        - We have to compare n elements log2(n) times so O(n)=n*log2(n)
    Worst Case Scenario:
        - Depth: n
        - O(n) = n**2

RGB System:
    - Each image is a matrix, each pixel is a tuple with 3 components: (R,G,B)
    - Additive System: each color is given by the sum of the light from the 2 pixels

import pngmatrix

# Mario into Luigi
mario = pngmatrix.load_png8(r'.\img\Mario.png')
luigi = [[pixel if pixel!=(227,6,19) else (29, 227, 6) for pixel in x] for x in mario]
pngmatrix.save_png8(luigi, r'.\img\Luigi.png')
# Mirror Luigi
luigimir = luigi.copy()
l = [row[::-1] for row in luigimir]
pngmatrix.save_png8(l, r'.\img\LuigiMir.png')

# Mario(sx) & Luigi(dx)
patch=[mario[x]+l[x] for x in range(len(l))]
pngmatrix.save_png8(patch, r'.\img\patch.png')

# Luigi Transposed
tmario = [[mario[y][x] for y in range(len(mario[0]))] for x in range(len(mario))]
pngmatrix.save_png8(tmario, r'.\img\TMario.png')

# Mario rotated
rotmario = [[mario[y][x] for y in range(len(mario[0])-1, -1, -1)] for x in range(len(mario))]
pngmatrix.save_png8(rotmario, r'.\img\RotMario.png')

The part you are interested in is  after the line: import pngmatrix

We have modified an image (list of lists of tuples with syntax (R,G,B)) of Super Mario as follows. From top to bottom:

  • Changed a particular tuple with another (Mario's Red to Luigi's Green)
  • Mirrored the image with respect to the vertical axis
  • Concatenate two images
  • Transpose an image (just like in linear algebra, rows become colums and vice versa)
  • rotate an image by 90°

I really like using list comprehensions, as you might see, I hope it is understandable...

The files where shared by professor Mancini in "Unit 1, class exercises" \ "Mario", click here.

angelaob (1190 points)
2 4 7
commented Nov 23, 2021 by angelaob (1,190 points)
thank you, this is very helpful!
Luigi Pizza (6120 points)
11 20 65
commented Nov 24, 2021 by Luigi Pizza (6,120 points)
You're welcome!
rokshana03 (7140 points)
1 2 26
answered Nov 23, 2021 by rokshana03 (7,140 points)

I think, the professor might have forgotten to record the lecture after that break. In any case, @Luigi Pizza has pretty much covered all the topics prof. Mancini talked about so just check that out.