Cody

# Problem 42616. Detect circles in images

Solution 773489

Submitted on 8 Nov 2015 by Alfonso Nieto-Castanon
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','circles.png')); [centers,radii] = detectcircles(I,[18 20],13); c = [119 222; 185 218; 124 116; 37 37; 178 184; 93 167; 37 72; 71 38; 93 132; 122 186; 97 96; 71 74; 151 204]; r = 19*ones(13,1); d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[120 223;186 219;72 39;38 73;38 38;94 168;179 185;125 117;94 132;72 74;98 97;122 186;152 204] [19;19;19;19;19;19;19;19;19;19;19;19;19]

2   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','circlesBrightDark.png')); [centers,radii] = detectcircles(I,[32 64],6); c = [75 250; 100 100; 250 400; 300 120; 450 240; 330 370]; r = [35; 50; 60; 40; 50; 55]; d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[330 370;300 120;450 240;100 100;75 250;250 400] [55;40;50;50;35;60]

3   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','coins.png')); [centers,radii] = detectcircles(I,[24 30],10); c = [236 174; 149 35; 56 50; 266 103; 217 71; 120 209; 110 85; 175 120; 96 146; 37 107]; r = [25; 29; 25; 24; 29; 29; 24; 29; 29; 29]; d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[266 103;149 35;236 173;56 50;217 71;120 209;37 107;96 146;175 120;110 85] [24;28;24;24;29;30;29;29;29;24]

4   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','coloredChips.png')); [centers,radii] = detectcircles(I,[20 28],26); c = [83 177; 304 336; 420 88; 434 165; 244 166; 327 297; 273 53; 130 44; 271 281; 408 265; 312 192; 420 346; 146 199; 228 232; 329 135; 175 297; 366 224; 150 258; 217 107; 345 119; 445 68; 372 293; 150 342; 251 8; 259 217; 198 107]; r = [23; 24; 23; 23; 23; 23; 23; 23; 23; 23; 23; 24; 23; 23; 23; 24; 23; 24; 23; 23; 23; 24; 25; 23; 23; 25]; d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[312 193;408 265;129 44;272 53;420 346;271 281;243 166;150 258;145 199;365 224;444 68;174 297;326 297;198 108;328 135;372 293;250 8;345 119;228 231;259 218;150 342;219 107;420 88;302 336;431 165;81 176] [23;23;23;23;24;24;23;24;24;23;23;24;24;23;23;23;23;23;24;23;24;21;23;23;23;23]

5   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','eight.tif')); [centers,radii] = detectcircles(I,[35 40],4); c = [198 189; 247 72; 62 141; 124 58]; r = [37; 37; 38; 37]; d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[198 189;247 72;123 58;61 141] [38;38;38;38]

6   Pass

[254 287] 206

7   Pass
%% I = imread(fullfile(matlabroot,'toolbox','images','imdata','pillsetc.png')); [centers,radii] = detectcircles(I,[15 55],4); c = [103 240; 252 326; 119 130; 319 84]; r = [17; 17; 50; 37]; d1 = squeeze(sqrt(sum(bsxfun(@minus,centers,permute(c,str2num('3 2 1'))).^2,2))); d2 = squeeze(sqrt(sum(bsxfun(@minus,radii,permute(r,str2num('3 2 1'))).^2,2))); mask = d1<5 & d2<5; Re = mean(any(mask)); Pr = sum(any(mask))/size(mask,1); assert(Pr>=0.5) assert(Re>=0.75)

[120 131;103 240;252 326;321 82] [49;17;17;37]

8   Pass

[236 173] 81

9   Pass