For loop stoping mid way with empty array
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 23 Dez. 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 Kommentare
Hugo Duarte
am 23 Dez. 2016
Image Analyst
am 23 Dez. 2016
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
am 23 Dez. 2016
Image Analyst
am 23 Dez. 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).
Kategorien
Mehr zu Particle & Nuclear Physics finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
