lundi 2 mars 2015

Subsample Matrix with For loop

I have a quick question about subsampling a matrix. I am trying to do this while only using for and/or while loops. basically the question is a reiteration of:



function output = subsample(img,2)

output = img(1:factor:end, 1:factor,end);


But now I am trying to rewrite the function to do the exact same process but with using for loops and/or while loops and without using two or more ":" (colon) operators and without accessing matrix/vector elements using the color operator. This is what i have so far:



function output = subsamplex(img,factor)

[r, c] = size(img);

output = zeros(r/factor,c/factor);

j = 1;

i = 1;

for x = 1:r;

for y = 1:c;
j = factor*j-1;
i = factor*i-1;
output(j,i) = img(x,y);
end
end

end


Though what I'm getting is the image re sized but its all black and I'm trying to figure out where I am going wrong or if I am completely wrong. Any help in the right direction will be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire