Re: Rookie having problems with some filter code. Any help?
- From: "Cliff Hewitt" <somebug@xxxxxxxxxxxxxx>
- Date: Tue, 13 Dec 2005 20:01:58 GMT
"Don Bruder" <dakidd@xxxxxxxxx> wrote in message
news:439f0fbc$0$38644$742ec2ed@xxxxxxxxxxxxxxxxx
>
> Hi folks.
....
> The code in question (commented to the point of ridiculousness for this
> post, since I haven't got a clue who might read it and wonder what on
> earth it's trying to do) as well as a "raw" image and the results of
> shoving that image through my attempt at a matrix-convolution based
> sharpness filter, plus a link to Frederic's paper, can be seen here:
> <http://www.sonic.net/~dakidd/Filterproblems.html>
This code implements the Laplacian filter, which I'm sure many of us know.
> I'd also welcome any pointers to more and/or better info on coding
> digital image processing stuff, if anyone would care to point me in the
> right direction. (Please... Spare me the "google it" - I've been wearing
> out my eyeballs trying to figure out what is and isn't relevant in the
> literally millions of results google hands me)
Mostly, since you're just starting on image processing, don't worry too much
about the speed of the code, which of course you state in one of your
subsequent paragraphs. Concern yourself more with readability, i.e., if you
can remove lines like
Color = getpixel(Source, i - ((sharp_w - 1) >> 1) + k, j - ((sharp_h - 1) >>
1) + l);
and replace it with something like
Color = getpixel(Source, i-k+1, j-l+1);
you'll be much better off -- especially since this is one of the sources of
your problem. Basically, in the event that you don't see what's going on,
you want to take the eight pixels surrounding point (i, j) and apply your
mask.
Another thing that with which you should take care is avoiding overflow in
your variables. sumr+(some value) may be greater than the limits of the
destination (that is, a byte, which can only hold a value up to 255, and no
less than 0). So, just in case it matters -- and I don't know the function
"makecolor" -- you should put a little logic in there to test for this over-
or underflow, i.e.:
if (sumr>255) {
sumr=255;
} else if (sumr<0) {
sumr=0;
}
You already know the Normalizer is useless for this filter, so I won't say
anything about that.
I suspect that if you correct these two things, your output might be
something closer to what you expect.
> At this point, I just plain don't care how slow/inefficient/etc the code
> I'm working with may be - I can worry about optimizing it later - AFTER
> I've gotten it to the point where it's properly functional. I'm
> currently MUCH more interested in getting basic correct functionality
> out of it than any attempt at making it "the fastest, bestest, greatest
> filter ever written".
One thing that I like to do is start from the top-most row and continue
left-to-right on each row, to the last row. Although this doesn't matter
much for filters like the Laplacian, there are other times when it does
benefit, since the difference is sequencial access versus purely random
access. For example, when I tested your code, I changed pixel access to
for (j=1; j<Height-1; j++) {
for (i=1; i<Width-1; i++) {
...
}
}
> Thanks in advance for any assistance you might be able to provide!
>
> --
> Don Bruder - dakidd@xxxxxxxxx - If your "From:" address isn't on my
> whitelist,
> or the subject of the message doesn't contain the exact text
> "PopperAndShadow"
> somewhere, any message sent to this address will go in the garbage without
> my
> ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more
> info
Good luck,
Cliff Hewitt
.
- References:
- Rookie having problems with some filter code. Any help?
- From: Don Bruder
- Rookie having problems with some filter code. Any help?
- Prev by Date: Re: Rookie having problems with some filter code. Any help?
- 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: Luminance and RGB layers question
- Index(es):
Relevant Pages
|
Loading