Using CreateProceduralSineGrating function to create colored gratings

Hello, 


I am using the CreateProceduralSineGrating to create color modulated gratings. My goal is to create a grating which peaks at green cyan (RBG [0 0.8 0.5]) and troughs at middle cyan [0 0.5 0.5]. However, I have been unable to create what I want so far. The code I have used to create my gratings is below.  


% To create the grating

backgroundColorOffsetCy = [0 0.5 0.5 1]; %RGBA offset color

[gratingidG, gratingrectG] = CreateProceduralSineGrating(windowPtr, screenXpixels, screenXpixels, backgroundColorOffsetCy, [], 1);


% To display the grating

modulateCol = [0 0.8 0.5];

 propertiesMat = [0, 0.005, 1, 0];

Screen('DrawTexture', windowPtr, gratingidG, [], dstRect , Angle, [] , [], [modulateCol], [], [], propertiesMat' );


This code creates a grating similar to what can be seen in the attachment. It looks to peak at the right color however it fades into black instead of middle cyan. Any help in changing the creation commands to achieve what I want would be greatly appreciated. 


Thanks,


Michael 

Hi,

Thank you for sharing codes here. This codes are not running for me, There is a problem  here:

 Undefined function or variable 'windowPtr'.

Error in Gratings12 (line 3)
[gratingidG, gratingrectG] = CreateProceduralSineGrating(windowPtr, screenXpixels, screenXpixels,
backgroundColorOffsetCy, [], 1);

Would you please suggest me what to do nest?

Thank you,

Best,

Debarshi
Hello Debarshi,

I am very sorry about getting back to you so long after your initial question. So I was never able to specify the colors for a sine grating properly with that function. I ended up writing my own code to create an RGB matrix with exactly the color content I wanted to present. 

That might be your best option depending on how exact you need to be your presentation. 

Best,

Michael

HI Michael,

Can you explain how you created the RGB matrix? I’m trying to make colored gabors with equiluminant colors and this seemed relevant. Thanks!

Ming-Ray

Since this last post, PTB now has a CreateProceduralColorGrating.m function added, you can see it working in ProceduralColorGratingDemo.m

This uses the GLSL mix function to blend between two colours against a background colour. If you want to generate a gabor you could use this with an overlaid gaussian mask, or modify the GLSL code itself to spatially modulate the grating with a gaussian (look at the procedural gabor code for guidance).

Now, how to choose equiluminant colors is another issue, depending on whether you require physical or perceptual equilumance :stuck_out_tongue_winking_eye: