
For loop stoping mid way with empty array
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Image Analyst
2016 年 12 月 23 日
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 件のコメント
Image Analyst
2016 年 12 月 24 日
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.
その他の回答 (1 件)
Image Analyst
2016 年 12 月 23 日
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 件のコメント
Image Analyst
2016 年 12 月 23 日
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).
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!