简体   繁体   English

显示图像中的红-绿和蓝-黄对立颜色通道

[英]Display Red-Green and Blue-Yellow opponent color channels from an image

I'm doing an image processing code to split opponent colors Red-Green and Blue-Yellow from an image based on R, G and B channels.我正在做一个图像处理代码,以从基于 R、G 和 B 通道的图像中拆分对手 colors红绿蓝黄 I'm doing this in Octave software.我在 Octave 软件中执行此操作。 Actually I'm based on the following articles related to visual attention modeling: Itti1998 , GaoVasconcelos2007 , Heinen2009 .其实我是基于以下与视觉注意力建模相关的文章: Itti1998GaoVasconcelos2007Heinen2009 This code explains how I'm extracting the channels:此代码解释了我如何提取通道:

clc
rgbNormImage = im2double(imread('sample.jpg'));
Rn = rgbNormImage(:, :, 1); %red normalized channel
Gn = rgbNormImage(:, :, 2); %green normalized channel
Bn = rgbNormImage(:, :, 3); %blue normalized channel

R = Rn - ( Gn + Bn )/2; %tuned Red
G = Gn - ( Rn + Bn )/2; %tuned Green
B = Bn - ( Rn + Gn )/2; %tuned Blue
Y = ( Rn + Gn )/2 - abs( Rn - Gn )/2 - Bn; %Tuned Yellow

RG = R - G; %red-green opponent channel
BY = B - Y; %blue-yellow opponent channel

I verified the code both in Matlab and Octave and it runs well.我验证了 Matlab 和 Octave 中的代码,它运行良好。 However, I still don't figure out how to display the RG and BY channels in a figure or plot where I can see the extracted colors.但是,我仍然不知道如何在图形或 plot 中显示 RG 和 BY 通道,在那里我可以看到提取的 colors。 What I want to display and see in the output is something like this:我想在 output 中显示和看到的是这样的:

Figures h) and i) show the Red-Green and Blue-Yellow color opponency maps图 h) 和 i) 显示了红-绿和蓝-黄颜色对立图


Previous image was taken from this article: CORTICAL MECHANISMS OF COLOUR VISION上一张图片取自这篇文章:彩色视觉的皮质机制

My plot looks like this:我的 plot 看起来像这样:

My plot of the opponent channels RG and BY我的对手频道 RG 和 BY 的 plot

I appreciate a lot if someone knows how to display this in the way I'm trying to do it.如果有人知道如何以我尝试的方式显示它,我将不胜感激。 Thanks!谢谢!

I'm not 100% sure about my interpretation below, so do take it with a grain of salt.我不是 100% 确定我在下面的解释,所以一定要持保留态度。

My understanding is that you are supposed to use the obtained R, G, B, Y channels to define a 3D coordinate system, such that the first dimension differentiates along a black-white axis, the second differentiates along a red-green axis, and the third along a blue-yellow axis.我的理解是,您应该使用获得的 R, G, B, Y 通道来定义 3D 坐标系,使得第一个维度沿黑白轴微分,第二个维度沿红绿轴微分,以及第三个沿蓝黄色轴。 I haven't read the 4 papers you cited above, but I'll assume your derivation of RGBY is correct.我还没有阅读您上面引用的 4 篇论文,但我假设您对 RGBY 的推导是正确的。

In the code below, I have assumed that the black-white dimension is R+G, which is what I understood from the explanatory image you posted, but even if I got that wrong, it could probably be replaced by any other grayscale image representing 'luminance' (eg using rgb2gray ).在下面的代码中,我假设黑白维度是 R+G,这是我从您发布的解释性图像中理解的,但即使我弄错了,它也可能被任何其他灰度图像所取代“亮度”(例如使用rgb2gray )。

Then, the other two dimensions are specified by RG, and BY in your code.然后,其他两个维度由代码中的 RG 和 BY 指定。 My understanding is that in the RG axis, lower values correspond to 'red colours', and higher values correspond to 'green' colours.我的理解是,在 RG 轴上,较低的值对应于“红色”,较高的值对应于“绿色”。 Similarly, in the BY axis, my understanding is that lower values correspond to 'blue colours', and higher values correspond to 'yellow colours'.同样,在 BY 轴上,我的理解是较低的值对应于“蓝色”,较高的值对应于“黄色”。

Therefore, one can visualise the RG layer as a normal truecolour (ie rgb) image, where the Red, Green, and Blue channels are set to RG, 1-RG, and 0 respectively (for an RG that is normalised between 0 and 1), such that when the red channel increases in the truecolor image, the green channel decreases, and vice versa.因此,可以将 RG 层可视化为正常的真彩色(即 rgb)图像,其中红色、绿色和蓝色通道分别设置为 RG、1-RG 和 0(对于在 0 和 1 之间归一化的 RG ),这样当真彩色图像中红色通道增加时,绿色通道减少,反之亦然。

Similarly, since 'yellow' is composed of equal values of red and green in a truecolor image, one can visualise the BY layer as the rgb image 1-BY, 1-BY, BY (again for a suitably normalised BY), such that the more 'blue' a pixel is assigned, the less 'yellow' it has, and vice versa.类似地,由于“黄色”由真彩色图像中相等的红色和绿色值组成,因此可以将 BY 层可视化为 rgb 图像 1-BY、1-BY、BY(同样是适当归一化的 BY),这样一个像素被分配的“蓝色”越多,它的“黄色”就越少,反之亦然。

Here I normalise arbitrarily and liberally throughout the code, even though the exact normalisation that takes place in the brain is unlikely to be the same.在这里,我在整个代码中任意和自由地进行规范化,即使在大脑中发生的确切规范化不太可能相同。 But it's good enough for visualisation purposes, and I couldn't simply use the unnormalized values otherwise we'd be trying to plot values that can go into negative ranges.但这对于可视化目的来说已经足够好了,我不能简单地使用未标准化的值,否则我们会尝试使用 plot 值,这些值可以 go 进入负范围。 So, while we cannot compare between the different layers in terms of absolute intensities, the visualisation is good enough to get an idea of where a layer shows higher or lower values for the dimension that it represents, allowing a comparison to be made with respect to the original image.因此,虽然我们无法在绝对强度方面比较不同层之间的差异,但可视化足以了解层在其所代表的维度上显示更高或更低值的位置,从而可以就以下方面进行比较原始图像。

Here is the code:这是代码:

  clear all; clc;
  pkg load image;

% Get image and RGB channels
  rgbNormImage = im2double(imread('sample.png'));
  Rn = rgbNormImage(:, :, 1); %red   normalized channel
  Gn = rgbNormImage(:, :, 2); %green normalized channel
  Bn = rgbNormImage(:, :, 3); %blue  normalized channel

% Define Red, Green, Blue, and Yellow 'heatmaps'
  Hot_red    = hot(256);
  Hot_green  = hot(256)( :, [3, 1, 2] );
  Hot_blue   = hot(256)( :, [3, 2, 1] );
  Hot_yellow = hot(256)( :, [1, 1, 2] ); 

% Plot Original RGB Channels in their respective 'heatmap'
  figure(1, 'name', 'Original (normalized) RGB channels');
  axes( 'position', [ 0.26, 0.51, 0.48, 0.48 ] ); imagesc( rgbNormImage )            ; axis image off;
  axes( 'position', [ 0.01, 0.01, 0.31, 0.48 ] ); subimage( im2uint8(Rn), Hot_red )  ; axis image off;
  axes( 'position', [ 0.34, 0.01, 0.31, 0.48 ] ); subimage( im2uint8(Gn), Hot_green ); axis image off;
  axes( 'position', [ 0.67, 0.01, 0.31, 0.48 ] ); subimage( im2uint8(Bn), Hot_blue ) ; axis image off;

% Transform from RGB to RGBY
  R = Rn - ( Gn + Bn ) / 2;          %tuned Red
  G = Gn - ( Rn + Bn ) / 2;          %tuned Green
  B = Bn - ( Rn + Gn ) / 2;          %tuned Blue
  Y = (Rn+Gn)/2 - abs(Rn-Gn)/2 - Bn; %Tuned Yellow

% Plot 'tuned' RGBY channels in their respective 'heatmap'
  figure(2, 'name', 'Tuned RGBY channels');
  axes( 'position', [ 0.01, 0.51, 0.48, 0.48 ] ); subimage( im2uint8(mat2gray(R)), Hot_red    ); axis image off;
  axes( 'position', [ 0.51, 0.51, 0.48, 0.48 ] ); subimage( im2uint8(mat2gray(G)), Hot_green  ); axis image off;
  axes( 'position', [ 0.01, 0.01, 0.48, 0.48 ] ); subimage( im2uint8(mat2gray(B)), Hot_blue   ); axis image off;
  axes( 'position', [ 0.51, 0.01, 0.48, 0.48 ] ); subimage( im2uint8(mat2gray(Y)), Hot_yellow ); axis image off;

% Transform RGBY to Black-White, Red-Green, Blue-Yellow channels
  BW = R + G; % black-white opponent channel
  RG = R - G; % red-green   opponent channel
  BY = B - Y; % blue-yellow opponent channel

% Normalise and convert to RGB images for visualisation purposes
  BW = mat2gray( BW );
  RG = mat2gray( RG );
  BY = mat2gray( BY );

  Z = zeros( size( BW ) );
  BW_asRGB = cat( 3, BW    , BW    , BW );
  RG_asRGB = cat( 3, RG    , 1 - RG, Z  );
  BY_asRGB = cat( 3, 1 - BY, 1 - BY, BY );

% Plot BW, RG, BY channels
  figure(3, 'name', 'Black-White, Red-Green, and Blue-Yellow channels')
  axes( 'position', [ 0.26, 0.51, 0.48, 0.48 ] ); imagesc( rgbNormImage ); axis image off;
  axes( 'position', [ 0.01, 0.01, 0.31, 0.48 ] ); imagesc( mat2gray(BW_asRGB)  ); axis image off
  axes( 'position', [ 0.34, 0.01, 0.31, 0.48 ] ); imagesc( mat2gray(RG_asRGB) ); axis image off
  axes( 'position', [ 0.67, 0.01, 0.31, 0.48 ] ); imagesc( mat2gray(BY_asRGB) ); axis image off


And here are the resulting images.这是生成的图像。
(Note: The heatmaps in Fig 1, and Fig 2, all show lower values as darker pixels, and higher values as brighter pixels, but the colours used are otherwise irrelevant. It's just used for nicer color-coding, but they could have just as well been grayscale images). (注意:图 1 和图 2 中的热图都将较低的值显示为较暗的像素,将较高的值显示为较亮的像素,但使用的颜色在其他方面无关紧要。它只是用于更好的颜色编码,但它们可能只是以及灰度图像)。


Fig. 1 - Original image and respective RGB channels (colorized using red, green, and blue heatmaps respectively)图 1 - 原始图像和各自的 RGB 通道(分别使用红色、绿色和蓝色热图着色)


Fig. 2 - 'Tuned' RGBY channels (colorised using red, green, blue, and yello heatmaps respectively)图 2 - 'Tuned' RGBY 通道(分别使用红色、绿色、蓝色和黄色热图着色)


Black-white, Red-green, and Blue-yellow layers黑白色、红绿色和蓝黄色层


The outputs seem to make sense visually.输出在视觉上似乎是有意义的。 :) :)

Eg, if we focus on the plate, which is a dark greenish-blue, in the normal RGB case in Fig 1, you can see that the red channel has very low values there, whereas the green has a bit more brightness, and then the blue has even more than the green, ie it has the largest contribution compared to the other two (but note that neither the green nor the blue are that bright themselves, since the plate isn't very high in intensity overall).例如,如果我们关注图 1 中正常 RGB 情况下深绿蓝色的盘子,您可以看到红色通道的值非常低,而绿色通道的亮度更高,然后蓝色甚至比绿色还要多,即与其他两个相比,它的贡献最大(但请注意,绿色和蓝色本身都不是那么亮,因为该板的整体强度不是很高)。

In Fig2 you can similarly see that the red and yellow channels do not contribute very much to the plate, (the blue seems to contribute a lot more than the green here, which again is what we might expect... but keep in mind that this large difference may also be due to the normalization applied, so a direct comparison between the layers may not be very appropriate here)在图 2 中,您同样可以看到红色和黄色通道对板块的贡献不大,(蓝色似乎比这里的绿色贡献更多,这也是我们所期望的......但请记住这种大的差异也可能是由于应用了归一化,所以在这里直接比较层之间可能不是很合适)

Finally, Fig 3 is our three dimensions of interest.最后,图 3 是我们感兴趣的三个维度。 The first dimension shows us that the plate has a low value in the black-white dimension (ie it is of lower luminance).第一个维度向我们展示了该版材在黑白维度上的值较低(即亮度较低)。 The red-green dimension shows us that the plate is more 'green' than it is 'red' in that dimension.红-绿维度向我们表明,在该维度上,盘子比“红色”更“绿色”。 And finally, the blue-yellow dimension shows us that the plate is more 'blue' than it is 'yellow'.最后,蓝黄色维度向我们展示了该板块比“黄色”更“蓝色”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么红色,绿色,蓝色图像通道是灰度级的(Matlab)? - Why Red, Green, Blue channels of image separetely are grayscaled (Matlab)? Matlab中RGB图像中红色,绿色,蓝色的比例 - Proportion of Red, Green, Blue in RGB image in Matlab 使用Python计算红色,绿色和蓝色通道的总和 - Compute the sum of the red, green and blue channels using Python 检测图像是否通常为红色,绿色,蓝色或黑色 - detect if an image is generally red, green, blue, or black 使用Matlab从红色,蓝色和绿色三个波段制作真实的彩色合成图像 - Make a true colour composite image from three bands Red, Blue and Green using Matlab 使用适用于Android的OpenCV分别显示红色蓝色和绿色值 - Display the Red Blue and Green values separately using OpenCV for Android application 如何使用flipdim翻转图像中的红色和绿色通道? - How do I use flipdim to flip the red and green channels in an image? 如何从像素更改红色/绿色/蓝色/ alpha值的值 - How to change value of red/green/blue/alpha values from pixels 当其中至少一个没有值时,使用php从图像中查找红色,绿色和蓝色数组的最大值 - Find maximum value of red, green and blue arrays from an image using php when at least one of them doesn't have values 将图像颜色空间从RGB转换为对手颜色 - Convert image color space from RGB to opponent color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM