MATLAB: My own nearest neighbor interpolation function does not display the image

digital image processinghomeworkimage processinginterpolation

Hi, everyone. I created my own nearest neighbor interpolation implementation. I tried it with using dummy matrix, and it works. However, when I try it with an picture, it does not display anything. What I am missing with this code
clc;
profImg = imread('profile.jpeg');
%Shrinked Image
shrkImgNear = imresize(profImg, [128, 128], "nearest");
shrkImgLin = imresize(profImg, [128, 128], "bilinear");
shrkImgCub = imresize(profImg, [128, 128], "bicubic");
%Image Ratio
ratio = 1024/128;
%test = [10 4 22; 2 18 7; 9 14 25];
%New Image
newImgRow = ones(1024, 1) * (1: 1024);
newImgRow = ceil(newImgRow / 8);
newImgRow = nearestNeig(shrkImgNear, newImgRow);
figure;
imshow(newImgRow);
function destImg = nearestNeigh(srcImg, destImg)
for i = 1:1024
for j = 1:1024
col = ceil(j / 8);
row = ceil(i / 8);
destImg(i, j) = srcImg(row, col);
%for k = 1:3
% destImg(i, j, k) = srcImg(row, col, k);
%end
end
end
end

Best Answer

I found the solution. I had to transform the matrix using "uint8" function.