#include <bits/stdc++.h>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/video.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/ml.hpp"
#define inf 2333333333333333
#define N 100010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)
//by war
//2020.10.27
using namespace std;
using namespace cv;
int n,k,cnt,lim,r;
int t[510][510][251];
Mat image,img0,out;
struct ki{
int x;
int y;
}a[N];
struct node{
int x;
int y;
int r;
int cnt;
bool operator < (const node & k) const{
return cnt<k.cnt;
}
}temp;
priority_queue<node,vector<node>,less<node> >q;
void in(int &x){
int y=1;char c=getchar();x=0;
while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
x*=y;
}
void o(int x){
if(x<0){p('-');x=-x;}
if(x>9)o(x/10);
p(x%10+'0');
}
signed main(){
img0 = imread("/Users/war/Downloads/test8/7.jpg",0);
//cvtColor(img0, img0, COLOR_RGB2GRAY);
GaussianBlur(img0,img0,Size(3,3),1);
Canny(img0,img0,50,200,3);
cnt=0;
For(i,0,img0.rows-1)
For(j,0,img0.cols-1){
if((int)img0.at<Vec3b>(i,j)[0]!=0){
a[++cnt].y=i;
a[cnt].x=j;
}
}
lim=0;
For(i,0,img0.rows-1)
For(j,0,img0.cols-1){
For(k,1,cnt){
r=sqrt((a[k].y-i)*(a[k].y-i)+(a[k].x-j)*(a[k].x-j));
if(r>i || r>j || r>img0.rows-i || r>img0.cols-j) continue;
lim=max(lim,r);
t[i][j][r]++;
}
}
For(i,0,img0.rows-1)
For(j,0,img0.cols-1){
For(k,1,lim){
if(t[i][j][k]>0){
q.push(node{i,j,k,t[i][j][k]});
}
}
}
out = Mat::zeros(img0.rows, img0.cols, img0.type());
cnt=0;
in(lim);
while(!q.empty() && (++cnt)<=lim){
temp=q.top();q.pop();
circle(out, Point (temp.y,temp.x), temp.r, Scalar (255, 255, 255), 1, 8, 0);
}
imshow("out0",img0);
imshow("out1",out);
waitKey();
return 0;
}