image processing

I need an explanation for this MathLab question to help me study.

  1. First thing we’re going to do is learn how to create a sample image that will be useful for this lab. We will do this by using the Matlab command ‘checkerboard’.
  2. To give you an idea on how this command works, from the matlab command prompt, type the following:
    1. imshow(checkerboard(20));
  3. It should create the image shown below: (see fig1.png)
  4. The 20 in the command is the number of pixels that each box on the checkerboard will represent.
  5. Let’s create an image from this matrix that we can use later. In order to do that, we need to use the ‘imwrite’ command.
    1. imwrite(checkerboard(20), ‘checkerboard.jpg’, ‘JPEG’);
  6. To verify the above worked correctly, let’s read in the newly made image and display it:
    1. myImage = imread(‘checkerboard.jpg’);
    2. imshow(myImage);
  7. Now that we have a nice image to use for our edge detection algorithm, let’s begin to implement it. First thing we want to do is create our x and y gradient filters:
    1. Sx = [1 0 -1; 2 0 -2; 1 0 -1];
    2. Sy = [1 2 1; 0 0 0; -1 -2 -1];
  8. Convolve each of the above filters with the checkerboard image. Before we are able to use the convolve function we must convert our image into a double. We do that by using the ‘double’ command and passing it image variable name, in this case ‘myImage’.

sobelXImage = conv2(double(myImage), Sx, ‘same’);

sobelYImage = conv2(double(myImage), Sy, ‘same’);

  1. Let’s go ahead and take a peek at what our images currently look like:

figure(‘Name’, ‘X gradient’);


figure(‘Name’, ‘Y gradient’);


  1. Do the gradient images look like you expect them too? Why or why not?
  2. What is missing from the above question and how would you fix it?
  3. Now that we understand what the gradients are doing and are able to display them properly, let’s continue on with our edge detection. We now need to square each of the X and Y portions, and then take the square root of them to determine the magnitude of our gradients.

E(u,v) = sqrt( (Dx(u,v))2 + (Dy(u,v))2 )

  1. Enter the appropriate matlab command for the above formula and display the image. You should see something like fig.png
  2. Each of the edges are shown in white.

Part B

  1. Download a sample image from the net. Repeat the above steps and display the original image, the X gradient, and the Y gradient on one form/figure (Note: Don’t forget to convert it to black and white first) .
  2. After we sum the squares and take the square root we have the magnitude of our edge strength. We may not want to look at every single edge detected. We can limit which edges we want to see by applying a threshold. We can do this by using the following matlab commands:

threshold = 50;

edgeDetectedImage = (uint8(edgeDetectedImage) > threshold) * 255;

  1. Create 4 additional figures each with their own respective image on it (using threshold {50, 100, 150, 200} ). Make sure the titles of the figures reflect their contents.
  2. Turn in the final matlab script that you used to accomplish part B. It should display 5 figures

Get 20% discount on your first order with us. Use code: GET20