Path: utzoo!attcan!uunet!husc6!think!ames!pasteur!ucbvax!decwrl!hplabs!well!ewhac From: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Newsgroups: comp.graphics Subject: Floyd-Steinberg Errors: What do I do with them? Summary: What happens if you {under,over}flow the intensity range? Message-ID: <6506@well.UUCP> Date: 12 Jul 88 06:24:18 GMT Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Organization: The International Beam-Wesley-Into-A-Bulkhead Society Lines: 48 Quote: "Business. Numbers. Money. People." -- Kraftwerk [ Maybe I should write an automatic line-eater line generator... ] Hi there. After some helpful suggestions from this group, I've started playing around with the Floyd-Steinberg image quantization algorithm. You know, the one where you distribute the quantization error to neighboring pixels. However, I've run into a weird snag. Occasionally, depending on the Phase of The Moon, it translates black pixels into grey ones. Needless to say, this is The Wrong Thing. After considering a number of possible problems, it struck me that perhaps I'm not dealing with overflow and underflow correctly. Consider the following scenario: Suppose we have two monochromatic pixels side by side with the following intensities (0 == black, 1 == white): +-----+-----+ | .51 | .02 | Threshold is .5 +-----+-----+ So Floyd and Steinberg come along, see the .51 pixel, and quantize it to 1.0. By the rules of the algorithm, the pixel immediately to the right gets 3/8 of the quantization error. This leaves us with: +-----+-----+ | 1.0 |-.16 | ((.51 - 1.0) * 3 / 8) + .02 == -.16 +-----+-----+ Now clearly, -.16 is out of range for the value of a pixel; it's too black. So my question is this: What do I do with this pixel when it comes time to process it? Do I pretend like there's no problem, and treat it like all the other pixels (doesn't seem right, since this negative pixel will suck the brightness out of the neighboring pixel when I process it)? Do I I truncate its value to the valid range (also seems wrong, since I'm tossing part of the error out the window)? If I do truncate it, when should I do it: when I encounter the errant pixel and process it; or while I'm distributing the error to it, thus "preventing the problem in the first place"? Thanks in advance. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape INET: well!ewhac@ucbvax.Berkeley.EDU \_ -_ Recumbent Bikes: UUCP: pacbell > !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Hmm, you're right. Air is made up of suspended meat loaf." -- Josh Siegel