作业帮 > 英语 > 作业

几个h-a-s-k-e-l-l问题

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/23 02:15:47
几个h-a-s-k-e-l-l问题
This question deals with the processing of grey-scale images (pictures).An image consists of a rectangular array of pixels,and each row of an image is represented in Haskell by a list of integers in which 0 represents black,255 represents white,and intermediate integers represent shades of grey.The whole image consists of a list of these rows.
So,for example,the 3 x 4 pixel image:
Could be denoted by the Haskell list:
[[208,152,240,29 ],
[0,112,255,59],
[76,185,0,152]]
(a) Write a Haskell type definition for pixel images.
(b) A common task in image processing is to darken the image.This can be achieved by reducing each pixel number by one third of its value.
(i) Write a function darkenRow that darkens each pixel in a row of pixel numbers.
(ii) Write a function darkenImage that darkens the whole image in this way.
(c) Another common image processing task is to increase the contrast of the image – darkening the darker pixels and lightening the lighter ones.Write a function increaseImageContrast that darkens (by one third) any pixel with a value that is less than 128 and lightens any pixel with a value of 128 or more (by adding (255 – x) / 3 to any such pixel with value x).
(d) A third image processing task is to shift an image one pixel to the right.The rightmost column of pixels in the original image is dropped and the leftmost column is duplicated so that the image retains its original dimensions.
In order to do this,first write a function dropLastPixel that takes a single row of pixels and drops the last pixel.Then write a function duplicateFirstPixel that adds a copy of the first pixel to the start of the row.Finally,use these two functions to construct a function shiftImageRight that shifts the hole image one pixel to the right.
(e) Write a function shiftImageLeft that shifts an image one pixel to the left,dropping the first column of pixels and adding a copy of the final column to the end.[Hint:You may find it helpful to write functions dropFirstPixel and duplicateLastPixel and structure your answer in a similar way to part (d).]
a
An image consists of a rectangular array of pixels
b
y=2x/3 of each pixel numbe