Thresholding of a color image (Three-channels RGB)

h.benoudjit at gmail.com h.benoudjit at gmail.com
Wed Sep 9 09:22:30 EDT 2015


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 <javascript:> 
> 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. 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20150909/5e23c9e7/attachment.html>


More information about the scikit-image mailing list