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

Please help me this on MATLAB: In this problem, you will create two function fil

ID: 3809936 • Letter: P

Question

Please help me this on MATLAB:

In this problem, you will create two function files that both perform the same task - turning a color image into a black and white image based on a given threshold value. Every pixel in the original image that is "brighter" than the threshold value should be set to white. Every pixel in the original image that is "darker" than the threshold value should be set to black. Assume that pixel brightness is represented by the average of the R, G and B values. Your ThresholdImage1.m should utilize logical arrays to do the image processing. Your ThresholdImage2 function should use nested for loops to do the image processing. Both functions will have the same inputs and output: Inputs: (1) RGB image array, (2) scalar threshold value Output: Modified RGB image array In a new cell in your HW11.m script: 1. Read in an image (of your choice, or you can download and use BB-8.jpg from Canvas) 2. Call your ThresholdInnage1 function 3. Display the original and thresholded image side-by-side in a single figure window 4. Call your ThresholdImage2 function 5. Display the original and thresholded images side-by-side in a new figure window Be sure to submit your image file (BB-8.jpg or your own image file) so that the grader will be able to run your script. Example output is shown below.

Explanation / Answer

function out = ThresholdImage1(in, threshold)

    y = (in(:,:,1)+ in(:,:,2)+ in(:,:,3))/3;

    out = y > threshold; %logical operation

end

function out = ThresholdImage2(in, threshold)

    y = (in(:,:,1)+ in(:,:,2)+ in(:,:,3))/3; %find avg of each pixel

    out = zeros([size(y)]); %create array

    [row col] = size(y);

    for i = 1:row

       for j = 1:col

           if y(i,j) > threshold; % chk if the pixel intensity is more than threshold

               out(i,j) = 1;

           end

       end

    end

end

fileName = 'abc';

x = imread(fileName);

y = ThresholdImage1(x, 120);

figure

subplot(1,2,1), imshow(x)

subplot(1,2,2), imshow(y)

y = ThresholdImage2(x, 120);

figure

subplot(1,2,1), imshow(x)

subplot(1,2,2), imshow(y)

Hello. I coded this for you. Hope you like it. Let me know if you face any issue with the code. And don't forget to change the file name before executing the code.