Re: Rookie having problems with some filter code. Any help?



"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


.



Relevant Pages

  • Re: Anyone Want To Recommend...
    ... >>> ink tank takes care of the text printing. ... > If people don't want to read Cliff, filter him. ... Cliffy rejects anyone who attempts to get him to understand he has lost ... Bing has said he's ...
    (alt.machines.cnc)
  • Re: Anyone Want To Recommend...
    ... Dan. ... >> individual ink tanks will save you money in the long run. ... I don't care at all. ... If people don't want to read Cliff, filter him. ...
    (alt.machines.cnc)
  • Re: www.as-ms.com up and running
    ... Sorry David, but I really don't care what your opinion is. ... But then again I'm not expecting everyone to understand and nor do I care, but the site will be up for anyone to use if they wish. ... Any posts made within the forum will be posted to this newsgroup automatically as well. ... The great news is I can filter out any Trolls or spammers. ...
    (alt.support.mult-sclerosis)
  • Re: Conditional Formating - Different row color also when using fi
    ... All we really care about is the counta from column A, ... " If the hidden rows are cause by applying a filter ... Select the rows to format ... Enter the formula as if it were for the the currently active cell (in this ...
    (microsoft.public.excel.misc)
  • Re: what does phase distortion look like in image processing?
    ... > I read the following in Matlab Help Document of Image Processing ToolBoxes, ... > stability and ease of design and implementation of the FIR filter. ... Wescott Design Services ...
    (sci.image.processing)

Loading