필터 지우기
필터 지우기

Understanding montage() command settings

조회 수: 17 (최근 30일)
Matt J
Matt J 2013년 9월 26일
편집: Jin Ren 2024년 3월 28일
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일
편집: Jin Ren 2024년 3월 28일
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 CenterFile Exchange에서 Red에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by