You are on page 1of 5

EE530 Image Processing Project #1

20215259 Kangmin Lee

2023.03.28

1. Color Profile Conversion using for-loops

The image is downloaded and displayed:

ColorChecker.jpeg

The maximum and minimum values of the image between [0, 255] are 247 and 1, respectively. The image is
then converted into double format and normalized to [0, 1]. The nonlinear sRGB image is converted to linear
RGB image using 2.2 gamma. The linear sRGB image is displayed:

Linear sRGB Image

The image is then converted to linear p3 RGB, then to nonlinear p3 RGB using 1/2.2 gamma. The nonlinear p3
RGB image is displayed:
Nonlinear p3 RGB Image

The image looks pale for the nonlinear p3 RGB image because it uses a larger range of color gamut. The color
difference between nonlinear sRGB and nonlinear p3 RGB is calculated. The average color difference is 27.4230
and the maximum color difference is 35.6018.

2. Color Profile Conversion without using for-loops

Problem 1 is repeated without using for loops. The result is the same as problem 1.

3. Color Profile Conversion with 10-bit Integer Precision

Problem 2 is repeated using 10-bit integer precision. The average color difference is 0.1151 and the maximum
color difference is 0.8416. For 8-bit precision, the average is 0.4733 and the maximum is 2.5992. For the 6-bit
precision, the average is 2.1358 and the maximum is 8.9071.
Code
%% 1. Color Profile Conversion
close all, clear all, clc

% 1.1
img = imread('ColorChecker.jpeg');
figure, imshow(img);

% 1.2
[a,b,c] = size(img);
RGB = reshape(img, a*b,c);
RGB_max = max(RGB(:));
RGB_min = min(RGB(:));
RGB_double= double(RGB);
sRGB_nl = RGB_double/255;

% 1.3
sRGB = zeros(size(sRGB_nl));
for i = 1:size(sRGB,1)
for j = 1:size(sRGB,2)
sRGB(i,j) = sRGB_nl(i,j)^(1/2.2);
end
end
sRGB = sRGB_nl.^(2.2);
img_sRGB = sRGB*255;
img_sRGB = uint8(real(img_sRGB));
img_sRGB = reshape(img_sRGB,a,b,c);
figure, imshow(img_sRGB);

% 1.4
M_sp = [0.8225 0.1775 0.0001
0.0331 0.9668 0.0000
0.0171 0.0724 0.9105];
pRGB = M_sp*sRGB';

% 1.5
pRGB_transpose = pRGB';
pRGB_nl = zeros(size(pRGB_transpose));
for i = 1:size(pRGB_nl,1)
for j = 1:size(pRGB_nl,2)
pRGB_nl(i,j) = pRGB_transpose(i,j)^(1/2.2);
end
end
img_pRGB = pRGB_nl*255;
img_pRGB = uint8(real(img_pRGB));
img_pRGB = reshape(img_pRGB,a,b,c);
figure, imshow(img_pRGB);

% 1.6
M_sRGB2XYZ = [0.4124 0.3576 0.1805
0.2126 0.7152 0.0722
0.0193 0.1192 0.9505];

M_pRGB2XYZ = [0.4866 0.2657 0.1982


0.2290 0.6917 0.0793
0.0000 0.0451 1.0439];

sXYZ = M_sRGB2XYZ * sRGB';


pXYZ = M_pRGB2XYZ * pRGB_nl';
sLab = xyz2lab(sXYZ');
pLab = xyz2lab(pXYZ');
dE1 = sqrt(((sLab(:,1,:)-pLab(:,1,:)).^2)+((sLab(:,2,:)-pLab(:,2,:)).^2)+((sLab(:,3,:)-
pLab(:,3,:)).^2));
dE1_mean = mean(dE1)
dE1_max = max(dE1)

%% 2. Color Profile Conversion without using for-loops

% 2.1
img = imread('ColorChecker.jpeg');
figure, imshow(img);

% 2.2
[a,b,c] = size(img);
RGB = reshape(img, a*b,c);
RGB_max = max(RGB(:))
RGB_min = min(RGB(:))
RGB_double= double(RGB);
sRGB_nl = RGB_double/255;

% 2.3
sRGB = sRGB_nl.^(2.2);
img_sRGB = sRGB*255;
img_sRGB = uint8(real(img_sRGB));
img_sRGB = reshape(img_sRGB,a,b,c);
figure, imshow(img_sRGB);

% 2.4
M_sp = [0.8225 0.1775 0.0001
0.0331 0.9668 0.0000
0.0171 0.0724 0.9105];
pRGB = M_sp*sRGB';

% 2.5
pRGB_nl = pRGB'.^(1/2.2);
img_pRGB = pRGB_nl*255;
img_pRGB = uint8(real(img_pRGB));
img_pRGB = reshape(img_pRGB,a,b,c);
figure, imshow(img_pRGB);

% 2.6
M_sRGB2XYZ = [0.4124 0.3576 0.1805
0.2126 0.7152 0.0722
0.0193 0.1192 0.9505];

M_pRGB2XYZ = [0.4866 0.2657 0.1982


0.2290 0.6917 0.0793
0.0000 0.0451 1.0439];

sXYZ = M_sRGB2XYZ * sRGB';


pXYZ = M_pRGB2XYZ * pRGB_nl';
sLab = xyz2lab(sXYZ');
pLab = xyz2lab(pXYZ');

dE2 = sqrt(((sLab(:,1,:)-pLab(:,1,:)).^2)+((sLab(:,2,:)-pLab(:,2,:)).^2)+((sLab(:,3,:)-
pLab(:,3,:)).^2));
dE2_mean = mean(dE2)
dE2_max = max(dE2)

%% 3. Color Profile Conversion with 10-bit Integer Precision

% 3.1
bit = 1024; % 256, 64
iRGB = round(bit.*sRGB);
% 3.2
P = round(bit*M_sp);

% 3.3
oRGB = round(P*iRGB'/bit);

% 3.4
p3RGB = oRGB/bit;
p3XYZ = M_pRGB2XYZ*p3RGB;
p3Lab = xyz2lab(p3XYZ');

% 3.5
sXYZ = M_sRGB2XYZ * sRGB';
pXYZ = M_pRGB2XYZ * pRGB_nl';
sLab = xyz2lab(sXYZ');
pLab = xyz2lab(pXYZ');

dE3 = sqrt(((sLab(:,1,:)-p3Lab(:,1,:)).^2)+((sLab(:,2,:)-p3Lab(:,2,:)).^2)+((sLab(:,3,:)-
p3Lab(:,3,:)).^2));
dE3_mean = mean(dE3)
dE3_max = max(dE3)

You might also like