imwarp function - bands during interpolation

12 visualizaciones (últimos 30 días)
arnaud COQ
arnaud COQ el 24 de Feb. de 2022
Comentada: arnaud COQ el 10 de Mzo. de 2022
Hey guys,
I'm trying to use imwarp function and apply either small transformation or displacement field to an image generated, via:
Im1 = randi([0 255],2000,2000);
tform = affine2d([1. 0. 0; 0. 0.99 0; 0 0 1]);
Im2 = imwarp(Im1,tform, "linear"); % or 'nearest' or 'cubic' interpolation fct.
imshow(Im2,[0 255]);
But final image Im2 shows bands that must appear due to interpolation function. This problem also appears when applying a displacement field.
I am wondering, if I am doing something wrong or if someone had the same problem how you circumvent it.
Thanks,

Respuesta aceptada

Steve Eddins
Steve Eddins el 7 de Mzo. de 2022
First, let me run Arnaud's reproduction code and display the result so that everyone can see what we are talking about.
Im1 = randi([0 255],2000,2000);
tform = affine2d([1. 0. 0; 0. 0.99 0; 0 0 1]);
Im2 = imwarp(Im1,tform, "linear");
imshow(Im2,[0 255]);
I can see the horizontal banding effect (although you might not see it in your browser, after the image has been resized once for figure capture and then resized again for browser display). I wondered about three possibilities:
  • Interpolation artifact
  • Aliasing artifact
  • Display artifact
I ruled out a display artifact by trying different image sizes, figure sizes, and image interpolation options, and the banding was always visible. I could see the banding when I wrote out the image to a file and viewed it in another app, and the banding did not go away or even really change appearance when I changed the display zoom.
Aliasing was my initial suspicion, at least until I changed 0.99 to 1.01 in the affine transformation matrix and observed very similar banding.
That brought me back to reconsidering interpolation, but I was still puzzled until I tried it with a much smaller image. Viewing the result brought a light bulb moment.
Im1 = randi([0 255],200,200);
tform = affine2d([1. 0. 0; 0. 0.99 0; 0 0 1]);
Im2 = imwarp(Im1,tform, "linear");
imshow(Im2,[0 255]);
I had the impression that the top, center, and bottom bands looked sharp, whereas the two horizontal bands in between those three looked vertically blurred.
Let's zoom in.
figure
imshow(Im2,[0 255])
axis([0.5 100.5 0.5 100.5])
The blurring effect in the middle band is more obvious now. That's when the answer hit me.
At roughly 100 pixel intervals (vertically), the interpolation locations line up very closely with the pixel centers. That means that the interpolation outputs will be almost exactly the same as the original pixels in those locations.
In between those sharper-looking bands, though, the interpolation locations are in between the original pixel locations, and so the interpolation outputs are producing an average of two vertically adjacent pixels. That difference is producing the visual "banding" effect.
I don't think it is fair, however, to call this an "interpolation artifact." I'm not sure exactly what words to use, but roughly speaking, I think this is a fundamental mismatch between the data and the very concept of interpolation.
All of the original pixel values are completely uncorrelated! One pixel value is unrelated to the values of its immediate neighbors. What does it even mean to interpolate between independent, unrelated values? Interpolation presupposes the existence of an underlying, continuous-domain, smoothly varying signal that we can meaningfully resample, and that doesn't exist here.
I think that the only way you can perform this warp without that banding is to use some form of smoothing interpolation, like a smoothing spline, or to smooth the data before performing the warp.
  1 comentario
arnaud COQ
arnaud COQ el 10 de Mzo. de 2022
Hi Steve,
Thanks a lot for this answer, that helps me a lot !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by