Daniel Osuto
Daniel Osuto

Reputation: 35

Computing a global threshold using Otsu's method for a ROI in an image in MATLAB

Suppose I have obtained a ROI using roipoly in an image. Is there a way that one can compute a global threshold using Otsu's method for that area only? If one uses the graythresh(I) function, all pixels including those outside the ROI are taken into account in the computation of the threshold. Is there a way that can only make use of the pixels in the ROI?

Upvotes: 1

Views: 331

Answers (1)

buzjwa
buzjwa

Reputation: 2652

This should work if you simply give the list of relevant pixels to graythresh. If you look at the code:

edit graythresh

You will see that the image I is immediately flattened (line 44 in R2013b):

I = im2uint8(I(:));

This means that graythresh can work with a vector of pixel values just as with an image, so doing

level = graythresh(I(mask));

should work just fine.

Upvotes: 1

Related Questions