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

% Function Name: checkImage % Inputs (2): - (char) the name of an image file % -

ID: 3539917 • Letter: #

Question


% Function Name: checkImage

% Inputs (2): - (char) the name of an image file

%              - (char) the name of a second image file

% Outputs (1): - (char) a sentence comparing the two images

%

% Function Description:

% Given two images, write a function called "checkImage" that determines

% if the two images are the same, and if they are different, why.

%

% - If the two images are completely identical, the output should read 'The

%    images are the same.'

% - If the two images do not have the same dimensions, the output should

%    read 'The images have different dimensions.'

% - If the two images have the same dimensions, but have different color

%    values at the same pixel, the output should read 'The RGB values are

%    different.'. Additionally, if the two images have different colors,

%    you should write a new image that is white everywhere the two images

%    have the same RGB values and black everywhere they are different. This

%    new image should be called VS.png. For example, if I

%    was comparing 'lilacs.png' and 'roses.png', I would call my new image

%    'lilacsVSroses.png'.

%

% Hints:

% - You may find the function imwrite() useful.

% - It is not necessary to use iteration for pixel-by-pixel comparisons.

%    This will cause your code run very slowly and is inefficient.

% - This function should be useful for the rest of your homework.

%

% Test Cases:    

%   out1 = checkImage('apples.png', 'oranges.png');

%       out1 => 'The images have different dimensions.'

%   out2 = checkImage('flower1.png', 'flower2.png');

%       out2 => 'The images are the same.'

%   out3 = checkImage('oranges.png', 'tangerines.png');

%      out3 => 'The RGB values are different.'

%      'orangesVStangerines.png' => should look like

%                                   'orangesVStangerinesTest.png'

ORANGES SAME AS ABOVE

% As a double-check:

% out4 = checkImage('orangesVStangerines.png', 'orangesVStangerinesTest.png')

%    out4 => 'The images are the same.'

JUST USE SAME IMAGE

Explanation / Answer

function [out] = checkImage(a,b)

close all;

image1 = rgb2gray(a);

image2 = rgb2gray(b);

if(size(image1) ~= size(image2))

disp('The images have different dimensions.');

elseif(image1==image2)

disp('the images are the same');

else

disp('The RGB values are different');

out = im2bw(image1-image2,0);

imshow(out);

end

end

==================== testing ==============

a = imread("<your first image>");

b = imread("<your second image>);

out = checkImage(a,b);

imwrite(out,'image1VSimage2.jpg');