无需imresize调整图像大小(MATLAB)

时间:2014-09-04 20:44:52

标签: matlab pixels

如何在不使用matlab中的imresize的情况下调整图像大小

1 个答案:

答案 0 :(得分:8)

此代码使用最近邻插值完成。

%# 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,:);

您只需要相应地更改比例因子。