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.
Just add subfolder matlab
to your MATLAB path, and then you can use all the tools.
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);
Here are also several visualization tools for color gamut.
% Show chromaticity diagram boundary.
colorvis.plot_chromaticity_diagram();
% Fill chromaticity diagram
colorvis.plot_chromaticity_diagram('Fill', true, 'Background', [1, 1, 1]);
And also you can plot 2D and 3D density map for color distribution. Say if we have this 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.
% Plot 3D density map (here I call it bubble plot).
% Default shown in Lab space.
colorvis.plot_gamut_bubble_hist(rgb_image, 'sRGB');
% 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.
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(:)]);
- Add more test cases
- Add python codes