I have a function compare_images(k, a, b)
that compares two 2d-arrays a
and b
Inside the funcion, I apply a gaussian_filter
with sigma=k
to a
My idea is to estimate how much I must to smooth image a
in order for it to be similar to image b
The problem is my function compare_images
will only return different values if k
variation is over 0.5
, and if I do fmin(compare_images, init_guess, (a, b)
it usually get stuck to the init_guess
value.
I believe the problem is fmin
(and minimize
) tends to start with very small steps, which in my case will reproduce the exact same return value for compare_images
, and so the method thinks it already found a minimum. It will only try a couple times.
Is there a way to force fmin
or any other minimizing function from scipy
to take larger steps? Or is there any method better suited for my need?
EDIT:
I found a temporary solution.
First, as recommended, I used xtol=0.5
and higher as an argument to fmin
.
Even then, I still had some problems, and a few times fmin
would return init_guess
.
I then created a simple loop so that if fmin == init_guess
, I would generate another, random init_guess
and try it again.
It's pretty slow, of course, but now I got it to run. It will take 20h or so to run it for all my data, but I won't need to do it again.
Anyway, to better explain the problem for those still interested in finding a better solution:
- I have 2 images,
A
andB
, containing some scientific data. A
looks like a few dots with variable value (it's a matrix of in which each valued point represents where a event occurred and it's intensity)B
looks like a smoothed heatmap (it is the observed density of occurrences)B
looks just like if you applied a gaussian filter toA
with a bit of semi-random noise.- We are approximating
B
by applying a gaussian filter with constantsigma
toA
. Thissigma
was chosen visually, but only works for a certain class of images. - I'm trying to obtain an optimal
sigma
for each image, so later I could find some relations ofsigma
and the class of event showed in each image.
Anyway, thanks for the help!