Lab 4: Matrices and Images

Part 1: Making synthetic images

MATLAB allows the creation of synthetic images.

Let's start with a 100x100 matrix of zeros (black).

img = zeros(100,100);

Then we'll add a white (1.0), 20x20, square in the upper left corner:

img(1:20,1:20) = 1.0;

Then we'll add a grey (0.50), 30x60, rectangle, as show in the picture to the right:


Now, let's take a little clip of our image, as shown by the red square below:


Now, let's make a new picture, using the clip from the old picture.

Let's start with a white background:

newpic = ones(100,100);

And add in the clip in two places:

to produce this picture:


Inverting greyscale images

Let's revisit the little clip shown below:

clip = img(11:30,11:30);

How can we create the clip's cousin, flip (shown below) in MATLAB?

hmmm, what is the relationship between clip and flip?

And how about clip's other cousin, upsidedown_clip, how can we make the picture below?