Thresholding of a color image (Three-channels RGB)

Emmanuelle Gouillart emmanuelle.gouillart at nsup.org
Wed Sep 9 08:41:13 EDT 2015


Hi,

thanks for your question.

The first line of the threshold_otsu function is
hist, bin_centers = histogram(image.ravel(), nbins)
meaning that all channels are combined together with ravel (in other
words, the algorithm behaves as if the color image were a 3-D image).

I think that this is a bug and that the function should behave in a
different way.

An option for you is to convert the image to grayscale before using
threshold_otsu

Cheers,
Emmanuelle

On Wed, Sep 09, 2015 at 05:15:03AM -0700, h.benoudjit at gmail.com wrote:
> Hi,

> I have a very basic question about thresholding in Scikit-image (or maybe it's
> actually a numpy question).
> I'm performing a simple otsu thresholding on an image, that I've read
> previously:


> img = io.imread('flood.jpg')
> print img.shape

> # otsu thresholding of the image
> cell2 = fig.add_subplot(1, 2, 2)
> threshold = threshold_otsu(img)
> thresholded_img = img > threshold

> Everything is working, however I've a question concerning the thresholding on a
> multi-dimensional of the image read.
> I noticed that image has been loaded as three-channels RGB; How is the
> thresholded RGB image drawn on the screen?

> Knowing that the thresholded_img object is a boolean numpy array still having
> three dimensions (the three color axes). I mean, if it had only one channel, it
> would be easy True=255 and False=0; but in the case of a 3-channels image, is a
> logical-AND performed on the RGB-image to flatten it to a single-channel image?

> Thanks.



More information about the scikit-image mailing list