Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with MATLAB coding pls part c especially Question 3 (45 marks) a) You can identify if an object is in the image by calculating

Help with MATLAB coding pls part c especially

image text in transcribedimage text in transcribedimage text in transcribed

Question 3 (45 marks) a) You can identify if an object is in the image by calculating the Sum Squared Differences (SSD) between the object and the image, and determining the location of the lowest value. Given an image (represented by an mxn matrix) and an object image T(represented by an m'n' matrix), the element in row u (u E [1, m-m' + 1]), column v(v [1, n - n + 1]) of SSD can be calculated as follows: min SSD(u, v) = (T(ij)-I(u + i - 1,v + i - 1)) where I(u: u + m' - 1,v: v + n' - 1)is the sub-image when the template is slid across the image pixel-by-pixel. For example, given a 3-bit 9x9 Image and 3x3 Object, the resulting SSD metric is as follows: Object: SSD: 162 Image: 121146771 63 2740315 15 06 2012 2 044326 6 5 5 266117263 5 5 5 5 3 42 42 536 254 422 0 0 2 7 7 5 515 |413|400|42|1 64 84 116 | 37 | 68 11692 116 93 43 101 133 71 85 93 1040 135 132 74 79 70 68 55 93 64 85 86 64 86 85 97 23 100 16 90 118 129 103 52 54 26 | 83 89 125 49 101 72 51 (7 SSD(1,3) is calculated by: (1 - 0)2 + (1 - 6)2 + (4 - 2)2 + (2 - 4)2 + - 3)2 + (4 - 2)2+ (0 - 6)2 + (6 - 1)2 + (2 - 1)? The location of the object is then given by the element that has the lowest value in the SSD matrix e.g. SSD(3,3). Write a program to perform the SSD calculation in the example and print out the location of the object, save the file as unikey_q3a.m. Your program should display: Location of object is at 3,3. To reduce errors in translating Image matrix into MATLAB, the matrix is contained in the file 03.txt. The only in-built MATLAB functions that you can use for this question are sum(), csvread() and size(). b) You notice it is difficult to find the lowest value in the returned SSD results as the results may span different ranges e.g. [min max]. To solve this problem, you create a function called minmax_norm which takes one parameter (an array of any size) and returns the transformed array so that the values in the array falls between the range of 0 and 1. The formula to perform min-max normalization is as follows: normalization = value - min max - min For example, a 3x3 input array into your function will return the following output: Input: Output: 06 2 0 1 0.33 4 3 2 0.67 0.50 0.33 61 1 0.17 0.17 Test your function using the given input in the example and display the output in the command window. Save the file as unikey_q3b.m. You may use the MATLAB in-built function min() and max() for this question if you choose to do so. c) You would like to test if the programs that you created in questions 3(a) and 3(b) would work for an actual image. Write a program that identifies the location of onion by using the in-built images contained in the Image Processing Toolbox: peppers.png as the image and onion.png as the object. Save your program file as unikey_q3c.m. Validate your results by using the location to crop out a sub-image the same size as onion.png from peppers.png and calculating the SSD between both images OR checking if the frequency count between both images are the same. Write comments on your codes to explain your results. You are expected to reuse the codes following principles of good practices that you have written in the previous questions (inclusive of Questions 1 and 2 if needed) to answer this question. Question 3 (45 marks) a) You can identify if an object is in the image by calculating the Sum Squared Differences (SSD) between the object and the image, and determining the location of the lowest value. Given an image (represented by an mxn matrix) and an object image T(represented by an m'n' matrix), the element in row u (u E [1, m-m' + 1]), column v(v [1, n - n + 1]) of SSD can be calculated as follows: min SSD(u, v) = (T(ij)-I(u + i - 1,v + i - 1)) where I(u: u + m' - 1,v: v + n' - 1)is the sub-image when the template is slid across the image pixel-by-pixel. For example, given a 3-bit 9x9 Image and 3x3 Object, the resulting SSD metric is as follows: Object: SSD: 162 Image: 121146771 63 2740315 15 06 2012 2 044326 6 5 5 266117263 5 5 5 5 3 42 42 536 254 422 0 0 2 7 7 5 515 |413|400|42|1 64 84 116 | 37 | 68 11692 116 93 43 101 133 71 85 93 1040 135 132 74 79 70 68 55 93 64 85 86 64 86 85 97 23 100 16 90 118 129 103 52 54 26 | 83 89 125 49 101 72 51 (7 SSD(1,3) is calculated by: (1 - 0)2 + (1 - 6)2 + (4 - 2)2 + (2 - 4)2 + - 3)2 + (4 - 2)2+ (0 - 6)2 + (6 - 1)2 + (2 - 1)? The location of the object is then given by the element that has the lowest value in the SSD matrix e.g. SSD(3,3). Write a program to perform the SSD calculation in the example and print out the location of the object, save the file as unikey_q3a.m. Your program should display: Location of object is at 3,3. To reduce errors in translating Image matrix into MATLAB, the matrix is contained in the file 03.txt. The only in-built MATLAB functions that you can use for this question are sum(), csvread() and size(). b) You notice it is difficult to find the lowest value in the returned SSD results as the results may span different ranges e.g. [min max]. To solve this problem, you create a function called minmax_norm which takes one parameter (an array of any size) and returns the transformed array so that the values in the array falls between the range of 0 and 1. The formula to perform min-max normalization is as follows: normalization = value - min max - min For example, a 3x3 input array into your function will return the following output: Input: Output: 06 2 0 1 0.33 4 3 2 0.67 0.50 0.33 61 1 0.17 0.17 Test your function using the given input in the example and display the output in the command window. Save the file as unikey_q3b.m. You may use the MATLAB in-built function min() and max() for this question if you choose to do so. c) You would like to test if the programs that you created in questions 3(a) and 3(b) would work for an actual image. Write a program that identifies the location of onion by using the in-built images contained in the Image Processing Toolbox: peppers.png as the image and onion.png as the object. Save your program file as unikey_q3c.m. Validate your results by using the location to crop out a sub-image the same size as onion.png from peppers.png and calculating the SSD between both images OR checking if the frequency count between both images are the same. Write comments on your codes to explain your results. You are expected to reuse the codes following principles of good practices that you have written in the previous questions (inclusive of Questions 1 and 2 if needed) to answer this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Forensics Body Of Knowledge

Authors: Darrell D. Dorrell, Gregory A. Gadawski

1st Edition

0470880856, 978-0470880852

More Books

Students also viewed these Accounting questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago