Re: Rookie having problems with some filter code. Any help?
- From: davem@xxxxxxxxx (Dave Martindale)
- Date: Wed, 14 Dec 2005 21:33:06 +0000 (UTC)
Don Bruder <dakidd@xxxxxxxxx> writes:
>> If you're just going to write out the image again, negative values
>> should be clamped to zero, and values greater than 255 should be clamped
>> to 255 - not wrapped around to zero.
>Hmmm... So simple clamping is, despite the counterintuitiveness
>involved, the way to go? Without chasing every possiblity, it seems
>likely to me that would end up with a whole slew of pixels whose
>color-component values are pegged at either 0 or 255, with comparatively
>little "middle ground".
It depends on the filter, and what you expect of it. For most filters
applied to photographic images, the output is supposed to look rather
like the input. Sharpening filters *can* cause overrange values, either
less than zero or greater than 255, but the right thing to do is to
clamp to the nearest representable value. So "blacker than black"
(negative) values become black (zero), and "super white" (>255) values
become white. That's better than turning black into white or vice
versa, which is what happens if you take the result mod 255.
>OK, that does make at least SOME sense, but it still hits the same wall
>mentioned above - At first glance, it would seem that clamping,
>particularly in a "many-control-one" situation needing many
>multiplications (some of them possibly involving negative multipliers)
>and additions to arrive at a value, whether it happens "in the middle"
>or "at the end" of an ops sequence, would tend to skew things pretty
>strongly to the extremes of the range, eating the bejeebers out of the
>"middle" values in the process.
Only if you're doing something that grossly exaggerates the size of
differences, such as an edge-finding filter.
>> There are occasions (e.g. differencing) when keeping the result mod 256
>> is the right thing to do - but that's not usually the case.
>Are you saying "differencing" to mean what I think you are? As in "XOR",
>subtract, or otherwise combine two frames (or segments of frames) -
>let's call them "F1" and "F2", and the "combined" version that results
>"R" for convenience - so that if a pair of pixels, F1[x,y] and F2[x,y],
>share a common RGB value - let's say they're both r=101, g=30, b=222 -
>then R[x,y]'s color will be set to <some arbitrary color value>? (which
>will probably, but not necessarily, be white or black due to common
>practice, but whatever it actually is, the intent is to convey a
>"nothing to see here" message.)
One way of showing differences is to subtract two images pixel by pixel,
component by component, and then optionally add 128. Then differences
show up as deviations from grey.
But what I meant is this: Suppose you have two values A and B, and
calculate the difference D in ordinary math: D = A - B. Then you can
reconstruct either of the originals from the other plus the difference:
A = B + D, B = A - D. This is *also* true if A, B, and D are images,
provided *no clampling* happens. Clamping loses information, and makes
the operation non-reversible.
In practical terms, this means that D needs to be 9 bits wide, if A and
B are 8 bits wide, and you use ordinary integer arithmetic. However, if
you use *modular* arithmetic, with all results taken mod 256, then all
the expressions above remain true with D only 8 bits wide.
So, using mod-256 arithmetic (which is what CPUs natively provide)
without clamping allows a difference operation that's invertible,
without needing extra bits. It's more difficult to interpret visually
than the usual clamped version though.
Dave
.
- References:
- Rookie having problems with some filter code. Any help?
- From: Don Bruder
- Re: Rookie having problems with some filter code. Any help?
- From: Don Bruder
- Re: Rookie having problems with some filter code. Any help?
- From: Dave Martindale
- Re: Rookie having problems with some filter code. Any help?
- From: Don Bruder
- Rookie having problems with some filter code. Any help?
- Prev by Date: CFP - Fourth,Conference Eurographics Italian Chapter February 2006 (Deadline is approaching)
- Next by Date: Re: Luminance and RGB layers question
- Previous by thread: Re: Rookie having problems with some filter code. Any help?
- Next by thread: Re: Rookie having problems with some filter code. Any help?
- Index(es):
Relevant Pages
|