MATLAB pcolor / surf bilinear interpolation (shading interp)

Consider the following MATLAB code:

C = [ 0 0 0 0 0 0 1 2 1 0 0 2 4 2 0 0 1 2 1 0 0 0 0 0 0 ]; pcolor( C ); shading interp; axis square 

Note that C invariant under 90 degree rotations. Also note this suggestion from the help for pcolor :

Using shading interp, each cell is colored by bilinear interpolation of colors at its four vertices, using all the elements of C.

However, the constructed image is as follows:

Codeoutput

Note that the image is not invariant under 90-degree rotation (consider, for example, four angles). Now, if I do not mistakenly understand bilinear interpolation, this should be wrong. MATLAB seems to interpolate on triangles, which is not the same as bilinear interpolation.

Is there any way around this MATLAB error and get the correct bilinear interpolation? (In addition to manually interpolating additional points that still have not cured the problem, if it had come close enough.)

+7
matlab matlab-figure surface shading
source share
1 answer

I remember reading several topics about this strange behavior on official Matlab forums in the past. Unfortunately, I did not find it right now with a quick search. In any case ... this is not the first time you have indicated that the shading interp used in combination with pcolor behaves strangely, creating forms that do not reflect the underlying data.

The main problem is that the shading interp interpolates between data points without worrying about how smart your grid is for smoothing. If you want a result that does not look jagged, you need to provide data sampled with a higher resolution:

 C = [ 0 0 0 0 0 0 1 2 1 0 0 2 4 2 0 0 1 2 1 0 0 0 0 0 0 ]; C = interp2(C,5,'cubic'); pcolor(C); shading interp; axis square; 

This gives an amazing result, and the output does not display an artifact or asymmetry:

Output

0
source share

All Articles