uint8 vs int8 in imshow
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dani D
el 12 de Mzo. de 2016
Hello, What is difference between these? When i use int8 , the most of pixel been 127 and when i use uint8 the problem is solve.
I=imread('cameraman.tif');
I = uint8(I);
imshow(I);
I=imread('cameraman.tif');
I = int8(I);
imshow(I);
0 comentarios
Respuesta aceptada
Walter Roberson
el 12 de Mzo. de 2016
When you give int8() a value that is greater than 127, then it "saturates" and returns 127. A lot of your input values are greater than 127 so they are "saturating" at 127.
The same kind of thing happens for uint8 if you give it a value greater than 255: it saturates at 255.
0 comentarios
Más respuestas (1)
DGM
el 27 de Nov. de 2023
Editada: DGM
el 12 de Jun. de 2024
Imshow() is odd in that it does actually support int8 images. It seems most other IPT tools which are class-sensitive don't. As usual though, the image needs to be properly-scaled for its class in order to display as expected.
The data needs to be rescaled as appropriate when casting in order for the image to be treated as intended. As Walter explained, simply casting a uint8() array using int8() will simply result in truncation without otherwise scaling or shifting the data. Consider the case with uint16 -> int16 conversion:
inpict = imread('cameraman16.png'); % uint16
A = int16(inpict); % half the data is truncated
imshow(A,'border','tight')
B = im2int16(inpict); % rescaled/offset as needed
imshow(B,'border','tight')
Why did I do this example with uint16/int16 instead of uint8/int8? Well remember that I said int8 support is an oddity in IPT? Yeah. There is no such im2int8() tool like there is for 16 bit images. You would either have to do it yourself:
inpict = imread('cameraman16.png'); % uint8 (could be any other class)
ir = getrangefromclass(inpict);
or = [-128 127];
scalefactor = diff(or)/diff(ir);
C = int8(round((double(inpict) - ir(1))*scalefactor) + or(1)); % int8
imshow(C,'border','tight')
... but there's no need to reinvent that wheel every time. MIMT imcast() supports int8, and it offers other practical conveniences.
% supports
% uint8,uint16,uint32,uint64,
% int8,int16,int32,int64,
% double,single,logical
outpict = imcast(inpict,'int8');
Either way, a workflow centered around int8 working images is going to be a huge hassle with no obvious benefit.
0 comentarios
Ver también
Categorías
Más información sobre Get Started with Image Processing Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!