1. Engineering
  2. Computer Science
  3. matlab this should be the output please provide a working...

Question: matlab this should be the output please provide a working...

Question details

Matlab

4. [5 points Perform binary thresholding on the original normalized grayscale image C. A threshold 0.3 is chosen and all values in C greater than or equal to the threshold are set to 1, otherwise set to 0 Find two efficient solutions to obtain the thresholded binary image and save it in bw1 and bw2. Both solutions should not use any loop structure, should not call Matlab built-in function im2bw, and should be distinct in nature. Use the Matlab built-in function im2bw to do the same task and save its thresholded binary image in bw3 Compare your results bw1 and bw2 with the Matlabs result bw3. If they are equal, display the message My two methods worked; otherwise, display the message One of my two methods or both did not work. Of course, the first message should be displayed when running the program Display bwl, bw2, and bw3 side-by-side on figure 5 and label the three images with my first method, my second method, and Matlab method, respectively Matlab Hint: find, >=, zeros, ones, &, &&

This should be the output:

Figure 5 File Edit View Insert Tools Desktop Window Help mentat ge P hile t my first me my second method Matlab method 0 tle tle tle um: or roc

Please provide a working code, this one does not work:

I YOU HAVE ANY DOUBTS COMMENT BELOW I WILL THERE TO HELP YOU

RATE THUMBSUP

ANSWER:

CODE:

% Rean an image into A
A = imread('lena.jpg');

% Convert the image A into grayscale image B
B = rgb2gray(A);

% Normalize image B to C
C = im2double(B);

% Calculate the threshold binary image
% First method
bw1 = C(1:end, 1:end) >= 0.3;   

% Second method
bw2 = zeros(size(C));
% find indexes above or equla to thresholr
ind_above = (C >= 0.3);
% set value abouve to 1
bw2(ind_above) = 1;

% Calculate using matlab built-in function im2bw
bw3 = im2bw(C, 0.3);

% Comprare the results
if (bw1 == bw3)
if (bw2 == bw3)
disp('My two methods worked.');
end
else
disp('One of my two methods or both did not work.');
end

%Display the images
subplot(2, 3, 1);
imshow(A);
title('Original Image');
subplot(2, 3, 2);
imshow(C);
title('Normalized Image');
subplot(2, 3, 4);
imshow(bw1);
title('My First Method');
subplot(2, 3, 5);
imshow(bw2);
title('My Second Method');
subplot(2, 3, 6);
imshow(bw2);
title('Matlab Method');

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution