-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDistInColor.m
78 lines (64 loc) · 2.06 KB
/
getDistInColor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function [ dist ] = getDistInColor( imgA, imgB )
%getDistInColor Calculate the difference between two pictures in terms of
%their chrominance.
% 0% image colors identical
% 1% slightly off color
% 5% some sections miscolored
% 10% significant deviation
% 15% catastrophic failure (e.g. inverse coloring)
multiplier = 5;
% With multipler = 5:
% 0% image colors identical
% 5% slightly off color
% 20% some sections miscolored
% 50% significant deviation
% 75%+ catastrophic failure (e.g. inverse coloring)
%Read in, if not already
if ischar(imgA)
imgA = imread(imgA);
end
if ischar(imgB)
imgB = imread(imgB);
end
imgA=addRGBchannels(im2double(imgA));
imgB=addRGBchannels(im2double(imgB));
numRows = size(imgA,1);
numCols = size(imgA,2);
%Assumes the same size
aR = imgA(:,:,1);
aG = imgA(:,:,2);
aB = imgA(:,:,3);
bR = imgB(:,:,1);
bG = imgB(:,:,2);
bB = imgB(:,:,3);
% aY = getY(aR,aG,aB);
aI = getI(aR,aG,aB);
aQ = getQ(aR,aG,aB);
% bY = getY(aR,aG,aB);
bI = getI(bR,bG,bB);
bQ = getQ(bR,bG,bB);
diffMatrix = abs(aI-bI) + abs(aQ-bQ);
diffSum = sum(diffMatrix(:));
%Calculate max dist possible
%I parameter has the range [-0.523,0.523], and the Q parameter has the range [-0.596,0.596]
% aIdistToMax = abs(aI - 0.523*ones(numRows,numCols));
% aQdistToMax = abs(aQ - 0.596*ones(numRows,numCols));
% bIdistToMax = abs(bI - 0.523*ones(numRows,numCols));
% bQdistToMax = abs(bQ - 0.596*ones(numRows,numCols));
%
% aIdistToMin = abs(aI - -0.523*ones(numRows,numCols));
% aQdistToMin = abs(aQ - -0.596*ones(numRows,numCols));
% bIdistToMin = abs(bI - -0.523*ones(numRows,numCols));
% bQdistToMin = abs(bQ - -0.596*ones(numRows,numCols));
%
%
% aIMaxDiff = bsxfun(@max, aIdistToMax, aIdistToMin);
% aQMaxDiff = bsxfun(@max, aQdistToMax, aQdistToMin);
% bIMaxDiff = bsxfun(@max, bIdistToMax, bIdistToMin);
% bQMaxDiff = bsxfun(@max, bQdistToMax, bQdistToMin);
% totalMaxDiff = aMaxDiff+bMaxDiff;
% totalMaxDiff = sum(totalMaxDiff(:));
maxDiff = 2*numRows*numCols; %I1-I2=1.0, Q1-Q2=1.0
dist = diffSum/maxDiff *100 * multiplier;
% dist = diffSum/totalMaxDiff *100;
end