实验四、彩色图像处理

  • 实验目的

使用MatLab软件对图像进行彩色处理,熟悉使用MatLab软件进行图像彩色处理的有关方法,并体会到图像彩色处理技术以及对图像处理的效果。

  • 作业1:生成一副256*256的RGB图像,使得该图像左上角为黄色或者青色,左下角为蓝色,右上角为绿色,右下角为黑色。

rgb_R=zeros(256, 256); %红色分量

rgb_R(1:128,1:128)=1;

rgb_G=zeros(256, 256); %绿色分量

rgb_G(1:128,1:256)=1;

rgb_B=zeros(256, 256); %蓝色分量

rgb_B(128:256,1:128)=1;

rgb=cat(3,rgb_R,rgb_G,rgb_B); %生成一副RGB彩色图像的基本语法

imshow(rgb);title('RGB 彩色图像')

 

  • 作业2:利用作业1生成的RGB图像展示其R、G、B三个分量与RGB图;将其转化为HSI彩色模型,然后展示H、S、I三个分量及HSI图。

I=RGB;

r=I(:,:,1);

g=I(:,:,2);

b=I(:,:,3);

figure;

subplot(2,2,1);imshow(I);title('RGB彩色图像');

subplot(2,2,2);imshow(r);title('R分量');

subplot(2,2,3);imshow(g);title('G分量');

subplot(2,2,4);imshow(b);title('B分量');

hsi = rgb2hsv(I);

h=hsi(:,:,1);

s=hsi(:,:,2);

i=hsi(:,:,3);

figure;

subplot(2,3,1);imshow(I);title('original image');

subplot(2,3,2);imshow(hsi);title('HSI彩色图形');

subplot(2,3,4);imshow(h);title('色调H');

subplot(2,3,5);imshow(s);title('饱和度S');

subplot(2,3,6);imshow(i);title('亮度I');

rgb_hsi=hsv2rgb(hsi);

subplot(2,3,3);imshow(rgb_hsi);title('RGB彩色图形');

 

  • 作业3:将作业1中的图像进行上下镜像。

image=imread('D:\ALLDOWNLOAD\实验四、彩色图像处理\彩色图像处理\shiyan4.1.png');

res = im2uint8(zeros(size(image)));%生成image图像大小的0值unit8图片

[rows,cols,n] = size(image); % 图像行列数

res1 = im2uint8(zeros([rows,cols]));

res2 = im2uint8(zeros([rows,cols]));

res3 = im2uint8(zeros([rows,cols]));

temp1 = image(:, :, 1);

temp2 = image(:, :, 2);

temp3 = image(:, :, 3);

for i = 1:rows

for j = 1:cols

% 左右镜像

res1(rows-i+1,j) = temp1(i,j);

res2(rows-i+1,j) = temp2(i,j);

res3(rows-i+1,j) = temp3(i,j);

end

end

res(:, :, 1) = res1;

res(:, :, 2) = res2;

res(:, :, 3) = res3;

res = uint8(res);

subplot(121),imshow(image);

subplot(122),imshow(res);

 

  • 作业4:对例3的图片进行5x5均值滤波后的图片进行拉普拉斯锐化并显示。

>> f=imread('D:\ALLDOWNLOAD\实验四、彩色图像处理\彩色图像处理\lena_color.bmp');

w=ones(5)/(5*5);

f1=imfilter(f,w,'replicate');

w4=fspecial('laplacian',0);

w8=[1 1 1; 1 -8 1; 1 1 1];

g4=imfilter(f,w4,'replicate');

figure,imshow(g4),title('g4');

g4g=f-g4;

figure,imshow(g4g),title('g4g');

g8=imfilter(f,w8,'replicate');

f2=im2double(f);g8_f2=imfilter(f2,w8,'replicate');

figure,

subplot(221),imshow(g8),title('g8');

subplot(222),imshow(g8_f2),title('g8_f2');

g8g_f2=f2-g8_f2;

g8g=f-g8;

figure

subplot(223),imshow(g8g),title('g8g');

subplot(224),imshow(g8g_f2),title('g8g_f2');

>>

 

  • 作业5:采用’canny’方法寻找彩色边缘;或者自选一幅图像计算彩色图像的梯度并绘图。

I=imread('D:\ALLDOWNLOAD\实验四、彩色图像处理\彩色图像处理\lena_color.bmp');

subplot(231),imshow(I);title('原图像');%显示原图像

% edge - 查找强度图像的边缘

% 此 MATLAB 函数 返回二值图像 BW,其中的值 1 对应于灰度或二值图像 I 中函数找到边缘的位置,值 0 对应于其他位置。默认情况下,edge 使用 Sobel 边缘检测方法。

I_R=I(:,:,1);

BW1_R=edge(I_R,'sobel');

I_G=I(:,:,2);

BW1_G=edge(I_G,'sobel');

I_B=I(:,:,3);

BW1_B=edge(I_B,'sobel');

out(:,:,1)=BW1_R;

out(:,:,2)=BW1_G;

out(:,:,3)=BW1_B;

subplot(232);imshow(double(out),[]);title('out3arrays');

out2=cat(3,BW1_R,BW1_G,BW1_B);

subplot(233);imshow(double(out2),[]);title('cat3arrays');

%f 是RGB 图像,T是[0,1]范围内的阈值选项(默认为0);VG是RGB向量梯度F(x, y);

%A 是以弧度计的角度θ(x, y),并且PPG 是由单独彩色平面的2D 梯度之和形成的梯度图像

[VG,A,PPG]=colorgrad(I);%计算彩色图像的梯度

subplot(234);imshow(VG);title('VG');

subplot(235);imshow(A);title('A');

subplot(236);imshow(PPG);title('PPG');

 

 

I=imread('D:\ALLDOWNLOAD\彩色图像处理-实验\你的图.tif');

subplot(331),imshow(I);title('原图像');

I_R=I(:,:,1);

BW1_R=edge(I_R,'sobel');

I_G=I(:,:,2);

BW1_G=edge(I_G,'sobel');

I_B=I(:,:,3);

BW1_B=edge(I_B,'sobel');

out(:,:,1)=BW1_R;

out(:,:,2)=BW1_G;

out(:,:,3)=BW1_B;

subplot(332);imshow(double(out),[]);title('out3arrays');

out2=cat(3,BW1_R,BW1_G,BW1_B);

subplot(333);imshow(double(out2),[]);title('cat3arrays');

[VG,A,PPG]=colorgrad(I);

subplot(334);imshow(VG);title('VG');

subplot(335);imshow(A);title('A');

subplot(336);imshow(PPG);title('PPG');

subplot(337);imshow(BW1_R);title('Red Sobel edge');

 

 

应用:证件照更换底色(附加内容,自愿)

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值