RetouchPRO

Go Back   RetouchPRO > Tools > Software
Register Blogs FAQ Site Nav Search Today's Posts Mark Forums Read


Software Photoshop, Lightroom, Paintshop Pro, Painter, etc., and all their various plugins. Of course, you can also discuss all other programs, as well.

Free Plug-In Filters: Custom Filter & Adaptive Equalization

Reply
 
Thread Tools
  #11  
Old 10-23-2002, 09:48 PM
Tim_S's Avatar
Tim_S Tim_S is offline
Member
 
Join Date: Dec 2001
Location: California
Posts: 67
Chris, please keep going. This is great stuff.

I worked with convolution for linear data streams for signal processing, but 2D images are a great deal more complex. There are a lot of transforms I have wanted to try, and I know there are many more that are more specific to other kinds of images than the microscopy I used to work with... I will happily read whatever you are willing to type on the subject.

--tks
Reply With Quote top
  #12  
Old 10-24-2002, 02:58 AM
Stephen M Stephen M is offline
Senior Member
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 439
Chris, please post on!

I have printed out your 'basic' post for extended study and practice. This is deep stuff for a GUI user to get into - so I have not had time to really push things.

I will hold back on my current questions, as they may well be covered in your next tutorial...if not I will post away.

Here is a link to a great little tutorial which forces you to think and to correctly answer a question before proceeding to the next step - which I think is a novel way to present such a deep topic:

http://www.eas.asu.edu/~karam/2dconvolution/

Regards,

Stephen Marsh.
Reply With Quote top
  #13  
Old 10-24-2002, 03:56 AM
DannyRaphael's Avatar
DannyRaphael DannyRaphael is offline
Moderator
 
Join Date: Mar 2002
Location: Near Seattle, Washington, USA
Posts: 6,300
Thumbs down

Chris:

Yours is the BEST how-to / decriptive writeup on custom filters I've seen anywhere. Most are just a paragraph or two with no depth whatsoever.

This is EXCEPTIONAL stuff.

Many thanks to you for sharing your expertise.

~~~~~~~
And another BIG thumbs up to Stephen for another enlightening thread with valuable content.

~Danny~
Reply With Quote top
  #14  
Old 10-24-2002, 08:01 AM
jcr6's Avatar
jcr6 jcr6 is offline
Member
 
Join Date: Oct 2002
Location: Asheville, NC
Posts: 72
Convolution, Round 2

So, let us recap a little bit. The center of the 5x5 or 7x7 (or whatever size the kernel is) refers to the weight on each pixel in the original image. The positions around that center pixel refer to weights on the neighbors of that pixel. All of this applies when creating a new image from the original.

Gaussian Filters

Back in the dark old days where computers were slow we had to do a lot of work-arounds to get the operations done in our respective lifetimes. We also worked with 3x3 Kernels because they were easier and a lot faster.

So, you would think that the first blur that we developed was the following kernel:

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 1 1 0 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 9, offset = 0)

But you’d be wrong. This kernel has two problems:
  1. The sum is 9. Division was a sloooow operation, unless you were dividing by a power of 2. As we saw before, you’d have to use a scale of 9 in order to make this kernel work, so this wasn’t a good choice.
  2. The kernel is square. More blurring goes on in the diagonals than horizontally and vertically and this is a visible artifact.

So, instead we used the following kernel which is nearly a Gaussian:

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 2 1 0 0
0 0 2 4 2 0 0
0 0 1 2 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 16, offset = 0)

It turns out that dividing by 16 on a computer is really easy and fast, and even more useful, multiplying by a power of 2 is really easy and fast, so this was the first useful blur kernel.

Another useful tidbit is that if you reapply several little Gaussians, you get a big Gaussian. Try it.

One big problem with kernels is that as they get bigger, they get a lot slower. A 5x5 has 25 multiplications. A 7x7 has 49 multiplications and takes about twice as long. Yet, the difference in the blur between radius=2 and radius=3 really isn’t that much. And if I want a radius=20, this could really take a lot of time.

So how does Chris Cox (the optimization guru at Adobe) do it? How does he make the Gaussian blur function so fast? He cheats.

First he convolves the image with a horizontal Gaussian Blur (example below is a radius=1.0) and then with a vertical Gaussian Blur. He doesn’t have to do any work where there are 0’s, so it is really fast. In fact, that 7x7 = 49 multiplies is reduced to 7 + 7 = 14 multiplies. At the larger radius, these advantages become really obvious.

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0.011 0.135 0.607 1.000 0.607 0.135 0.011
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 2.506, offset = 0 or use autoscale)
Horizontal Blur, radius = 1

0 0 0 0.011 0 0 0
0 0 0 0.135 0 0 0
0 0 0 0.607 0 0 0
0 0 0 1.000 0 0 0
0 0 0 0.607 0 0 0
0 0 0 0.135 0 0 0
0 0 0 0.011 0 0 0 (scale = 2.506, offset = 0 or use autoscale)
Vertical Blur, radius = 1

So if you did both of them to your image, and the order doesn’t matter, you’d get almost exactly the same effect as the built-in Gaussian function.

Edge Enhancing II – The Laplacian

Earlier we saw that a directional derivative was really the same thing as embossing, and if we took the directional derivative in several directions and kept the biggest value, we’d find the edges. There is a different way that came first. This is called the Laplacian, after the guy. If you’ve got a math background, this is really the second derivative.

Let’s start with the simplest version of the Laplacian:

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 -1 0 0 0
0 0 -1 4 -1 0 0
0 0 0 -1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 1, offset = 128)

(You could also use scale = 4 if you’re following the Scale & Offset Rule from the last post.)

This will trace every edge and highlight every bit of noise in your entire image. In fact, the Laplacian is the best noise amplifier of all of the edge detectors.

There is an additive version of that kernel (notice the different center value and that Offset = 0):

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 -1 0 0 0
0 0 -1 5 -1 0 0
0 0 0 -1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 1, offset = 0)

What I did was add the original image back to the edge image. You could use the FADE tool here to get as much emphasis as you want… if you like noise, that is.
However, if you had some kind of QuickMask (Selection) that isolated the processing to where the edges are… Nevermind. We’ll talk about that some other time.

This kernel setting works because the sum of the positive values is one more than the sum of the negative values. Because the difference is just one, I can use scale = 1, offset = 0. This causes a uniform area on the image to be unchanged.

Back with the –1’s and the 4, the positive sum was the same as the negative sum so a uniform area on the image would give a zero and it was possible to get negatives, so we used an offset=128 to put the unchanging values in the middle of the histogram.

One other Laplacian kernel is used fairly often because it emphasizes diagonals, too:

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 -1 -1 -1 0 0
0 0 -1 8 -1 0 0
0 0 -1 -1 -1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 (scale = 8 or 1, offset = 128)

If you replace the 8 in the middle with a 9, set scale = 1, offset = 0.

I’m running out of time. Next time we’ll do a High Pass filter which is basically subtracting the blurred image from the original, show how that is related to the UnSharp Mask (and where the USM came from) and we’ll go from there.

-Chris Russ

Last edited by jcr6; 10-24-2002 at 08:14 AM.
Reply With Quote top
  #15  
Old 10-25-2002, 09:17 PM
Stephen M Stephen M is offline
Senior Member
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 439
Wow - thanks again Chris, you are really helping with your posts on convolution and I appreciate you sharing your time and knowledge on this topic.

I don't want to sidetrack your posts, but I have a link to some custom convolution kernels for sub pixel motion simulation for anyone following this thread to experiment with:

http://www.retouchpro.com/forums/sho...4352#post34352

P.S. PC users should add a .acf file name extension to the downloaded kernel files if it is missing (Photoshop, Adobe Custom Filter preset file extension).

Stephen Marsh.
Reply With Quote top
  #16  
Old 10-26-2002, 07:25 PM
DJ Dubovsky's Avatar
DJ Dubovsky DJ Dubovsky is offline
Senior Member
 
Join Date: Aug 2001
Location: Upper Penninsula of Michigan
Posts: 1,659
Chris,
I'm amazed and thankful that you took the time to type all that out for us and try to explain the mechanics behind it all. It does seem overwhelming but I definately bookmarked this page for future numbers to plug in and save as settings. I think if I really sit down and plug through it and look at the results of your numbers I will begin to feel more comfortable with this filter.
DJ
Reply With Quote top
  #17  
Old 10-28-2002, 06:47 AM
jcr6's Avatar
jcr6 jcr6 is offline
Member
 
Join Date: Oct 2002
Location: Asheville, NC
Posts: 72
Let's go back and try some of these. If you have trouble figuring out what I wrote, we can go over those things again.

The point is that convolution is a fundamental part of image processing and that it is a powerful tool.

Not necessarily an EASY tool.

(It's not like I can look at a kernel and intuitively tell you what it does. I have to stare at it for awhile and then guess.)

-Chris
Reply With Quote top
  #18  
Old 10-28-2002, 08:28 PM
Flora's Avatar
Flora Flora is offline
Senior Member
 
Join Date: Mar 2002
Location: Milan, Italy
Posts: 2,325
Blog Entries: 3
Hi Chris!

I have been asking around about Custom Filter, (Photoshop), a while ago.

Stephen has been a big help pointing out several links where I could find a lot of information on the topic....Unfortunately all that proved to be "Way over my head" too....

It will probably remain that way for me but, after reading your posts, I'll definitely start experimenting with it again.... It fascinated me before and now that I have a better glimpse on the starting point....well......

So, let me join everybody else in thanking you for "sharing your time and knowledge on this topic"
Reply With Quote top
  #19  
Old 10-30-2002, 06:26 AM
stewreno's Avatar
stewreno stewreno is offline
Junior Member
 
Join Date: Oct 2002
Location: Honolulu
Posts: 1
Hi Chris! Could you explain Scale and Offset in more detail? I'm not sure I get what I am trying to accomplish with those numbers.

Is the Offset added to the center value? Or the final product? Or is something else completely?

To get something even close to the original, the sum of the values in your kernel should be 1, Correct? It seems that an Offset value of 128 would throw this way off, wherever it's used.

I can't figure exactly where the Scale fits in either, although I know it divides some part of the convulsion.

Paint Shop Pro uses the terms Division Factor and Bias. I'm assuming they are the same thing as Scale and Offset.

That's all the questions I have right now. Thanks in advance (and thanks for the awesome tutorials, I hope to see more).
Reply With Quote top
  #20  
Old 10-30-2002, 06:50 AM
jcr6's Avatar
jcr6 jcr6 is offline
Member
 
Join Date: Oct 2002
Location: Asheville, NC
Posts: 72
Quote:
Is the Offset added to the center value? Or the final product? Or is something else completely?

To get something even close to the original, the sum of the values in your kernel should be 1, Correct? It seems that an Offset value of 128 would throw this way off, wherever it's used.

I can't figure exactly where the Scale fits in either, although I know it divides some part of the convulsion.

Paint Shop Pro uses the terms Division Factor and Bias. I'm assuming they are the same thing as Scale and Offset.
Let's say I had a kernel that was like this:
0 0 0
1 1 1
0 0 0

(remember to put this in the center and add the extra zeros all around -- I'm a lazy typist today)

I would want to divide the result by 3 because the sum of the kernel is 3. Since the sum isn't zero, we can leave the offset at 0.
(Scale is what we divide the product of the pixels and the kernel by. Offset is added afterwards.)

You could invert the image with:
0 0 0
0 -1 0
0 0 0 (scale = 1, offset = 0)

The case where offset matters is when the sum of the kernel is zero:
0 -1 0
-1 4 -1
0 -1 0

In a uniform area on the image, where all of the neighbors are the same, this will give you a zero result. It the edges are getting darker, you could get a negative result and if the edges are getting brighter you could get a positive result. So we add 128 (gray) to push these values to the middle of the histogram.

What do you use for scale in this case? I like to use 4 which is the sum of the positive values. You could use 1 and really see the effects more strongly.

The one that really causes confusion is this one:

0 -1 0
-1 8 -1
0 -1 0 (scale = 4, offset = 0)

Now, the positive sum is 8, the negative sum is 4 and the overall sum is 4. Because the sum isn't zero the offset should be 0. The scale should be the sum of the kernel, or in this case 4.

Does this make sense?
Reply With Quote top
Reply

  RetouchPRO > Tools > Software


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHOTO ART: Mini-challenge #49 – Park Bench DannyRaphael Photo Art Mini-Challenges 100 12-25-2010 08:49 PM
Impressionist plugin: Troubleshooting Cheryl H Photo-Art Resources 34 06-15-2009 11:13 PM
Sharpening T Paul Scratch Pad 34 08-16-2004 11:02 AM
Photoshop Filters: Books and websites DannyRaphael Photo-Based Art 1 03-20-2003 05:17 PM
Impressive Free Filters thomasgeorge Software 1 01-02-2002 11:40 AM


All times are GMT -6. The time now is 09:00 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
Copyright © 2016 Doug Nelson. All Rights Reserved