Index and RGB problems

조회 수: 4 (최근 30일)
Maine MacConville
Maine MacConville 2016년 3월 15일
답변: Amal George M 2019년 12월 30일
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;
subplot(1,2,1);
imagesc(A);
subplot(1,2,2);
imagesc(fixed);
---
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?

답변 (1개)

Amal George M
Amal George M 2019년 12월 30일
'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:
imagesc(fixed,[4,6]);

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by