
For loop stoping mid way with empty array
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hugo Duarte
il 23 Dic 2016
Commentato: Image Analyst
il 24 Dic 2016
Hi,
I'm doing a university project with images using guide.
But in my method to determin the mean of an image using a box value, my for loop stops mid way, l becomes [] and i don't know why.
function [ imagemFinal ] = toMeanAluno( imagem, masc )
aux = idivide(int32(masc), int32(2));
contador = 0;
valor = 0;
imagemFinal = imagem;
for i = 1+aux:size(imagem,1)-aux
for j = 1+aux:size(imagem,2)-aux
for k = i-aux:masc
for l = j-aux:masc
valor = valor + imagem(k,l);
contador = contador + 1;
end;
end;
imagemFinal(i,j) = valor / contador;
valor = 0;
contador = 0;
end;
end;
end
0 Commenti
Risposta accettata
Image Analyst
il 23 Dic 2016
If you want a fully manual version of convolution with no calling conv2() or imfilter(), then see the attached demo code (below these images that it creates).

2 Commenti
Image Analyst
il 24 Dic 2016
Well I do teach a few classes in our company. We have hired many professors who became disillusioned with academic life - low pay, long hours, political infighting, tenure battles, too much time spent searching for grants or contracts, not as much freedom to research what they want as they had expected, etc. No thanks - not for me. Well, maybe when I retire - who knows? Plus a surprising number of professors can't program - they just think and delegate all the actual hands-on programming to their grad students. Like my son's engineering professor who assigns homework in MATLAB but who barely knows how to use it herself. I like to both think and do.
Thanks for accepting the answer.
Più risposte (1)
Image Analyst
il 23 Dic 2016
It looks like you're trying to do a moving window mean. So why not just do
windowSize = 7; % Whatever
kernel = ones(windowSize)/windowSize^2;
outputImage = conv2(inputImage, kernel, 'same');
or
outputImage = imfilter(inputImage, kernel);
4 Commenti
Image Analyst
il 23 Dic 2016
What does auxiliar mean? In English Auxilliary mean like "extra" so I'm not sure what it means when you use it.
What values does k take on in "k = i-aux:masc" Let's say you were at pixel (100,100) and the window size was 7 so the half window size was 3. Then k should go from i-3 to i+3. It doesn't look like it does that for you. I'd do
for k = (i-halfWindowSize) : (i + halfWindowSize)
and similar for l (ell).
Vedere anche
Categorie
Scopri di più su Particle & Nuclear Physics in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!