我试图在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');
答案 0 :(得分:1)
尝试type Props = {
color: string,
block: boolean,
component: React.ComponentType<*> | string,
className: string,
domProps: Object
}
。您没有指定类型就创建了imshow(M,[])
,因此创建了M
。 double
的图像为[0-1],因此默认情况下,double
将所有白色值都大于1的东西都变成白色。
或者,将imshow
创建为M
作为原始图像
uint8
更好的代码是:
M = zeros(NewX, NewY,'uint8');