For loop stoping mid way with empty array
古いコメントを表示
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
採用された回答
その他の回答 (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 件のコメント
Hugo Duarte
2016 年 12 月 23 日
Image Analyst
2016 年 12 月 23 日
What does this line intend to do:
aux = idivide(int32(masc), int32(2));
What is idivide()? Is it imdivide() or did you write your own function that you forgot to attach?
Can you please translate these into English so I know what is intended: aux, masc, valor, & contador. From the context, I think valor is sum, and contador is count, and masc might be mask or window or window width, but I still don't know what aux is (auxilliary?) and I want to make sure.
Hugo Duarte
2016 年 12 月 23 日
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).
カテゴリ
ヘルプ センター および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
