Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: edgy Inputs 1. (char) Filename of an image with file extension Fi

ID: 3714911 • Letter: F

Question

Function Name: edgy Inputs 1. (char) Filename of an image with file extension File Outputs: 1. An edgy image Background you decide to brush up on your numerical methods and learn about edge detection in images. Function Description In an attempt to become less conventional and more edgy after the downfall of GT Wi-Fi, Write a function to perform basic edge detection on an image, according to the following steps 1. Convert the image to grayscale 2. Using the numerical pixel values in the gray image, calculate the numerical derivative of the pixel values across both the horizontal and vertical directions and take the absolute value of each array Since the resulting x-direction and y-direction derivative arrays will have different dimensions, remove the last row/column to make both difference arrays the same a. size b. Additionally, crop the original image to this new size 3. Calculate the averages and standard deviations of the x-direction and y-direction difference arrays and calculate a minimum threshold difference that will be considered an edge according to the following formula: A(brightness) + std thresholdmean AJthreshold mean A(brightness))+ std A (brightness) (std is short for standard deviation). Determine which points in the red layer of the x-direction and y-direction derivative arrays are greater than or equal to the corresponding thresholds. Points that are greater than or equal to the threshold in either direction should be considered an edge. Change these edge pixels in the original color image to pure red. Write the new edgy image to edgy_.png. 4. 5. 6.

Explanation / Answer

Let us consider a image. To convert the image in to grayscale we first need to consider the image with its pixel size. first separate the image into three different 2d matrices of R, G, and B. It is basically used to identify the pixels of the image. If we are using the R, then syntax for implementing the such case will be "R = i(:, :, 1);".

The syntax basically means that we are creating a new matrix R and setting it equal to all the rows and columns of the first layer in image i .

To implement the such code we are using the following code.

function returnedImage = toGrayscale(image)

        i = image;

        R = i(:, :, 1);

        G = i(:, :, 2);       

        B = i(:, :, 3);

        newImage = zeros(size(i,1), size(i,2), 'uint8');

       for x=1:size(i,1)

           for y=1:size(i,2)

               newImage(x,y) = (R(x,y)*.3)+(G(x,y)*.6)+(B(x,y)*.1);

           end

        end

           returnedImage = newImage;

    end

To convert the image into gray scale we use the following code:

myImage = imread('faceplantImage.jpg');// reading the image form the source figure

subplot(1,2,1); // plotting the figure pixel wise

imshow(myImage);

title('Original Image');// providing the image title.

subplot(1,2,2);

grayScaleImage = toGrayscale(myImage);// conversion of the image

imshow(grayScaleImage);

title('Grayscale Image');

Note: the basic thresold can be computed on the given formula by identifying the image after the conversion is over.

for this we may use the I,J coordinate to compute the value by using the following code.

J=filter2(fspecial(‘image’),I);

Min_matrix=min(J(:))

Min_matrix=-779

Max_matrix=max(J(:))

Max_matrix=560