Skip to content

Adding threshold_bradley.#3877

Closed
alexdesiqueira wants to merge 1 commit intoscikit-image:masterfrom
alexdesiqueira:thresh_bradley
Closed

Adding threshold_bradley.#3877
alexdesiqueira wants to merge 1 commit intoscikit-image:masterfrom
alexdesiqueira:thresh_bradley

Conversation

@alexdesiqueira
Copy link
Copy Markdown
Member

Description

Revisiting #919.

Checklist

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks
Copy link
Copy Markdown

Hello @alexandrejaguar! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 1063:80: E501 line too long (81 > 79 characters)

@alexdesiqueira alexdesiqueira changed the title Addind threshold_bradley. Adding threshold_bradley. Apr 30, 2019
@alexdesiqueira
Copy link
Copy Markdown
Member Author

Hi everyone,
first of all, thanks @mailjenil for all your work and code!
The main issue with this function is that it does not follow our API: it returns an image instead of a threshold value. Any ideas on how to adapt that, @jni @hmaarrfk and the others? Thanks!

# checking condition for Bradley threshold
image = image * block_size ** 2
thresh_image = image - int_image * (100 - bright_perc) / 100
thresh_image = thresh_image > 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexandrejaguar a bit of rearrangement shows that the resulting threshold image should be integral_image * (1 - q), where q is a quantile:

result = (image - integral_image * (1 - q) > 0)
result = (image > integral_image * (1 - q))

The lower form is the format we want for applying a threshold, ie normally we would say image > t for some threshold t.

However, rearranging also shows that this is equivalent to niblack thresholding with k=0, so I'm not sure this addition needs to happen. Maybe a note on that function is sufficient. Otherwise, the implementation should just call that function, since it is n-dimensional rather than 2D only.

@scikit-image/core any thoughts on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note also that the implementation above has a mistake: the integral image needs to be divided by the window size, otherwise we are looking at the sum of the surrounding window, not the mean as the docstring suggests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jni, @stefanv and I were discussing if this should be implemented. Based on your first comment, maybe it shouldn't. +1 on the note on niblack thresholding.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better of we don't have to. Perhaps add a line to niblack stating the equivalence?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I spoke too quickly: the q/bright_perc muddles things up. It's actually equivalent to Niblack times (1-q).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem on putting that on niblack's notes, and maybe an example on the docs. Is it okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

@alexdesiqueira
Copy link
Copy Markdown
Member Author

Closing this as it feels redundant (a particular case of threshold_niblack; see [1]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants