Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fp:lab07 [2022/04/29 11:15] pdmatei |
fp:lab07 [2022/05/03 17:25] (current) pdmatei |
||
---|---|---|---|
Line 58: | Line 58: | ||
</code> | </code> | ||
- | **7.8.** Write a function which inverts an image (values 0 become 255, 1 - 254, and so forth). | + | **7.6.** Write a function which inverts an image (values 0 become 255, 1 - 254, and so forth). |
- | **7.9.** Write a function which crops a given image, using two, two-dimensional coordinates: the higher-left point x and y, and the lower-right point x and y. An example is shown below: | + | **7.7.** Write a function which crops a given image, using two, two-dimensional coordinates: the higher-left point x and y, and the lower-right point x and y. An example is shown below: |
<code scala> | <code scala> | ||
val img = List(List(0,0,1,0,0), List(0,1,0,1,0), List(0,1,1,1,0), List(1,0,0,0,1), List(1,0,0,0,1)) | val img = List(List(0,0,1,0,0), List(0,1,0,1,0), List(0,1,1,1,0), List(1,0,0,0,1), List(1,0,0,0,1)) | ||
Line 75: | Line 75: | ||
</code> | </code> | ||
- | **7.10.** Write a function which returns a list of all positions which have pixels of larger intensity than x | + | **7.8.** Write a function which returns a list of all positions which have pixels of larger intensity than x |
<code scala> | <code scala> | ||
def largerPos(img: Img, int: Int): List[(Int,Int)] = ??? | def largerPos(img: Img, int: Int): List[(Int,Int)] = ??? | ||
</code> | </code> | ||
- | **7.11.** Write a function which adds ''x'' to the intensity of each pixel. | + | **7.9.** Write a function which adds ''x'' to the intensity of each pixel. |
<code scala> | <code scala> | ||
def contrast(x: Int)(img: Img): Img = ??? | def contrast(x: Int)(img: Img): Img = ??? | ||
</code> | </code> | ||
- | **7.12.** Write a function which takes two images ''X'' and ''Y'' and //glues// them on the horizontal axis (the resulting image will be ''XY'') | + | **7.10.** Write a function which takes two images ''X'' and ''Y'' and //glues// them on the horizontal axis (the resulting image will be ''XY'') |
<code scala> | <code scala> | ||
def hglue(img1: Img, img2: Img): Img = ??? | def hglue(img1: Img, img2: Img): Img = ??? | ||
</code> | </code> | ||
- | **7.13.** Write a function which takes two images ''X'' and ''Y'' and //glues// them on the vertical axis: | + | **7.11.** Write a function which takes two images ''X'' and ''Y'' and //glues// them on the vertical axis: |
<code scala> | <code scala> | ||
def vglue(img1: Img, img2: Img): Img = ??? | def vglue(img1: Img, img2: Img): Img = ??? | ||
</code> | </code> | ||
- | **7.14.** Define a function that takes a **square** image, and draws two diagonal lines of intensity 1 across it. Use ''_.until(_)'' and ''_.toList''. | + | **7.12.** Define a function that takes a **square** image, and draws two diagonal lines of intensity 1 across it. Use ''_.until(_)'' and ''_.toList''. |
<code scala> | <code scala> | ||
def diag(img: Img): Img = ??? | def diag(img: Img): Img = ??? | ||
</code> | </code> | ||
- | **7.15.** Define a function which blurs an image as follows: | + | **7.13.** Define a function which blurs an image as follows: |
* for each pixel p of intensity > 1: make all neighbouring pixels of intensity 0 equal to p-1 (including diagonals). | * for each pixel p of intensity > 1: make all neighbouring pixels of intensity 0 equal to p-1 (including diagonals). | ||
* if some pixel of intensity 0 is in the vicinity of two different >1 pixels of different intensities, the one which is larger should be taken into account | * if some pixel of intensity 0 is in the vicinity of two different >1 pixels of different intensities, the one which is larger should be taken into account | ||
Line 109: | Line 109: | ||
</code> | </code> | ||
- | **7.16.** Define a function which builds an effect of intensity x as shown below: | + | **7.14. (!) ** Define a function which builds an effect of intensity x as shown below: |
<code scala> | <code scala> | ||
val img2 = List( | val img2 = List( |