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

1. Write a MATLAB script that will apply a uniform border (same number of pixels

ID: 3715092 • Letter: 1

Question

1. Write a MATLAB script that will apply a uniform border (same number of pixels on all sides) to any RGB image. The size of the border is in pixels and will be provided by the user in a variable. The name of the image is provided in a string variable. The color of the border is determined by the user in a 1x3 vector. The output is the original image with the specified color border applied. You may use any image of your choice for this exercise, so long as it is in color.

2.Write a MATLAB program that will take an image as input. The name of the image is provided by the user in a variable. Suppose the image is NxP pixels in size. The program will output a new image that is 2*Nx2*P in size. In the upper left quadrant of the new image, the original image is shown. In the upper right quadrant, the red channel image is shown (in red). In the lower left quadrant, the green channel image is shown (in green). In the lower right quadrant, the blue channel image is shown (in blue). You may use any image of your choice, so long as it is a color image.

3.Write a MATLAB program that computes the average intensity of each color in an RGB image. The image name to open and process is stored in a string variable. The program should compute the average intensity of R, G, and B in the image and then produce a new image with the same dimensions as the original image, but with all pixels set to that average intensity. You must use loops to do this assignment. Do NOT employ the MATLAB mean command. You may use any image of your choice for this exercise, so long as it is in color.

Explanation / Answer

Please post 1question at a time

Answer to question 1:

function applyBorder(imgName, width, color)

    %sanity check: color is valid

    if color(1) < 0 || color(1) > 255 || color(2) < 0 || color(2) > 255 || color(3) < 0 || color(3) > 255

       fprintf("Color provided is out of range ");

       return;

    end

    %sanity check: width of the border is non negative

    if width < 0

       fprintf("Border width cannot be less than 0 ");

       return;

    end

    img = imread(imgName);

    sz = size(img);

   

    for i = 1:sz(1)

       for j = 1:sz(2)

           if (i <= width || j <= width || i > sz(1)-width || j > sz(1)-width )

               img(i,j,1) = color(1);

               img(i,j,2) = color(2);

               img(i,j,3) = color(3);

           end

       end

    end

    imshow(img)

    %If you want to write the image to file 'border.jpg' uncomment the next line

    %imwrite(img, 'border.jpg')

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote