A list,

1 Grayscale

The process of transforming color image into grayscale image is called image grayscale. The pixel value in the color image is determined by the RGB three components, and each component has 0-255 (256) options, so that the pixel value of a pixel point can have 16 million possibilities (256256256), while the pixel value of the gray map is a special color image with the same values of the RGB three components, with only 256 possibilities. Therefore, in image processing, all kinds of images are often grayscale into grayscale images first for subsequent processing, reducing the amount of calculation. Gray scale refers to the image that contains only brightness information but no color information. A black and white photograph is a gray scale, characterized by a continuous change in brightness from dark to light. The description of grayscale image, like color image, still reflects the distribution and characteristics of overall and local chromaticity and brightness level of the whole image.

The advantages of using grayscale map: ① RGB values are the same. ② The image data is the palette index value, which is the actual RGB value, which is the brightness value. ③ Because of the 256 color palette, one byte in the image data represents one pixel, very neatly. Therefore, do image processing generally adopt grayscale map. To represent the grayscale image, it is necessary to quantify the brightness value. There are four methods:

(1) The component method takes the brightness of the three components in the color image as the gray value of the three gray images, and can select a gray image according to the application needs. (2) The maximum method takes the maximum brightness of the three components in the color image as the gray value of the gray image. (3) The mean value method averages the brightness of the three components in the color image to obtain the gray value of the gray image. (4) Weighted average method according to the importance and other indicators, the three components are weighted average with different weights. Since human eyes are most sensitive to green and least sensitive to blue, a more reasonable grayscale image can be obtained by weighted average of RGB three components according to the following formula, f(I,j)= 0.30r (I,j)+ 0.59g (I,j)+ 0.11b (I,j)).

2. Binaryzation

Image binarization is to set the gray value of pixels on the image to 0 or 255, that is, the whole image presents an obvious black and white effect. The binarization image which can still reflect the whole and local features of the image can be obtained by selecting the appropriate threshold value for 256 gray images of brightness levels. All pixels with a gray value greater than or equal to the threshold are deemed to belong to a particular object and have a gray value of 255, otherwise they are excluded from the object area and a gray value of 0 represents the background or exceptional object area. In digital image processing, binary image plays a very important role. First of all, the binary image is conducive to further image processing, making the image simple, and the amount of data is reduced, which can highlight the outline of the target of interest. Secondly, to carry on the binary image processing and analysis, first of all to the gray image binarization, binarization image. Common binarization algorithms are:

Global binarization: an image includes target object, background and noise. In order to directly extract target object from multi-value digital image, the most commonly used method is to set a global threshold value T and use T to divide the image data into two parts: pixel group larger than T and pixel group smaller than T. Set the pixel value of the pixel group greater than T to white (or black), and the pixel value of the pixel group less than T to black (or white). Global binarization has great defects in the representation of image details. In order to make up for this defect, local binarization method is introduced.

Local binarization: the whole image is divided into N Windows according to certain rules, and the pixels in each of these N Windows are divided into two parts according to a unified threshold T for binarization processing. Local binarization also has a drawback. This flaw exists in the selection of the uniform threshold. This threshold value is obtained without reasonable operation, and is generally the parity value of the window. As a result, the global binarization defect still appears in every window. In order to solve this problem, a local adaptive binarization method appears.

Local adaptive binarization: on the basis of local binarization, the threshold setting is more reasonable. The threshold of this method is calculated by setting a parametric equation based on various local features such as the mean value E of pixels in the window, the square difference P between pixels, and the root mean square value Q between pixels, for example: T=aE+bP+ C *Q, where a, B, and C are free parameters. In this way, the binaryized image can better show the details in the binaryized image.

The actual meaning of inverse color is to reverse the values of R, G and B. If the quantization level of the color is 256, the R, G, and B values of the new image are 255 minus the R, G, and B values of the original image. This is for all images, including true color, color with color palette (also known as false color), and grayscale. True color map without color palette, each pixel with 3 bytes, representing R, G, B three components. So the processing is very simple, write the inverted values of R, G and B into the new graph, for example, a point color is (0,0,0), the inverted color is (255,255,255). In a color map with a color palette, the data in the bitmap is only an index value in the corresponding color palette. We only need to reverse the colors in the color palette to form a new color palette, and the bitmap data can be reversed without moving.

Ii. Source code

clc; % Clear the contents of the command window close all; % Clear all figure Windows; % I=imread (I=imread ('C:\Users\lenovo\Desktop\ New folder \1.png'); % subplot(331); % Set the image display style, three lines and three columns, display position as the first imshow (I); % show original title('original'); % I = imnoise(I,'speckle'.0.8); % add speckle noise to simulate real noise interference subplot(332); % display position for second imshow(I); % Show denoised image title('add noise'); R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3); % The R,G and B components of the color image after denoising are stored in the matrix R,G and B respectively R= Wiener2 (R,[15.15]); % Wiener filtering for R component matrix G= Wiener2 (G,10.10]); % Wiener filtering for G component matrix B= Wiener2 (B,5.5]); % Wiener filtering is performed on the B component matrix1)=R;
I(:,:,2)=G;
I(:,:,3)=B; % Restore the filtered R,G and B components to the image. I is the filtered color image subplot(333); % display position for the third imshow(I); % Display filtered image title('Wiener filtered'); % R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3); % The R,G and B component data of the image are stored in the matrices R,G and B respectively, R((R<=60|R>=130)|(G<=120|G>=180=))255; % R,G,B components G((R<=) of mosquito coil and background were obtained by using Photoshop60|R>=130)|(G<=120|G>=180=))255;
B((R<=60|R>=130)|(G<=120|G>=180=))255; % The data in the matrix of R,G and B components are processed, and those not in the color range of mosquito coil are set as white I(:,:,1)=R;
I(:,:,2)=G;
I(:,:,3)=B; % Assign the processed tricolor data to the original image I1= rGB2gray (I); % Convert true color image to grayscale image subplot(334); % display position is the fourth imshow(I1); % Display gray image title('Grayscale image'); % name it "grayscale image" thresh=graythresh(I1); % Using grathresh function, find the appropriate threshold of gray image I2= IM2BW (I1, THRESH); % Use threshold to turn gray image into binary image subplot(335); % display position for the fifth imshow(I2); % displays a binary imageI2
title('Binary image'); % name it "binary image" SE0=strel('disk'.5); % Before performing expansion and corrosion operations, a mask needs to be created. Here, create a radius of5, SE0 is a matrix SE= Strel ('disk'.12); % Before performing expansion and corrosion operations, a mask needs to be created. Here, create a radius of12,SE is a matrix I2=imdilate(I2,SE0); % Perform the expansion operation, the white part expands, and eliminate the noise (mainly boundary area) that is not filtered clean by Wiener filter336); % display position is first6aCopy the code

3. Operation results

Fourth, note

Version: 2014 a