What to do |
How to do it |
Comments |
Enter image data into the variable "a" |
a = [1 3 5 2; 21 7 9 12;...
9 8 40 6] |
The ellipsis "..." is how you continue a command on a new
line of input |
Display the data values you just entered (as a matrix) |
a |
|
Visualize the matrix as an image |
image(a) |
|
Add a colorbar |
colorbar |
|
Explain what happens when you do this -> |
colormap(gray) |
|
Try this -> |
figure |
|
Now try this -> |
imagesc(a); colorbar
colormap(gray) |
Note that you can combine multiple commands on a single line |
Talk it over: Can you explain the difference between
image and imagesc? |
|
|
Display the pixel value at row 1, second pixel from the left |
a(1,2) |
|
Display all the pixel values in row 1 |
a(1,:) |
|
Extract the second row (a vector) and place it in a new
variable |
r = a(2,:) |
|
Plot the row vector and add axis labels and a title |
See "help" for these commands:plot
xlabel, ylabel, title |
|
Extract the third column vector from the image "a", assign
it to the variable "p", and plot the column vector in a new figure window |
Try to do this yourself based on what you have learned so
far |
|
Extract a subimage from "a" |
b = a(1:2,3:4) |
Make sure you understand what is happening here! |
Set the third pixel in the third row of image "a" to zero |
a(3,3) = 0 |
|
Set the first row of pixels in the image "a" to 30 |
Try to do this yourself |
|
What to do |
How to do it |
Comments |
Load a PNG (pronounced "ping") image |
[x map] = imread('boats.png') |
PNG = Portable Network Graphics format |
If the image data numerical values are still spewing out,
type Ctrl-C to interrupt. Now, repeat the previous command and add a
semicolon to suppress the output |
Use the up arrow to retrieve the previous command, attach
the semicolon, then resubmit the command |
Note that the arrow keys allow you to scroll through
previous commands to save typing effort. You can also type one or more
letters first, then the arrow keys retrieve only the commands that begin
with those letters. |
Determine the size of the variables returned by "imread" |
whos x
whos map |
"who" displays the variable names. "whos" displays the
names with their sizes. |
Display the image data as a grayscale image. Add a colorbar,
too. |
You know how to do this now (see above, if needed) |
|
Create a new figure window, and repeat using imagesc |
|
|
Create yet another figure window, and try these new image
display commands |
imshow(x,map); colorbar
imshow(x,[]); colorbar |
The "imshow" method is preferred since it deals more
effectively with both grayscale and color image files. |
Try some of the built-in tools in the figure window to zoom
in and out, and to add text and axis labels |
|
|
Make sure that you have the
profiles.m file in your MATLAB search
path. |
which profiles |
If "profiles' is not currently in your search path, then do
a shift+click on the link at left, and save it to a directory that is in
your search path. |
Experiment with the "profiles" function. Talk it over:
Can you explain what you see? |
Use "helpwin profiles" to learn how to use it |
|
While still using "profiles", find the coordinates (row
number and pixel number) of the very top of the lighthouse. |
|
|
Extract the row vector and column vector (also called row
and column "slices") that intersect the coordinates that you found in the
previous step. |
|
|
Make a plot of the row vector. Scale the vertical axis to
the range 0 to 255. Repeat for the column vector. |
Look up the "axis" command |
You may find it necessary to enter "figure(n)" to set the
current figure before you enter the "axis" command. You can find the figure
number in the title strip at the top of the figure window. Side note: If
you ever need to delete a figure, just do "delete(n)" |
Deliverable: Make hardcopy of your plots |
Either type "print" in the MATLAB command window, or select
"File | Print" in the figure window. |
|
Find and record the minimum and maximum brightness values in
the image |
bmin = min(x(:))
bmax = max(x(:)) |
"x(:)" converts the 2-D matrix into a 1-D vector. You
typically have to do this before using other functions that are designed to
work with matrices. For example, can you explain what happens when you
enter "min(x)"? |
Find the coordinates of the brightest pixel(s): |
[r,p] = find(x==bmax) |
Make sure you know what is happening here... maybe look at
the help page for "find" |
Extract a 128x128 subimage centered about the first
coordinate your found in the last step. |
You can do it! |
|
Deliverable: Display your subimage, put a title on it, and print it |
|
|
When you are finished, close down MATLAB |
exit |
Please shut down MATLAB when you finished to free up the
license for another user. Thanks! |