Table of Contents

Deadline: May 31th, 23:55

Introduction

Similar to the first assignment, we will perform some image manipulations. You do not need to have worked on the first assignment in order to work on this one, but you should read its statement to understand the basic ideas behind the image formats used.

Tasks (total 1p)

1. Common transformations (0.4p)

1.1. scaling (0.2p)

1.2. stamping (0.2p)

2. Type-specific transformations (0.6p)

2.1 superimposition (0.15p)

2.2 contrast (0.15p)

2.3 bordering (0.15p)

2.4 blur (0.15p)

For all the tasks listed above you do not need to implement any sanity check on the inputs; you can safely assume all inputs are valid. For example, you can assume that all lists of lists you work with are valid two-dimensional matrices (no line is longer or shorter than the others); all color values are between 0 and 255; for superimposing, the images are the same size etc.

You can download the starting code here. Unpack the archive and look in the folder skel/. Write the implementations in the files Common.hs, Greyscale.hs and Color.hs; the function types are already provided. You can ignore all the other haskell source files in that folder, they are only needed if you intend to test it on real Netpbm images.

For the transformations provided, the specific implementation techniques presented are suggestions; if you wish to use algorithms with greater complexity but better results (e.g. for scaling, blur), feel free to do so.

Mixing integers and floating numbers

Much like Java (and unlike C), the type-system in Haskell is very strict and does not allow mixing integers and floating points numbers in a single operation (such as adding an Int and a Float together). In order to get around this, you need to use explicit casts:

Usage

To run the provided helper code and test your functionality, you first need to select which function you want to test out. For that, you need to edit one or two lines in the file Main.hs.

After having edited Main.hs you can run it; depending on the number of arguments, it will choose an appropriate type of transformation (single/multiple image); it also correctly chooses between greyscale/RGB functions based on the actual filetype. To run the file you need the runhaskell binary (or runghc; both should come with the haskell platform), then run it from a shell:

# Runs the single-image transformation set on line 13 on the image in file "./input.ppm"; the result is written to "./out.ppm".
runhaskell Main.sh ./input.ppm ./out.ppm
# Runs the mask transformation set on line 16 on the images in files "./input1.ppm" and "./input2.ppm"; the result is written to "./out.ppm".
runhaskell Main.hs ./image1.ppm ./image2.ppm ./out.ppm

The folder res/ contains several greyscale and RGB images.

Scoring

The assignment is worth 1 point; 0.4p for the common transformations; 0.3p for greyscale and 0.3p for RGB.

Assignment 1 redo

You can also send any (and even all) tasks from the first assignment that you didn't manage to solve in time, for half the points. So if you did not submit anything for the first assignment and you now submit a complete solution, you will receive 0.5 points.

If you do so, please specify this in the README.

Submission

For submitting you should create a zip archive of the three files you modified: Common.hs, Greyscale.hs and Color.hs and a README. The README should contain a succinct high-level presentation of your work. The archive name should be LASTNAME_Firstname_FP_A1.zip (if you have multiple firstnames, separate them by an underline “_”). Upload the archive to the corresponding activity on moodle.