ECE 280/Imaging Labs
This page serves as a supplement to the Digital Image Processing Labs for ECE 280. It has been updated for the Fall 2020 semester, including providing instructions for working on labs remotely.
Contents
Running MATLAB
MATLAB can be run remotely on the Duke Linux system, but it will generally be more convenient for you to install it on your own computer.
Installing MATLAB
MATLAB is free for Duke students. Follow the instructions in the Installation section of the EGRWiki page on MATLAB. Be sure to select the appropriate PRODUCTS when asked.
Using MATLAB Remotely
If you do not want to install MATLAB, you can use Duke's installation. You will first need to connect to the Duke Linux system using either MobaXterm (Windows) or XQuartz (macOS), making sure you correctly issues the ssh command to get graphics. Then simply type matlab &
to start MATLAB. More information is available at the page How To Get Work Done
Image Processing Toolbox
The following will take you through several examples from the MATLAB Image Processing Toolbox. Along the way you will learn about different types if images, how they are stored and saved, and what you can do with them in MATLAB. Open the Add-On Explorer, search for Image Processing, and complete the following:
Overview Tab
Read the overview. Several of the terms may be meaningless to you at the moment.
Learn More Button
On the right of the Explorer screen, there is a Learn More box; click that to go to the Image Processing Toolbox web page. Watch the video (~2 minutes). Once that is done, you can close that page and go back to the Add=On Explorer.
Open Documentation Button
Also on the right of the Explorer screen, there is an Open Documentation button; click that to open the toolbox documentation. You will be going through several sections of this documentation.
Get Started with the Image Processing Toolbox
In the Tutorials section of this page, go through Basic Image Import, Processing, and Export. By the end of it, you will have used several basic commands: imread, imshow, whos, figure, imhist, histeq, imwrite, and iminfo. You will see more details about these as you go along. Once done, go back to the Get Started page.
Next, in the About Image Processing section, go through Image Types in the Toolbox. There are 7 different types of images listed but we will only concern ourselves with the first four: binary, indexed, grayscale, and truecolor. Read through the descriptions of each along with the following accompaniment:
- Binary images only have two values (0/1, False/True, Off/On). They store the least amount of information but can certainly still be useful.
- Indexed images are basically electronic "paint by numbers." Each pixel is given an integer value, and that integer value refers to a row in a lookup table that contains the amount of red, green, and blue with which to color that pixel. In the example, anything mapped to a 4 would be pure blue since the fourth row of the color map yields [0, 0, 1].
- Grayscale images will have a range of brightness values - typically either a float in the range of 0 to 1 or an 8-bit unsigned integer in the range of 0 to 255, though 16-bit signed or unsigned integers can also be used.
- Truecolor images will have three value for each pixel representing the amount for red, green, and blue. These ranges will also generally either be a float between 0 and 1 or an 8-bit unsigned integer between 0 and 255. These images therefore take up 3 times the amount of memory as a similarly-sized grayscale image and 24 times as much memory as a similarly-sized binary image! 16-bit unsigned integers can also be used.
You can certainly read about the other image types but we will not be using them in this lab.
Import, Export, and Conversion
In this section, go to the Read and Write Image Data from Files page. Under Functions, click the "Generic File Import and Export" section to expand the dropbox. We will be looking at each of the three functions:
imread
: Note that the example file is built in to the Image Processing Toolbox; for instance, you can follow along by typingin the command window and then typing any other commands in the documentation in the command window. You can also follow along by opening the live script and running it (F5). What follows will be some extra information or explanation of the examples.A = imread('ngc6543a.jpg');
- Read and Display Image: pretty straightforward - reads a built-in image and then displays it. If you type
whos A
you will see that the information is stored in three layers - that is because it is a truecolor image. Try the codeimshow(A(:,:,1))
. That will display only the red layer as a grayscale image - notice that this image is brighter where there is more red. See if you can show just the green layer as a grayscale - there should be some bright parts on the far left and right of the nebula since that is where the green is. Note that for all three layers the text will show up as white. - Convert Indexed Image to RGB: this will take an image that has a set of indices and a colormap and convert it into a three-layer array. X represent the "paint by numbers" sheet, cmap is the dictionary to see what color each number is, and RGB has three layers where each row and column now has three layers with values taken from the cmap based on the X value that was at that location before. For example, X(1,1) is color 105, and cmap(106,:) (X is 0-indexed but cmap is 1-indexed) gives (0.82, 0.56, 0.49) which is kind of a pink clay color. RGB(1,1,:) will show those same three values stored in three different layers of a single matrix. Note that the memory required to store the RGB matrix is much larger than the total memory required for X and cmap together!
- Read and Display Image: pretty straightforward - reads a built-in image and then displays it. If you type