一段时间后,我在
MATLAB Image Processing Toolbox中通过了
imresize功能的代码,为图像的最近邻插值创建了一个简化版本。以下是如何应用于您的问题:
%# Initializations:
scale = [2 2]; %# The resolution scale factors: [rows columns]
oldSize = size(inputImage); %# Get the size of your image
newSize = max(floor(scale.*oldSize(1:2)),1); %# Compute the new image size
%# Compute an upsampled set of indices:
rowIndex = min(round(((1:newSize(1))-0.5)./scale(1)+0.5),oldSize(1));
colIndex = min(round(((1:newSize(2))-0.5)./scale(2)+0.5),oldSize(2));
%# Index old image to get new image:
outputImage = inputImage(rowIndex,colIndex,:);
另一个选择是使用内置的interp2功能,尽管您提到不想在其中一个注释中使用内置函数。
编辑:解释
如果有人有兴趣,我以为我会解释上面的解决方案如何工作?
newSize = max(floor(scale.*oldSize(1:2)),1);
首先,要获取新的行和列大小,将旧的行和列大小乘以比例因