Index and RGB problems

1 view (last 30 days)
Maine MacConville
Maine MacConville on 15 Mar 2016
Answered: Amal George M on 30 Dec 2019
I'm writing a script that takes a 2D matrix, finds the value of the centre element, and changes the other elements to this value. This is a test as I want to try this on images. I have:
A = [6,6,6,6,6,6; 6,5,5,5,5,6; 6,5,4,4,5,6; 6,5,4,4,5,6; 6,5,5,5,5,6; 6,6,6,6,6,6];
[x,y] = size(A);
x = x/2;
y = y/2;
cent = A(x,y);
flat = A./cent;
rec = 1./flat;
fixed = rec.*A;
When I run this, I get the right matrix (ie, a 6x6 matrix with all entries = 4). But when I plot the images, I'm getting this
On the left, the indexes are 6, 5, and 4, from out to in. On the right, the index is 4, but it has the same [RGB] as the pixels on the left with index = 5.
How can I fix this so the image on the right is navy?

Answers (1)

Amal George M
Amal George M on 30 Dec 2019
'imagesc' tries to map the 'C' matrix values to the colormap. If no scale is specified the minimum value will be mapped to the bluish end and the maximum value to the yellowish end. But, if the input has only one distinct input, the value will be something in the middle (greenish). This is the case here.
To map with a known color limit we can specify the limits:

Community Treasure Hunt

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

Start Hunting!