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:

>>imshow(img)

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

>>imshow(clip)

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:

>>imshow(newpic)

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?
robinson.jpg
in your
assign3_exercises
folder. Read this image into MATLAB like
this: nate = double(imread('robinson.jpg'))/255;
This reads in the JPG file (where the numbers range from 0255) and scales it into a matrix with double precision numbers ranging from 0.01.0. The double refers to the precision and not to the value. In other words, double does not mean that any numbers are being multipled by 2, but rather that the numbers are highly precise.
Peek in the workspace to see your (large) variable named nate.
Now let's use imtool
to figure out the coordinates to get a closeup
of his face.
imtool(nate);
imtool(nate)
brings up the window below (without the red dashed lines and yellow dots). As you move your cursor over the image, you can see the coordinate in the lower left corner of the Image Tool window. The coordinates of the box around Nate's face are labeled in the image below:
Now, using your matrix variable nate
, take a subset of
nate
using the coordinates above as a guideline. Think
carefully about which coordinates to use (remember that imtool
reverses x and y). Save his face in a variable called
face
and then show his face using imshow
.
Note that his face closeup will appear in grayscale (as opposed to
color). We'll talk about why this occurs later in the course, but
if you are curious, here is a brief explanation.