My own nearest neighbor interpolation function does not display the image
10 views (last 30 days)
Show older comments
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
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!