为什么在 Psychtoolbox(带 alpha 通道)中显示灰度 .png 文件时,图像显示为鲜红色?

Why, when displaying a greyscale .png file in Psychtoolbox (with an alpha channel), is the image displaying in bright red?

我目前正在准备一些将在 Psychtoolbox 中显示的灰度 .png 图像。这些 .png 文件都有透明背景,所以我一直在将 alpha 层添加到文件矩阵中,如下所示:

% sets up for the alpha
Screen('BlendFunction', w, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');

[pngImage,~,alpha] = imread('image.png'); % read in the image
pngImage(:,:,4) = alpha; % add in the alpha channel
pngTexture = Screen('MakeTexture',w, pngImage); % create image texture

显示这些图片时,背景确实是透明的。但是,它们也显示为 bright red instead of greyscale (link to image). When I comment out the line of code that adds in the alpha channel, the background is no longer transparent, but it is in greyscale(link 图片)。

集合中的一些图像呈现得很好,没有问题。这些图像在 Photoshop 中进行了批处理。出现问题的图像似乎是在 GIMP 中手动处理过的图像。然而,整个图像集在 Psychopy 中呈现得很好。 (由于时间限制和需要一些特定于 MATLAB 的函数,无法在 Psychopy 中编写此项目。)

如果我不得不猜测,以我的极其有限的知识,我会说将第四个二维矩阵添加到图像矩阵中会引发颜色值相乘的论点.但是,我不知道如何。有人有什么想法吗?

因为你没有添加G和B通道,所以它们是零!

试试这个:

pngImage(:,:,2) = pngImage(:,:,1); 
pngImage(:,:,3) = pngImage(:,:,1); 
pngImage(:,:,4) = alpha; % add in the alpha channel