【发布时间】:2019-04-03 22:59:53
【问题描述】:
我试图在 Matlab 中创建自己的最近邻插值算法,以将 556×612 的图像放大到 1668×1836。
这是作业!!!
我已经尝试过了,但遇到了错误,其中 M 中的值(不是全部,而是大部分)转换为 255(空白),我无法理解为什么。任何帮助,将不胜感激!图片是斑马的图片。
%Take in image and convert to greyscale
I = imread('Zebra.jpg');
Igray = rgb2gray(I);
% Step-3: Resize the image to enlarged 1668x1836 by interpolation
% Step-3(a) : Using nearest neighbour
%First we will need to work out the dimension of the image
[j , k] = size(Igray);
%Now we need to set the size of the image we want
NewX = 1836;
NewY = 1668;
% Work out ratio of old to new
ScaleX = NewX./(j-1);
ScaleY = NewY./(k-1);
%Image Buffer
M = zeros(NewX, NewY);
%Create output image
for count1 = 1:NewX
for count2 = 1:NewY
M(count1,count2) = Igray(1+round(count1./ScaleX),1+round(count2./ScaleY));
end
end
%Show Images
imshow(M);
title('Scaled Image NN');
【问题讨论】:
-
哦,我不能使用任何内置的matlab函数!
标签: matlab interpolation nearest-neighbor