Thresholding a dark region in an image

32 views
Skip to first unread message

Nabil Freij

unread,
May 19, 2016, 10:26:36 AM5/19/16
to scikit...@googlegroups.com
Hello,

I have been investigating how to threshold a structure in my images. More specifically, a sunspot, that can be seen in Figure 1. The aim has been to isolate and measure the number of pixels that are part of the central part of a sunspot, which is the darkest region of the structure. 

The method I have been using is to define a region which contains no features that are similar to a sunspot. The size of this region is not fixed but I generally make it as large as the data allows. This region is at the bottom black box in Figure 1 (ignore the slider). The mean and standard deviation of this region is calculated, which allows me to define a threshold limit, which is subtracting the standard deviation multiplied by a user defined constant from the mean. The constant is chosen so that overall, the threshold is selecting the pixels we know that are part of the central region. But this value varies depending the structure and the data source. 

Another method I have discussed or looked into are related to Figure 2. On the left is a cropped field of view of the sunspot and on the right is a histogram of this image in red and in yellow is the histogram of the background box from Figure 1. By using the histogram, I can work out the numerical gradient and pick the points with the largest shift. I also tried this method on the original image by taking slices along the sunspot, however, due to the non-uniform nature of a sunspot the results were not very good.

I was wondering if there were any suggestions to threshold this region that is not as ad hoc as my method?

Thanks,
Nabil
figure_1.png
figure_2.png

Juan Nunez-Iglesias

unread,
May 22, 2016, 11:34:14 PM5/22/16
to scikit...@googlegroups.com
Hi Nabil,

Have you looked at the skimage.filters.threshold_* functions? I would start by looking at the results from each of those on a few example sunspots to see whether one reliably gives you a reasonable result.

Juan.
--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com.
To post to this group, send email to scikit...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/CADwJ0z1Sthz7OW8uu2G2i%2Bm9VaKPOEfnkuu%2BV70u-0Tjz75PMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

François Boulogne

unread,
May 25, 2016, 5:11:34 PM5/25/16
to scikit...@googlegroups.com
Hi,

I'm actually working to add threshold algorithms to scikit-image.

We are almost ready to merge the minimum algorithm (see
https://github.com/scikit-image/scikit-image/pull/2104), Jeff made the
implementation.

I believe the histogram could be fruitful in your case and I think that
you can study how this algorithm works and generalize it for 3 peaks in
the histogram. Then, you will get two minima where you can threshold.

Let us know if it works or not. You can probably cut your histogram "by
hand" at one minimum to check if the result looks good or not.

--
François Boulogne.
http://www.sciunto.org
GPG: 32D5F22F


Nabil Freij

unread,
Jun 16, 2016, 6:46:15 AM6/16/16
to scikit...@googlegroups.com
Hi Juan and François,

Thanks for those suggestions. So from my understanding, threshold_isodata, threshold_li, threshold_otsu and threshold_yen return values that allow me to threshold an image. Using these on the whole image returns a threshold value which return a value which does a good job of getting the entire sunspot. Which can be seen in Figure 1. Varying the bin size, where possible, changes very little. So I decided to use them on a smaller image that shows just the sunspot and the results are very good as you can see in Figure 2. I will carry on trying the various routines to see what the results are. 

I used the minimum algorithm when it was merged into scikit master and I have found it to be the most useful in my cases so far. But my current results are very rough.  

Thanks for all the help!
Nabil

figure_1.png
figure_2.png

François Boulogne

unread,
Jun 17, 2016, 2:50:23 AM6/17/16
to scikit...@googlegroups.com
Le 16/06/2016 à 12:45, Nabil Freij a écrit :
> Hi Juan and François,
>
> Thanks for those suggestions. So from my
> understanding, threshold_isodata, threshold_li, threshold_otsu and
> threshold_yen return values that allow me to threshold an image. Using
> these on the whole image returns a threshold value which return a
> value which does a good job of getting the entire sunspot. Which can
> be seen in Figure 1. Varying the bin size, where possible, changes
> very little. So I decided to use them on a smaller image that shows
> just the sunspot and the results are very good as you can see in
> Figure 2. I will carry on trying the various routines to see what the
> results are.
>
> I used the minimum algorithm when it was merged into scikit master and
> I have found it to be the most useful in my cases so far. But my
> current results are very rough.
>

You can give a try to multiotsu.
https://github.com/scikit-image/scikit-image/pull/2076
It's not merged yet, there is a missing import (from skimage.util import
img_as_float). For the rest, it should be good enough for a quick test. :)

Feel free to comment on this one.
Reply all
Reply to author
Forward
0 new messages