Graphics Programs Reference
In-Depth Information
We define a red disc by setting all the pixels that are within a circle to
one; all the other pixels are zero. The circle is defined by the equation:
x 0 ) 2 +( y
y 0 ) 2 = R 2 ,
( x
where ( x 0 ,y 0 ) is the centre of the circle, and R is the radius. We set the
centre of the red disc to (
0 . 4 ,
0 . 4) and the radius to 1.0:
R = 1.0;
r = zeros(size(x));
rind = find((x + 0.4).^2 + (y + 0.4).^2 < R^2);
r(rind) = 1;
The green and blue discs are defined in the same way, just shifting the
centre of the circle in each case:
g = zeros(size(x));
gind = find((x - 0.4).^2 + (y + 0.4).^2 < R^2);
g(gind) = 1;
b = zeros(size(x));
bind = find(x.^2 + (y - 0.4).^2 < R^2);
b(bind) = 1;
Now we concatenate the matrices r , g , and b into one 200
×
200
×
3
matrix called rgb :
rgb = cat(3,r,g,b);
We use rgb as an input to imagesc , which interprets the intensities in
the range 0.0 to 1.0:
imagesc(rgb)
axis equal off
On your screen you can see these as overlapped discs of coloured light.
Exercise 13 Redefine the red, green, and blue discs so that
instead of a circular disc of light at uniform maximum intensity,
the intensity increases within each circle from zero at the centre
to one at the edge; outside the circles the intensity should be zero.
Create the new overlapped image. (Answer on page 189.)
Search WWH ::




Custom Search