axtimwalde/mpicbg

extractFeatures is not thread safe in SIFT.java

Closed this issue · 2 comments

I invokes in scala code as below:
List(
"img1_url"
, "img2_url"
, "img3_url"
, "img4_url"
).par.foreach(url => {
val imp = new ImagePlus(imgTitle, img)
val sift = new FloatArray2DSIFT(new Param())
val ijSIFT = new SIFT(sift)
val fs = new util.ArrayList[Feature]
val imp = new ImagePlus(url)
ijSIFT.extractFeatures(imp.getProcessor, fs)
println(s"url -> feature.size ${fs.size}")
})
I used the FloatArray2DSIFT.Param as below:
{"fdSize":4,"fdBins":8,"maxOctaveSize":800,"minOctaveSize":64,"steps":3,"initialSigma":0.8}
When I set initialSigma bigger than 1.0. There will no the issue.

When you move the "par"(parallel) from the loop or change the list element count to 1, you will find the number of feature is not stable.
I am looking into the code, but cannot get any good idea.

Can you fix the issue and point out the reason of the issue for me?

Many thanks,
Wang

This is not an issue but a user mistake due to bad documentation. I guess this line

val sift = new FloatArray2DSIFT(new Param())

is not what you're executing but a placeholder for something like

val sift = new FloatArray2DSIFT(param)

with a param object that you initially created somewhere with your chosen parameters? If param.initialSigma < 1 then the image size will be doubled which is implemented among other stuff by writing something into param. I.e. the param instance is not thought to be thread safe (which shows in this particular case). Not the best design probably, but not a big deal if you know about it. If you call it with a clone of param and you should be safe to go

val sift = new FloatArray2DSIFT(param.clone())

Let me know if that fixes your problem, then I can close the issue.

Thanks,
Stephan

My falt, Stephan.
It is correct when I clone the Param instance every time I extract SIFT features.
You can now close the issue.

Thanks,
Wang