Demo entry 6354685

1

   

Submitted by 1 on Apr 10, 2017 at 10:52
Language: Matlab. Code size: 833 Bytes.

%% init
close all;
clc;
rgb=im2double(imread('11.png'));

%% 方法一:将rgb转成ycbcr后对第三个通道进行处理
ycbcr=rgb2ycbcr(rgb);
cr=ycbcr(:,:,3);
mask1_r=cr>.55;
mask1_g=cr<.45;
s1_r=rgb.*cat(3,mask1_r,mask1_r,mask1_r);
s1_g=rgb.*cat(3,mask1_g,mask1_g,mask1_g);
figure
subplot(131),imshow(rgb),title('原始图像')
subplot(132),imshow(s1_r),title('红色信号')
subplot(133),imshow(s1_g),title('绿色信号')

%% 方法二:对彩色图像用欧氏距离或马氏距离进行阈值分割,这里使用欧氏距离
T_r=[1 0 0];
T_g=[0 1 0];
T=.65;
R=rgb(:,:,1);
G=rgb(:,:,2);
B=rgb(:,:,3);
mask2_r=((R-T_r(1)).^2+(G-T_r(2)).^2+(B-T_r(3)).^2)<T;
mask2_g=((R-T_g(1)).^2+(G-T_g(2)).^2+(B-T_g(3)).^2)<T;
s2_r=rgb.*cat(3,mask2_r,mask2_r,mask2_r);
s2_g=rgb.*cat(3,mask2_g,mask2_g,mask2_g);
figure
subplot(131),imshow(rgb),title('原始图像')
subplot(132),imshow(s2_r),title('红色信号')
subplot(133),imshow(s2_g),title('绿色信号')

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).