Digital image processing Matlab- color image processing (with code)

1.Objectives:

1, the learning RGB, and Gray Indexed between the image transfer function
2, and the control algorithm color image sharpening smoothing
3, the learning of Color Image Segmentation

2.Experiment Content:

To learn and master the following functions: rgb2ind, rgb2gray, gray2ind, ind2gray, ind2rgb, colormap, dither, cat, colorseg

3.Experiment Principle:

See the book.

4.Experiment Steps Result and Conlusion:

1, using inter RGB, Indexed Gray image conversion function, and

Image "Fig0630 (01) (strawberries_fullcolor) .tif" rgb2ind generated using jitter and non jitter 8-color images, respectively; rgb2gray implemented using the image conversion, and dither functions generate their use dithering images.
Here Insert Picture Description
CON: grayscale can be converted only after the order of eight kinds of gray, gray junction of visual information not as a result of jitter before and not very obvious, because the transition has been allowed to shake at the junction
Here Insert Picture Description
CON ; this is still an eight-color indexed image, the comparison with the original, it does not seem so rich in color color. For the shake of the image, we can see some color variation range is relatively large, there will be some small bit, and this is the effect of the jitter, may benefit effect in this picture is not very clear, jitter purpose It is to make the transition color image is not so suddenly, become smooth

2, the color image sharpening smoothing

Image "" Fig0604 (a) (iris) .tif "to achieve a smooth image in the RGB color space (w = ones (25) ./ (25 * 25)) and sharpening (w = [1 1 1 1 1; 11111; 11-2411; 11111; 11111];) (IMFilter function)

In the HSI color space to achieve a smooth image (w = ones (25) ./ (25 * 25)), ( function imfilter, rgb2hsi, cat), was observed only smooth the luminance component (Intensity) and smoothing the difference between the results of all three components of .
Here Insert Picture Description
Here Insert Picture DescriptionIs first filtered in FIG rgb filter, see the entire image becomes smooth, vague, view of the entire image as long as the upper right color change have become acute in places, distinct color change can be seen in the space hsi the filter, intended to smooth see the effect on the strength of i, such that little change in the intensity of each color, each color is more prominent, the filtering HSI all found not clear to see the entire FIG.

3, color image segmentation

Implemented colorseg function based on skin color of face segmentation. Image " 'Fig0636 (woman_baby_original) .tif" In the HSI space, with each function colorseg parameter "euclidean" and "mahalanobis" for face segmentation.
Here Insert Picture Description
This is what we do in the original image segmentation, the right is our elected interested in the region want to split out, we chose the baby's skin, you want to divide the image part of the skin.
Here Insert Picture Description
This is the first use segmentation method, we see that in general can basically separate the skin of some people, seen from the original, the area we selected children forehead skin brighter, so the selected area, children are left half of his face more dark areas would not be split up after the second image segmentation obtained by dividing, dividing basically completed all skin areas, the effect is very good. Therefore, we need to split again when HSI space division, found that all white pictures can not be divided according to the distance of the ellipsoid through this program. So choose divided space in the RDB.

[Appendix] implementation code

A program:

clear all;clc;
f=imread('E:\数字图像处理\程序与图像\图像库\Fig0630(01)(strawberries_fullcolor).tif');
[f1,map1]=rgb2ind(f,8,'nodither');%将rgb图像转化为索引图像,且索引图像为8种颜色,不抖动
figure(1);
subplot(1,2,1);
imshow(f1,map1);
title("rgb2ind无抖动");
[f2,map2]=rgb2ind(f,8,'dither');%将rgb图像转化为索引图像,且索引图像为8种颜色,有抖动
subplot(1,2,2);
imshow(f2,map2);
title("rgb2indy有抖动"); 

f3=rgb2gray(f);%将rgb图像转化为灰度图像,且灰度图像为8种颜色,不抖动
figure(2);
subplot(1,2,1);
imshow(f3,[]);
title("rgb2gray无抖动");
f4=dither(f3);
subplot(1,2,2);imshow(f4,[]);
title("rgb2gray有抖动");

Procedure 2

clear all;clc;
f=imread('E:\数字图像处理\程序与图像\图像库\Fig0604(a)(iris).tif');
w=ones(25)./(25*25);
f_filtered=imfilter(f,w,'replicate');
figure(1);
subplot(1,3,1);
imshow(f,[]);
title("原图");
subplot(1,3,2);
imshow(f_filtered,[]);
title("rgb平滑后图像");
fb=f;w=[1 1 1 1 1;1 1 1 1 1;1 1 -24 1 1;1 1 1 1 1;1 1 1 1 1];%拉普拉斯算子
fen=fb-imfilter(fb,w,'replicate');%锐化处理
subplot(1,3,3);imshow(fen,[]);title("rgb锐化后图像");  

addpath('E:\大三下\数字图像处理(通一)\程序与图像\dipum_toolbox_2.0.2(only run)');%添加相应的.p文件 

hsi=rgb2hsi(f);%得到hsi空间的图像
h=hsi(:,:,1);%得到hsi空间的色调,饱和度,亮度分量
s=hsi(:,:,2);i=hsi(:,:,3);
w=ones(25)./(25*25);%滤波器参数
i_filtered=imfilter(i,w,'replicate');%对亮度进行平滑处理
hsi1=cat(3,h,s,i_filtered);
f1=hsi2rgb(hsi1);%转化为rgb图像
figure(2);
subplot(1,3,1);imshow(f,[]);title("原图");
subplot(1,3,2);imshow(f1,[]);title("hsi亮度平滑");

h_filtered=imfilter(h,w,'replicate');
i_filtered=imfilter(i,w,'replicate');
s_filtered=imfilter(s,w,'replicate');
hsi2=cat(3,h_filtered,s_filtered,i_filtered);
f2=hsi2rgb(hsi2);%转化为rgb图像
subplot(1,3,3);imshow(f2,[]);title("hsi三个分量平滑");

Procedure 3:

clear all;clc;
rgb_image=imread('E:\数字图像处理\程序与图像\图像库\Fig0636(woman_baby_original).tif');
figure(2);
imshow(rgb_image);
mask=roipoly(rgb_image);%获得感兴趣区域,感兴趣区域值为1,其余值为0 
red=immultiply(mask,rgb_image(:,:,1));
green=immultiply(mask,rgb_image(:,:,2));
blue=immultiply(mask,rgb_image(:,:,3));%分别获得感兴趣区域rgb矩阵的值;
g=cat(3,red,green,blue);
figure(3);
imshow(g);
%显示感兴趣区域

%求感兴趣区域的均值与协方差矩阵
[M,N,K]=size(g);
I=reshape(g,M*N,3);%将g变成一个m*n行3列的矩阵
idx=find(mask);%返回mask中不为0区域的行坐标(这一步是先把图像都变成一列矩阵处理的,因此返回的是一个列矩阵)
I=double(I(idx,1:3));
[C,m]=covmatrix(I);%求协矩阵与均值
d=diag(C);%返回矩阵对角线行的元素
sd=sqrt(d);%求出标准差 

E25=colorseg('euclidean',rgb_image,25,m);%这里使用'euclidean'进行分割,选取阈值为25
M25=colorseg('mahalanobis',rgb_image,25,m,C);%这里使用'mahalanobis'进行分割,选取阈值为25
figure(4);
subplot(211);imshow(E25);
subplot(212);imshow(M25);

Image: Screenshot above all to show

Published 17 original articles · won praise 12 · views 1661

Guess you like

Origin blog.csdn.net/weixin_42784535/article/details/105123604