Region of interest definition algorithm

3 次查看(过去 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 个评论
Brittney Gorman
Brittney Gorman 2021-4-29
编辑:Brittney Gorman 2021-4-29
I am sorry, I think I misunderstood your question. I call it with the following command.
[S_boarderx,S_boardery,Board_val] = shadowedge(Image,shadowx,shadowy,10, 45, .5, 0);
This should take the point in the Image array at [shadowx,shadowy] and search radially outward until the threshold of 1.5*the value at [shadowx,shadowy] is reached or a local maxima.
10 = maximum radius
45 = the number of radial directions it searches
Specifically I use the function above and run it through a loop on many points within image file SS.mat
[dimx,dimy] = size(SS,1,2);
mask = zeros(dimx,dimy,size(shadow_loc,1));
for i=1:size(shadow_loc,1)
[sboardx, sboardy, Board_val] = shadowedge(SS,shadow(i,1),shadow(i,2),10, 45, .5, 0);
R = roipoly(SS,sboardy(:),sboardx(:));
mask(:,:,i) = R;
end
smask = sum(mask,3);
smask(smask>0) = 1;
Image Analyst
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 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by