Region of interest definition algorithm
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to build an algorithm that can detect the edges of a particle. The function attached itterates radially outword from a point and detects if each location that is either a localmaximum or exceeds a threshold. As shown in the attached image this should allow the code to independently identify the edges of each low point in the data matrix.
The problem that I have with my current code is that because it iterates both radially and outward it is incredibly time consuming. Can anyone suggest something better?
I have also attached some sample data:
function [S_boarderx,S_boardery,Board_val] = shadowedge(im,shadowx,shadowy,R, dirmax, thres, PM)
SS = im;
[dimx, dimy] = size(SS,1,2);
xx = shadowx;
yy = shadowy;
shadow_loc = sub2ind([dimx dimy], xx, yy);
shadow_Val = SS(shadow_loc);
thres_val = shadow_Val+shadow_Val*thres;
for t = 1:dirmax
for j=1:R
theta = (2*pi*t)/dirmax;
Sx = xx+round(j*cos(theta));
Sy = yy+round(j*sin(theta));
Sx(Sx<= 1) = 2;
Sy(Sy<= 1) = 2;
Sx(Sx>= dimx-1) = dimx-1;
Sy(Sy>= dimy-1) = dimy-1;
val = SS(sub2ind([dimx dimy], Sx, Sy));
if val >= thres_val
S_boarderx(t,:) = Sx;
S_boardery(t,:) = Sy;
break
elseif sum(sub2ind([dimx dimy],Sx,Sy) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx+1,Sy+1) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx+1,Sy) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx,Sy+1) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx-1,Sy-1) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx-1,Sy) == find(islocalmax(SS,'MinProminence',PM)))...
|| sum(sub2ind([dimx dimy],Sx,Sy-1) == find(islocalmax(SS,'MinProminence',PM)))
S_boarderx(t,:) = Sx;
S_boardery(t,:) = Sy;
break
else
S_boarderx(t,:) = Sx;
S_boardery(t,:) = Sy;
end
end
end
Board_loc = sub2ind([dimx dimy], S_boarderx(:), S_boardery(:));
Board_val = SS(Board_loc);
댓글 수: 10
Image Analyst
2021년 6월 26일
@Brittney Gorman, Sorry I didn't see your reply until now. Are you still having a problem with this code?
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!