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!
