graythresh dosn't work with variables other than uint8?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Say I have a matrix B (some image):
B=[1 2 3 ;5 6 7 ; 10 11 12;14 56 45];
if the B is defined as uint8, graythresh returns a level:
level=graythresh(B)
ans =
0.1137
But, if B is defined as a uint16 or double (which the documentation says it supports), it returns 0.
B= uint16(B)
B =
4×3 uint16 matrix
1 2 3
5 6 7
10 11 12
14 56 45
level=graythresh(B)
level =
0
What is going on? Thank you.
0 commentaires
Réponse acceptée
DGM
le 8 Oct 2024
Like many tools in IPT, graythresh() depends on the class of the image array to know what its scale is. When you change classes, the data must be correctly scaled. Unless you know the difference, don't use uint16() or double() to change image class. Use im2uint16() or im2double().
% a properly-scaled uint8 image
A = uint8([1 2 3 ; 5 6 7; 10 11 12; 14 56 45])
% the threshold in unit-scale
graythresh(A)
Do the same thing in uint16. The result is the same.
% a properly-scaled uint16 image
B = im2uint16(A)
% the threshold in unit-scale
graythresh(B)
Casting without scaling means this image data is essentially black. The brightest pixel in this image is darker than 1LSB in uint8. Internally, the image is quantized to 256 levels for histogram generation. Since the entire image lies in the very bottom of the lowest bin, there's no histogram to split.
% a improperly-scaled uint16 image
% this is uint8-scale data in a uint16 container
B = uint16(A)
% so it gets interpreted completely wrong
graythresh(B)
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!