• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

RGB颜色空间转HSI颜色空间的matlab程序实现

原作者: [db:作者] 来自: [db:来源] 收藏 邀请


RGB 颜色空间转 HSI 颜色空间的matlab程序实现



2014.10.20之前的内容有误,这里依据wikipedia更新了算法内容. 算法以wiki为准

https://en.wikipedia.org/wiki/HSL_and_HSV


这里demo出 HSI中 S 空间的图像和暗通道图的对照.

会发现,确实右边到非常暗,这是由于HSV转换的时候对RGB值做了归一化处理,假设打印出归一化处理后的R+G+B值会发现输出图像非常亮(白茫茫一片~)



下图是取自图像第321列的数据分布,能够看见图像的灰度分布是非常明晰的




以下给出了我写的转换函数,直接调用就可以.

%%************************************************************************** 
% Function writer : EOF
% code file       : RGB2SHI_Color.m
% code date       : 2014.10.16
% Translate RGB into HSI-space
%
% Code Description:
%
%       If you want to translate a colourful Image which is coded as
% RGB colour space into HSI space, what you need to do is just input your
% colour image.
%
% This function would return HSI as a matrix [H,S,I].
%
%% *************************************************************************
function [H,S,I] = RGB2SHI_Color(Image)

        if size(Image,3) ~= 3
            fprintf('ERROR Imput-Image must be three channel image\n');
            return;
        end
        
        Height_Image  = size(Image,1);
        Width_Image   = size(Image,2);
        Channel_Image = size(Image,3);

        H      = zeros(1,Height_Image * Width_Image);
        H_temp = zeros(1,Height_Image * Width_Image);
        S      = zeros(1,Height_Image * Width_Image);
        I      = zeros(1,Height_Image * Width_Image);
        %% Normalization into (0,1)
        R_temp = double(Image(:,:,1));
        G_temp = double(Image(:,:,2));
        B_temp = double(Image(:,:,3));

        R = R_temp./(R_temp + G_temp + B_temp);
        G = G_temp./(R_temp + G_temp + B_temp);
        B = B_temp./(R_temp + G_temp + B_temp);

        
        Max_channel = max(max(R,G),B);
        Min_channel = min(min(R,G),B);
        Difference  = Max_channel - Min_channel;
        
        I = (R + G + B)./3;
        
        for row = 1:Height_Image
            for col = 1: Width_Image
                
                % In fact , if Difference(row,col) is zero, the H_temp is 
                % undefine , it means that H_temp(row,col) close to
                % infinite.
                if Difference(row,col) == 0
                    H_temp(row,col) = 0;
                end
                
                if Max_channel(row,col) == R(row,col)
                    H_temp(row,col) = mod((G(row,col) - B(row,col)) ...
                        ./Difference(row,col), 6 );
                end
                
                if Max_channel(row,col) == G(row,col)
                    H_temp(row,col) = (B(row,col) - R(row,col)) ...
                        ./Difference(row,col) + 2;
                end
                
                if Max_channel(row,col) == B(row,col)
                    H_temp(row,col) = (B(row,col) - R(row,col)) ...
                        ./Difference(row,col) + 4;
                end       
                
                H(row,col) = H_temp(row,col)*60;
                
                if I(row,col) == 0
                    S(row,col) = 0;
                else
                    S(row,col) = 1 - (Min_channel(row,col)./I(row,col));
                end
            end
        end
       
end





鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
论文学习心得 DELPHI: A Cryptographic Inference Service for Neural Networks发布时间:2022-07-18
下一篇:
delphi7project--options打开出错发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap