Random color matrix in matlab

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).

Answers


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');

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')

Need Your Help

What is the best way to return an error from a function when I'm already returning a value?

c return

I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid number. In the past I retur...

Live streaming from iOS to Wowza and viceversa

ios objective-c streaming live wowza

I need to know something more about the integration of Wowza with iOS. I need to publish the live camera streaming to Wowza from the iPhone and also to see live streaming from the server. There are