[comp.dcom.fax] Compression of image matrices

gilge@ICSI.Berkeley.EDU (Michael Gilge) (03/08/91)

We are often faced with the problem of transmitting large image matrices 
to a postscript printer, e.g. sampled images or screen captures from X.
This causes large transmission times and we are thinking about compressing
the binary data before transmission. Together with the data, a postscript 
decompression program is also send to the printer. The printer applies 
the program to the data and kind of unfolds the original image matrix.

Before we start writing anything, has anybody ever done something like that?
Especially is there a postscript program to decode fax Group3 encoded
bitmaps?

Any hints are greatly appreciated.

Heinz W. Schmidt, hws@icsi.berkeley.edu
Michael Gilge,    gilge@icsi.berkeley.edu

International Computer Science Institute
1947 Center Street, Suite 600
Berkeley, California 94704
Phone: 1-415-642-4274-134
Fax:   1-415-643-7684

johnmark@neon.Stanford.EDU (John M. Agosta) (03/08/91)

Heinz W. Schmidt, hws@icsi.berkeley.edu, writes, about sending
compressed images to postscript printers:

>> Before we start writing anything, has anybody ever done something like that?
>> Especially is there a postscript program to decode fax Group3 encoded
>> bitmaps?     

Adobe has. The "level 2" spec for postscript includes both binary
compressed transmission to the printer, and fax images. These are
implemented as "filters."  "CCITTFaxDecode" produces binary data
from fax encoded data. Likewise "DCTDecode" works with a JPEG standard.
I think I have seen ads for level 2 printers, but you'd have to 
check about availability. 

.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.
John Mark Agosta   		      internet: johnmark@neon.stanford.edu
Robotics Lab				     
				         voice: 415/723-1143
P.O. Box 4847			     voicemail: 408/441-1166 x4547
Stanford, CA 94309

"So much uncertainty, so little time."

sam@oxford.berkeley.edu (Sam Leffler) (03/09/91)

I tried a number of different schemes for printing Group 3
facsimile on PostScript printers, including decoding the binary
Group 3 data with PostScript in the printer.  My final solution
for the problem was to write a preprocessor that converted
the Group 3-encoded data to a compressed sequence of line draw
operations.  This worked out reasonably well, although it still
took around a 1 minute/page to print a filled page of text on
a LaserWriter-class PostScript printer connected by a 9600
baud serial line.

The basic algorithm for converting the image is straightforward:

1. convert the rasterized data to a sequence of horizontal
   move-draw operations (note that if you're working with
   g3-encoded data, this operation is trivial -- it *is* the g3
   encoding).
2. select an encoding for the move-draw operations (for
   example, using frequency of use)
3. emit a postscript dictionary that defines the move-draw
   operations as short tokens (e.g. /a {100 rmove 2 rlineto})
4. emit the move-draw operations using the dictionary
   encoding built in step 3.

The key things to consider are:

1. how much time you devote to doing the encoding.
2. how much compression you get from doing the encoding.

If you spend lots of time doing the encoding, then you might've
been better off just sending the raw image instead.  Likewise,
halftone data and such may not compress well using a simplistic
scheme -- you may want to do things like rotate the image, look
for coherence in the move-draw pairs, etc.

In any event, this scheme tends to work well for text.  However,
if you're printing lots of facsimile, you're best off getting a printer
that's more suited for your needs -- either one that supports the
PS Level 2 operators for transferring encoded data, or one that
takes plain rasters.

	Sam

klg@george.mc.duke.edu (Kim Greer -- rjj) (03/09/91)

In article <11757@pasteur.Berkeley.EDU> gilge@ICSI.Berkeley.EDU (Michael Gilge) writes:
+We are often faced with the problem of transmitting large image matrices 
+to a postscript printer, e.g. sampled images or screen captures from X.
+This causes large transmission times and we are thinking about compressing
+ .....
+Before we start writing anything, has anybody ever done something like that?
+Especially is there a postscript program to decode fax Group3 encoded
+bitmaps?
+
+Any hints are greatly appreciated.
+
+Heinz W. Schmidt, hws@icsi.berkeley.edu
+Michael Gilge,    gilge@icsi.berkeley.edu

  I wrote a (series of) program(s) sometime back to get around a similar
problem on a non-PostSript printer (HP LJII) and later for a PostScript
printer.  The big problem with the HP was that I often over-filled the
memory, resulting in either garbage or blanks.  What I did was to take the
image matrix and search by rows and/or columns to see how big of a
rectangle, rather than a single pixel, that could be sent.  If the entire
row was the same value for all pixels, then a significant speedup could be
achieved.  Better still was a row that was identical to the previous row.
Even better was rows of "blank" or non-printing values, in which nothing had
to be written at all (but be sure to increment the next starting position to
the correct location).  You of course win big with nearly-uniform images and
images with lots of big, non-printing (blank) spots.  While this causes
variable computer->printer dump times, no one is likely to complain.

  If you do the "compression" after re-"digitizing" the image to, say, 16
gray levels, then you might gain, by having less "values" to have to look at
and sort, rather than the original, you might gain again.  I'll have to
think about that a little more.

  Anyway, if you are fairly comfortable with writing PostScript, I hope the
above info will gain you a little, at least.  I personally would try to stay
away from "compressing" in the sense of the PD unix "compress" program
style, though someone else may have may better ideas on the subject than I.

Good luck.

-- 
Kim L. Greer                       
Duke University Medical Center		 klg@orion.mc.duke.edu
Div. Nuclear Medicine  POB 3949		 voice: 919-681-5894
Durham, NC 27710  		         fax: 919-681-5636

jrobie@netmbx.UUCP (Jonathan Robie) (03/11/91)

In article <11757@pasteur.Berkeley.EDU> gilge@ICSI.Berkeley.EDU (Michael Gilge) writes:
>We are often faced with the problem of transmitting large image matrices 
>to a postscript printer, e.g. sampled images or screen captures from X.
>This causes large transmission times and we are thinking about compressing
>the binary data before transmission. Together with the data, a postscript 
>decompression program is also send to the printer. The printer applies 

You can cut your data size in half without any compression by simply
transmitting the binary image data instead of converting it to ASCII
heas in the standard PostScript format.  This will also require fairly
minimal processing time.

However, are you *sure* that you processing is due to transmission times?
Remember that PostScript will scale the images to match the space allotted
to them.  If you do not carefully ensure that you are printing at same
size, a large image at high resolution can tie up a PostScript printer
for a long time.  You might want to monitor network activity or compare
times for images printed at same size.:d

>Before we start writing anything, has anybody ever done something like that?
>Especially is there a postscript program to decode fax Group3 encoded
>bitmaps?

What are you sampling with?  You will get very little compression for high
quality grey scale or color images using Group3.  In fact, Lempel-Ziv and
most of your other common compression mechanisms get less and less useful
as your grey scale information gets better.  Unfortunately, the more
appropriate methods for this kind of data are defined in the Frequency
Domain, and I suspect that the amount of calculation involved would
bog down your printer more than the savings in transmission time.

>
>Heinz W. Schmidt, hws@icsi.berkeley.edu
>Michael Gilge,    gilge@icsi.berkeley.edu
>
>International Computer Science Institute
>1947 Center Street, Suite 600
>Berkeley, California 94704
>Phone: 1-415-642-4274-134
>Fax:   1-415-643-7684

csb@gdwb.oz.au (Craig Bishop) (03/22/91)

gilge@ICSI.Berkeley.EDU (Michael Gilge) writes:

>We are often faced with the problem of transmitting large image matrices 
>to a postscript printer, e.g. sampled images or screen captures from X.
>This causes large transmission times and we are thinking about compressing
>the binary data before transmission. Together with the data, a postscript 
>decompression program is also send to the printer. The printer applies 
>the program to the data and kind of unfolds the original image matrix.

>Before we start writing anything, has anybody ever done something like that?
>Especially is there a postscript program to decode fax Group3 encoded
>bitmaps?

I had to do a similar thing recently. We used a SUN SPARCprinter, these
printers are just a raster engine with the postscript being decoded on
the SPARCstation and the raster image being written to the printer via
a fast video port. What is different is that we accessed the video port
directly. When it is not being used by lpr and printing postscript I
can open it up and pump bitmaps at it. The code is trivial. The speed
of printing is amazing.

A 400dpi 3456 x 5214 bitmap printed in less than 5 seconds. 

--
Craig Bishop			Geelong & District Water Board
Phone: +61 52 262506		61-67 Ryrie St Geelong
Fax:   +61 52 218236		Victoria 3220 Australia