This is the 19th day of my participation in the August More Text Challenge
1.Objectives:
1. Learn the conversion function between RGB, Indexed and Gray images; 2. Master the algorithm of color image smoothing and sharpening; 3
2. The Experiment Content:
Rgb2ind, RGB2Gray, gray2IND, IND2gray, IND2RGB,colormap, dither, cat, colorseg
3.Experiment Principle:
See book digital Image Processing
(By Gonzalez, published by Publishing House of Electronics Industry on December 1, 2009)
4.Experiment Steps Result and Conlusion:
1. Use conversion functions between RGB, Indexed, and Gray images
For the image “Fig0630(01)(strawberries_fullcolor).tif”, rGB2IND is used to generate 8-color dithered and non-dithered images respectively. Use RGB2Gray image conversion, and make use of function dither to produce its dither form of the image.CON: The converted grayscale image has only eight grayscale levels. The visual vision is not as clear as the previous information jitter, and the gray interface is not obvious, because the jitter makes it transition at the junctionCON; This is still an eight-color index image, so the color is not as rich as the original image. For the jitter image, we can see that in the case of some large color changes, there will be some small dots, this is the effect of jitter, may be the benefit of this picture, not very obvious, the purpose of jitter is to make the image color transition is not so sudden, become smooth
2, color image smooth sharpening
The image “” Fig0604 (a) (iris). Tif” the color image in RGB space smooth (w = ones (25)/(25 * 25)) and sharpening (w = [1 1 1 1 1 1 1 1 1; 1; 1 1 1 1-24; 1 1 1 1 1; 1 1 1 1 1];) (Function imfilter)
In the HSI space, the color image is smooth (w=ones (25)./(25*25)), (function IMfilter, RGB2HSI, CAT), and the differences between the results of smoothing only the intensity and the whole three components are observed.
Filtering the first figure is filtering on RGB, see the whole image is smoothed, vague, YouShangTu the entire image with color change places become sharp rise, can see the obvious color change, in hsi space filtering, see to I smooth effect on strength, the strength of the color of the little change, That is, every color is more prominent. Hsi filters all of them and finds that the whole picture is not very clear.
3. Color image segmentation
With colorseg function based on the skin color of the face cut. Figure “‘Fig0636(woman_baby_original). Tif” in the HSI space, with the function colorseg respectively with parameters “Euclidean” and “mahalanobis” to achieve face segmentation.This is the original image that we did the image segmentation, and on the right is the area that we selected that we were interested in, that we wanted to segment, and we chose the skin of the baby, and we wanted to segment the skin part of the image.This is to use the first method, generally we can see that the basic cent gives a person’s skin part, from the original image, we choose children in the area of forehead skin more bright, so in selected areas, children left side face relatively dark area is not split out after the second segmentation method for image segmentation, basic completed all skin area of the break up, It worked out pretty well. Therefore, we need to use this scheme to segment the image according to the distance of ellipsoid. When we segment the image in HSI space, we find that the image is completely white and cannot be segmented. Therefore, the RDB space is selected for segmentation.
[Appendix] Implementation code
A program:
clear all; clc; f=imread('E: digital Image Processing, Programs and Images, Image Library, Fig0630(01)(strawberries_fullcolor).tif');
[f1,map1]=rgb2ind(f,8,'nodither'); % Convert RGB image to index image, and index image is 8 colors, without dithering figure(1); Subplot (1, 2, 1); imshow(f1,map1); title("Rgb2ind no jitter");
[f2,map2]=rgb2ind(f,8,'dither'); % convert RGB images into index images with 8 colors and dither subplot(1,2,2); imshow(f2,map2); title("Rgb2indy has jitter"); f3=rgb2gray(f); % Convert RGB image to gray image, and gray image is 8 colors, without dithering figure(2); Subplot (1, 2, 1); imshow(f3,[]); title("Rgb2gray no jitter"); f4=dither(f3); Subplot (1,2,2); imshow(f4,[]); title("Rgb2gray has jitter");
Copy the code
Program 2
clear all; clc; f=imread('E: Digital Image Processing, Programs and Images, Image Library, Fig0604(a)(iris).tif');
w=ones(25)./(25*25);
f_filtered=imfilter(f,w,'replicate'); figure(1); Subplot (1,3,1); imshow(f,[]); title("Original"); Subplot (1, 31); imshow(f_filtered,[]); title("RGB smoothed image"); 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]; % Laplacian fen=fb-imfilter(fb,w,'replicate'); % sharpen subplot(1,3,3); imshow(fen,[]); title("RGB sharpened image");
addpath(E: digital Image Processing (General) Programs and Images dipum_toolbox_2.0.2(only run)'); % add corresponding. P file hsi=rgb2hsi(f); % get the image of HSI space h=hsi(:,:,1); % to obtain the hue, saturation and brightness components of HSI space s= HSi (:,:,2); i=hsi(:,:,3); w=ones(25)./(25*25); % filter parameter i_filtered=imfilter(I,w,'replicate'); Hsi1 = CAT (3, H, S, I_filtered); f1=hsi2rgb(hsi1); % into RGB image Figure (2); Subplot (1,3,1); imshow(f,[]); title("Original"); Subplot (1, 31); imshow(f1,[]); title("Hsi brightness smoothing");
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); % convert to RGB image subplot(1,3,3); imshow(f2,[]); title("Hsi three-component smoothing");
Copy the code
Three procedures:
clear all; clc; rgb_image=imread(Figure 0636(woman_baby_original).tif'); figure(2); imshow(rgb_image); mask=roipoly(rgb_image); Rgb_image (:,:,1) red=immultiply(mask, rGB_image (:,:,1)); green=immultiply(mask,rgb_image(:,:,2)); blue=immultiply(mask,rgb_image(:,:,3)); % respectively to obtain the value of the RGB matrix of the region of interest; g=cat(3,red,green,blue); figure(3); imshow(g); % Show region of interest % Find the mean and covariance matrix [M,N,K]=size(g); I=reshape(g,M*N,3); % change g to a matrix with m*n rows and 3 columns idx=find(mask); I=double(I(idx,1:3)); I=double(I(idx,1:3)); [C,m]=covmatrix(I); % comatrix and mean d=diag(C); % return sd= SQRT (d); % E25=colorseg('euclidean',rgb_image,25,m); % is used here'euclidean'M25=colorseg('mahalanobis',rgb_image,25,m,C); % is used here'mahalanobis'Figure (4); Figure (4); subplot(211); imshow(E25); subplot(212); imshow(M25);Copy the code
Image: All above are shown in screenshots
Code word is not easy, all see here as well as a point of praise oh ~ I also wrote a lot of articles, welcome to pay attention to me oh ~