image/imagesc scaling colors to a specific range
129 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 20 de Dic. de 2012
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.
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!