Hello, there is no error message regarding my code but the program is busy forever. what id the problem?
조회 수: 1 (최근 30일)
이전 댓글 표시
im = imread('retina.png');
im=rgb2gray(im);
S=size(im);
numR=S(1);
numC=S(2); %now without edges
%Voting
Accumulator = zeros(S); % initialize the accumulator
[yIndex ,xIndex] = find(im); % find x,y of edge pixels
r=30; r2 = r^2; % square of radius, to prevent its calculation in the loop
for cnt = 1:numel(xIndex)
low=xIndex(cnt)-r;
high=xIndex(cnt)+r;
if (low<1)
low=1;
end
if (high>numC)
high=numC;
end
for x0 = low:high
yOffset = sqrt(r2-(xIndex(cnt)-x0)^2);
y01 = round(yIndex(cnt)-yOffset);
y02 = round(yIndex(cnt)+yOffset);
if y01 < numR && y01 >= 1
Accumulator(y01,x0) = Accumulator(y01,x0)+1;
end
if y02 < numR && y02 >= 1
Accumulator(y02,x0) = Accumulator(y02,x0)+1;
% rectangle('position',[x y 1 1],'EdgeColor','r');
end
end
end
% Finding local maxima in Accumulator
thresh=4;
y0detect = []; x0detect = [];
AccumulatorbinaryMax = imregionalmax(Accumulator);
[Potential_y0 ,Potential_x0] = find(AccumulatorbinaryMax == 1);
Accumulatortemp = Accumulator - thresh;
for cnt = 1:numel(Potential_y0)
if Accumulatortemp(Potential_y0(cnt),Potential_x0(cnt)) >= 0
y0detect = [y0detect;Potential_y0(cnt)];
x0detect = [x0detect;Potential_x0(cnt)];
end
end
figure,imshow(im);
for i=1:length(x0detect)
x0=x0detect(i);
y0=x0detect(i);
for x=1:numC
y=round(y0-sqrt(r2-(x-x0)^2));
if y<=numR && y>=1
rectangle('position',[x y 1 1],'EdgeColor','r');
end
end
end
답변 (2개)
Cris LaPierre
2018년 12월 22일
You are looping through every pixel in the image. Your comment (% find x,y of edge pixels) makes me think this may be unintentional. That is going to take a while.
There are also several nested for loops, which add to the run time.
댓글 수: 0
Image Analyst
2018년 12월 22일
Not really sure what you're doing due to lack of comments but I see where you're trying to dynamically enlarge an array:
y0detect = [y0detect;Potential_y0(cnt)];
That takes a lot of time. You might try to preallocate y0detect and x0detect at their maximum expected size, then crop afterwards to the actual size.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!