Skip to main content

LH Computer Vision and Imaging - Lab 1

info

The lab sheet and files can be downloaded here

Introduction 介紹

In this lab exercise, you will look at applying edge detectors to images and comparing two different methods. You will also learn how to write a function in MATLAB and evaluate the difference when using an approximation for calculation of a parameter. 在本實驗練習中,您將了解將邊緣檢測器應用於圖像並比較兩種不同的方法。您還將學習如何在 MATLAB 中編寫函數,並在使用近似值計算參數時評估差異。

At this stage, we will assume that you are able to use MATLAB, and understand its basic use. 在此階段,我們假設您能夠使用 MATLAB,並了解其基本用法。

You are asked to write a short (no more than 2 pages) report of your work, answering specific questions, and showing example images. This work is not assessed (it will not count towards your module mark) but you will get formative feedback. 你被要求寫一份簡短的(不超過 2 頁)工作報告,回答具體問題,並展示示例圖片。這項工作不會被評估(它不會計入你的模塊分數)但你會得到形成性的反饋。

Step

Step 1

  • Download the zip file and extract the .m files and the data files (.gif) for Lab 1 from CANVAS and save them in your working directory 下載 zip 文件並從 CANVAS 中提取 Lab 1 的 .m 文件和數據文件 (.gif),並將它們保存在您的工作目錄中

  • In MATLAB type

    shakey = read_image('','shakey.150.gif');

    This will load up the .gif file from the current directory into the variable shakey. To see a help command for the function type 這將從當前目錄加載 .gif 文件到變量 shakey 中。要查看函數的幫助命令,請鍵入

    help read_image

  • You can display the image by typing 你可以通過鍵入來顯示圖像

    show_image(shakey)

    This only works for grey images. 這只適用於灰度圖像。

  • Now you can load up different sets of masks. To load up the sobel masks type 加載不同的蒙版集。要加載 sobel 蒙版,請鍵入

    load sobel

    If you now type 如果你現在輸入

    who

    you will get a list of variable names. You can see the sobel horizontal mask by typing 你會得到一個變量名列表。您可以通過鍵入來查看 sobel 水平掩碼

    sobelX

    and the array will print on screen. 並且數組將在屏幕上打印。

Step 2

  • You can convolve the image with the mask by typing 您可以通過鍵入將圖像與蒙版進行卷積

    shakey_sobelX = conv2(shakey,sobelX,'valid');

    You can display the new image. 你可以顯示新圖像。

  • Apply both the sobelX and sobelY operators to the image. You can try to threshold the resulting images using 將 sobelX 和 sobelY 運算符應用於圖像。您可以嘗試使用閾值生成的圖像

    show_image(abs(shakey_sobelX)>5)

    or whatever number you wish to use as the threshold. 或者您希望用作閾值的任何數字。

Task

Task 1

  • Combine the two resulting arrays using Pythagoras theorem. To do this you will need to write your own m-file. Call it magnitude.m. You need to make it into a MATLAB function, such that: 使用畢達哥拉斯定理組合兩個結果數組。為此,您需要編寫自己的 m 文件。稱它為 magnitude.m。你需要把它變成一個 MATLAB 函數,這樣:

    m = magnitude(x,y)

    Now display the resulting image using 現在使用顯示生成的圖像

    show_image(m)

    You can also display this edge image after thresholding it, using 你也可以在閾值之後顯示這個邊緣圖像,使用

    show_image(m>40)

    create several of these with different thresholds. 創建具有不同閾值的幾個這些。

    QUESTION 1: What do you notice regarding the effect of changing the threshold? 問題 1:關於更改閾值的影響,您注意到什麼?

Task 2

  • Now load up the Roberts operator. Repeat your previous exercise, 現在加載 Roberts 運算符。重複你之前的練習,

    QUESTION 2: What do you notice regarding the difference between Sobel and Roberts? 問題 2:關於 Sobel 和 Roberts 之間的區別,您注意到什麼?

Task 3

  • You now need to write a new function, that rather than taking the magnitude of the gradients, it takes the absolute value of Gx+Gy|G_x|+|G_y|. This is an approximation to the magnitude. 您現在需要編寫一個新函數,它不是獲取梯度的大小,而是獲取 Gx+Gy|G_x|+|G_y| 的絕對值。這是幅度的近似值。

    QUESTION 3: What do you notice regarding the difference between magnitude and absolute when calculating the edge? 問題 3:當計算邊緣時,關於幅度和絕對值之間的區別,您注意到什麼?