Skip to content

ENH: try_all to choose the best threshold algorithm and DOC refactoring - #2110

Merged
soupault merged 19 commits into
scikit-image:masterfrom
sciunto:mosaic
Jun 19, 2016
Merged

soupault merged 19 commits into
scikit-image:masterfrom
sciunto:mosaic

Conversation

@sciunto

@sciunto sciunto commented May 25, 2016 •

Copy link
Copy Markdown
Member

Description

For a while, I wanted a feature similar to imagej, called try_all. As a user, it's convenient to visualize the effect of different thresholding algorithms to find the best one.

Here is an example (updated):

img = data.page()
fig, ax = mosaic_threshold(img, radius=10, figsize=(10,8))
fig
skimage.filters.thresholding.threshold_isodata
skimage.filters.thresholding.threshold_otsu
skimage.filters.thresholding.threshold_li
skimage.filters.thresholding.threshold_yen
skimage.filters.thresholding.threshold_adaptive
skimage.filters.rank.generic.otsu

sphx_glr_plot_thresholding_0011

I open this to start discussions.

Checklist

  • implementation python 3
  • compatibility with python 2.7 (or we kick away py2.7 :) )
  • Use it to illustrate our examples in the gallery (edit doc/examples/segmentation/plot_otsu.py).
  • Gallery
  • Make a longer example to gather the different algorithms and avoid to multiply similar examples in the gallery
  • Wait for ENH: implement mean and triangle thresholding #2126 to be merged.
  • Mean and triangle thresholding algorithms have to be covered (@soupault).
  • Proofread the doc

@sciunto sciunto changed the title ENH: add mosaic ENH: mosaic to choose the best threshold algorithm May 25, 2016
Comment thread skimage/filters/thresholding.py Outdated


def mosaic_global_threshold(image, figsize=None):
"""Returns a figure with images generated from different methods.

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.

Returns a figure comparing the outputs of different thresholding methods?

@emmanuelle

Copy link
Copy Markdown
Member

This is really cool! How about printing the names of the different skimage functions to use?

Also, would it be possible to include adaptive thresholding in the default mosaic, with one or two values of the block size? I don't know if automatic methods exist to compute the best block size (which should be larger than the objects of interest but smaller than the global intensity gradient).

@sciunto

sciunto commented May 28, 2016

Copy link
Copy Markdown
Member Author

I'm glad you appreciate it @emmanuelle. :)

I can try to print the full name of the functions, I'm just a bit concerned by the length.

For the adaptive threshold, I think it's a good idea. We can transform the code in my first post into a function. It could also includes a rank filter. As you said, my only concern is about the parameters.
I'm still playing with this code (2nd version right now).

My last thoughts are:

  • a generic function to plot a mosaic (_mosaic or mosaic). This might be useful also for something totally different.
  • a function considering only global algorithms.
  • a function including local algorithms.

@emmanuelle

Copy link
Copy Markdown
Member

About printing the name, I was thinking of printing in the Python shell, not about the titles of subfigures.

@sciunto

sciunto commented May 28, 2016

Copy link
Copy Markdown
Member Author

@emmanuelle Done. Now, the output for the second example is:

skimage.filters.thresholding.threshold_isodata
skimage.filters.thresholding.threshold_otsu
skimage.filters.thresholding.threshold_li
skimage.filters.thresholding.threshold_yen
skimage.filters.thresholding.threshold_adaptive
skimage.filters.rank.generic.otsu

@emmanuelle

Copy link
Copy Markdown
Member

Thanks for the changes! A radius of 10 is maybe too small for an optimal thresholding with local methods, otherwise, LGTM.

@sciunto

sciunto commented May 29, 2016 •

Copy link
Copy Markdown
Member Author

I switched to 20 for the example. Now, only the example uses this value. After I wrote the second function, I realized I could write only one and set the radius to None by default. If it's None, then, only histogram-based algorithms are called.

I also started to illustrate this feature in the gallery. I'm also planning to refactor/merge some other examples to make something more comprehensive on thresholding.

@jni

jni commented May 30, 2016

Copy link
Copy Markdown
Member

This is super cool. Thanks @sciunto! Are you done with the implementation?

@soupault

Copy link
Copy Markdown
Member

@sciunto nice feature!
If you're going to generalize _mosaic function, you should think about output variable selection. For example, some segmentation algorithms in skimage return tuple of 2 instead of a single variable with image.
The second point, I'd like to discuss more is the naming. As for me, try_all is much clearer than mosaic. As far as this functionality is meant to be much appreciated by the new users, the function name (in my opinion) has to be self-telling and very catchy.

@sciunto

sciunto commented Jun 1, 2016

Copy link
Copy Markdown
Member Author

@jni I think I'm good with that one. I made few corrections to myself.

@soupault I changed the name. I'm +1 with your argument. For the api for _try_all, we can think about it later. I would like to focus on thresholding first. I have another PR to submit ;)

@sciunto

sciunto commented Jun 5, 2016

Copy link
Copy Markdown
Member Author

I made some work on the gallery.

@codecov-io

codecov-io commented Jun 10, 2016 •

Copy link
Copy Markdown

Current coverage is 90.58%

Merging #2110 into master will increase coverage by <.01%

@@             master      #2110   diff @@
==========================================
  Files           297        297          
  Lines         21291      21340    +49   
  Methods           0          0          
  Messages          0          0          
  Branches       1959       1963     +4   
==========================================
+ Hits          19285      19331    +46   
- Misses         1656       1657     +1   
- Partials        350        352     +2   

Powered by Codecov. Last updated by eb3be49...9fef985

@sciunto

sciunto commented Jun 10, 2016

Copy link
Copy Markdown
Member Author

mean and triangle are integrated. I updated the syntax for sphinx-gallery.


Thresholding is used to create a binary image from a grayscale image [1]_.
If you are not familiar with the details of the different algorithms and the
underlying assumptions, it is often to know which algorithm will give the best

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.

often ... to know?

@soupault

Copy link
Copy Markdown
Member

I like it the way it is. Unless we are going to present slightly different use case, I see no need to duplicate the examples.





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.

That's a lot of blank lines.

@sciunto

sciunto commented Jun 18, 2016

Copy link
Copy Markdown
Member Author

Thanks for your comments :) I'll push tomorrow.

@sciunto

sciunto commented Jun 19, 2016

Copy link
Copy Markdown
Member Author

I realized my imports were sloppy. I fixed that.

@sciunto

sciunto commented Jun 19, 2016

Copy link
Copy Markdown
Member Author

@soupault @emmanuelle Fixed.

@emmanuelle

Copy link
Copy Markdown
Member

Thanks! 👍 for merging

@soupault

Copy link
Copy Markdown
Member

@sciunto could you squash the commits, please?

@@ -1,10 +1,15 @@
import math

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.

Not clear why you need this import. There is numpy already.

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.

math is faster than numpy for scalars, it's therefore good practice to use it.

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.

In [2]: %timeit a = math.sqrt(100.)
The slowest run took 59.41 times longer than the fastest. This could mean that an intermediate result is being cached 
10000000 loops, best of 3: 68.2 ns per loop

In [3]: %timeit a = np.sqrt(100.)
The slowest run took 27.52 times longer than the fastest. This could mean that an intermediate result is being cached 
1000000 loops, best of 3: 511 ns per loop

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.

OK, doesn't make a huge difference, but say you have a function that's going to be called zillions of times, then you should really use math instead of numpy.

@sciunto

sciunto commented Jun 19, 2016

Copy link
Copy Markdown
Member Author

I squashed the last ones. I kept the others to keep the granularity. There is a lot of addition/deletion ;)

@soupault

Copy link
Copy Markdown
Member

Thanks @sciunto!

@soupault
soupault merged commit 030e623 into scikit-image:master Jun 19, 2016
@emmanuelle

Copy link
Copy Markdown
Member

Yeehaa !

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants