Question

I would like to generate a matrix of random color blocks -- 10 by 10 pixel blocks of random colors -- such as:

http://i.stack.imgur.com/Jlc8L.png

So far, I have generated random numbers and enlarged the matrix with kron:

http://i.stack.imgur.com/eBU0T.png

using:

I = kron(randn([10 10]), ones(10));
imshow(I);

I would like to add random colors to this, but:

I = kron(randn([10 10 3]), ones(10));

reports:

error: invalid conversion of NDArray to Matrix

How can I generate a matrix of random color blocks?

This is for use with Psychtoolbox-3 (DrawTexture does not seem able to scale up a 10x10 random color matrix to 100x100 without interpolation).

Was it helpful?

Solution

You might as well generate the matrix directly:

    R = rand(10,10,3);
    figure;imshow(R);

In order to create a block matrix, use imresize:

    Rb = imresize(R,10,'nearest');

OTHER TIPS

This is the way I usually do something similar, in case it helps:

R = rand(10,10);
subplot(1,1,1)
imshow(mat2gray(R(:,:,1)));
colormap jet

Where the colormap can be changed to any of Matlab's presets, or your own, to reflect the value in the matrix.

The proper solution is to switch the interpolation algorithm for the particular texture.

Behind the scenes Psychtoolbox uses OpenGL, which allows you to fiddle with raw OpenGL commands between MakeTexture and DrawTexture.

roughly, from memory. Fill in the "blanks"

Screen('MakeTexture')
Screen('GetOpenGLTexture')
glTexParameterfv(target,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
Screen('DrawTexture')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top