本题是ee261中Problem Set 6的一道matlab代码题,主要用到了采样定理和混淆相关的知识。
ee261相关知识点整理博客:https://www.cnblogs.com/TaigaCon/p/5079156.html
结果分析
alpha=0.99
当alpha = 0.99时,linear和nearest两种方法的结果都很不错,毕竟此时采样率还是基本符合采样定理的。
linear

nearest

alpha=0.95
alpha=0.95时,可以发现图片已经受到混淆的严重影响了,“nearest”下图片体现出了“像素风”,也就是说图片的精细化程度下降很多;
而“linear”相比于“nearest”,它的边缘要更模糊一些。推测是因为linear相比nearest更加平均,过渡更均匀。
linear

nearest

alpha=0.90
混淆的作用在这里比alpha=0.95更要严重,图片已经面目全非。当然,linear依然比nearest模糊。
linear

nearest

matlab代码
代码中alpha=0.90,插值类型“nearest”,若要修改这两个参数,修改26行和59行的参数值即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
clc;clear; img = imread('man.gif'); [row,col] = size(img);
imgVector = []; for i = 1:row imgVector = [imgVector,img(i,:)]; end imgVector = double(imgVector)/256; vectorLength = length(imgVector);
imgVectorFren = fftshift(fft(imgVector)); fValues = -vectorLength/2:1:vectorLength/2-1; zeroPoint = length(fValues)/2+1; plot(fValues,imgVectorFren);
alpha = 0.90; energyTotal = 0; energyP = abs(imgVectorFren(zeroPoint))^2;
for i = 1:vectorLength energyTotal = energyTotal + abs(imgVectorFren(i))^2; end
p = 0; while(energyP/energyTotal<alpha) p = p+1; energyP = energyP+abs(imgVectorFren(p+zeroPoint))^2+abs(imgVectorFren(-p+zeroPoint))^2; end
rate = p*2/vectorLength; interval = floor(1/rate);
indexTotal = 1; vectorSampled = []; indexSampled = []; while(indexTotal<=vectorLength) indexSampled = [indexSampled,indexTotal]; vectorSampled = [vectorSampled,imgVector(indexTotal)]; indexTotal = indexTotal + interval; end
indexInterped = 1:vectorLength; vectorInterped = interp1(indexSampled,vectorSampled,indexInterped,'nearest');
imgInterped = []; for i = 0:row-1 imgInterped = [imgInterped;vectorInterped(1,i*col+1:(i+1)*col)]; end
subplot(1,2,1); imshow(img); title('imgOri');
subplot(1,2,2); imshow(imgInterped); title('imgInterped');
|