Understanding montage() command settings

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 Commento

No thoughts, here? I only recently came across montage and it would be useful to get it working.

Accedi per commentare.

 Risposta accettata

Matt J
Matt J il 1 Ott 2013
Modificato: Matt J il 1 Ott 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 Commento

Jin Ren
Jin Ren il 28 Mar 2024
Modificato: Jin Ren il 28 Mar 2024
See no point why MONTAGE acts like this, Colormap and DisplayRange apparently should be independent.

Accedi per commentare.

Più risposte (1)

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 Commenti

Matt J
Matt J il 27 Set 2013
Modificato: Matt J il 27 Set 2013
Hi Jeff,
Your first image is scaled to the colormap immediately when you call imagesc.
Yes, I know that, but that's not the question. The question is about the behavior of montage() not of imagesc(). Why doesn't montage() also scale the image to the color map when the DisplayRange option is set to []?
From "doc montage":
If you specify an empty matrix ([]), montage uses the minimum and maximum values of the images to be displayed
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))
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])

Accedi per commentare.

Tag

Richiesto:

il 26 Set 2013

Modificato:

il 28 Mar 2024

Community Treasure Hunt

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

Start Hunting!

Translated by