matlab - Removing equidistant points from image -


i have image- enter image description here

i want remove these point marked yellow circles- enter image description here

so, want remove points equidistant , lies on same line between given 2 points.

this have tried.i found equation between 2 points , removed points lie on line.here have tried-

clc; i=imread('untitled.png'); imshow(i); i=im2bw(i);  l = bwlabel(i,8) ;  %calculating connected components mx=max(max(l));  i=1:mx     [r1,c1] = find(l==i);      x1=mean(c1);     y1=mean(r1);     j=1:mx         if i~=j             [r2,c2] = find(l==j);             x2=mean(c2);             y2=mean(r2);             slope=(y2-y1)./(x2-x1);             k=1:mx                 [r,c] = find(l==k);                 rc = [r,c];                                 x3=mean(c);                 y3=mean(r);                 temp=((y3-y2)-(slope).*(x3-x2));                 if k~=i & k~=j                    if temp >=-0.5 & temp <=0.5                        l=1:r                            m=1:c                                i(l,m)=0;                            end                        end                    end                 end             end         end     end end figure,imshow(i); 

but here,it remove points lie on line , not equidistant points.also, time complexity o(n^5),so algorithm not work small values.i not check above code input image provided taking way time. so, there way can this?

i think way doing it. it's ~o(n) number of circles

>> timingfunction(1000, 2) elapsed time 0.103834 seconds. >> timingfunction(1000, 4) elapsed time 0.179529 seconds. >> timingfunction(1000, 8) elapsed time 0.270225 seconds. >> timingfunction(1000, 16) elapsed time 0.601423 seconds. >> timingfunction(1000, 32) elapsed time 1.070139 seconds. 

and o(n^2) image size (i used square test)

>> timingfunction(500, 16) elapsed time 0.139831 seconds. >> timingfunction(1000, 16) elapsed time 0.531034 seconds. >> timingfunction(2000, 16) elapsed time 1.974798 seconds. 

and function is:

function timingfunction(squaresize, numbercircles) %this generating sample "image" = ones(squaresize);  %this generating sample circles x = randi(round(0.9*size(i, 2)), numbercircles, 1); y = randi(round(0.9*size(i, 1)), numbercircles, 1); r = randi(round(min(size(i)) / 20), numbercircles, 1);  %this timing tic ip = circleerase(i, x, y, r); toc  %just allow visualization surf(ip)  end  %this actual code function = circleerase(i, x, y, r) %i image, if it's rgb rather matrix need modify last line %x vector of x coordinates of center of circle %y vector of y coordinates of center of circle %r vector of circles radii  %assign x,y coordinates each point [gridx, gridy] = meshgrid(1:size(i, 2), 1:size(i, 1));  %want points within 1 unit within = 1;  %finds points within 1 unit each circle edge closeenough = arrayfun(@(x, y, r) abs(r - sqrt((x - gridx).^2 + (y - gridy).^2)) <= within, x, y, r, 'uni', 0);  %changes cell array 3d array (using: %   http://www.mathworks.com/matlabcentral/answers/35766-cell-array-into-3d-matrix) %   finds if points intersect of circles eraseit = any(permute(reshape(cell2mat(closeenough).',size(closeenough{1}, 1),size(closeenough{1},2),[]),[3 2 1]), 1);  %then erases i(eraseit) = 0; end 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -