几个关于函数方程编程语言h-a-s-k-e-l-l的问题

发布于 2022-09-01 21:00:01 字数 2727 浏览 21 评论 3

本帖最后由 lazyboy2046 于 2010-08-15 12:46 编辑

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:

QQ截图未命名.jpg (2.36 KB, 下载次数: 26)

下载附件

2010-08-15 12:45 上传


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).]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风也等你 2022-09-10 20:36:38

你想说哪不明白呢

谎言 2022-09-07 20:55:00

type Pixel3 = Int
type Row3 = [Pixel]
type PixelImage3 = [Row]
img3 :: PixelImage3
img3 = [[208,152,240,29],[0,112,255,59],[76,185,0,152]]
scaleRow1 :: (RealFrac a) => PixelImage -> a -> Int -> PixelImage
scaleRow1 img3 x i = modifyRow img3 f i
    where f :: Row -> Row
          f = let clamp z | z < 0 = 0
                  | z > 255 = 255
                  | otherwise = truncate z
        in map (clamp.(x *).fromIntegral)

这个是1a 和1b的答案 大家指点下呢

疏忽 2022-09-07 06:28:21

麻烦大家给下答案 救急

跪谢

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文