Pergunta

Why does the following code extract components similar to the red channel of an image?

diff_im = imsubtract(data(:,:,1), rgb2gray(data));
Foi útil?

Solução

It only looks like the red channel. Your code is extracting the luminance (rgb2gray(data)) from the red channel (data(:,:,1)), which would give a kind of normalized red channel except that negative values are truncated to zero.

If data is an unsigned integer (probably uint8), the subtraction cannot give negative values, so any pixel without a prominent red component will be set to zero. You can see a map of these pixels by subtracting in a signed data type and comparing the result:

redMap = diff_im > (double(data(:,:,1))-double(rgb2gray(data)))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top