Thresholding of a color image (Three-channels RGB)

Emmanuelle Gouillart emmanuelle.gouillart at nsup.org
Wed Sep 9 09:53:49 EDT 2015


The image you link to is almost grayscale already, meaning that the three
channels have comparable values. With an image where one of the channels
is dominant (like the coffee image of our data module), I think the
results would be very different.

Nice image by the way! Out of curiosity, what is your application?

Emma

On Wed, Sep 09, 2015 at 06:22:30AM -0700, h.benoudjit at gmail.com wrote:
> Hi,

> Thanks for your reponse.
> You're right, the image needs to be converted to gray scale (single channel)
> before being given as input to threshold_otsu.
> Indeed, in the present case, the threshold is computed for the flatten 1D array
> of all three channels, inside the otsu_threshold function.

> However, I'm getting better results with the previous code than with the
> thresholding of the gray scale image for this image: http://www.e-geos.it/
> gallery/featured/flooding_veneto/
> CSKS1_SCS_B_HI_08_HH_RD_SF_20101103172214_20101103172222_orto_hh_slc_geo_subset.jpg.
> Maybe, it's because the threshold is computed from the accumulated intensities
> of all the channels.

>  Maybe I could obtain similar results if I perform the otsu thresholding on all
> three channels and try to stack them (OR operator).

> Le mercredi 9 septembre 2015 13:41:14 UTC+1, Emmanuelle Gouillart a écrit :

>     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.ben... 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