# 图像处理——MATLAB

1.编写一个命令 m 文件，实现的功能是：
• 读入一幅灰度图像，假设为 ‘rose.tif’，并放在当前目录。
• 以图像的中心为中心，截取原图的二分之一，生成新图像。
• 在同一个窗口并排显示两幅图像。

% hw2_2.m
I = imread(‘rose.tif’);     % 1 point
[M N] = size(I);                % 2 points
J = uint8(zeros(M/2, N/2));         % 2 points
J = I(M/2 - M/4 : M/2 + M/4,N/2 - N/4 : N/2 + M/4);  % 4 points
figure, subplot(121), imshow(I);
subplot(122), imshow(J);

2.编写一个函数 m 文件，实现的功能是：将读入的灰度图像（只考虑 double 和uint8 class的图像）的灰度分辨率降低为原来的1/32（即原来的灰度级别 0~31 映射为 0，灰度级别 32~61 映射为 1，……）。然后在同一个窗口显示两幅图像。并返回新图像的矩阵，要求新图像的数据类型与输入图像的一致。

function J = hw2_3(I)             % define the function, 1 point
if strcmp(class(I), 'double')
I_255 = I * 255;
else
I_255 = double(I);
end                     % change values to 0~255, 2 points
J = floor(I_255 / 32);        % generate a matrix containing new gray levels, 2 points
J = mat2gray(J);            % change to the normalized values, 2 points
if strcmp(class(I), 'uint8')
J = uint8(J * 255);
end % if class of input image is uint8, then change output image to uint8, 2 points
figure, subplot(121), imshow(I);
subplot(122), imshow(J);        % display 2 images, 1 point

3.阅读下列程序，请说出实现的功能。当调用形式为
B = hw2_4( A, 2, 3 );

function B = hw2_4(A, m, n)
u = 1 : size(A, 1);
u = u(ones(1, m), :);
u = u(:);
v = 1 : size(A, 2);
v = v(ones(1, n), :);
v = v(:);
B = A(u, v);

Function of function: make every element in matrix  A duplicate m times in row and n time in column.        % 5 points
When calling the function is as follows:
B = pixeldup( A, 2, 3 );
the vector u and v are respectively as follows:
u = [1 1 2 2 3 3]’
v = [1 1 1 2 2 2 3 3 3]’    % 5 points. Note: u and v are column vectors.

4.二维离散傅里叶变换有哪些特点？

Answer:
(1) Periodicity
(2) Symmetry
(3) Rotation property
(4) Separability
(5) Shifting property
(6) Convolution Theory

5．频域的低频信号对应于空间域图像的特征是 the slowly varying components of an image, such as walls and floor ；

6．低通滤波对应于空间域的滤波器是 averaging filter( smoothing filter) ；

7．图像在频域滤波时，需要将图像进行零值填充，原因是
Multiplication of DFTs of two signals is equivalent to perform circular convolution in the spatial domain, which would generate “Wrap around” effect .

8．写出图像在频域进行滤波的步骤。（假设图像频域不平移）

1.  Convert the input image to floating point using function to float:
[ f , revertclass ] = tofloat ( f ) ;
2.  Obtain the padding parameters using function
3.  Obtain the fourier transform with padding:
F = fft2(f, PQ(1), PQ(2)) ;
4.  Generate a filter function, H, of size PQ(1)*PQ(2) using any of the methods, which must not be centered.
5.  Multiply the transform by the filter:
G = H .* F ;
6.  Obtain the real part of the inverse FFT of G:
g = real( ifft2(G) ) ;
7.   Crop the top, left rectangle to the original size:
g = g(1:size(f, 1), 1:size(f, 2)) ;
8. Convert the filtered image to the class of the input image, if so desired:
g = revertclass ( g ) ;

9.有哪些常用的去噪方法？

There have spatial filtering for additive noise and frequency domain filtering for periodic noise.
Spatial filtering have mean filters, order-statistics filters, and adaptive filters to de-noise.
Mean filters have (1) mathematic mean filter; (2) geometric mean filter; (3) harmonic mean filter; (4) contraharmonic mean filter.
Order-statistic filters have (1) median filter; (2) max filer; (3) min filter; (4) midpoint filter; and (5) alpha trimmed mean filter.
Adaptive filters have adaptive local noise reduction filter and adaptive median filter.

10.与中值滤波器相比，自适应中值滤波器的优点是什么？

Adaptive median filter could remove impulse noise effectively and the level of noise removal is similar to that of median filter, but it could preserve more small details than median filter.