Understanding montage() command settings

25 views (last 30 days)
Matt J
Matt J on 26 Sep 2013
Edited: Jin Ren about 18 hours ago
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 Comment
Matt J
Matt J on 27 Sep 2013
No thoughts, here? I only recently came across montage and it would be useful to get it working.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 1 Oct 2013
Edited: Matt J on 1 Oct 2013
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 Comment
Jin Ren
Jin Ren about 18 hours ago
Edited: Jin Ren about 18 hours ago
See no point why MONTAGE acts like this, Colormap and DisplayRange apparently should be independent.

Sign in to comment.

More Answers (1)

Jeff E
Jeff E on 27 Sep 2013
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 Comments
Jeff E
Jeff E on 27 Sep 2013
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 on 28 Sep 2013
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])

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!