• RGB彩色工业标准到CIEXYZ空间转换示例:


    https://blog.csdn.net/lxw907304340/article/details/45641419#comments_15463002

    https://blog.csdn.net/lxw907304340/article/details/45641675#comments_13292433

    https://blog.csdn.net/lxw907304340/article/details/45641675】

    Color math and programming code examples

    These are the formulas used by our Color Calculator to convert color data in different color spaces.
    Each conversion formula is written as a "neutral programming function", easy to be translate in any specific programming language:

    XYZ → Standard-RGB
    //X, Y and Z input refer to a D65/2° standard illuminant.
    //sR, sG and sB (standard RGB) output range = 0 ÷ 255
    
    var_X = X / 100
    var_Y = Y / 100
    var_Z = Z / 100
    
    var_R = var_X *  3.2406 + var_Y * -1.5372 + var_Z * -0.4986
    var_G = var_X * -0.9689 + var_Y *  1.8758 + var_Z *  0.0415
    var_B = var_X *  0.0557 + var_Y * -0.2040 + var_Z *  1.0570
    
    if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055
    else                     var_R = 12.92 * var_R
    if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055
    else                     var_G = 12.92 * var_G
    if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055
    else                     var_B = 12.92 * var_B
    
    sR = var_R * 255
    sG = var_G * 255
    sB = var_B * 255

    clc;
    close all;
    clear all;
    rgb = imread('lena.bmp');
    subplot(2,3,1),imshow(rgb,'InitialMagnification','fit');title('原图像');
    rgb =double(rgb);%双精度化(0-255)
    x = 0.607*rgb(:,:,1)+0.174*rgb(:,:,2)+0.201*rgb(:,:,3);
    x = mat2gray(x);%把矩阵转化为灰度图像
    y = 0.299*rgb(:,:,1)+0.587*rgb(:,:,2)+0.114*rgb(:,:,3);
    y = mat2gray(y);
    z = 0.066*rgb(:,:,2)+0.117*rgb(:,:,3);
    z = mat2gray(z);
    xyz = cat(3,x,y,z);%把x,y,z连在一起
    subplot(2,3,3),imshow(xyz);title('XYZ图像');
    subplot(2,3,4),imshow(x);title('X图像');
    subplot(2,3,5),imshow(y);title('Y图像');
    subplot(2,3,6),imshow(z);title('Z图像');

    运行结果:

    注:Matlab中没有lena.bmp文件,可以从网上下载,此外imshow(rgb,'notruesize')在Matlab2012中不在支持应改为 imshow(rgb,'InitialMagnification','fit')。



  • 相关阅读:
    POJ 3630 Phone List/POJ 1056 【字典树】
    HDU 1074 Doing Homework【状态压缩DP】
    POJ 1077 Eight【八数码问题】
    状态压缩 POJ 1185 炮兵阵地【状态压缩DP】
    POJ 1806 Manhattan 2025
    POJ 3667 Hotel【经典的线段树】
    状态压缩 POJ 3254 Corn Fields【dp 状态压缩】
    ZOJ 3468 Dice War【PD求概率】
    POJ 2479 Maximum sum【求两个不重叠的连续子串的最大和】
    POJ 3735 Training little cats【矩阵的快速求幂】
  • 原文地址:https://www.cnblogs.com/carl2380/p/14608690.html
Copyright © 2020-2023  润新知