Otsu method (graythresh function in matlab) gives scaled result, at what scale? 0: 255, 0: max (intensity px), min: max.

Just clarifying the question of Otsu's threshold method, which has no definition in the docs and wikipedia articles. If you use Otsu's method (a function in matlab graythresh

), it returns a threshold value between 0 and 1.

Given two hypothetical grayscale images:

  • dark

    (with pixel intensities ranging from 0 to 100) and
  • light

    (with pixel intensities ranging from 155 to 255)

If I have an Otsu threshold of 0.75 for images dark

and thus light

what grayscale brightness will be displayed in each case?

  • dark -> 75

    and light -> 231

    for example. relative to the range of values ​​in each image
  • dark -> 75

    and light -> 191

    for example. relative to the range from 0 to maximum pixel value
  • dark -> 191

    and light -> 191

    for example. relative to the full range of grayscale pixel values ​​(0-255)?
+3


source to share


4 answers


The correct answer is the first one:

dark = 75 and light = 230, relative to the range of values ​​in each image



graythresh

uses the minimum and maximum values ​​in the image as boundaries, which is the most logical behavior.

0


source


The accepted answer by @Ratbert makes incorrect statements that

The correct answer is the first

and

graythresh

uses the min and max values ​​in the image as boundaries, which is the most logical behavior.

and Rayryeng seems to agree with this. David Parks seems to have empirically confirmed this.

The correct answer is given by Anand, who, oddly enough, has a negative vote. He explains very convincingly that

full range of grayscale pixel values ​​depends on the type input image



As he explains,

this is the third option

except that the image dark

cannot get a threshold of 0.75.

First, let's clarify the difference between the claims for the simplest case, in clear MATLAB, so there is no confusion. For an image with values ​​from min

to max

, the question presents three possibilities, which when translated into an equation:

  • threshold = min + (max-min) * graythresh

  • threshold = max * graythresh

  • threshold = 255 * graythresh

Suppose the image consists of two points with an intensity of 0 and the other with 100. That means dark = uint8([0 100]);

. Second image light = dark+155;

. When we calculate 255*graythresh(dark)

, we get exactly 49.5

. When we calculate 255*graythresh(light)

, we get exactly 204.5

. These answers clearly indicate that the third option is the only option.

There is one more subtle point. If you try 255*graythresh(uint8(1:2))

, the answer is 1

, not 1.5

. So it seems that if you are using an greythresh

image for the threshold, you should use image <= 255*graythesh(image)

less than or equal, not equal less.

+2


source


Your third answer seems to me the most correct, with the clarification that the "full range of grayscale pixel values" depends on the data type of the input image. For example, for a uint8 image, the Otsu threshold of 0.75 corresponds to approximately 191. For a uint16 image, this would correspond to 49151.

+1


source


Ok, for posterity, I've made a comparison of the approaches mentioned above. I took a typical image with the full range of brightness in shades of gray, and then took the version dark

, and light

the same image, and received a value graythresh

for each. I have applied Otsu Threshold using each of the above mappings.

The light image demonstrates quite clearly that the algorithm creates a threshold in a range of pixel intensities. If we were to assume the full range of pixel intensities, Otsu's algorithm would create a threshold below whatever is present in the image, which doesn't make much sense, at least assuming the existing black background is transparent / inactive.

I'm guessing someone can make an argument to assume the full range of pixel intensities if you assume that the existing black portion of the image matches darkness. I would certainly welcome comments there.

Full size images below

Comparison of grayscale intensity obtained from OTSU threshold


Making changes to my words above: When I blacken everything except the top half of the image light

and get the Otsu threshold again, I get the same 0.3020 threshold. If the dark parts of the image related to Otsu's threshold were created, the extra darkness would affect the value, so Ratbert's answer is empirically demonstrated to be correct.

Further test

+1


source







All Articles