To overcome infinite loop problem to assign a particular value

1 次查看(过去 30 天)
I want to assign zero to a pixel whose intensity value is greater than a certain threshold value, but my programme goes to an infinite loop. How can I overcome this problem. The code is
[M N]=size(I)
for i=1:M
for j=1:N
P(i,j)=improfile(I,i,j)
if(P(i,j)>t)
I(i,j)=0;
else
I(i,j)=1;
end
end
end
figure,imshow(I)% I is the input image array
Please help me to overcome this problem.

采纳的回答

Walter Roberson
Walter Roberson 2013-11-24
P(i,j)=improfile(I,i,j) attempts to select the path using x = i and y = j as the endpoint of the line. You have not specified a second point to end at, and it is not documented what it would do in such a case. If you are expecting it to return I(i,j) then why not just code that directly instead of calling improfile() ?
It looks to me like your entire code could be replaced by
P = 0 + (I <= t);

更多回答(1 个)

Image Analyst
Image Analyst 2013-11-24
编辑:Image Analyst 2013-11-24
Looks like you're trying to do image segmentation. If so, just do
binaryImage = grayImage <= thresholdValue;
Notice how I use descriptive variable names, not an alphabet soup of single letter names. And it's not recommended to use i as a loop variable since i is also the imaginary variable. And of course I is a horrible variable letter to use because a capital I looks like a 1 or an l (lower case ell) in some fonts.
Anyway, you might be interested in my image segmentation tutorial: http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by