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

This is a MatLAB question. All parts needed. Attached is a picture of the butter

ID: 3882077 • Letter: T

Question

This is a MatLAB question. All parts needed. Attached is a picture of the butterfly. 2 modified commands and 2 command scripts needed.

At the MATLAB command prompt, type the following:

>> load HW2; imshow(Butterfly)

You should see a grayscale image of a Butterfly. Paste the original image in the space below.

ORIGINAL IMAGE

Notice that Butterfly is a 2-d array (matrix) of type uint8. Each entry in the matrix is a pixel of the digital image. All entries are in the range of 0 to 255 (the range of an 8 bit unsigned integer). A pixel value of 0 is Black, a pixel value of 255 is White, and pixel values in between create 254 shades of grey – getting progressively lighter as value increases.

Create a script file that will first load the Butterfly image (load HW2). Then create a nested for loop that will look at the value of each pixel (entry) in the Butterfly image (matrix). If a pixel value is larger than 125, the value will be replaced with 255 (White). If a pixel value is not larger than 125, the value will be replaced with 0 (Black). Use the imshow command to display the modified image. It should be purely Black and White (no shades of grey). Run your script and paste the modified image and the MATLAB code in the space below.

Note: if you decide to create a new matrix for the new image, make sure it is of type uint8 and not the default of double. This can be done as follows:

NewPic = uint8(zeros(size(Butterfly))); or NewPic = Butterfly;

MODIFIED IMAGE and SCRIPT COMMANDS:

Create another script file that will first re-load the original Butterfly image (load HW2). Then create a nested for loop that will look at the value of each pixel (entry) in the Butterfly image (matrix). Modify each pixel in the Butterfly matrix using the table below. Run your script and paste the modified image and the MATLAB code in the space below.

Note: if you decide to create a new matrix for the new image, make sure it is of type uint8 and not the default of double. This can be done as follows:

NewPic = uint8(zeros(size(Butterfly))); or NewPic = Butterfly;

Original Pixel Value

New Pixel Value

Value > 200

New Value = 255

150 < Value < 200

New Value = 175

100 < Value < 150

New Value = 125

50 < Value < 100

New Value = 75

Value < 50

New Value = 0

MODIFIED IMAGE and SCRIPT COMMANDS:

Original Pixel Value

New Pixel Value

Value > 200

New Value = 255

150 < Value < 200

New Value = 175

100 < Value < 150

New Value = 125

50 < Value < 100

New Value = 75

Value < 50

New Value = 0

Explanation / Answer

CODE 1

%Butterfly = imread('');
% butterfly = rgb2gray(butterfly); %incase image is not b/w

newPic = uint8(zeros(size(Butterfly)));

[r, c] = size (Butterfly);

for i = 1:r
    for j = 1:c
        if Butterfly(i, j) > 125
            newPic(i, j) = 255;
        end
    end
end

imshow(newPic);

CODE 2

%Butterfly = imread('');
% butterfly = rgb2gray(butterfly); %incase image is not b/w

newPic = uint8(zeros(size(Butterfly)));

[r, c] = size (Butterfly);

for i = 1:r
    for j = 1:c
        if Butterfly(i, j) > 200
            newPic(i, j) = 255;
        elseif Butterfly(i, j) > 150
            newPic(i, j) = 175;
        elseif Butterfly(i, j) > 100
            newPic(i, j) = 125;
        elseif Butterfly(i, j) > 50
            newPic(i, j) = 75;
        end
    end
end

imshow(newPic);

NOTE: it is up to you how you would like to load the image

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