I try to write a matlab function that upsamples me a picture (matrix of grey values). It is actually nothing overwhelmingly complicated, but I yet manage to do it wrong.
My objective is it to resize it by factor 2 and for the start I just want to see my upscaled picture. I want to fill the gaps with zeros, hence every 2nd row/column is a filled with zeros.
When I am done, I wonder why I see nothing but a grey ocean of pixels. I would have expected to be able to recognize at least some stuff in my picture.
Here is my function, does anyone see my mistake?
function [upsampled] = do_my_upsampling(image)
[X Y] = size(image);
upsampled = zeros(X*2, Y*2);
upsampled(1:2:end, 1:2:end) = image(1:1:end, 1:1:end);
end
Your code works fine for me (with
image = rand(100);. However, it’s not a very Matlab-way to achieve the result.If you just want to spread out your pixels, why don’t you do direct indexing?