looping image analysis problem.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I've been attempting to have my code run a set of images, and they all have the same naming format, and I want to analyze them, but when I try to loop them, it keeps going on and on and on with no end. What am I doing wrong?
My code loop:
clear all;
image='img_000000000_Default_000.tif';
s=4;
results=zeros(2,s+1);
for i = 0:s
while (i<10)
image=['img-00000000', int2str(i), '_Default_000.tif'];
end
while (i<100 && i>= 10)
image=['img-0000000', int2str(i), '_Default_000.tif'];
end
while (i<1000 && i>=100)
image=['img-000000', int2str(i), '_Default_000.tif'];
end
results(1:2,i+1) = imagefunction(image,3);
end
My code for imagefunction
function [tubemean, tablemean] = imagefunction(image,boxsidelength)
imagex=imread(image);
imshow(image);
boxalter = (boxsidelength-1)/2;
newimage1= zeros(110-(2*boxalter), 130-(2*boxalter));
boxstartpointx = 370 + boxalter;
boxendpointx=480-boxalter;
boxstartpointy=150+boxalter;
boxendpointy=280-boxalter;
box1startpointx = 420 + boxalter;
box1endpointx=426-boxalter;
box1startpointy=201+boxalter;
box1endpointy=208-boxalter;
image1sum=0;
pixelcount1=0;
box2startpointx = 458;
box2endpointx=464;
box2startpointy=181;
box2endpointy=188;
image2sum=0;
pixelcount2=0;
for r = boxstartpointx:boxendpointx
for c = boxstartpointy:boxendpointy
box=imagex(r-boxalter:r+boxalter,c-boxalter:c+boxalter);
boxmean= mean2(box);
boxstd= std2(box);
eqn= boxstd/boxmean;
newimage1(r-(370-boxalter),c-(150-boxalter)) = eqn;
end
end
for r=box2startpointx:box2endpointx
for c = box2startpointy:box2endpointy
image2sum=image2sum+imagex(r,c);
pixelcount2=pixelcount2+1;
end
end
for r=box2startpointx:box2endpointx
for c = box2startpointy:box2endpointy
image2sum=image2sum+imagex(r,c);
pixelcount2=pixelcount2+1;
end
end
for r=box1startpointx:box1endpointx
for c = box1startpointy:box1endpointy
image1sum=image1sum+imagex(r,c);
pixelcount1=pixelcount1+1;
end
end
imagemean=mean2(image);
imshow(imagex);
tubemean=imagemean;
tablemean=image2sum/pixelcount2;
Images are .tif btw, if that is important
0 comentarios
Respuestas (1)
KALYAN ACHARJYA
el 23 de Mzo. de 2019
Editada: KALYAN ACHARJYA
el 24 de Mzo. de 2019
for i = 0:s
while (i<10)
image1=['img-00000000', int2str(i), '_Default_000.tif'];
end
while (i<100 && i>= 10)
image1=['img-0000000', int2str(i), '_Default_000.tif'];
end
while (i<1000 && i>=100)
image1=['img-000000', int2str(i), '_Default_000.tif'];
end
results(1:2,i+1) = imagefunction(image1,3);
end
Yes, your loop run for infinite time
Start from for loop
when i=0
Next go to
while (i<10) % Condition true
%Do operation
end
This while loop runs for infinite time, till i<10, as there are no change of i inside while loop, therefore it runs for infinite times.
Same case may be for other while loop also, please check. While loop run until the condition is true.
Better to use if else, in your case.
for i = 0:s
if i<10
image1=['img-00000000', int2str(i), '_Default_000.tif'];
elseif i<100 && i>= 10
image1=['img-0000000', int2str(i), '_Default_000.tif']
elseif i<1000 && i>=100
image1=['img-000000', int2str(i), '_Default_000.tif'];
else
%do nothing
end
results(1:2,i+1)=imagefunction(image1,3);
end
Hope it helps!
2 comentarios
Image Analyst
el 23 de Mzo. de 2019
image is a built-in function. Don't use it for the name of a variable or you will run into trouble if you try to call image later as a function.
KALYAN ACHARJYA
el 24 de Mzo. de 2019
@Image Analyst Yes sir, I missed it. Answer edited, Thank You!
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!