4.7 图像处理
系统提供了四个处理任务进程,它们是:
(1) Chop(裁切),对输入图像应用一个已定义的窗口。
(2) Scale(缩放),把输入图像放大或缩小到已定义的尺寸。
(3) Merge(合并),把输入图像放到背景图像的指定区域上。
(4) Clean(清理),去除输入图像上的噪点。
这些处理任务支持 Clean and Simple 接口,因此可以在命令字符串中使用。不过,这些任务在命令字符串中既不能充当源,也不能充当汇。它们的输入和输出数据格式是向量。
例如,一页传真可以先被清理,再在传真机上打印。注意,图像数据在送往传真机之前必须重新压缩;如果原始数据是 DACOM 块形式,则必须先解压缩,因为处理任务只接受行向量。所需的命令字符串如下所示。
fs"e,page|clean|recomp|fax"w
where fs - file system task
e - read an existing file
page - file name
clean - cleaning task
recomp - re-compression task
fax - interface task for facsimile machine
w - print an image on facsimile machine
这些处理任务的描述见附录 2(chop(fax)、scale(fax)、merge(fax) 和 clean(fax))。
在 'chop' 和 'merge' 任务中,窗口通过给出其顶点坐标来设定。然而,人工用户通常很难确定准确的坐标。系统提供了子程序 choice(),它通过在显示该图像的 Grinnell 显示器屏幕上交互地操作一个矩形子区域,来指定图像的一个矩形部分。它提供一组交互命令,用户可以据此直观地选择自己感兴趣的区域。注意,该子程序必须由 MOS 进程调用,且系统中必须包含 Grinnell 显示器。
借助这些图像处理模块,可以完成 2.4 节所述的图像编辑。来看一个例子:要把从图片 'a' 中截取的一块图像合并到另一幅图片 'b' 的指定区域上。首先,应把图片 'a' 和 'b' 分别显示在屏幕的左半边和右半边。假设这两幅图片是标准的 DACOM 页面,尺寸为 1726x1200,必须把它们缩小到适合半屏的尺寸(256x512)。注意,如果数据格式不是向量,应先进行转换。所需的命令字符串为:
e,a|scale"1726,1200,256,512|grinnell"0,511,255,0,z,g
fs"e,b|scale"1726,1200,256,512|grinnell"256,511,511,0,z,b
where fs - file system task
e - read an existing file
a - file name
b - file name
scale - scale task
1726,1200 - old dimension
256,512 - new dimension
grinnell - grinnell display interface task
0,511,255,0 - presentation area (the left half)
256,511,511,0 - presentation area (the right half)
z - zero write mode
g - green
b - blue
在应用进程中,按以下方式调用子程序 choice(),供用户在两幅图片上选择区域。
choice(r, 1726, 1200, 1, 0, 0);
/* choice the area on 'a' */
/* r - red
1726 - width of the original picture
1200 - height of the original picture
1 - left half of the screen
0 - the subsection can be of any width
0 - the subsection can be of any height
*/
choice(r, 1726, 1200, 2, 0, 0);
/* choice the area on 'b' */
/* r - red
1726 - width of the original picture
1200 - height of the original picture
2 - right half of the screen
0 - the subsection can be of any width
0 - the subsection can be of any height
*/
用户完成编辑后,所选矩形区域的坐标被返回。下表给出一个示例。表中列出的宽度和高度实际上是根据返回的坐标计算得出的,它们表明源图像必须被放大才能适合其目的区域。
(0, 0)
+-------------------------------> x
|
| (x0, y0) w
| +--------------------+
| ! !
| ! !
| ! ! h
| ! !
| ! !
| +--------------------+
| (x1, y1)
V
y
original x0 y0 x1 y1 w h
a 30 40 100 120 70 80
b 100 100 1100 1100 1000 1000
此时,执行下面指定的作业即可达成我们的最终目标。假设结果图像要存为新文件 'c'。
fs"e,a|chop"30,40,100,120|scale"70,80,1000,1000
|merge"b,0,100,100,1100,1100|fs"c,c
where fs - file system task
e - read an existing file
a - file name
chop - chop task
30,40,100,120 - the area to be abstracted
scale - scale task
70,80 - old dimension
1000,1000 - new dimension
merge - merge task
b - file name of the background image
0 - to be overlaid
100,100,1100,1100 - the area to be overlaid
fs - file system task
c - create a new file
c - the name of the file to be
created