我正在寻找以下问题的解决方案,任何提供的帮助都将受到高度感谢。
使用0,15中的随机整数在数组中生成大小为256 x 256的灰度图像。使用4 x 4抖动矩阵以二进制强度(即零强度或最大强度)显示抖动图像。显示原始图像(使用随机数生成的图像)和抖动图像。
发布于 2014-08-27 18:54:42
下面的Gforth程序创建一个15级的随机灰度图像,用4×4的索引矩阵将其抖动成一个双层图像,并排复制到一个512×256字节的数组中,并将其作为PGM图像写入标准输出,以便可以从ImageMagick包通过管道传输到display:
include random.fs
256 constant image-size
15 constant max-gray-value
create grayscale-image image-size dup * chars allot
create result-image image-size dup * 2* chars allot
create index-matrix 0 , 12 , 3 , 15 ,
8 , 4 , 11 , 7 ,
2 , 14 , 1 , 13 ,
10 , 6 , 9 , 5 ,
: randomly-fill-grayscale-image ( -- )
image-size dup * 0
?do
max-gray-value random grayscale-image i chars + c!
loop
;
: copy-grayscale-to-result-image { offset -- }
image-size 0
?do
grayscale-image i image-size * chars +
result-image i image-size 2* * offset + chars +
image-size
move
loop
;
: dither-grayscale-image ( -- )
image-size 0
?do
image-size 0
?do
grayscale-image j image-size * i + chars + dup c@
index-matrix j 4 mod 4 * i 4 mod + cells + @
< if 0 else max-gray-value then
swap c!
loop
loop
;
: print-pgm ( -- )
." P5" cr
image-size dup 2* 2dup . . max-gray-value . cr
* result-image swap type
;
: main ( -- )
utime drop seed !
randomly-fill-grayscale-image
0 copy-grayscale-to-result-image
dither-grayscale-image
image-size copy-grayscale-to-result-image
print-pgm
;
main bye这可以被称为:
$ gforth dither.fs | display如果display不可用,则可以将图像重定向到文件中,并使用其他图像查看器或编辑器进行查看:
$ gforth dither.fs > dither_image.pgm生成的图像如下所示:

https://stackoverflow.com/questions/25486984
复制相似问题