Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's several things you can do to make your code more efficient, though some of them depend on exactly what you want in the end, and on what assumptions you can make about the circles (e.g. can they overlap? Are there many similar radii?). </p> <p>Below is a solution that assumes that there is very little repetition among radii, and center coordinates are always integer pixel values.</p> <pre><code>%# image dim_x = 1000; dim_y = 1000; A=rand(dim_x,dim_y); %# center positions and ... c = [222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112]; %#... radii of the circles r = [10 33 55 2 22 10 33 55 2 22 10 33 55 2 22 10 33 55 2 22]; %# find the largest circle... rMax = max(r); %#... and create a distance array distFromCenterSquared = bsxfun(@plus,(-rMax:rMax).^2,transpose(-rMax:rMax).^2); %# now we can loop over the radii to create the logical mask for all circles mask = false(dim_x,dim_y); %# initialize inside the loop if you want one circle at a time for i=1:length(r) %# create logical mini-circle mask miniMask = distFromCenterSquared(rMax-r(i)+1:end-(rMax-r(i)),rMax-r(i)+1:end-(rMax-r(i)))... &lt; r(i)^2; %# add to the mask. The ranges need to be fixed, obviously, if %# circles can be only partially inside the image %# also, the "or" is only necessary if you're adding to %# a mask, instead of recreating it each iteration mask(c(i,1)-r(i):c(i,1)+r(i),c(i,2)-r(i):c(i,2)+r(i)) = ... mask(c(i,1)-r(i):c(i,1)+r(i),c(i,2)-r(i):c(i,2)+r(i)) | ... miniMask; end </code></pre> <p>By the way: If you have non-overlapping circles, you can use <code>bwlabel</code> after the loop (or use find and sub2ind to write <code>i</code> into the individual circles), so that you can process all circles in one go using <code>accumarray</code>. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload