pascal_ghost
pascal_ghost

Reputation: 1

Global image threshold in Matlab

When you use graythresh in Matlab it obtains a value that is a normalized between 0 to 1, so when you use a threshold for something else such as imextendedmax or im2bw how would you use graythresh? I guess you have to probably multiply it by something but what?

Upvotes: 0

Views: 5350

Answers (2)

Jonas
Jonas

Reputation: 74940

You need to normalize your image to [0...1] in order to use graythresh.

%# test image
img = randn(512);
img(200:end,100:end) = img(200:end,100:end) + 5;

%# normalize. Subtract minimum to make lowest intensity equal to 0, then divide by the maximum
offset = min(img(:));
img = img - offset;
mult = max(img(:));
img = img./mult;

%# apply graythresh
th = graythresh(img);

%# if you want to know the threshold relative to the original intensities, use mult and offset like this
oriThresh = th*mult+offset;

Upvotes: 1

Dima
Dima

Reputation: 39419

Either normalize your image to range between 0 and 1, or multiply the threshold by the maximum possible value of the image.

Upvotes: 0

Related Questions