image/imagesc scaling colors to a specific range
조회 수: 133 (최근 30일)
이전 댓글 표시
Hi folks,
Im hoping some of you image processing gurus know how to do this with little effort.
I have 2 matrices with similar, but not equivalent, data ranges. Id like to visualize them independently using image/imagesc but use a common color scale so that "red" can be compared to "red". If I use imagesc, each visual uses an independent scale based on the respective matrices' data range.
For example, c1 ranges from 0 to 2:
c1 = 2*rand(5,5);
and c2 ranges from 1 to 3:
c2 = 2*rand(5,5) + 1;
I'd like to graph each independently in different figures but use a common color scale that ranges from 0 to 3.
Thanks!
댓글 수: 0
채택된 답변
추가 답변 (1개)
Walter Roberson
2012년 12월 20일
colormap(jet(128)); %set colormap choice and colormap size as appropriate, not more than 256
minV = min(min(c1(:)), min(c2(:)));
maxV = max(max(c1(:)), max(c2(:)));
rangeV = maxV - minV;
thismap = colormap();
maxcol = size(thismap, 1) - 1;;
c1s = uint8(floor((c1 - minV) ./ rangeV .* maxcol));
c2s = uint8(floor((c2 - minV) ./ rangeV .* maxcol));
f1 = figure();
ax1 = axes('Parent', f1);
image(c1s, 'Parent', ax1);
colormap(f1, thismap);
f2 = figure();
ax2 = axes('Parent', f2);
image(c2s, 'Parent', ax2);
colormap(f2, thismap);
Setting the colormap before creating a figure is not strictly necessary; it just makes the code easier to follow. The number of entries in the colormap needs to be known when c1s and c2s are being calculated, but the colormap content itself is not needed at that point. And the scaling can be postponed until after the first figure is created. Just makes it a bit harder to read the code.
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!