Reducing moiré effects in downsizing for web posting

A forum to ask questions, post setups, and generally discuss anything having to do with photomacrography and photomicroscopy.

Moderators: rjlittlefield, ChrisR, Chris S., Pau

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Reducing moiré effects in downsizing for web posting

Post by rjlittlefield »

This month's Administrators Appreciation Award winner in the macro division was a bit trickier to process than usual.

I thought you might be interested in how I did it, since the concept is pretty general and I can't remember it being discussed in the forums here.

The image we're talking about was originally posted by daemonoropsis (Morten Aagaard) as image #3 in his topic "First season stacking, my 10 favorites + setup". Other versions and more information can be found on his website, http://mortenaagaard.com/focus-stacking/.

As it appeared in his photomacrography.net post, the image looks like this:
Image

This image looked great to me, but I could see a problem looming.

As posted, the image was 1024 pixels wide. That made it big enough for most of even the small ommatidia to span 4 pixels or more. That's generally considered to be a safe ratio for avoiding aliasing problems.

But our front page format requires images that are only 621 pixels wide.

At that reduced size, the small ommatidia would span only about 2 pixels, and that's well known to be a recipe for disaster in the form of moiré effects. (For discussion and illustration, see "On the resolution and sharpness of digital images...".)

A quick test confirmed the problem, so I asked Morten for a copy of the full-sized image to play with.

Let's start at the beginning. Here's a crop from that full-sized image.

Image

As you can see, it's gorgeous. Crisply delineated throughout, with uniformly sharp rendering of the ommatidia and the "fur" on neighboring surfaces. Beautiful, simply beautiful.

But when we pull that image into Photoshop and do a simple Image > Image Size... > Resample Image: "Bicubic Sharper (best for reduction)", here's what gets produced:

Bicubic Sharper
Image

There's a significant amount of moiré in the eye, certainly much more than I'd prefer to put on our front page.

Now I grant that it's not bad compared to some of the alternatives. Here are resizings with "Bilinear" and "Nearest Neighbor (preserve hard edges)".

Bilinear
Image

Nearest Neighbor
Image

OK, clearly this is going in the wrong direction. Rather than sharper, what we want is smoother. Here are resizings with "Bicubic (best for smooth gradients)" [the default method] and with "Bicubic Smoother (best for enlargement)".

Bicubic [default]
Image

Bicubic Smoother (best for enlargement)
Image

Ironically, it's the "best for enlargement" method that actually does a better job for reducing the eye. But we can do even better than this.

The key to minimizing aliasing is to work with the original size image, filter out any spatial frequencies that cannot be represented in the final smaller image, and then do the actual reduction. By filtering the original size image, we give the filter enough information to do its job accurately.

The exact filter we need is not available in Photoshop (or if it is, I don't know where).

But a reasonable approximation is provided by Gaussian Blur with a width that corresponds to about 0.5 pixels in the reduced image.

In this case I'm producing an image of 641 pixels from a starting image that's about 5 times bigger, so I'll use a Gaussian Blur of 2.5 pixels (2.5/5 = 0.5).

When applied to the original image, the first thing we see is so badly blurred that it looks like complete junk:

original plus Gaussian Blur of 2.5 pixels
Image

But this blurred junk version is just the pre-filtering we need to get a lot less moiré after resizing!

With this pre-filtering, here is what gets produced by "Bicubic (best for smooth gradients)" and "Bicubic Sharper (best for reduction)":

prefiltered, then Bicubic
Image

prefiltered, then Bicubic Sharper
Image

That last one looks pretty good, at least on the eye. There's a very small amount of moiré left, but nothing I'm motivated to go after, and in general the eye presents an appearance of sharpness that strikes me as representing well the original image.

However, when I go back and look at the rest of the fly, I'm not so happy with the overall sharpness. It strikes me as too soft, not well representing the original.

Of course moiré is not a problem on the rest of the fly, because there are no repeating patterns to make aliasing visible.

So, I can cheat ... um, "have my cake and eat it too" ... by using some simple layers and masks to merge the best rendition of the eye and the best rendition of the body, each in their respective areas.

For the eye, I like what we've done above, and for the body I like what's produced by my usual process of "Bicubic" resizing followed by Unsharp Mask of 35% at 0.3 pixels to add a bit of bite.

Here is the result of the merge:

final merged image
Image

This may look like quite a bit of trouble, but really the process went a lot faster than it takes to tell about.

Besides, I think it's worth putting in some time to make our front page image look good.

I hope this is helpful.

--Rik

Peter De Smidt
Posts: 233
Joined: Thu Jan 05, 2012 9:10 am
Contact:

Post by Peter De Smidt »

That's good stuff, Rik. I wonder how using better resizing methods such as Lanczos would work. http://www.faststone.org/FSViewerDetail.htm is a free editor that has more re-sizing options than Photoshop.

Chris S.
Site Admin
Posts: 3632
Joined: Sun Apr 05, 2009 9:55 pm
Location: Ohio, USA

Post by Chris S. »

Excellent, Rik! So a boiled-down quick reference might be:

To avoid moiré: Before downsizing, apply Gaussian blur with a radius calculated as R = L1 * 0.5 / L2

Where R=radius; L1 = long dimension of original image; L2 = long dimension of final image.

If result softens non-moiré-prone areas, mask together a traditionally-downsized layer with a “blurred-before-downsized” layer.


Lovely!

--Chris

DQE
Posts: 1653
Joined: Tue Jul 08, 2008 1:33 pm
Location: near Portland, Maine, USA

Post by DQE »

Rik,

In reviewing some of your previous posts on somewhat related topics, I came across a statement (which I very much support and believe):

"Sadly (and contrary to what's claimed in the article), that type of aliasing can not be corrected in post-processing either -- you're stuck with the Moiré patterns just like you're stuck with Bayer artifacts."

The URL to the previous thread is:

http://www.photomacrography.net/forum/v ... php?t=2439

Search for this text string within the above older thread to find Rik's post which I excerpt above:

"Posted: Mon May 07, 2007 11:33 am"

How can I reconcile Rik's previous post with his text and demonstrations in the current thread where clear advantages are shown by post-processing images to greatly reduce Moire?

I'm sure I'm just missing something basic, but at the moment I am clinging to my long-standing belief: once sampled, the information, artifacts (and Moire) obtained by the original sampling frequency are baked in.

(I'm not trying to create controversy; I just can't reconcile what seems to almost be a paradox or at least something in that direction.)
-Phil

"Diffraction never sleeps"

Chris S.
Site Admin
Posts: 3632
Joined: Sun Apr 05, 2009 9:55 pm
Location: Ohio, USA

Post by Chris S. »

Phil, how about this to reconcile the seeming paradox?

Moiré is difficult or impossible to remove after it is in an image, but can usually be prevented from getting into an image in the first place. In Rik’s quote from the earlier thread, he was discussing the impracticability of the former; in this thread, he presented a method for the latter.

--Chris

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

Chris S. wrote:So a boiled-down quick reference might be:
...
Yes, that's a very good and concise summary.
DQE wrote:How can I reconcile Rik's previous post with his text and demonstrations in the current thread where clear advantages are shown by post-processing images to greatly reduce Moire?

I'm sure I'm just missing something basic, but at the moment I am clinging to my long-standing belief: once sampled, the information, artifacts (and Moire) obtained by the original sampling frequency are baked in.
Chris S. wrote:Moiré is difficult or impossible to remove after it is in an image, but can usually be prevented from getting into an image in the first place.
Yes, just so.

In more detail... In the current thread the high-res digital image plays the role of the "original signal", analogous to the optical image in my earlier thread. The Gaussian Blur filter that I've applied here does the same job as the AA filter on a digital sensor -- it removes high frequencies that would otherwise alias when sampled.

In other words (and linked images...), it's simple and effective to go from the original signal to a bandwidth limited signal to a non-aliased sample, but it's impossible to go from the original signal to an aliased sample and from there to a non-aliased sample.
Peter De Smidt wrote:I wonder how using better resizing methods such as Lanczos would work.
Certainly there are a lot better resizing methods than the assortment that Photoshop provides. For downsizing, the key aspect is anti-aliasing, which basically means paying proper attention to all the pixels "in the gaps" between the positions of new samples. There's a good discussion of this and other aspects of resampling at http://pixinsight.com/doc/docs/Interpol ... ithms.html. Bart van der Wolf has a good illustration of many options at http://bvdwolf.home.xs4all.nl/main/foto ... sample.htm and http://bvdwolf.home.xs4all.nl/main/foto ... ample1.htm.

One of the sources of confusion in talking about this stuff is that brief names like "Lanczos" can describe a wide range of methods, some of which are awful while others are quite good. For radical downsizing, bvdwolf.home shows that something called "Lanczos" is quite good. Meanwhile the pixinsight.com page shows that something they call "Lanczos-3" is awful. But I can easily imagine another method with the same name and most of the same math that would work very well, more like what bvdwolf.home shows. It just depends on whether that "-3" means number of lobes (potentially spanning many pixels and filling the gaps) or number of pixels (potentially leaving most of the gaps ignored). I'm pretty sure that bvdwolf.home tested a method that does the first, while pixinsight.com tested a method that does the second.
http://www.faststone.org/FSViewerDetail.htm is a free editor that has more re-sizing options than Photoshop.
Thanks for the pointer. The name sounded familiar, so I checked my computer and discovered that I had FastStone installed at one point and then removed it. As best I recall, it did something weird with thumbnails in my Windows Explorer panels so I removed it because the bad effects outweighed the good at that time. That was quite some time ago so the situation has probably changed.

--Rik

Peter De Smidt
Posts: 233
Joined: Thu Jan 05, 2012 9:10 am
Contact:

Post by Peter De Smidt »

Rik,

Thanks for the links. I'll definitely check them out. I mainly do 4x5 photography, and downsizing the hi-res files in Photoshop down to web sizes doesn't work very well. A friend recently recommended Faststone. I tried it on your fly image, and it did do a better job than with the straight re-sizing method in Photoshop.

DQE
Posts: 1653
Joined: Tue Jul 08, 2008 1:33 pm
Location: near Portland, Maine, USA

Post by DQE »

Chris S. wrote:Phil, how about this to reconcile the seeming paradox?

Moiré is difficult or impossible to remove after it is in an image, but can usually be prevented from getting into an image in the first place. In Rik’s quote from the earlier thread, he was discussing the impracticability of the former; in this thread, he presented a method for the latter.

--Chris
Chris, Rik -

Thanks for your clarifications and additional discussions.

A critical point I somehow overlooked is that we want to *resample* the original photograph in order to reduce the size of the photo (in pixels) and that this is a *new* sampling of the existing image and thus the resampling operation may benefit from prefiltering before the resampling is done. I'm not sure I've expressed this clearly but I hope it's both correct as well as reasonably clear. Now that I've written this out, I don't see how I missed these details, of course.

I am also enjoying the links Rik provided re interpolation, aliasing, and the like.

(I developed a special interest in interpolation techniques during the early years of my career (don't ask how long ago!). Perhaps I can resurrect this knowledge and attempt to tie this dormant special interest with aliasing theory, etc. It's certainly an interesting set of subjects.)
-Phil

"Diffraction never sleeps"

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

DQE wrote:A critical point I somehow overlooked is that we want to *resample* the original photograph in order to reduce the size of the photo (in pixels) and that this is a *new* sampling of the existing image and thus the resampling operation may benefit from prefiltering before the resampling is done. I'm not sure I've expressed this clearly but I hope it's both correct as well as reasonably clear.
This sounds right to me.
Now that I've written this out, I don't see how I missed these details, of course.
Ah, how often that happens!

I have not kept track of how many things I've written and then deleted because the writing made clear that the ideas weren't.

But trust me, the number would be embarrassingly large. :roll:

--Rik

Clintonwake
Posts: 216
Joined: Wed Feb 13, 2013 5:49 am
Location: Australia

Post by Clintonwake »

Wow Rik, awesome image and information

cheers
Denis

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

Thanks!

Again, the image comes from daemonoropsis (Morten Aagaard). I just tried to represent it as well as I could, in not nearly enough pixels on our front page.

--Rik

abpho
Posts: 1498
Joined: Wed Aug 17, 2011 7:11 pm
Location: Earth

Post by abpho »

To eliminate those moire patterns during down sizing I just do smaller reductions. From 5 to 10 times to get from the full 21MP image down to 1MP.
I'm in Canada! Isn't that weird?

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

abpho wrote:To eliminate those moire patterns during down sizing I just do smaller reductions. From 5 to 10 times to get from the full 21MP image down to 1MP.
That method is attractive for its simplicity, and it's certainly a big improvement over Photoshop's one-step method. It's not quite as effective as prefiltering, however.

For illustration, here is the test image downsampled from 3000x2000 (as it came to me) to 621x414 as needed for the front page.

5 steps of Bicubic (to widths of 2189, 1598, 1166, 851, 621):
Image

10 steps of Bicubic (to widths of 2563, 2189, 1870, 1598, 1365, 1166, 996, 851, 727, 621):
Image

Previous result again, by prefiltering:
Image

--Rik

abpho
Posts: 1498
Joined: Wed Aug 17, 2011 7:11 pm
Location: Earth

Post by abpho »

I'll see what happens next time I down size a similar shot. In my recent Robber Fly stack, the moire pattern is not visible after stepping down to the final size. Am I just not seeing it? I also only use Bilinear for my resolution changes. There was an article where someone compared the effects of the different algorithms and showed that Bilinear was the best for pretty much all occasions. Or that is what I walked away from that post. :D
I'm in Canada! Isn't that weird?

rjlittlefield
Site Admin
Posts: 21444
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

abpho wrote:I'll see what happens next time I down size a similar shot. In my recent Robber Fly stack, the moire pattern is not visible after stepping down to the final size. Am I just not seeing it?
Your robberfly looks great, as did Morten's in his original post. I think what you haven't seen yet is that your robberfly as posted is above the critical size scale where moiré hits hard, while Morten's robberfly as shrunk to fit on the front page is well below it.
I also only use Bilinear for my resolution changes. There was an article where someone compared the effects of the different algorithms and showed that Bilinear was the best for pretty much all occasions. Or that is what I walked away from that post. :D
Well, I don't know what was written and read, but it's definitely not true that Bilinear is the best for pretty much all occasions.

Here's what happens to Morten's robberfly with 10 steps of Bilinear. (Compare to 10 steps of Bicubic as shown above.)

Image

To illustrate my point about critical size, here's what the eye of Morten's robberfly looks like at each of those 10 steps after the original:
Image

As you can see, it holds up just fine until the facets reach a critical size scale, and then things start to go seriously bad.

Interpolating coarse features is easy. Interpolating fine irregular features is not so easy but at least the artifacts are hard to see. Interpolating fine regular features is where the problem gets tough, and that's the topic of this thread.

--Rik

Post Reply Previous topicNext topic