Hi I am now trying a slightly complicated model which actually consists analyzing an image of finding the parameters of 2 particles (location width and light intensity. Total of 8 parameters) and Image they would produce (I attached an Plot of an image).
I have the initial model of light encountered by each pixel.
Although I put very good initial values and constrains Mathematica takes long time (minutes…) to give an answer and at the end wasnt able to produce a correct result.
Note at the final stage I will need to decompose the location of 4 particles simultaneously and put this piece of code in a more automated process…
is there a way to increase the accuracy and speed of this process?
thanks a lot
Doron
J[i_, j_, ?_, ?_, xpos_, ypos_, clip_] := N[Clip[(? ?^2*?)/ 4*((Erf[(j - xpos)/? ] - Erf[(j + 1 - xpos)/? ])*(Erf[(i - ypos)/? ] - Erf[(i + 1 - ypos)/? ])), {0, clip}]];
PixelImage[mat_]:=ArrayPlot[Rescale[mat,{0,Max[mat]},{Max[mat],0}],Epilog->{Red,MapIndexed[Text[#1,Reverse[#2-1/2]]&,Reverse[mat],{2}]},Mesh->True];
MyThreshold = 4043;
model1 = Clip[N[(?1 ?1^2*?)/4*((Erf[(j - xpos1)/?1 ] - Erf[(j + 1 - xpos1)/?1 ])*(Erf[(i-ypos1)/?1 ] - Erf[(i + 1 - ypos1)/?1]))], {0,MyThreshold}];
model2 = Clip[N[(?2 ?2^2*?)/4*((Erf[(j - xpos2)/?2 ] - Erf[(j + 1 - xpos2)/?2 ])*(Erf[(i -ypos2)/?2 ] - Erf[(i + 1 - ypos2)/?2]))], {0, MyThreshold}];
Model = Clip[(model1 + model2), {0, MyThreshold}];
data1 = Flatten[Table[{i, j, J[i, j, 0.7, 500, 6.5, 6.5, MyThreshold]}, {i, 1, 14}, {j, 1, 14}], 1];
data2 = Flatten[Table[{i, j, J[i, j, 0.6, 300, 4.5, 4.2, MyThreshold]}, {i, 1, 14}, {j, 1, 14}], 1];
Data = Transpose[{data1[[All, 1]], data1[[All, 2]], Clip[data1[[All, 3]] + data2[[All, 3]], {0, MyThreshold}]}];
PixelImage[Round[Partition[Data[[All, 3]], 14]]]
nlm = NonlinearModelFit[Data, {Model,
{0.4 <= ?1 <= 0.8, 0 <= ?1 <= 6000, 0 <= xpos1 <= 8,
0 <= ypos1 <= 8, 0.4 <= ?2 <= 0.8, 0 <= ?2 <= 6000,
0 <= xpos2 <= 8, 0 <= ypos2 <= 8}}, {{?1, 0.6}, {?1,
300}, {xpos1, 6.5}, {ypos1, 6.5}, {?2, 0.6}, {?2,
300}, {xpos2, 4.5}, {ypos2, 4}}, {i, j}, Method -> "NMinimize"];
nlm["BestFitParameters"]