I am currently preparing some greyscale .png images that will be displayed in Psychtoolbox. These .png files all have transparent backgrounds, and so I've been adding in the alpha layer into the file matrix like so:
% 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
When displaying these images, the background is indeed transparent. However, they also present as 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 to image).
Some of the images in the set present just fine, with no problem. Those images were batch-processed in Photoshop. The images that present the issue appear to be images that were hand-processed in GIMP. However, the entire image set presents just fine in Psychopy. (Writing this project in Psychopy is not an option, due to time constraints and some MATLAB-specific functions required.)
If I had to guess, with my extremely limited knowledge, I'd say that adding the fourth 2D matrix into the image matrix is setting off the argument that multiplies colour values. However, I've no idea how. Anyone got any thoughts?