How does EWA work with sample locations and filter weights?
Posted: 2014-05-29T22:33:53-07:00
By default, ImageMagick's distort operator often uses an "elliptical weighted average" of source samples to produce a destination pixel. I understand the concept on the most basic level: Project a circular pixel into the coordinate frame of the source, and you'll get an ellipse or similar conic shape for most sane distortions. Take a bunch of samples inside this shape, weight them with a combined reconstruction/resampling filter, and you'll get your destination pixel color. It's similar to hardware anisotropic filtering in a way, except the sampling is more comprehensive than AF's supersampling approach (and based on point samples, not mipmapped linear samples), and it's generalized for arbitrary filters.
However, that's about the extent of what I understand, and I don't know the details of how resampling with distortion actually works:
However, that's about the extent of what I understand, and I don't know the details of how resampling with distortion actually works:
- What radius should your circle have for EWA? What happens if you use squares instead of circles? I assume this would bias the filters toward diagonals, but could this cause serious artifacts with negative-lobed filters like jinc, cubics, etc.? Is supersampling as compatible with arbitrary reconstruction/resampling filters as EWA sampling?
- How exactly are the sample locations chosen for EWA? Does ImageMagick just search for all source texels whose centers are inside some multiple of your circle's radius from the pixel center ("some multiple" being the filter's support width)? This would partially explain why certain distortions don't work with EWA: It's easy to find the source coords for any point inside the destination circle, but it's harder for crazy distortions to determine whether the center of the nearest source texel is still inside that circle, and it's especially hard if you need to convert back into destination coords to calculate weights.
- Do you compute sample weights for distortions based on destination-space distances or source-space distances? (Would this differ for supersampling vs. EWA?) This would clearly make a huge difference in sample weights at oblique angles (where samples on the "far" side of the center will be more numerous or spaced farther apart in source space, depending on whether you do strict EWA or supersample), but I can't determine which is "correct." My best guess is you compute weights on destination-space distances, but I'm not sure, and it worries me that you do things differently for orthogonal resizing depending on whether you're upsizing or downsizing: For orthogonal downsizing, you scale the reconstruction/resampling filter to fit over a specific number of destination pixels. For orthogonal upsizing, you scale your filter to fit over a specific number of source pixels (to maintain minimum source support)...but I may just be looking at it from the wrong perspective too.
- If you compute weights based on source-space distances, how does the hugely asymmetrical sampling interact with negative-lobed filters like jinc, cubics, etc.? How do you size the filter to ensure sufficient support on each side (relative to ellipse axes)?
- This question applies to resizers in general, but assuming negative-lobed filters, how much error would you introduce by placing an unbalanced number of samples on each "side" of your destination circle's center? I suppose increasing the support size would alleviate this? (I ask because I'm considering the benefits of reweighting the same samples for different R/G/B subpixels. It adds a tolerable amount of bias to a Gaussian filter, but I'm not sure if it would totally break something like Lanczos jinc.)