SeamlessTG - New Sharpen Algorithm! (image heavy)

Community Forums/Showcase/SeamlessTG - New Sharpen Algorithm! (image heavy)

sswift(Posted 2005) [#1]
After a week of head scratching and reading lots of research papers with lots of pretty pictures, and a bunch of math I don't understand, I've developed a new algorithm for sharpening images which will be in the next update for my Seamless Texture Generator!

Why have I developed a new sharpening algorithm, you might ask?

The standard method of sharpening an image is called "unsharp masking". Unsharp masking is an old photographic technique where one makes a blurrier version of an image and then subtracts that from the original, producing an image where the edges made brighter on one side, and darker on the other.

This brightening and darkening of the edges creates the appearance of a sharper edge, but it also creates what is known as a "ringing" effect. A bright dot in an image will end up with a dark circle around it.

In photographs, one can get away with this ringing effect, because one's images are generally not examined too closely. But textures are often seen from up close, and on a zoomed image, such sharpening artifacts look horrible.

My algorithm GREATLY reduces this ringing effect while still allowing you to sharpen the image just as much as with unsharp masking. Also, my algorithm does not squeeze edges like unsharp masking does... It does not make narrow gaps into even narrower ones.

But don't take my word for it, see for yourself, pictures speak louder than words. :-)

I'm not sure yet when this new version will be out, I'm still working on it and adding stuff, but it will be fairly soon. Besides sharpening the update will also have other functions to improve the final image before saving.


sswift(Posted 2005) [#2]
Btw, if you're struggling to see the difference, just take the cropped unsharp radius 0.5, and the cropped version of mine radius 1, and open them in different tabs or save them so you can switch between them and see the changes as you switch. It'll be pretty obvious then.


WolRon(Posted 2005) [#3]
You keep calling it Unsharp, but isn't what you're doing called Sharpening? (The reverse of that would be Softening)


sswift(Posted 2005) [#4]
What I'm doing is sharpening, but "unsharp masking" is a specific method of sharpening, probably the most popular one among artists. "Unsharp masking" is what it is called in Photoshop, and every other program out there, as well as by computer scientists.

Unsharp masking is called unsharp masking because it has its origins in photography.

In the old days, it was done in dark rooms by creating blurry negatives from photos and then using them to "mask the unsharpness" of the original image by placing the blurry mask negative over the original negative to produce a sharp final image on the photo paper.

So that's how it got its name. Make sense if you know the origins, but I wouldn't have called it that. :-)


sswift(Posted 2005) [#5]
I'm posting the sample images here instead so I can stick them side by side for easier comparison:

(Note that a radius of 0.5 for an unsharp mask is approximately equivalent to a radius of 1 in my program.)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Original image:


Unsharp radius 0.3 : 0,5 : 1.0


Mine radius 1 : 1 : 2



I have also cropped and zoomed the images so you can see the differences more easily.

Note the ringing around the white panels, and note how the gap there gets smaller.
Also note the square metal bracket, and how unsharp making makes it very dark so the detail is effectively lost.
And note how the gaps in the bricks are more defined with my filter.

Original image:


Unsharp radius 0.3 : 0.5 : 1.0


Mine radius 1 : 1 : 2



big10p(Posted 2005) [#6]
How's the game coming along, sswift?

i.e. Apps = bugger all money.
Games = possibly good money.


sswift(Posted 2005) [#7]
Big10:
I'm making enough money on this to justify a couple more weeks of work on it. :-)


Grey Alien(Posted 2005) [#8]
I look forward to the update!


ImaginaryHuman(Posted 2005) [#9]
I can't reall tell the difference?


sswift(Posted 2005) [#10]
Yeah, it's kinda hard to tell the difference in my examples.

Look at just these two images:




That is unsharp 0.5 radius on the top, and mine, radius 1 on the bottom.

Look at the brown rectangle in the middle of the white plywood. See how it is darker and has a light outline around it in the top image?

Also, look on the right, where the grey border touches the white plywood. In the top image, the edge of the grey wood is much lighter.

Unfortunately, I didn't sharpen these examples enough to really show the difference. These samples aren't as sharp as they could be, and you want them as sharp as possible obviously.

Increasing the sharpness with the unsharp making would grealy increase those light borders you see there. Here I am only using 100% strength on the sharpening, but if you crank my algorithm up to 200% then you get a much sharper image, and you still don't have those ugly outlines. But if you cranked up the unshapr mask to 200% you'd see very bright outlines and stuff like that brown rectangle would be really dark.

I'll come up with some better examples for ya.


sswift(Posted 2005) [#11]
Lovely, the domain name server crashed just now.


sswift(Posted 2005) [#12]
I had to change the domain name server my domain is using. I guess the change will propogate over the next few hours until everyone can access the domain name again.


Pongo(Posted 2005) [#13]
They all look the same to me,... tiny white box with a red X in it,...

Sorry,... couldn't resist. Looking forward to seeing the pics when all is well again.


sswift(Posted 2005) [#14]
First me website goes down, then the DNS servers go down, and now Share*It is reporting that they are the target of a distributed DOS attack by 100 PC's.

Ugh.


Hotcakes(Posted 2005) [#15]
Now you know why you stuck with PayPal for so long ;]

...

Just kidding! It's not ShareIts fault their popular...


sswift(Posted 2005) [#16]
I've been doing some more research, and it looks like my algorithm isn't really new or original... I've found some pages describing an algorithm which is pretty much identical, if not an improvement on my own algorithm. It's not used in more than one image editing program I know of though.

So I guess it won't hurt to explain what I'm doing.

Apparently, what I am doing is called Weighted Median Sharpening, though I'm doing it without the weighting.

Imagine a 1D slice of an edge in a blurry image. It might look like this:



That is unsharp maksing at work. Unsharp masking works by taking the original image, applying a gaussian blur, then subtracting that from the original image to produce a high pass image which is then multiplied with the original image.

As the high pass image will have edges highlighted with light and dark bands, this brightens and darkens the area around the edge.

But look at the waveform above. See the bumps at the top and bottom of the waveform? The idea wave for a perfectly sharp edge is a square wave. We don't want those bumps. We especially don't want to modify portions of the wave that don't need to be modified, like the flat bits there.

That modification happens because the flat bits are averaged with the bits that are next to them that are lower or higher, and that averaging means the resulting color there is lighter or darker than the flat bit.

We only want to modify the slanty bit of the waveform, ideally, to push it up in the middle. to make a square wave.

Now if we could work on these waveforms in 1D that would be easy to do, but we have to work in 2D or we'll get weird artifacts on things like circles. We can't work in a horizontal direction and a vertical.

So I came up with the best solution I could think of. Median filtering.

If you have a list of numbers, and you order them from high to low, and then take the middle number, that is a median.

A median differs from an average in that an average can be skewed if one of the values is really high or really low.

The median doesn't have this problem. The median is not affected by outlying values.

So look at our waveform again, and imagine you are sampling the point at the edge of the cliff. At that point, the average of several pixels to the left and right would say that the color of that pixel is dark. Just inside that edge on the top flat part, you'd still have some dark pixels in there saying the pixel is dark.

But the median of that point is the center value. And if half the pixels are on the flat part, and half are on the slanty bit, then the median would be the value of the flat part!

If you move in a little bit down the slanty bit, now you've got more slanty pixels, and your median is a tiny bit lower. In fact, in this particular case, the median will generally be about the value of the pixel at that location, but all edges are not this smooth a gradient.

Anyway, so what's so special about that... Well, what it means is that now the only values that will be modified are those on the slanty bit. The edges in our high pass image will be razor sharp and lined up against the edges of the slanty bit. That means the dark and light bits will only be inside the slanty bit, and when we brighten or darken the pixels, only those bits which are in the slanty bit will get pushed up or down.

This stops the bits that shouldn't be modified at all from being brightened or darkened, and gives us a much closer approximation of a square wave, and shrinks the ringing artifacts down to be very small if there are any at all.

Here is a picture of a cameraman which has been sharpened using unsharp masking:



And here is the same image sharpened using my method, which I guess you would call "Median Sharpening"*



You should be able to see the ringing on the edges in the unsharp version, if you save the images and zoom in on them a bit.


* As opposed to Weighted Median, because I'm not doing any weighting which would reduce the amplification of the noise, which I consider makes the texture sharper in appearance and is appropriate for a texture, though inappropriate for a photograph.


Ruz(Posted 2005) [#17]
the camera man is holding a sswifts special real world sharpening device. works great on creases for suits/trousers etc.
Or it could be a comdey water squirting camera

( I will go away now)


Rob Farley(Posted 2005) [#18]
I think you're trying to sell this to the wrong bunch of people!

I don't really see the difference apart from the top one looks sharper... which I guess isn't what you're looking for. But you look at the tower in the background and it certainly stands out better than in your "Median Sharpening" example.

I do see the ringing in the top one though which is not in the lower (white outline on the tripod leg).


Mustang(Posted 2005) [#19]

I don't really see the difference



Do you have a CRT or LCD? I'm on my laptop now and those pictures look like day and night to me.


sswift(Posted 2005) [#20]
Mustang:
And the Unsharp one looks sharper right? :-)

You really need to look at them zoomed in, like you would see a texture. The Unsharp Maksing makes the image look better when it is small, but as you get closer you'll see that it doesn't have a lot of fine detail and you've got the ringing artifacts.