Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem you will be implementing the 2D convolution algorithm that is usually used in image processing applications. For example, 2D convolution is used

In this problem you will be implementing the 2D convolution algorithm that is usually used in image processing applications. For example, 2D convolution is used to implement image filters in your favorite social media application and to detect objects using machine learning.

A straightforward implementation of 2D convolution in C consists of deeply nested for loops:

// Initialization int fx [10][10] ={ {183, 207, 128, 30, 109, 0, 14, 52, 15, 210}, {228, 76, 48, 82, 179, 194, 22, 168, 58, 116}, {228, 217, 180, 181, 243, 65, 24, 127, 216, 118}, {64, 210, 138, 104, 80, 137, 212, 196, 150, 139}, {155, 154, 36, 254, 218, 65, 3, 11, 91, 95}, {219, 10, 45, 193, 204, 196, 25, 177, 188, 170}, {189, 241, 102, 237, 251, 223, 10, 24, 171, 71}, {0, 4, 81, 158, 59, 232, 155, 217, 181, 19}, {25, 12, 80, 244, 227, 101, 250, 103, 68, 46}, {136, 152, 144, 2, 97, 250, 47, 58, 214, 51} }; // 2D Image int kx [5][5] = { {1, 1, 0, -1, -1}, {0, 1, 0, -1, 0}, {0, 0, 1, 0, 0}, {0, -1, 0, 1, 0}, {-1, -1, 0, 1, 1} }; // Kernel int gx [10][10]; // Output Result int iw = 10; // Image Width = 10 int ih = 10; // Image Height = 10 int kw = 5; // Kernel Width = 5 int kh = 5; // Kernel Height = 5

int ksw = 2; // Kernel Width Stride = (Kernel Width-1)/2 int khw = 2; // Kernel Height Stride = (Kernel Height-1)/2

// 2D Convolution Algorithm for (int y = 0; y < ih ; y++) {

for (int x = 0; x < iw ; x++) {

int sum = 0;

for (int i = 0; i < kw ; i++) {

for (int j = 0; j < kh ; j++) {

int temp1 = x+j -ksw;

int temp2 = y+i -khw;

if (temp1>=0 && temp1<=9 && temp2>=0 && temp2<=9)

sum = sum + kx[j][i] * fx [temp1][temp2];

}

}

gx[x][y] = sum;

}

} /* Output: Array = { {656 ,160 ,113 ,72 ,-51 ,-430 ,23 ,333 ,-70 ,-191 }, {586 ,261 ,99 ,33 ,200 ,294 ,161 ,299 ,-378 ,-431}, {217 ,631 ,482 ,311 ,86 ,-31 ,-30 ,-64 ,148 ,-9}, {-68 ,256 ,485 ,319 ,-96 ,17 ,208 ,271 ,285 ,125}, {-99 ,-77 ,404 ,691 ,354 ,-427 ,-389 ,0 ,211 ,205}, {43 ,103 ,244 ,497 ,420 ,101 ,-142 ,123 ,67 ,38}, {85 ,660 ,344 ,199 ,571 ,838 ,38 ,-468 ,-408 ,9 }, {12 ,137 ,-40 ,-138 ,98 ,697 ,316 ,-295 ,55 ,215}, {-170 ,-211 ,-282 ,88 ,507 ,409 ,352 ,235 ,222 ,208}, {39 ,-142 ,-301 ,-351 ,92 ,72 ,-62 ,427 ,624 ,517}, } */

You may assume that the input image and kernel are square.

Exercise

  1. Write an ARM V7 assembly program that implements 2D convolution. Note that fx, image and kernel sizes, are all parameters passed to the program.

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

Which type of soil has more ability to absorb water?

Answered: 1 week ago

Question

4. Who should be invited to attend?

Answered: 1 week ago