imagej2: Bug in AutoThresholder / Minimum algorithm?

Hi, I was looking into the AutoThresholder.Minimum method code, and I’ve noticed something that does not make sense, starting at the line 635:

double [] tHisto = iHisto;
while (!bimodalTest(iHisto) ) {
    //smooth with a 3 point running mean filter
    for (int i=1; i<255; i++)
        tHisto[i]= (iHisto[i-1] + iHisto[i] +iHisto[i+1])/3;
    tHisto[0] = (iHisto[0]+iHisto[1])/3; //0 outside
    tHisto[255] = (iHisto[254]+iHisto[255])/3; //0 outside
    iHisto = tHisto;
  • First the line double [] tHisto = iHisto; is just a pointer affectation, not a copy. And then in the loop, we have the opposite iHisto = tHisto;. This pointer affectation followed by the opposite affectation does not have any sense.
  • Second, a smoothing is performed into the while loop. But the result in put into tHisto (for example tHisto[i]= (iHisto[i-1] + iHisto[i] +iHisto[i+1])/3;), but we’ve seen before that double [] tHisto = iHisto;. So the result is in fact put directly into the original array. When doing a smoothing, the result has to be stored into a separated array.

I think that a bug and it comes from a misunderstanding of the MatLab code. I guess that MatLab duplicates the code when doing an affectation like in the first line.

Am I wrong?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@FiReTiTi I remember it now, @imagejan mentioned it recently: Open a pull request. https://help.github.com/articles/creating-a-pull-request/ Go to the Pull request tab and create a new one.