matlab 色彩布局描述符(Color layout descriptor)

%color layout descriptor (CLD)
%im = imread('cs.jpg');
function result = CLD(im)

% 1.图像分割 代表色彩选择 
n = 8;  %8 * 8 = 64块
[height,width,channal] = size(im);
block_h = fix(height/n); %块高度
block_w = fix(width/n);  %块宽度
im_n = zeros(n,n,channal);  %存放8x8的微小图像
for i = 1:n
    for j = 1:n
        for k = 1:channal
            % 确定块 
            a = block_h * (i-1)+1;  b = block_h * i; %高 a-b
            c = block_w * (j-1)+1;  d = block_w * j; %宽 c-d
            % 边界情况(右下块)
            if(i == n)   
                b = height;  end
            if(j == n)
                d = width;   end
            % 块代表色选择 这里选择平均值
            pix = mean(mean(im(a:b,c:d,k))); %计算块中像素平均值
            im_n(i,j,k) =  pix;              %赋值
        end
    end
end
%disp(im_n);

% 2.转换为YCbCr色彩空间 取值范围
im_YCbCr = rgb2ycbcr(im_n);  
%disp(im_YCbCr);

% 3.DCT变换
A = dctmtx(8); 
im_DCT = zeros(n,n,channal); %存放结果
im_DCT(:,:,1) = A * im_YCbCr(:,:,1) * A'; %DCT_Y
im_DCT(:,:,2) = A * im_YCbCr(:,:,2) * A'; %DCT_Cb
im_DCT(:,:,3) = A * im_YCbCr(:,:,3) * A'; %DCT_Cr
%disp(im_DCT);

% 4.使用q(量化矩阵)进行量化 典型的量化矩阵(质量为原始JPEG标准中规定的50%)
q = [16  11  10  16   24   40   51   61
     12  12  14  19   26   58   60   55
     14  13  16  24   40   57   69   56
     14  17  22  29   51   87   80   62
     18  22  37  56   68  109  103   77
     24  35  55  64   81  104  113   92
     49  64  78  87  103  121  120  101
     72  92  95  98  112  100  103   99];
im_DCT(:,:,1) = im_DCT(:,:,1)./q;
im_DCT(:,:,2) = im_DCT(:,:,2)./q;
im_DCT(:,:,3) = im_DCT(:,:,3)./q;

% 5.按照zig扫描im_DCT 存储到descript中
zig = [1     2     6     7    15    16    28    29
       3     5     8    14    17    27    30    43
       4     9    13    18    26    31    42    44
      10    12    19    25    32    41    45    54
      11    20    24    33    40    46    53    55
      21    23    34    39    47    52    56    61
      22    35    38    48    51    57    60    62
      36    37    49    50    58    59    63    64 ];
descript = zeros(n^2,channal);  
for i = 1:n
    for j = 1:n
        descript(zig(i,j),:) = im_DCT(i,j,:);
    end
end
%disp(descript);
%result(:,1) = DY  result(:,2) = DCb  result(:,3) = DCr 

% 6.结果赋值
result = descript;


%{
参考:
https://zhuanlan.zhihu.com/p/85299446                          详解离散余弦变换(DCT)
https://blog.csdn.net/dugudaibo/article/details/78410570       离散余弦变换(DCT)的来龙去脉
https://www.cnblogs.com/dujuan/archive/2012/02/02/2335237.html 颜色布局描述符(CLD)在Matlab中的实现
http://en.wikipedia.org/wiki/Color_layout_descriptor           Color layout descriptor
*https://en.wikipedia.org/wiki/Jpeg#Discrete_cosine_transform  JPEG-包含一个更容易理解的DCT转换示例
%}   
% 图像匹配 
% D_CLD为两个描述符之间的距离 2幅图像在距离接近0的情况下是相似的

function D_CLD = D(im1,im2)
CLD_im1 = CLD(im1);
CLD_im2 = CLD(im2);

% 计算距离  
D_2  = (CLD_im1 - CLD_im2).^2;
D_DY  = sum(D_2(:,1));
D_DCb = sum(D_2(:,2)); 
D_DCr = sum(D_2(:,3)); 
D_CLD = sqrt(D_DY) + sqrt(D_DCb) + sqrt(D_DCr);

%disp(D_CLD);

参考:
https://zhuanlan.zhihu.com/p/85299446                                                 详解离散余弦变换(DCT)
https://blog.csdn.net/dugudaibo/article/details/78410570                    离散余弦变换(DCT)的来龙去脉
https://www.cnblogs.com/dujuan/archive/2012/02/02/2335237.html   颜色布局描述符(CLD)在Matlab中的实现
http://en.wikipedia.org/wiki/Color_layout_descriptor                           维基百科 Color layout descriptor
*https://en.wikipedia.org/wiki/Jpeg#Discrete_cosine_transform         JPEG-包含一个更容易理解的DCT转换示例

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大米粥哥哥

感谢认可!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值