Original post address: http://blog.verycd.com/ari/showentry=48371
I. Read and Write image files
1 imread
The imread function is used to read various image files, such as a = imread ('e:/w01.tif ')
Note: The corresponding. tif file w01 must be available on the computer's elastic drive.
2 imwrite
The imwrite function is used to write image files, such as imwrite (a, 'e:/w02.tif ', 'tif ')
3 imfinfo
The imfinfo function is used to read information about an image file, for example, imfinfo ('e:/w01.tif ')
2. Image Display
1 image
The image function is the most primitive image display function provided by MATLAB, such:
A = [1, 2, 3, 4; 4, 5, 6, 7; 8, 9, 10, 11, 12];
Image ();
2 imshow
The imshow function is used to display image files, for example:
I = imread ('e:/w01.tif ');
Imshow (I );
3 colorbar
The colorbar function displays the color bar of an image, for example:
I = imread ('e:/w01.tif ');
Imshow (I );
Colorbar;
4. figure
The figure function is used to set the image display window, for example, figure (1);/figure (2 );
Three-image transformation
1 fft2
The fft2 function is used for two-dimensional Fourier transformation of digital images, for example:
I = imread ('e:/w01.tif ');
J = fft2 (I );
2 ifft2
The ifft2 function is used for two-dimensional Fourier inverse transformation of digital images, such:
I = imread ('e:/w01.tif ');
J = fft2 (I );
K = ifft2 (j );
3. Use fft2 to calculate two-dimensional convolution
The fft2 function can be used to calculate two-dimensional convolution, for example:
A = [8, 1, 6; 3, 5, 7; 4, 9, 2];
B = [, 1;, 1;, 1];
A (8, 8) = 0;
B (8, 8) = 0;
C = ifft2 (fft2 (a). * fft2 ();
C = c );
Conv2 (two-dimensional convolution function) is used for verification, for example:
A = [8, 1, 6; 3, 5, 7; 4, 9, 2];
B = [, 1;, 1;, 1];
C = conv2 (,;
Four functions for generating analog noise and predefined Filters
1 imnoise
The imnoise function is used to generate analog noise for an image, for example:
I = imread ('e:/w01.tif ');
J = imnoise (I, 'gaussian ', 0, 0.02); % simulate gaussian Noise
2 fspecial
The fspecial function is used to generate a predefined filter, for example:
H = fspecial ('sobel '); % sobel horizontal edge enhancement Filter
H = fspecial ('gaussian '); % gaussian low-pass filter
H = fspecial ('laplacian '); % Laplace Filter
H = fspecial ('log'); % Gaussian Laplace (log) Filter
H = fspecial ('average'); % Mean Filter
5. Image Enhancement
1 Histogram
The imhist function is used to display the histogram of a digital image, for example:
I = imread ('e:/w01.tif ');
Imhist (I );
2 histogram homogenization
The histeq function is used to normalize the histogram of digital images, for example:
I = imread ('e:/w01.tif ');
J = histeq (I );
3. Contrast Adjustment
The imadjust function is used to adjust the contrast of a digital image, for example:
I = imread ('e:/w01.tif ');
J = imadjust (I, [0.3, 0.7], []);
4 logarithm Transformation
The log function is used to convert the logarithm of a digital image, for example:
I = imread ('e:/w01.tif ');
J = double (I );
K = log (j );
5 Convolution-based image filtering functions
The filter2 function is used for image filtering, for example:
I = imread ('e:/w01.tif ');
H = [, 1;, 0;-1,-2,-1];
J = filter2 (H, I );
6. linear filtering
Use two-dimensional conv2 convolution for filtering, such:
I = imread ('e:/w01.tif ');
H = [, 1;, 1;, 1];
H = H/9;
J = conv2 (I, H );
7. Median Filter
The medfilt2 function is used for image median filtering, for example:
I = imread ('e:/w01.tif ');
J = medfilt2 (I );
8 sharpen
(1) sharpen an image by using the Sobel operator, for example:
I = imread ('e:/w01.tif ');
H = [, 1;, 0;-1,-2,-1]; % Sobel operator
J = filter2 (H, I );
(2) sharpen an image by using the Laplace operator, for example:
I = imread ('e:/w01.tif ');
J = double (I );
H = [, 0; 1,-;, 0]; % LAPLACE OPERATOR
K = conv2 (J, H, 'same ');
M = J-K;
Example 6
Two-dimensional Fourier transformation and two-dimensional Fourier inverse transformation:
I = imread ('e:/w01.tif ');
Figure (1 );
Imshow (I );
Colorbar;
J = fft2 (I );
K = fftshift (j );
Figure (2 );
L = log (abs (k ));
Imshow (l, []);
Colorbar
N = ifft2 (j)/255;
Figure (3 );
Imshow (n );
Colorbar;