Mount an RGB matrix that is equivalent to a Grayscale with an altered color

Asked

Viewed 434 times

1

I have a matrix in Matlab of one dimension or Grayscale, but I would like to create an equivalent in RGB in which all this black, i.e. all zero is a shade of green. And that all other colors white and gray be kept from the original matrix in the same color.

1 answer

1


Since you didn’t inform the original matrix, I’ll assume this:

% matriz original:
matrix_cinza = rand(64, 64);

And visualizing:

% imagem original
% Sendo: cat(3, VERMELHO, VERDE, AZUL)
% Mas, como é escala de cinza os três canais são iguais.
imagem_cinza = cat(3, matrix_cinza, matrix_cinza, matrix_cinza);

Imagem Orignal

To highlight the black elements you can create a matriz_destaca and change the value of those that are black to 1. In this case, the values below 0.1 were considered black, but you can change to the desired level in matrix_destaca < 0.1.

 matrix_destaca = matrix_cinza;
 matrix_destaca(matrix_destaca < 0.1) = 1;

Then, you can generate the highlighted image only the green layer image:

 imagem_destacada = cat(3, matrix_cinza, matrix_destaca, matrix_cinza);
 image(imagem_destacada);

Which results in:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.