12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We define a red disc by setting all the pixels that are within a circle toone; all the other pixels are zero. The circle is defined by the equation:(x − x 0 ) 2 +(y − y 0 ) 2 = R 2 ,where (x 0 ,y 0 ) is the centre <strong>of</strong> the circle, <strong>and</strong> R is the radius. We set thecentre <strong>of</strong> the red disc to (−0.4, −0.4) <strong>and</strong> 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 <strong>and</strong> blue discs are defined in the same way, just shifting thecentre <strong>of</strong> 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, <strong>and</strong> b into one 200 × 200 × 3matrix called rgb:rgb = cat(3,r,g,b);We use rgb as an input to imagesc, which interprets the intensities inthe range 0.0 to 1.0:imagesc(rgb)axis equal <strong>of</strong>fOn your screen you can see these as overlapped discs <strong>of</strong> coloured light.Exercise 13 Redefine the red, green, <strong>and</strong> blue discs so thatinstead <strong>of</strong> a circular disc <strong>of</strong> light at uniform maximum intensity,the intensity increases within each circle from zero at the centreto one at the edge; outside the circles the intensity should be zero.Create the new overlapped image. (Answer on page 189.)c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!