Skip to content

LoveDaisy/ColorScienceUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color Science Utilities

tags: [[tools]], [[programing]],

A toolkit for [[color science]]. The first codes are in MATLAB, which is just my personal favor. I will try python later.

Quick start

Just add subfolder matlab to your MATLAB path, and then you can use all the tools.

Color space conversion

I have implemented many conversions between [[color space]] in +colorspace package. They are easy to use:

% Read image. Assume it is an DisplayP3 image shot by a smart phone.
img = imread('DisplayP3_image.jpg');  

% Now convert it to sRGB gamut.
img_new = colorspace.rgb2rgb('DisplayP3', 'sRGB');

% And now it can be displayed safely on web, or just via imshow();
figure;
imshow(img_new);

And also I have implemented some conversions for [[HDR]] video. For example if you want to check YUV raw data of an HDR video,

% Read YUV rawdata. Here it is yuv420p10le pixel format.
% So component y, u, and v are all of uint16 class.
[y, u, v] = colorutil.read_yuv_rawdata('yuv420p10le_rawdata.yuv', [3840, 2160], 'yuv420p10le');

% Convert to float type and normalize to [0, 1].
[yfp, ufp, vfp] = colorutil.ycbcr_int2double(y, u, v, 10, 'tv');

% Merge into a 3-channel image.
yuv = colorutil.merge_ycbcr_channel(yfp, ufp, vfp);

% Display y component.
figure;
imshow(yfp);

% Or display them all.
figure;
colorvis.plot_yuv(yfp, ufp, vfp);

Result of plot_yuv(): plot_yuv

Gamut visualization

Here are also several visualization tools for color gamut.

% Show chromaticity diagram boundary.
colorvis.plot_chromaticity_diagram();

chm_boundary

% Fill chromaticity diagram
colorvis.plot_chromaticity_diagram('Fill', true, 'Background', [1, 1, 1]);

fill_chm

And also you can plot 2D and 3D density map for color distribution. Say if we have this image: scene_image

% Plot 2D density map
colorvis.plot_chromaticity_diagram('ColorData', rgb_image, 'ColorSpace', 'sRGB');

This image is quite saturated, so you can find many 'hot spots' lie on triangle shaped boundary, which is exactly the boundary of sRGB gamut in xy plane. xy_hist

% Plot 3D density map (here I call it bubble plot).
% Default shown in Lab space.
colorvis.plot_gamut_bubble_hist(rgb_image, 'sRGB');

lab_bubble

% Or display in xyY space, and use log scale for luminance axis,
% and cut off 15% dark pixels.
colorvis.plot_gamut_bubble_hist(rgb_image, 'sRGB', 'xyY', 'ZScale', 'log', 'DarkTh', 15);

You can see many bubbles are clipped and lay on bottom. xyy_bubble

Spectrum rendering

Here are some spectrum rendering functions, which can convert spectrum data into RGB colors.

% Get blackbody radiance of 5700K, at wavelength from 420nm to 700nm
lambda = 420:700;
spc = colorvis.black_body_radiance(lambda, 5700);

% Then render it to RGB color (should be like warm white)
rgb = spec_to_rgb([lambda(:), spec(:)]);

TODO

  • Add more test cases
  • Add python codes

About

some utilities for color science

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published