java - Making a convolution filter -


i've been making convolution filter in java, , mean it's seemed pretty simple. understand theory behind it, except 1 thing.

here's sharpening filter:

 0 -1  0 -1  5 -1  0 -1  0 

it seems simple enough. i've been having issues it. it's terribly easy result go beyond bounds (above 255 , below 0).

for instance, if have area of pixels these values (for simplicity let's it's single-channel image):

255 255 255 255 255 100 255 255 255 

this result in (5*255) - 255 - 255 - 255 - 100 = 410. that's high.

then, consider this:

255 255 255 255 100 255 255 255 255 

this (5*100) - 255 - 255 - 255 - 255 = -520. that's low.

if try , restrict value acceptable range this:

result = math.min(math.max(result, 0), 255); 

it turns out horrid , not @ want.

i'm @ loss it, , i'm not finding online. pretty every resource convolution i'm finding either has unhelpfully loose , vague explanations of normalisation, or doesn't mention @ all.

if want code can ask it, doubt has it. code functions fine, seems i'm misunderstanding theory or something?

welp, turns out design mistake on part. wasn't writing resulting pixels new image, source image. in case restricting using math.min() , math.max() acceptable solution.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -