Digital Image Processing: Experiment-Basics of MATLAB Image Processing

Experiment 1 MATLAB image processing basis

MATLAB 具有强大的图像处理工具箱,有助于人们更好的理解各种图像处理算法,通 过调用工具箱中的函数,可以减少编程的复杂性,简化编程。本次实验主要掌握 MATLAB中的一些基本图像操作函数,包括图像的输入、显示、查看图像属性、改变大小、获取图像的统计信息、保存、多波段图像读写等功能,并进行简单的图像处理编程操作。

1. The purpose of the experiment

1. Further consolidate the understanding of Matlab development environment;
2. 2. Understand the related functions of image processing and master their usage;
3. 3. Understand and master file operation functions
; 4. Master the help commands of matlab and learn to use the help functions of matlab
; Master the basic methods of matlab programming, and realize simple image processing operations through programming.

2. Experimental basis

1. Image processing related functions
Matlab provides a variety of image processing functions. Table 1 lists some functions and their functions.

imread
read image
imshow
image display
imwrite
save image
colorbar
display colorbar
imfinfo
get image info
subimage
display image
imresize
change image size
imcrop
cut image
imrotate
image zoom
imhist
display image histogram
mean
calculate image mean
warp
texture map
std2
calculate image standard deviation
multibandread
read multiband binary image
corr2
calculate correlation coefficient
multibandwrite
write multiband binary image

2. The file operation function
fopen
opens the file
fread
reads the binary file
fclose
closes the file
fwrite
writes the binary file
fscanf
reads the text file
fprintf
writes the text file
feof
tests whether the pointer is at the end of the file
fseek
sets the file pointer position
frewind
resets the pointer to the beginning of the file
ftell
get file pointer position

3. Image grayscale histogram
The image grayscale histogram is a function of grayscale, describing the number or frequency of each grayscale pixel in the image. The abscissa is the gray level, and the ordinate is the number of pixels each gray level has or the frequency of occurrence of the gray level.
Gray level frequency calculation formula:
v_i=n_i/n
where ni is the number of occurrences of gray level i, and n is the total number of pixels.
4. Entropy
Entropy is the representation of the amount of image information, which reflects the richness of image information and is of great significance in image coding and image quality evaluation.
H=-∑_(i=0)^(L-1)▒p_i 〖log〗_2 p_i
In the formula, pi is the probability of occurrence of gray level i.

3. Experiment content and steps

1. Familiar with the working environment of Matlab
(1) Turn on the computer, start the MATLAB program, and enter the working interface of MATLAB;
insert image description here

(2) Familiar with the MATLAB menu and the functions of each toolbar; the
menu bar
insert image description here

current folder
insert image description here

command line window
insert image description here

workspace
insert image description here

(3) Create a matrix in the command window and operate on the elements in the matrix;

a=zeros(5,5)
a =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

a(2:4,2:4)=1
a =
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
(4) Create a matrix and perform matrix operations;

a=[1 2 3 4 5 6];
b=[6 5 4 3 2 1];
a+b
ans =
7 7 7 7 7 7

a.*b
ans =
6 10 12 12 10 6

a-b
ans =
-5 -3 -1 1 3 5

a./b
ans =
0.1667 0.4000 0.7500 1.3333 2.5000 6.0000

a*b’
ans =
56

a'*
bans =
6 5 4 3 2 1
12 10 8 6 4 2
18 15 12 9 6 3
24 20 16 12 8 4
30 25 20 15 10 5
36 30 24 18 12 6
(5) Plot the following two-dimensional function , and change the color and line type of the curve, which are drawn with blue solid lines, red dotted lines, and black dots, respectively.
y=2e^(-5x) sin⁡(2πx) 0≤x≤2π

insert image description hereinsert image description here

2. Familiar with the help commands of Matlab, learn to use the help information of Matlab; and use the help commands to view the image processing functions.
help command: View help for a function

help subplot
subplot Create axes in tiled positions.
H = subplot(m,n,p), or subplot(mnp), breaks the Figure window
into an m-by-n matrix of small axes, selects the p-th axes for
the current plot, and returns the axes handle. The axes are
counted along the top row of the Figure window, then the second
row, etc. For example,

    subplot(2,1,1), PLOT(income)
    subplot(2,1,2), PLOT(outgo)

type command: view the original code

type fft2
function f = fft2(x, mrows, ncols)
%FFT2 Two-dimensional discrete Fourier Transform.
% FFT2(X) returns the two-dimensional Fourier transform of matrix X.
% If X is a vector, the result will have the same orientation.
% FFT2(X,MROWS,NCOLS) pads matrix X with zeros to size MROWS-by-NCOLS
% before transforming.
% Class support for input X:
% float: double, single
% See also FFT, FFTN, FFTSHIFT, FFTW, IFFT, IFFT2, IFFTN.
% Copyright 1984-2010 The MathWorks, Inc.

if ismatrix(x)
    if nargin==1
        f = fftn(x);
    else
        f = fftn(x,[mrows ncols]);
    end
else
    if nargin==1
        f = fft(fft(x,[],2),[],1);
    else
        f = fft(fft(x,ncols,2),mrows,1);
    end
end   

lookfor command:

lookfor plot(x,y,'k.')
did not find plot(x,y,'k.').

3. Familiar with the file operation functions in Matlab
(1) Create a data file test.dat to store the data of matrix A.
insert image description here

(2) Read the content of the file test.dat
insert image description here

B =
1 8
4 3
7 6
2 9
5 0
cnt =
9
(3) File positioning
insert image description here

dingwei
four =
4
position =
8
eight =
5

4. Basic image operations
Familiarize yourself with the matlab image processing functions provided in Table 1, and perform basic operations on images.
(1) Image read and write operations. Such as
insert image description hereinsert image description here

(2) Perform basic operations on images. Such as
insert image description hereinsert image description here

5. Programming
(1) Write function files, calculate
insert image description hereinsert image description hereinsert image description here

(2) Write and count the histogram of a grayscale image in Matlab language, and display the image and its grayscale histogram in the same graphics window;
insert image description hereinsert image description here

(3) Calculate the entropy of a grayscale image.

insert image description hereinsert image description here

(4) Program the image mirroring operation and display it.
insert image description hereinsert image description here

Fourth, the experimental experience

1. Know the MATLAB interface and know the basic programming statements.
2. Learned the input and output of images, basic image processing operations, and can solve the grayscale histogram and entropy of images.
3. The statements used are different, the programming codes are varied, and different statements have certain similarities, and they can all get the correct results.

Guess you like

Origin blog.csdn.net/chengzilhc/article/details/115533573