免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4628 | 回复: 3
打印 上一主题 下一主题

几个关于函数方程编程语言h-a-s-k-e-l-l的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-04 20:42 |只看该作者 |倒序浏览
本帖最后由 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:

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

论坛徽章:
0
2 [报告]
发表于 2010-08-04 20:44 |只看该作者
麻烦大家给下答案 救急

跪谢

论坛徽章:
0
3 [报告]
发表于 2010-08-15 12:47 |只看该作者
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的答案 大家指点下呢

论坛徽章:
0
4 [报告]
发表于 2010-08-16 13:59 |只看该作者
你想说哪不明白呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP