数字图像处理实验2(HGD)—— 帮助文档

本文介绍了数字图像处理中常用的函数:im2double用于将图像转换为双精度格式以避免数据溢出;fftshift将频谱的0频成分移至中心;imrotate实现图像的逆时针旋转,并支持不同插值方法;dct2与idct2分别执行二维离散余弦变换和反变换。文中通过实例解释了这些函数的工作原理和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

im2double

 im2double Convert image to double precision.

im2double takes an image as input, and returns an image of class double.  If the input image is of class double, the output image is identical to it. If the input image is not double, im2double returns the equivalent image of class double, rescaling or offsetting the data as necessary.

I2 = im2double(I1) converts the intensity image I1 to double precision, rescaling the data if necessary.

im2double即把图像转成双精度形式。为什么要把图像转换成双精度进行运算呢?原因在于:一般情况下,图片都以uint8数据储存。当对图片进行数据运算时,数据大于256就出现溢出,结果失真。而双精度数运算时不会出现溢出,故先把uint8数据转为双精度数,就不会使计算精度失真。

fftshift:

 fftshift Shift zero-frequency component to center of spectrum. For vectors, fftshift(X) swaps the left and right halves of X.  For matrices, fftshift(X) swaps the first and third quadrants and the second and fourth quadrants.

fftshift即把0频成分(直流分量)移至频谱的中心。即对频域的图像,(假设用一条水平线和一条垂直线将频谱图分成四块)对这四块进行对角线的交换与反对角线的交换。

Imrotate:

imrotate  Rotate image.

B = imrotate(A,ANGLE) rotates image A by ANGLE degrees in a counterclockwise direction around its center point. To rotate the image clockwise, specify a negative value for ANGLE. imrotate makes the output image B large enough to contain the entire rotated image. imrotate uses nearest neighbor interpolation, setting the values of pixels in B that are outside the rotated image to 0 (zero).

B = imrotate(A,ANGLE,METHOD) rotates image A, using the interpolation method specified by METHOD. METHOD is a string that can have one of the following values. The default value is enclosed in braces ({}).

         {'nearest'}  Nearest neighbor interpolation

          'bilinear'   Bilinear interpolation

          'bicubic'    Bicubic interpolation. Note: This interpolation

                      method can produce pixel values outside the original

                      range.

imrotate旋转图像。它是以逆时针方向绕其中心点旋转一个角度。若要顺时针旋转图像,指定角度为负值即可。imrotate使输出图像B大到足以包含整个旋转的图像。若旋转后非垂直或水平,会自动将在旋转的图像之外的像素值设置为0。不过可以采用bicubic即双三次插值方法进行对图像外的像素值进行设置。

dct2:

 dct2 2-D discrete cosine transform.

 B = dct2(A) returns the discrete cosine transform of A. The matrix B is the same size as A and contains the discrete cosine transform coefficients.

idct2:

 idct2 2-D inverse discrete cosine transform.

    B = idct2(A) returns the two-dimensional inverse discrete

    cosine transform of A.

 

    Example

RGB = imread('autumn.tif');

        I = rgb2gray(RGB);

        J = dct2(I);

        imshow(log(abs(J)),[]), colormap(jet), colorbar

 

    The commands below set values less than magnitude 10 in the

    DCT matrix to zero, then reconstruct the image using the

    inverse DCT function idct2.

    Example

 J(abs(J)<10) = 0;

        K = idct2(J);

        figure, imshow(I)

        figure, imshow(K,[0 255])

dct2与idct2,顾名思义即二维离散余弦变换和反变换。值得一提的是,实验题目要求把变换矩阵中小于10的值置换为0,然后用余弦反变换重构图像。在帮助文档里面刚好给出了这样的例程。如上。


附上博主实验二实验代码:

fourier1.m:   

I=imread('flower1.jpg');%读入图像
F=fft2(im2double(I));%FFT
F=fftshift(F);%FFT频谱平移

figure('NumberTitle', 'off', 'Name', 'Fourier.m')
subplot(2,2,1),imshow(I);title('原图像');
subplot(2,2,2),
imshow(F,[]);title('旋转前图像频谱');

I=imread('flower1.jpg');%读入图像
B=imrotate(I,90,'nearest');
subplot(2,2,3),imshow(B);title('旋转后图像');

F1=fft2(im2double(B));%FFT
F1=fftshift(F1);%FFT频谱平移
subplot(2,2,4),imshow(F1);title('旋转后图像频谱');
hdct2.m:
I=imread('flower1.jpg');%读入图像
J=rgb2gray(I);
figure('NumberTitle', 'off', 'Name', 'hhdct.m')
subplot(1,3,1);imshow(J);title('原图像');
J1 = dct2(J);
subplot(1,3,2);
imshow(J1);title('灰度图像DCT变换');
J1(abs(J1)<10)=0;
k=idct2(J1);
subplot(1,3,3);
imshow(k,[0 255]);title('dct反变换图像');


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值