Question: Need some help interpreting C code. It is used for Sobel masks (edge detection). Multi-part question but not long (all parts go with the single

Need some help interpreting C code. It is used for Sobel masks (edge detection). Multi-part question but not long (all parts go with the single program). Any help would be great.

Need some help interpreting C code. It is used for Sobel masks

a) In the provided Sobel.c code, the dimensions of the xmask is 3x3, and hence MR is 1 (line 37). Suppose the dimensions of xmask had been 7x7, what would the value of MR need to be?

-I'm thinking MR is either mask size or magnitude? As in 3x3 and MR=1 would mean that a single mask is a 3x3 grid, and that a 7x7 grid would be either mr=9 or mr=5.44..

b) In the double for loop from lines 38-39 and lines 54-55, why does it have mr in the code?

Code: for (i=mr; i

for (j=mr; j

-Obviously I don't know this one since I'm not sure what mr is. but since there's 256-mr a few times it looks like it might have to do with color codes.

c) What is the purpose of maxival, and explain why the code has line 65.

Code: ival[i][j] = (ival[i][j] / maxival) * 255;

-I know color codes go from 0 to 255, so I take it maxival is first set to 0,0,0 (line 53) for black. The maxival then set in lines 57-58 (maxival = ival[i][j];) and it looks like if the color is brighter than black (ival > maxival) then maxival is set to that color. The line 65 code looks like ival and maxival being averaged?

Thanks in advance! I tried but didn't get so far. Currently don't have anything to test the code on either.

#include #include #inc Lude 3 4 5 int pic [256] [256]; int outpicx [256] [256]; 7 6 int outpicy [256] [256]; 8 9 10 lint maskx[3] [3] {{-1,0,1), {-2,0,2}, {-1,0,1}); 11 int masky [3] [3] {{1,2,1), {0,0,0}, {-1,-2,-1)); double ival [256] [256], maxival; 12 int main (int argc, char *argv) int i, j, p, q, mr, sum1, sum2; double threshold; FILE *fo1, *fo2, *fp1, *fopen (); char *foobar; 15 argc-argv+; fp1 fopen (foobar, "rb"); argc-argv+; fol fopen (foobar, "wb"); argc-argv+; threshold = atof(foobar); 19 23 24 25 26 29 30 for (i-0; i maxival) ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!