![]() ece480 | doering | ece labs | ece | rhit |
|
![]() | Learn how to start MATLAB |
![]() | Set up a "startup" file to simplify access to course resources |
![]() | Learn how to visualize matrices as images |
![]() | Practice with image measurement tools |
![]() | Learn how to make hardcopy of your results |
Before you leave today, submit hardcopy of your subimage and row/column plots. Please include names of all who worked with you, and include a campus mail address. A write-up is not necessary for this lab.
There are at least four ways to access MATLAB on at Rose-Hulman:
![]() | On your own network-connected computer
| ||||||||
![]() | On a network-connected computer
| ||||||||
![]() | On the SGI computers in the Imaging Systems Laboratory (these are presently at version 5.3, other techniques are version 6) | ||||||||
![]() | On your own stand-alone computer
|
A startup.m file is useful for automatically setting up the MATLAB search path, for changing the current working directory to something other than the default, and for any other activity you would like to perform each time MATLAB starts up. You can place any valid MATLAB code inside your startup.m file. Common activities include:
Append your own path to the system search path: path(path,’C:\mypath\matlab’);
Change working directory: cd C:\mydir
Display a message to confirm that startup.m file commands were processed (put a line such as "disp('it works!')" in your file)
A sample startup.m file is available. Please edit it to suit your needs.
Recommended methods for using a startup file:
![]() | With locally-installed MATLAB: Place startup.m file in the "work" subdirectory of the MATLAB installation directory | ||||||||
![]() | Via Terminal Server method:
| ||||||||
![]() | On Imaging Lab SGI computers:
|
![]() | Once you have started MATLAB, type "demo". |
![]() | Feel free to look around at will so that you can develop some idea of the total scope of MATLAB capabilities. |
![]() | Also look at the Image Processing Toolbox demos |
The following activities are designed to help you learn how to work with image data using a small data set. You can get help on all MATLAB functions and commands by typing "help" or "helpwin" followed by the function name. "help" displays results in the MATLAB command window, while "helpwin" displays the results in a new window.
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! |
Please submit the deliverables mentioned at the top of the page before you leave the lab.
|