几个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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/27 15:34:50
几个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
几个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).]
几个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
这一个问题处理灰色- 刻度图像 (照片) 的处理人.一个图像有图素的矩形排列,而且每排的一个图像在 Haskell 被一连串完整的事物表现在 0 表现黑色,255 表现白色,而且中间的完整事物表现灰色的色度.整个的图像有一连串这些排.
如此,举例来说,3 x 4个图素图像:
可能被 Haskell 目录指示:
[[208,152,240,29],
[0,112,255,59],
[76,185,0,152]]
(一) 为图素图像写一种 Haskell 类型定义.
(b) 图像处理的一件通常的工作是弄暗图像.这能被藉由被三分之一的它价值减少每个图素数字达成.
(i) 写弄暗图素数字的接连每个图素的功能 darkenRow .
(ii) 写这样弄暗整个的图像功能 darkenImage.
(c) 处理工作的另外通常的图像是增加弄暗较黑暗的图素而且点亮较轻的一些图像–的差别.写弄暗 (藉着三分之一) 有价值的任何图素哪一是少于 128 ,而且用 128 的价值或更多点亮任何的图素功能 increaseImageContrast .(藉着对和价值 x 的任何如此的图素增加 (255 – x)/3)
(d) 一个处理工作的第三个图像是把一个图像一个图素移到权利.最初的图像那最右面纵队的图素被降低,而且最左边的专栏被复制,以便图像保有它的最初尺寸.
为了要做这,首先写轮流图素的单身排并且降低最后一个图素的功能 dropLastPixel.然后写把第一个图素的副本加入排的开始功能 duplicateFirstPixel .最后,使用这二个功能构造功能 shiftImageRight 以把洞图像一个图素移到权利.
(e)为那目的写把一个图像一个图素移到的功能 shiftImageLeft 那留下,降低图素的第一专栏而且增加最后的专栏副本.[暗示:你可能找以相似的方式写功能 dropFirstPixel 和 duplicateLastPixel 而且构成你的答案分开 (d) ]