Understanding montage() command settings

15 ビュー (過去 30 日間)
Matt J
Matt J 2013 年 9 月 26 日
編集済み: Jin Ren 2024 年 3 月 28 日 7:59
I feel like the following code should display virtually identical looking images in figure(1) and figure(2)
load mrislice;
figure(1); imagesc(X); axis image off, colormap(gray(256)),
figure(2); montage(X,gray(256),'DisplayRange',[]),
It does not, however. In figure(1), I see the expected result
whereas in figure(2), I see
Any clear reason why? Possibly, I'm misunderstanding something about how MONTAGE works.
  1 件のコメント
Matt J
Matt J 2013 年 9 月 27 日
No thoughts, here? I only recently came across montage and it would be useful to get it working.

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

採用された回答

Matt J
Matt J 2013 年 10 月 1 日
編集済み: Matt J 2013 年 10 月 1 日
I have been told by tech support that, when a colormap argument is fed to MONTAGE, the DisplayRange option is deliberately ignored. They will update the documentation to clarify this.
Furthermore, although I still don't see the logic of it, I have also been told that the following are equivalent,
>> figure(1), montage(X, 'DisplayRange',[1 100])
>> figure(2), montage(X, gray(100));
i.e., the number of colormap entries is used to determine the max value of X displayed...
  1 件のコメント
Jin Ren
Jin Ren 2024 年 3 月 28 日 7:58
編集済み: Jin Ren 2024 年 3 月 28 日 7:59
See no point why MONTAGE acts like this, Colormap and DisplayRange apparently should be independent.

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

その他の回答 (1 件)

Jeff E
Jeff E 2013 年 9 月 27 日
From the imagesc documentation, emphasis mine:
The imagesc function scales image data to the full range of the *current* colormap...
Your first image is scaled to the colormap immediately when you call imagesc. Try the following:
X2 = X ./ 2; %halve the image intensity
figure(1); imagesc(X); axis image off, colormap(gray(256))
figure(2); imagesc(X2); axis image off, colormap(gray(256))
figure(3); imagesc(X2, [0 255]); axis image off, colormap(gray)
The first two images look the same, while the third shows the expected decrease in intensity.
  3 件のコメント
Jeff E
Jeff E 2013 年 9 月 27 日
Because montage is the functional equivalent of figure 3, where the colormap is set, and then scaled. The way you're calling imagesc, the image is scaled and then the colormap is set.
figure(4); montage(X, gray(256), 'DisplayRange', []);
figure(5); montage(X2, gray(256), 'DisplayRange', []);
Note that figure 4 and 5 using montage look different, but figure 1 and 2 using imagesc look the same.
If you want montage to behave similarly to imagesc, then I think you want this:
figure(6); montage(X2, 'DisplayRange', []); axis image off, colormap(gray(256))
Matt J
Matt J 2013 年 9 月 28 日
where the colormap is set, and then scaled.
No, I'm not getting what you mean by this. Once set, the colormap is a fixed thing. It doesn't get scaled. The image values are the thing that get scaled and then compared to the colormap. I also don't understand the implications of your example
figure(3); imagesc(X2, [0 255]);
or why we need to consider X2. All this means is simply that X2 will be scaled internally so that all values that used to lie between [0,255] will now lie between [0,1] before being compared by the renderer to the colormap. I obtain the exact same image when I do
figure(3); imagesc(X, 2*[0 255]);
As for montage, it seems clear from the additional examples below that DisplayRange is ignored. The following produces the desired image
X=double(X);
montage(X*256/max(X(:)),gray(256))
But all of the following produce exactly the same image with no change
>> montage(X*256/max(X(:)),gray(256),'DisplayRange',[0,.001])
>> montage(X*256/max(X(:)),gray(256),'DisplayRange',[1000,1001])
>> montage(X*256/max(X(:)),gray(256),'DisplayRange',[rand,rand+1])

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by