Contents
Matlab Code:
Author: Minh Anh Nguyen (minhanhnguyen@q.com)
%This script will perform the followign tasks: %1. read in two ".png" file, display both images on the computer screen. %2. histogram of the images % 3. compare both image files. % 4. display a message on the computer screen if both image are not the % same. clear all; % Erase all existing variables. close all; % Close all figures (except those of imtool.) clc;% Clear the command window. imtool close all; % Close all imtool figures. workspace; % Make sure the workspace panel is showing. fontSize = 20; %%%%%%%%%%%%%
team: edit your file here
set the path
folder = 'C:\Users\Minh anh\Desktop\Image_demo'; %reading images as array to variable 'a' & 'b'. image1 = imread('.\Loaded-Mid Channel.PNG'); % image2= imread('.\Loaded-Mid Channel.PNG'); image2= imread('.\Gross Misloaded-Mid Channel.PNG'); % image2= imread('.\Mild Misloaded-Mid Channel.PNG');
info
imfinfo('.\Loaded-Mid Channel.PNG')
imfinfo('.\Gross Misloaded-Mid Channel.PNG')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % do not edit anything below here!!!! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% a = image1; b = image2;
size
a1= size(a);
b1= size (b);
figure;
% [rows columns numberOfColorBands] = size(a);
subplot(2, 2, 1); imshow(a, []);
title('Correct loading image', 'Fontsize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
redPlane = a(:, :, 1);
greenPlane = a(:, :, 2);
bluePlane = a(:, :, 3);
% [rows columns numberOfColorBands] = size(b);
subplot(2, 2, 2); imshow(b, []);
title('User loading image', 'Fontsize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
redPlane1 = b(:, :, 1);
greenPlane1 = b(:, :, 2);
bluePlane1 = b(:, :, 3);
% Let's get its histograms.
[pixelCountR, grayLevelsR] = imhist(redPlane);
subplot(2, 2, 3); plot(pixelCountR, 'r');
title('Histogram of correct loading image', 'Fontsize', fontSize);
% xlim([0 grayLevelsR(end)]); % Scale x axis manually.
xlim([0,256]); ylim([0,82000]);
xlabel('Intensity values','Fontsize', fontSize);
ylabel('Number of pixels','Fontsize', fontSize);
indexmin1 = find(min(pixelCountR) == pixelCountR);
xmin = grayLevelsR(indexmin1);
ymin = pixelCountR(indexmin1);
% strmax2a = ['Minimum = ',num2str(xmin2),' ',' ', num2str(ymin2),' '];
% text(xmin2,ymin2,strmax2a,'HorizontalAlignment','Right');
indexmax1 = find(max(pixelCountR) == pixelCountR);
xmax1 = grayLevelsR(indexmax1);
ymax1 = pixelCountR(indexmax1);
strmax1 = ['Number of intensity =',num2str(xmax1),' ','Number of pixels = ', num2str(ymax1),''];
text(xmax1,ymax1,strmax1,'HorizontalAlignment','Left');
[pixelCountR2, grayLevelsR1] = imhist(redPlane1);
subplot(2, 2, 4);
plot(pixelCountR2, 'r');
title('Histogram of user loading image', 'Fontsize', fontSize);
% xlim([0 grayLevelsR1(end)]); % Scale x axis manually.
xlim([0,256]); ylim([0,82000]);
xlabel('Intensity values','Fontsize', fontSize);
ylabel('Number of pixels','Fontsize', fontSize);
indexmin2 = find(min(pixelCountR2) == pixelCountR2);
xmin2 = grayLevelsR1(indexmin2);
ymin2 = pixelCountR2(indexmin2);
% strmax2a = ['Minimum = ',num2str(xmin2),' ',' ', num2str(ymin2),' '];
% text(xmin2,ymin2,strmax2a,'HorizontalAlignment','Right');
indexmax2 = find(max(pixelCountR2) == pixelCountR2);
xmax2 = grayLevelsR1(indexmax2);
ymax2 = pixelCountR2(indexmax2);
strmax2 = ['Number of intensity = ',num2str(xmax2),' ','Number of pixels =', num2str(ymax2),''];
text(xmax2,ymax2,strmax2,'HorizontalAlignment','Left');
%check image for different
different = a1- b1;
if different==0
disp('The images are same')%output display
else
disp('the images are not same')
msgbox('Centrifuge loading error. Please check channel is seated properly')
end;
the images are not same


No comments:
Post a Comment