9 double psf_ig2(
double x,
double y,
double const * p)
11 double s2s = sqrt(2)*p[2]*p[2];
12 double ex = (erf((x-p[0]+.5)/s2s)-erf((x-p[0]-.5)/s2s))*.5;
13 double ey = (erf((y-p[1]+.5)/s2s)-erf((y-p[1]-.5)/s2s))*.5;
14 return ex*ey*p[3]*p[3]+p[4]*p[4];
26 for (
int y = 0; y<l; y++)
for (
int x = 0; x<l; x++) {
28 tl += i[y*w+x]*log(psf)-psf;
39 double fn(
double const * p)
53 double const wk1[] = {1./16,1./4,3./8,1./4,1./16};
54 double const wk2[] = {1./16,0,1./4,0,3./8,0,1./4,0,1./16};
57 std::vector<double> bf(sz);
60 std::vector<double> v1(sz);
61 for (
auto i = 0; i<sz; i++) {
64 auto r1 = x+2<w?5:w+2-x;
65 for (
auto j = x<2?2-x:0; j<r1; j++) s += data[i+j-2]*wk1[j];
70 for (
auto i = 0; i<sz; i++) {
73 auto r1 = y+2<h?5:h+2-y;
74 for (
auto j = y<2?2-y:0; j<r1; j++) s += bf[i+j*w-2*w]*wk1[j];
76 double f1 = data[i]-s;
82 double threshold = 1.5*sqrt(f1a2-f1a*f1a);
83 debug <<
"threshold = " << threshold <<
'\n';
86 std::vector<double> f2(sz);
87 for (
auto i = 0; i<sz; i++) {
90 auto r1 = x+4<w?9:w+4-x;
91 for (
auto j = x<4?4-x:0; j<r1; j++) s += v1[i+j-4]*wk2[j];
94 for (
auto i = 0; i<sz; i++) {
97 auto r1 = y+4<h?9:h+4-y;
98 for (
auto j = y<4?4-y:0; j<r1; j++) s += bf[i+j*w-4*w]*wk2[j];
103 std::vector<int> nd{1,w+1,w,w-1};
104 std::vector<bool> n8(sz,
true);
105 double stps[] = {1,1,0.2,1,1};
107 for (
int i = 0; i<ne; i++) {
109 if (f2[i]>f2[i+d]) n8[i+d] =
false;
114 if (n8[i]&&x>=4&&x<w-4&&y>=4&&y<h-4&&f2[i]>threshold) {
116 double const * sq = data+i-(w+1)*4;
120 for (
int y = 0; y<9; y++)
for (
int x = 0; x<9; x++) {
123 else if (vv<mn) mn = vv;
125 double p[] = {4,4,sqrt(1.6),sqrt(mx-mn),sqrt(mn)};
131 for (
int i = 0; i<5; i++) {
132 std::cout << s << p[i];
145 int main(
int argc,
char ** argv)
148 std::cerr <<
"Missing expected filename!\nUsage:\n";
149 std::cerr <<
'\t' << argv[0] <<
" <filename of TIFF>\n\n";
153 Tiff tf(std::make_shared<std::ifstream>(argv[1]));
164 uint16_t * v =
reinterpret_cast<uint16_t *
>(imd.data());
166 std::vector<double> im(v,v+sz);
167 std::cout <<
"\n\n\nicnt = " << icnt <<
"\n===================\n";
double fn(double const *p)
Function to be minimized.
double nelder_mead(func_t f, int n, double *x, double const *steps, double mxrngy, double mxrngx, int mxiter)
Perform minimization with Nelder–Mead method.
double psf_ig2(double x, double y, double const *p)
Point-spread function with integrated Gaussian.
std::vector< char > read_image()
uint32_t image_width
width of image
uint32_t image_length
length of image
double likelihood(double const *i, int l, int w, double const *p)
negative Likelihood calculation for given parameter
double const * fn_im
cropped square image data
void process_image(double const *data, int w, int h)
Process a single 2D image.
int main(int argc, char **argv)
Main function for localization.
unsigned fn_cnt
count of function calls
Nelder–Mead method for function minimization.
std::ostream & debug
stream for debug messages
uint32_t parse_ifd(uint32_t i=0)
Parse image file directory (IFD)
Class for processing TIFF file.