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

去红眼不完善MATLAB代码

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

 

[FileName,PathName] = uigetfile('*.jpg');

imgdata = imread(FileName);

rgb = imgdata;

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

rgb = im2double(rgb);

r = rgb(:,:,1);

g = rgb(:,:,2);

b = rgb(:,:,3);

 

num = 0.5*( (r - g) + ( r - b ) );

den = sqrt( (r - g).^2 + (r-b).*(g-b) );

theta = acos(num ./ (den + eps));

 

H=theta;

H(b>g)=2*pi-H(b>g);

H=H/(2*pi);

 

num=min(min(r,g),b);

den=r+g+b;

den(den==0)=eps;

S=1-3.*num./den;

H(S==0)=0;

I=(r+g+b)/3;

%Combine all three results into an hsi image.

[width,height] = size(rgb);

 

height = height/3;

 

 

for i=1:width

    for j = 1:height

        h = H(i,j);

        s = S(i,j);

        if s>0.3

            if h < 3.1415926/4

                if h > -3.1415926/4

                    S(i,j,:) = 0;

                end

            end

                  %  rgb11(i,j,:) = I(i,j);

            

        end

        

    end

end

 

 

hsi=cat(3,H,S,I);

 

 

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

 

H=hsi(:,:,1)*2*pi;

S=hsi(:,:,2);

I=hsi(:,:,3);

 

%Implement the conversion equations.

R=zeros(size(hsi,1),size(hsi,2));

G=zeros(size(hsi,1),size(hsi,2));

B=zeros(size(hsi,1),size(hsi,2));

 

% RG sector (0<=H<2*pi/3).

idx=find((0<=H)&(H<2*pi/3));

B(idx)=I(idx).*(1-S(idx));

R(idx)=I(idx).*(1+S(idx).*cos(H(idx))./cos(pi/3-H(idx)));

G(idx)=3*I(idx)-(R(idx)+B(idx));

%BG sector (2*pi/3<=H<4*pi/3).

idx=find((2*pi/3<=H)&(H<4*pi/3));

R(idx)=I(idx).*(1-S(idx));

G(idx)=I(idx).*(1+S(idx).*cos(H(idx)-2*pi/3)./cos(pi-H(idx)));

B(idx)=3*I(idx)-(R(idx)+G(idx));

%BR sector.

idx=find((4*pi/3<=H)&(H<=2*pi));

G(idx)=I(idx).*(1-S(idx));

B(idx)=I(idx).*(1+S(idx).*cos(H(idx)-4*pi/3)./cos(5*pi/3-H(idx)));

R(idx)=3*I(idx)-(G(idx)+B(idx));

%Combine all three results into an RGB image. Clip to [0,1] to compensate for floating-point arithmetic rounding effects.

rgb=cat(3,R,G,B);

rgb=max(min(rgb,1),0);

 

rgb11 = rgb;

 

 

 

imshow(rgb11);

 

figure(1);

imshow(H);

 

figure(2);

imshow(I);

 

figure(3);

imshow(S);

 


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Delphi的DirectShow开发概述发布时间:2022-07-18
下一篇:
理解 Delphi 的类(十) - 深入方法[16] - 方法的顺序发布时间: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