Filter löschen
Filter löschen

MATLAB pcolor/surf bilinear interpolation (shading interp)

59 Ansichten (letzte 30 Tage)
Tom Holden
Tom Holden am 18 Nov. 2017
Kommentiert: Walter Roberson am 30 Apr. 2019
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` is invariant under 90 degree rotations. Also note this sentence from the help for `pcolor`: "With shading interp, each cell is colored by bilinear interpolation of the colors at its four vertices, using all elements of C."
However, the plotted image is as follows:
Note that the image is not invariant under 90 degree rotations (consider e.g. the four corners). Now, unless I horribly misunderstand bilinear interpolation, this must be wrong. MATLAB seems to be interpolating on triangles, which is not the same as bilinear interpolation.
Is there any way of working round this MATLAB bug, and getting correct bilinear interpolation? (Other than manually interpolating additional points myself, which still would not cure the issue if one zoomed in far enough.)
  3 Kommentare
Image Analyst
Image Analyst am 21 Dez. 2017
Joe, can you move this down to the "Answers" section with the rest of the answers? The comments section up here is reserved for requests for clarification of the original question. Sometimes when posters see comments up here, they think they are the answers and never scroll down to see the actual answers in the Answers section.
Tom Holden
Tom Holden am 21 Dez. 2017
The solution on the linked page is doing manual interpolation. The question asked for a solution other than manual interpolation...

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 21 Dez. 2017
pcolor() does NOT use all the elements in your array - it ignores the last row and last column. Just comment out the shading line of code and run it:
Is that what you want and were expecting? I'm guessing not.
So, don't use pcolor. Use imshow(). If you need higher resolution, then use imresize() to make bump up the resolution if you want to:
C2 = imresize(C, 100); % Blow up by a factor of 100;
imshow(C2, []);
axis on;
colorbar;
  5 Kommentare
marco riva
marco riva am 30 Apr. 2019
Bearbeitet: marco riva am 30 Apr. 2019
I want to use this method, with imresize. However I want to keep axis values from 0 to 5 (not 0 to 500 due to the resize). Is there a way to enforce that?
Thank you
Walter Roberson
Walter Roberson am 30 Apr. 2019
marco riva: you can provide XData and YData parameters to imshow() to specify the data units where the image is to be placed. Note that XData and YData are the coordinates of the center of the lower left and upper right pixels so the image edge will be at coordinates one half pixel beyond that.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by