MATLAB pcolor/surf bilinear interpolation (shading interp)

49 ビュー (過去 30 日間)
Tom Holden
Tom Holden 2017 年 11 月 18 日
コメント済み: Walter Roberson 2019 年 4 月 30 日
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 件のコメント
Image Analyst
Image Analyst 2017 年 12 月 21 日
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 2017 年 12 月 21 日
The solution on the linked page is doing manual interpolation. The question asked for a solution other than manual interpolation...

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2017 年 12 月 21 日
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 件のコメント
marco riva
marco riva 2019 年 4 月 30 日
編集済み: marco riva 2019 年 4 月 30 日
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 2019 年 4 月 30 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by